mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
This is an attempt to remove a lot of our supposedly unnecessary error handling. Every aircraft should have a price, a description, a name, etc; and none of those should require carrying around the faction's country as context. This moves all the data for aircraft into yaml files (only one converted here as an example). Most of the "extended unit info" isn't actually being read yet. To replace the renaming of units based on the county, we instead generate multiple types of each unit when necessary. The CF-18 is just as much a first-class type as the F/A-18 is. This doesn't work in its current state because it does break all the existing names for aircraft that are used in the faction and squadron files, and we no longer let those errors go as a warning. It will be an annoying one time switch, but it allows us to define the names that get used in these files instead of being sensitive to changes as they happen in pydcs, and allows faction designers to specifically choose, for example, the Su-22 instead of the Su-17. One thing not handled by this is aircraft task capability. This is because the lists in ai_flight_planner_db.py are a priority list, and to move it out to a yaml file we'd need to assign a weight to it that would be used to stack rank each aircraft. That's doable, but it makes it much more difficult to see the ordering of aircraft at a glance, and much more annoying to move aircraft around in the priority list. I don't think this is worth doing, and the priority lists will remain in their own separate lists. This includes the converted I used to convert all the old unit info and factions to the new format. This doesn't need to live long, but we may want to reuse it in the future so we want it in the version history.
179 lines
5.1 KiB
Python
179 lines
5.1 KiB
Python
import itertools
|
|
|
|
from PySide2.QtWidgets import (
|
|
QCheckBox,
|
|
QDialog,
|
|
QFrame,
|
|
QGridLayout,
|
|
QLabel,
|
|
QLayout,
|
|
QScrollArea,
|
|
QSizePolicy,
|
|
QSpacerItem,
|
|
QTabWidget,
|
|
QVBoxLayout,
|
|
QWidget,
|
|
)
|
|
|
|
from game.game import Game, db
|
|
from qt_ui.uiconstants import ICONS
|
|
from qt_ui.windows.finances.QFinancesMenu import FinancesLayout
|
|
|
|
|
|
class ScrollingFrame(QFrame):
|
|
def __init__(self) -> None:
|
|
super().__init__()
|
|
|
|
widget = QWidget()
|
|
scroll_area = QScrollArea()
|
|
scroll_area.setWidgetResizable(True)
|
|
scroll_area.setWidget(widget)
|
|
|
|
self.scrolling_layout = QVBoxLayout()
|
|
widget.setLayout(self.scrolling_layout)
|
|
|
|
self.setLayout(QVBoxLayout())
|
|
self.layout().addWidget(scroll_area)
|
|
|
|
def addWidget(self, widget: QWidget, *args, **kwargs) -> None:
|
|
self.scrolling_layout.addWidget(widget, *args, **kwargs)
|
|
|
|
def addLayout(self, layout: QLayout, *args, **kwargs) -> None:
|
|
self.scrolling_layout.addLayout(layout, *args, **kwargs)
|
|
|
|
|
|
class EconomyIntelTab(ScrollingFrame):
|
|
def __init__(self, game: Game, player: bool) -> None:
|
|
super().__init__()
|
|
self.addLayout(FinancesLayout(game, player=player))
|
|
|
|
|
|
class IntelTableLayout(QGridLayout):
|
|
def __init__(self) -> None:
|
|
super().__init__()
|
|
self.row = itertools.count(0)
|
|
|
|
def add_header(self, text: str) -> None:
|
|
self.addWidget(QLabel(f"<b>{text}</b>"), next(self.row), 0)
|
|
|
|
def add_spacer(self) -> None:
|
|
self.addItem(
|
|
QSpacerItem(0, 0, QSizePolicy.Preferred, QSizePolicy.Expanding),
|
|
next(self.row),
|
|
0,
|
|
)
|
|
|
|
def add_row(self, text: str, count: int) -> None:
|
|
row = next(self.row)
|
|
self.addWidget(QLabel(text), row, 0)
|
|
self.addWidget(QLabel(str(count)), row, 1)
|
|
|
|
|
|
class AircraftIntelLayout(IntelTableLayout):
|
|
def __init__(self, game: Game, player: bool) -> None:
|
|
super().__init__()
|
|
|
|
total = 0
|
|
for control_point in game.theater.control_points_for(player):
|
|
base = control_point.base
|
|
total += base.total_aircraft
|
|
if not base.total_aircraft:
|
|
continue
|
|
|
|
self.add_header(control_point.name)
|
|
for airframe, count in base.aircraft.items():
|
|
if not count:
|
|
continue
|
|
self.add_row(airframe.name, count)
|
|
|
|
self.add_spacer()
|
|
self.add_row("<b>Total</b>", total)
|
|
|
|
|
|
class AircraftIntelTab(ScrollingFrame):
|
|
def __init__(self, game: Game, player: bool) -> None:
|
|
super().__init__()
|
|
self.addLayout(AircraftIntelLayout(game, player=player))
|
|
|
|
|
|
class ArmyIntelLayout(IntelTableLayout):
|
|
def __init__(self, game: Game, player: bool) -> None:
|
|
super().__init__()
|
|
|
|
total = 0
|
|
for control_point in game.theater.control_points_for(player):
|
|
base = control_point.base
|
|
total += base.total_armor
|
|
if not base.total_armor:
|
|
continue
|
|
|
|
self.add_header(control_point.name)
|
|
for vehicle, count in base.armor.items():
|
|
if not count:
|
|
continue
|
|
self.add_row(vehicle.id, count)
|
|
|
|
self.add_spacer()
|
|
self.add_row("<b>Total</b>", total)
|
|
|
|
|
|
class ArmyIntelTab(ScrollingFrame):
|
|
def __init__(self, game: Game, player: bool) -> None:
|
|
super().__init__()
|
|
self.addLayout(ArmyIntelLayout(game, player=player))
|
|
|
|
|
|
class IntelTabs(QTabWidget):
|
|
def __init__(self, game: Game, player: bool):
|
|
super().__init__()
|
|
|
|
self.addTab(EconomyIntelTab(game, player), "Economy")
|
|
self.addTab(AircraftIntelTab(game, player), "Air forces")
|
|
self.addTab(ArmyIntelTab(game, player), "Ground forces")
|
|
|
|
|
|
class IntelWindow(QDialog):
|
|
def __init__(self, game: Game):
|
|
super().__init__()
|
|
|
|
self.game = game
|
|
self.player = True
|
|
self.setModal(True)
|
|
self.setWindowTitle("Intelligence")
|
|
self.setWindowIcon(ICONS["Statistics"])
|
|
self.setMinimumSize(600, 500)
|
|
self.selected_intel_tab = 0
|
|
|
|
layout = QVBoxLayout()
|
|
self.setLayout(layout)
|
|
self.refresh_layout()
|
|
|
|
def on_faction_changed(self) -> None:
|
|
self.player = not self.player
|
|
self.refresh_layout()
|
|
|
|
def refresh_layout(self) -> None:
|
|
|
|
# Clear the existing layout
|
|
if self.layout():
|
|
idx = 0
|
|
while child := self.layout().itemAt(idx):
|
|
self.layout().removeItem(child)
|
|
|
|
# Add the new layout
|
|
own_faction = QCheckBox("Enemy Info")
|
|
own_faction.setChecked(not self.player)
|
|
own_faction.stateChanged.connect(self.on_faction_changed)
|
|
|
|
intel_tabs = IntelTabs(self.game, self.player)
|
|
intel_tabs.currentChanged.connect(self.on_tab_changed)
|
|
|
|
if self.selected_intel_tab:
|
|
intel_tabs.setCurrentIndex(self.selected_intel_tab)
|
|
|
|
self.layout().addWidget(own_faction)
|
|
self.layout().addWidget(intel_tabs, stretch=1)
|
|
|
|
def on_tab_changed(self, idx: int) -> None:
|
|
self.selected_intel_tab = idx
|