Add ability to select loadout on flight creation (#426)

* Add ability to select loadout on flight creation

* Add pylon info on hover and add default loadout autoselect

* move loadout selector to method

* Cleanup loadout delegate
This commit is contained in:
Druss99 2024-12-14 17:38:41 -05:00 committed by GitHub
parent 09d7a4babf
commit 3d778a1ce0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,6 +1,6 @@
from typing import Optional, Type
from PySide6.QtCore import Qt, Signal
from PySide6.QtCore import Qt, Signal, QEvent
from PySide6.QtWidgets import (
QComboBox,
QDialog,
@ -10,12 +10,15 @@ from PySide6.QtWidgets import (
QVBoxLayout,
QLineEdit,
QHBoxLayout,
QStyledItemDelegate,
QToolTip,
)
from dcs.unittype import FlyingType
from game import Game
from game.ato.flight import Flight
from game.ato.flightroster import FlightRoster
from game.ato.loadouts import Loadout
from game.ato.package import Package
from game.ato.starttype import StartType
from game.squadrons.squadron import Squadron
@ -85,6 +88,12 @@ class QFlightCreator(QDialog):
self.update_max_size(self.squadron_selector.aircraft_available)
layout.addLayout(QLabeledWidget("Size:", self.flight_size_spinner))
layout.addWidget(QLabel("Loadout:"))
self.loadout_selector = QComboBox()
self.loadout_selector.setItemDelegate(LoadoutDelegate(self.loadout_selector))
self._init_loadout_selector()
layout.addWidget(self.loadout_selector)
required_start_type = None
squadron = self.squadron_selector.currentData()
if squadron is None:
@ -206,6 +215,7 @@ class QFlightCreator(QDialog):
member.assign_tgp_laser_code(
self.game.laser_code_registry.alloc_laser_code()
)
member.loadout = self.current_loadout()
# noinspection PyUnresolvedReferences
self.created.emit(flight)
@ -217,8 +227,9 @@ class QFlightCreator(QDialog):
self.task_selector.currentData(), new_aircraft
)
self.divert.change_aircraft(new_aircraft)
self.roster_editor.pilots_changed.emit()
if self.aircraft_selector.currentData() is not None:
self._init_loadout_selector()
def on_departure_changed(self, departure: ControlPoint) -> None:
if isinstance(departure, OffMapSpawn):
@ -290,3 +301,35 @@ class QFlightCreator(QDialog):
start_type = self.game.settings.default_start_type
self.start_type.setCurrentText(start_type.value)
def current_loadout(self) -> Loadout:
loadout = self.loadout_selector.currentData()
if loadout is None:
return Loadout.empty_loadout()
return loadout
def _init_loadout_selector(self):
self.loadout_selector.clear()
for loadout in Loadout.iter_for_aircraft(self.aircraft_selector.currentData()):
self.loadout_selector.addItem(loadout.name, loadout)
for loadout in Loadout.default_loadout_names_for(
self.task_selector.currentData()
):
index = self.loadout_selector.findText(loadout)
if index != -1:
self.loadout_selector.setCurrentIndex(index)
break
class LoadoutDelegate(QStyledItemDelegate):
def helpEvent(self, event, view, option, index):
if event.type() == QEvent.ToolTip:
loadout = index.data(Qt.UserRole)
if loadout:
max_pylon = max(loadout.pylons.keys(), default=0)
pylons_info = "\n".join(
f"Pylon {pylon}: {loadout.pylons.get(pylon, 'Clean')}"
for pylon in range(1, max_pylon + 1)
)
QToolTip.showText(event.globalPos(), pylons_info, view)
return True