mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Consider priority order in Aircraft selector
This commit is contained in:
parent
2836a89f91
commit
41d1ae099f
@ -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():
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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())
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user