Consider priority order in Aircraft selector

This commit is contained in:
RndName 2022-04-22 15:07:45 +02:00
parent 2836a89f91
commit 41d1ae099f
3 changed files with 16 additions and 7 deletions

View File

@ -76,12 +76,22 @@ class AirWing:
return squadron return squadron
return None 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 aircraft, squadrons in self.squadrons.items():
for squadron in squadrons: for squadron in squadrons:
if squadron.untasked_aircraft and task in squadron.mission_types: 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 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]: def auto_assignable_for_task(self, task: FlightType) -> Iterator[Squadron]:
for squadron in self.iter_squadrons(): for squadron in self.iter_squadrons():

View File

@ -1,5 +1,4 @@
"""Combo box for selecting aircraft types.""" """Combo box for selecting aircraft types."""
from typing import Iterable
from PySide2.QtWidgets import QComboBox from PySide2.QtWidgets import QComboBox
from game.dcs.aircrafttype import AircraftType from game.dcs.aircrafttype import AircraftType
@ -7,14 +6,14 @@ from game.dcs.aircrafttype import AircraftType
class QAircraftTypeSelector(QComboBox): class QAircraftTypeSelector(QComboBox):
"""Combo box for selecting among the given aircraft types.""" """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__() super().__init__()
self.model().sort(0) self.model().sort(0)
self.setSizeAdjustPolicy(self.AdjustToContents) self.setSizeAdjustPolicy(self.AdjustToContents)
self.update_items(aircraft_types) 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() current_aircraft = self.currentData()
self.clear() self.clear()
for aircraft in aircraft_types: for aircraft in aircraft_types:

View File

@ -56,7 +56,7 @@ class QFlightCreator(QDialog):
layout.addLayout(QLabeledWidget("Task:", self.task_selector)) layout.addLayout(QLabeledWidget("Task:", self.task_selector))
self.aircraft_selector = QAircraftTypeSelector( 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() self.task_selector.currentData()
) )
) )
@ -217,7 +217,7 @@ class QFlightCreator(QDialog):
def on_task_changed(self, index: int) -> None: def on_task_changed(self, index: int) -> None:
task = self.task_selector.itemData(index) task = self.task_selector.itemData(index)
self.aircraft_selector.update_items( 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()) self.squadron_selector.update_items(task, self.aircraft_selector.currentData())