dcs-retribution/qt_ui/widgets/combos/primarytaskselector.py
Dan Albert f719e1cfe7
Add an option to prefer primary tasked aircraft.
We're still using mostly the same aircraft selection as we have before
we added squadrons: the closest aircraft is the best choice.

This adds an option to obey the primary task set by the campaign
designer (can be overridden by players), even if the squadron is farther
away than one that is capable of it as a secondary task.

I don't expect this option to live very long. I'm making it optional for
now to give people a chance to test it, but it'll either replace the old
selection strategy or will be removed.

Fixes https://github.com/dcs-liberation/dcs_liberation/issues/1892.
2023-05-14 20:33:55 +02:00

40 lines
1.2 KiB
Python

from __future__ import annotations
from PySide6.QtWidgets import QComboBox
from game.ato import FlightType
from game.dcs.aircrafttype import AircraftType
from game.squadrons import Squadron
class PrimaryTaskSelector(QComboBox):
def __init__(self, aircraft: AircraftType | None) -> None:
super().__init__()
self.setSizeAdjustPolicy(QComboBox.SizeAdjustPolicy.AdjustToContents)
self.set_aircraft(aircraft)
@staticmethod
def for_squadron(squadron: Squadron) -> PrimaryTaskSelector:
selector = PrimaryTaskSelector(squadron.aircraft)
selector.setCurrentText(squadron.primary_task.value)
return selector
def set_aircraft(self, aircraft: AircraftType | None) -> None:
self.clear()
if aircraft is None:
self.addItem("Select aircraft type first", None)
self.setEnabled(False)
self.update()
return
self.setEnabled(True)
for task in aircraft.iter_task_capabilities():
self.addItem(task.value, task)
self.model().sort(0)
self.setEnabled(True)
self.update()
@property
def selected_task(self) -> FlightType | None:
return self.currentData()