dcs_liberation/qt_ui/windows/mission/flight/SquadronSelector.py
Dan Albert 94b8aa7213 Disallow squadrons from disabling mission types.
After this change, players will always have the final say in what
missions a squadron can be assigned to. Squadrons are not able to
influence the default auto-assignable missions either because that
property is always overridden by the campaign's air wing configuration
(the primary and secondary task properties). The `mission-types` field
of the squadron definition has been removed since it is no longer
capable of influencing anything. I haven't bothered cleaning up the now
useless data in all the existing squadrons though.

Fixes https://github.com/dcs-liberation/dcs_liberation/issues/2785.
2023-04-18 11:35:41 -07:00

60 lines
1.8 KiB
Python

"""Combo box for selecting squadrons."""
from typing import Optional
from PySide6.QtWidgets import QComboBox
from game.ato.flighttype import FlightType
from game.dcs.aircrafttype import AircraftType
from game.squadrons.airwing import AirWing
class SquadronSelector(QComboBox):
"""Combo box for selecting squadrons compatible with the given requirements."""
def __init__(
self,
air_wing: AirWing,
task: Optional[FlightType],
aircraft: Optional[AircraftType],
) -> None:
super().__init__()
self.air_wing = air_wing
self.model().sort(0)
self.setSizeAdjustPolicy(QComboBox.SizeAdjustPolicy.AdjustToContents)
self.update_items(task, aircraft)
@property
def aircraft_available(self) -> int:
squadron = self.currentData()
if squadron is None:
return 0
return squadron.untasked_aircraft
def update_items(
self, task: Optional[FlightType], aircraft: Optional[AircraftType]
) -> None:
current_squadron = self.currentData()
self.blockSignals(True)
try:
self.clear()
finally:
self.blockSignals(False)
if task is None:
self.addItem("No task selected", None)
return
if aircraft is None:
self.addItem("No aircraft selected", None)
return
for squadron in self.air_wing.squadrons_for(aircraft):
if squadron.capable_of(task) and squadron.untasked_aircraft:
self.addItem(f"{squadron.location}: {squadron}", squadron)
if self.count() == 0:
self.addItem("No capable aircraft available", None)
return
if current_squadron is not None:
self.setCurrentText(f"{current_squadron.location}: {current_squadron}")