mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
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.
This commit is contained in:
39
qt_ui/widgets/combos/primarytaskselector.py
Normal file
39
qt_ui/widgets/combos/primarytaskselector.py
Normal file
@@ -0,0 +1,39 @@
|
||||
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()
|
||||
@@ -38,6 +38,7 @@ from game.squadrons import AirWing, Pilot, Squadron
|
||||
from game.squadrons.squadrondef import SquadronDef
|
||||
from game.theater import ControlPoint
|
||||
from qt_ui.uiconstants import AIRCRAFT_ICONS, ICONS
|
||||
from qt_ui.widgets.combos.primarytaskselector import PrimaryTaskSelector
|
||||
|
||||
|
||||
class QMissionType(QCheckBox):
|
||||
@@ -210,6 +211,10 @@ class SquadronConfigurationBox(QGroupBox):
|
||||
self.livery_selector = SquadronLiverySelector(squadron)
|
||||
left_column.addWidget(self.livery_selector)
|
||||
|
||||
left_column.addWidget(QLabel("Primary task:"))
|
||||
self.primary_task_selector = PrimaryTaskSelector.for_squadron(self.squadron)
|
||||
left_column.addWidget(self.primary_task_selector)
|
||||
|
||||
left_column.addWidget(QLabel("Base:"))
|
||||
self.base_selector = SquadronBaseSelector(
|
||||
game.theater.control_points_for(squadron.player),
|
||||
@@ -262,6 +267,7 @@ class SquadronConfigurationBox(QGroupBox):
|
||||
try:
|
||||
self.name_edit.setText(self.squadron.name)
|
||||
self.nickname_edit.setText(self.squadron.nickname)
|
||||
self.primary_task_selector.setCurrentText(self.squadron.primary_task.value)
|
||||
self.base_selector.setCurrentText(self.squadron.location.name)
|
||||
self.player_list.setText(
|
||||
"<br />".join(p.name for p in self.claim_players_from_squadron())
|
||||
@@ -285,6 +291,7 @@ class SquadronConfigurationBox(QGroupBox):
|
||||
self.squadron.coalition.air_wing.unclaim_squadron_def(self.squadron)
|
||||
squadron = Squadron.create_from(
|
||||
selected_def,
|
||||
self.squadron.primary_task,
|
||||
self.squadron.location,
|
||||
self.coalition,
|
||||
self.game,
|
||||
@@ -331,6 +338,10 @@ class SquadronConfigurationBox(QGroupBox):
|
||||
def apply(self) -> Squadron:
|
||||
self.squadron.name = self.name_edit.text()
|
||||
self.squadron.nickname = self.nickname_edit.text()
|
||||
if (primary_task := self.primary_task_selector.selected_task) is not None:
|
||||
self.squadron.primary_task = primary_task
|
||||
else:
|
||||
raise RuntimeError("Primary task cannot be none")
|
||||
base = self.base_selector.currentData()
|
||||
if base is None:
|
||||
raise RuntimeError("Base cannot be none")
|
||||
@@ -583,6 +594,7 @@ class AirWingConfigurationTab(QWidget):
|
||||
|
||||
selected_type = popup.aircraft_type_selector.currentData()
|
||||
selected_base = popup.squadron_base_selector.currentData()
|
||||
selected_task = popup.primary_task_selector.selected_task
|
||||
selected_def = popup.squadron_def_selector.currentData()
|
||||
|
||||
# Let user choose the preset or generate one
|
||||
@@ -594,7 +606,7 @@ class AirWingConfigurationTab(QWidget):
|
||||
)
|
||||
|
||||
squadron = Squadron.create_from(
|
||||
squadron_def, selected_base, self.coalition, self.game
|
||||
squadron_def, selected_task, selected_base, self.coalition, self.game
|
||||
)
|
||||
|
||||
# Add Squadron
|
||||
@@ -744,6 +756,12 @@ class SquadronConfigPopup(QDialog):
|
||||
)
|
||||
self.column.addWidget(self.aircraft_type_selector)
|
||||
|
||||
self.column.addWidget(QLabel("Primary task:"))
|
||||
self.primary_task_selector = PrimaryTaskSelector(
|
||||
self.aircraft_type_selector.currentData()
|
||||
)
|
||||
self.column.addWidget(self.primary_task_selector)
|
||||
|
||||
self.column.addWidget(QLabel("Base:"))
|
||||
self.squadron_base_selector = SquadronBaseSelector(
|
||||
bases, None, self.aircraft_type_selector.currentData()
|
||||
@@ -774,6 +792,7 @@ class SquadronConfigPopup(QDialog):
|
||||
enabled = (
|
||||
self.aircraft_type_selector.currentData() is not None
|
||||
and self.squadron_base_selector.currentData() is not None
|
||||
and self.primary_task_selector.selected_task is not None
|
||||
)
|
||||
self.accept_button.setEnabled(enabled)
|
||||
|
||||
@@ -784,6 +803,9 @@ class SquadronConfigPopup(QDialog):
|
||||
self.squadron_def_selector.set_aircraft_type(
|
||||
self.aircraft_type_selector.currentData()
|
||||
)
|
||||
self.primary_task_selector.set_aircraft(
|
||||
self.aircraft_type_selector.currentData()
|
||||
)
|
||||
self.update_accept_button()
|
||||
self.update()
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ from game.theater import ConflictTheater, ControlPoint
|
||||
from qt_ui.delegates import TwoColumnRowDelegate
|
||||
from qt_ui.errorreporter import report_errors
|
||||
from qt_ui.models import AtoModel, SquadronModel
|
||||
from qt_ui.widgets.combos.primarytaskselector import PrimaryTaskSelector
|
||||
|
||||
|
||||
class PilotDelegate(TwoColumnRowDelegate):
|
||||
@@ -161,8 +162,20 @@ class SquadronDialog(QDialog):
|
||||
columns = QHBoxLayout()
|
||||
layout.addLayout(columns)
|
||||
|
||||
left_column = QVBoxLayout()
|
||||
columns.addLayout(left_column)
|
||||
|
||||
left_column.addWidget(QLabel("Primary task"))
|
||||
self.primary_task_selector = PrimaryTaskSelector.for_squadron(
|
||||
self.squadron_model.squadron
|
||||
)
|
||||
self.primary_task_selector.currentIndexChanged.connect(
|
||||
self.on_task_index_changed
|
||||
)
|
||||
left_column.addWidget(self.primary_task_selector)
|
||||
|
||||
auto_assigned_tasks = AutoAssignedTaskControls(squadron_model)
|
||||
columns.addLayout(auto_assigned_tasks)
|
||||
left_column.addLayout(auto_assigned_tasks)
|
||||
|
||||
self.pilot_list = PilotList(squadron_model)
|
||||
self.pilot_list.selectionModel().selectionChanged.connect(
|
||||
@@ -298,3 +311,9 @@ class SquadronDialog(QDialog):
|
||||
index = selected.indexes()[0]
|
||||
self.reset_ai_toggle_state(index)
|
||||
self.reset_leave_toggle_state(index)
|
||||
|
||||
def on_task_index_changed(self, index: int) -> None:
|
||||
task = self.primary_task_selector.itemData(index)
|
||||
if task is None:
|
||||
raise RuntimeError("Selected task cannot be None")
|
||||
self.squadron.primary_task = task
|
||||
|
||||
Reference in New Issue
Block a user