From a192e4c872ac894d37a2670686c0d3b2398a81d8 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Fri, 3 Sep 2021 13:54:28 -0700 Subject: [PATCH] Allow showing the enemy aircraft inventory. --- changelog.md | 1 + qt_ui/windows/AirWingDialog.py | 45 ++++++++++++++++++++++++---------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/changelog.md b/changelog.md index 5f37d371..d563e9d6 100644 --- a/changelog.md +++ b/changelog.md @@ -22,6 +22,7 @@ Saves from 4.x are not compatible with 5.0. * **[Kneeboard]** QNH (pressure MSL) and temperature have been added to the kneeboard. * **[New Game Wizard]** Can now customize the player's air wing before campaign start to disable, relocate, or rename squadrons. * **[UI]** Sell Button for aircraft will be disabled if there are no units available to be sold or all are already assigned to a mission +* **[UI]** Enemy aircraft inventory now viewable in the air wing menu. ## Fixes diff --git a/qt_ui/windows/AirWingDialog.py b/qt_ui/windows/AirWingDialog.py index b90e826b..6f5ac38a 100644 --- a/qt_ui/windows/AirWingDialog.py +++ b/qt_ui/windows/AirWingDialog.py @@ -14,6 +14,7 @@ from PySide2.QtWidgets import ( QTableWidget, QTableWidgetItem, QWidget, + QHBoxLayout, ) from game.squadrons import Squadron @@ -149,30 +150,47 @@ class AircraftInventoryData: class AirInventoryView(QWidget): def __init__(self, game_model: GameModel) -> None: super().__init__() - self.game_model = game_model - self.country = self.game_model.game.country_for(player=True) + + self.only_unallocated = False + self.enemy_info = False layout = QVBoxLayout() self.setLayout(layout) - self.only_unallocated_cb = QCheckBox("Unallocated Only?") - self.only_unallocated_cb.toggled.connect(self.update_table) + checkbox_row = QHBoxLayout() + layout.addLayout(checkbox_row) - layout.addWidget(self.only_unallocated_cb) + self.only_unallocated_cb = QCheckBox("Unallocated only") + self.only_unallocated_cb.toggled.connect(self.set_only_unallocated) + checkbox_row.addWidget(self.only_unallocated_cb) + + self.enemy_info_cb = QCheckBox("Show enemy info") + self.enemy_info_cb.toggled.connect(self.set_enemy_info) + checkbox_row.addWidget(self.enemy_info_cb) + + checkbox_row.addStretch() self.table = QTableWidget() layout.addWidget(self.table) self.table.setEditTriggers(QAbstractItemView.NoEditTriggers) self.table.verticalHeader().setVisible(False) - self.update_table(False) + self.set_only_unallocated(False) - def update_table(self, only_unallocated: bool) -> None: + def set_only_unallocated(self, value: bool) -> None: + self.only_unallocated = value + self.update_table() + + def set_enemy_info(self, value: bool) -> None: + self.enemy_info = value + self.update_table() + + def update_table(self) -> None: self.table.setSortingEnabled(False) self.table.clear() - inventory_rows = list(self.get_data(only_unallocated)) + inventory_rows = list(self.get_data()) self.table.setRowCount(len(inventory_rows)) headers = AircraftInventoryData.headers() self.table.setColumnCount(len(headers)) @@ -186,18 +204,19 @@ class AirInventoryView(QWidget): self.table.setSortingEnabled(True) def iter_allocated_aircraft(self) -> Iterator[AircraftInventoryData]: - for package in self.game_model.game.blue.ato.packages: + coalition = self.game_model.game.coalition_for(not self.enemy_info) + for package in coalition.ato.packages: for flight in package.flights: yield from AircraftInventoryData.from_flight(flight) def iter_unallocated_aircraft(self) -> Iterator[AircraftInventoryData]: - game = self.game_model.game - for squadron in game.blue.air_wing.iter_squadrons(): + coalition = self.game_model.game.coalition_for(not self.enemy_info) + for squadron in coalition.air_wing.iter_squadrons(): yield from AircraftInventoryData.each_untasked_from_squadron(squadron) - def get_data(self, only_unallocated: bool) -> Iterator[AircraftInventoryData]: + def get_data(self) -> Iterator[AircraftInventoryData]: yield from self.iter_unallocated_aircraft() - if not only_unallocated: + if not self.only_unallocated: yield from self.iter_allocated_aircraft()