diff --git a/game/squadrons/airwing.py b/game/squadrons/airwing.py index 105f3dd2..c674b617 100644 --- a/game/squadrons/airwing.py +++ b/game/squadrons/airwing.py @@ -76,12 +76,22 @@ class AirWing: return squadron return None - def available_aircraft_for_task(self, task: FlightType) -> Iterator[AircraftType]: + def best_available_aircrafts_for(self, task: FlightType) -> list[AircraftType]: + """Returns an ordered list of available aircrafts for the given task""" + aircrafts = [] + best_aircraft_for_task = aircraft_for_task(task) for aircraft, squadrons in self.squadrons.items(): for squadron in squadrons: if squadron.untasked_aircraft and task in squadron.mission_types: - yield aircraft + aircrafts.append(aircraft) + if aircraft not in best_aircraft_for_task: + best_aircraft_for_task.append(aircraft) break + # Sort the list ordered by the best capability + return sorted( + aircrafts, + key=lambda ac: best_aircraft_for_task.index(ac), + ) def auto_assignable_for_task(self, task: FlightType) -> Iterator[Squadron]: for squadron in self.iter_squadrons(): diff --git a/qt_ui/widgets/combos/QAircraftTypeSelector.py b/qt_ui/widgets/combos/QAircraftTypeSelector.py index 7c17db59..f64a55b0 100644 --- a/qt_ui/widgets/combos/QAircraftTypeSelector.py +++ b/qt_ui/widgets/combos/QAircraftTypeSelector.py @@ -1,5 +1,4 @@ """Combo box for selecting aircraft types.""" -from typing import Iterable from PySide2.QtWidgets import QComboBox from game.dcs.aircrafttype import AircraftType @@ -7,14 +6,14 @@ from game.dcs.aircrafttype import AircraftType class QAircraftTypeSelector(QComboBox): """Combo box for selecting among the given aircraft types.""" - def __init__(self, aircraft_types: Iterable[AircraftType]) -> None: + def __init__(self, aircraft_types: list[AircraftType]) -> None: super().__init__() self.model().sort(0) self.setSizeAdjustPolicy(self.AdjustToContents) self.update_items(aircraft_types) - def update_items(self, aircraft_types: Iterable[AircraftType]): + def update_items(self, aircraft_types: list[AircraftType]): current_aircraft = self.currentData() self.clear() for aircraft in aircraft_types: diff --git a/qt_ui/windows/mission/flight/QFlightCreator.py b/qt_ui/windows/mission/flight/QFlightCreator.py index d58af13b..fd1cdcc4 100644 --- a/qt_ui/windows/mission/flight/QFlightCreator.py +++ b/qt_ui/windows/mission/flight/QFlightCreator.py @@ -56,7 +56,7 @@ class QFlightCreator(QDialog): layout.addLayout(QLabeledWidget("Task:", self.task_selector)) self.aircraft_selector = QAircraftTypeSelector( - self.game.blue.air_wing.available_aircraft_for_task( + self.game.blue.air_wing.best_available_aircrafts_for( self.task_selector.currentData() ) ) @@ -217,7 +217,7 @@ class QFlightCreator(QDialog): def on_task_changed(self, index: int) -> None: task = self.task_selector.itemData(index) self.aircraft_selector.update_items( - self.game.blue.air_wing.available_aircraft_for_task(task) + self.game.blue.air_wing.best_available_aircrafts_for(task) ) self.squadron_selector.update_items(task, self.aircraft_selector.currentData())