mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
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:
parent
09d7a4babf
commit
3d778a1ce0
@ -1,6 +1,6 @@
|
|||||||
from typing import Optional, Type
|
from typing import Optional, Type
|
||||||
|
|
||||||
from PySide6.QtCore import Qt, Signal
|
from PySide6.QtCore import Qt, Signal, QEvent
|
||||||
from PySide6.QtWidgets import (
|
from PySide6.QtWidgets import (
|
||||||
QComboBox,
|
QComboBox,
|
||||||
QDialog,
|
QDialog,
|
||||||
@ -10,12 +10,15 @@ from PySide6.QtWidgets import (
|
|||||||
QVBoxLayout,
|
QVBoxLayout,
|
||||||
QLineEdit,
|
QLineEdit,
|
||||||
QHBoxLayout,
|
QHBoxLayout,
|
||||||
|
QStyledItemDelegate,
|
||||||
|
QToolTip,
|
||||||
)
|
)
|
||||||
from dcs.unittype import FlyingType
|
from dcs.unittype import FlyingType
|
||||||
|
|
||||||
from game import Game
|
from game import Game
|
||||||
from game.ato.flight import Flight
|
from game.ato.flight import Flight
|
||||||
from game.ato.flightroster import FlightRoster
|
from game.ato.flightroster import FlightRoster
|
||||||
|
from game.ato.loadouts import Loadout
|
||||||
from game.ato.package import Package
|
from game.ato.package import Package
|
||||||
from game.ato.starttype import StartType
|
from game.ato.starttype import StartType
|
||||||
from game.squadrons.squadron import Squadron
|
from game.squadrons.squadron import Squadron
|
||||||
@ -85,6 +88,12 @@ class QFlightCreator(QDialog):
|
|||||||
self.update_max_size(self.squadron_selector.aircraft_available)
|
self.update_max_size(self.squadron_selector.aircraft_available)
|
||||||
layout.addLayout(QLabeledWidget("Size:", self.flight_size_spinner))
|
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
|
required_start_type = None
|
||||||
squadron = self.squadron_selector.currentData()
|
squadron = self.squadron_selector.currentData()
|
||||||
if squadron is None:
|
if squadron is None:
|
||||||
@ -206,6 +215,7 @@ class QFlightCreator(QDialog):
|
|||||||
member.assign_tgp_laser_code(
|
member.assign_tgp_laser_code(
|
||||||
self.game.laser_code_registry.alloc_laser_code()
|
self.game.laser_code_registry.alloc_laser_code()
|
||||||
)
|
)
|
||||||
|
member.loadout = self.current_loadout()
|
||||||
|
|
||||||
# noinspection PyUnresolvedReferences
|
# noinspection PyUnresolvedReferences
|
||||||
self.created.emit(flight)
|
self.created.emit(flight)
|
||||||
@ -217,8 +227,9 @@ class QFlightCreator(QDialog):
|
|||||||
self.task_selector.currentData(), new_aircraft
|
self.task_selector.currentData(), new_aircraft
|
||||||
)
|
)
|
||||||
self.divert.change_aircraft(new_aircraft)
|
self.divert.change_aircraft(new_aircraft)
|
||||||
|
|
||||||
self.roster_editor.pilots_changed.emit()
|
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:
|
def on_departure_changed(self, departure: ControlPoint) -> None:
|
||||||
if isinstance(departure, OffMapSpawn):
|
if isinstance(departure, OffMapSpawn):
|
||||||
@ -290,3 +301,35 @@ class QFlightCreator(QDialog):
|
|||||||
start_type = self.game.settings.default_start_type
|
start_type = self.game.settings.default_start_type
|
||||||
|
|
||||||
self.start_type.setCurrentText(start_type.value)
|
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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user