From 8158cc71125a3d98670f73a70c95ad2e0c9e28fa Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Fri, 12 May 2023 17:16:42 -0700 Subject: [PATCH] Add livery selection dropdown to air wing config. Fixes https://github.com/dcs-liberation/dcs_liberation/issues/1861. --- changelog.md | 1 + qt_ui/widgets/combos/liveryselector.py | 31 +++++++++++++++++++++ qt_ui/windows/AirWingConfigurationDialog.py | 8 ++++++ 3 files changed, 40 insertions(+) create mode 100644 qt_ui/widgets/combos/liveryselector.py diff --git a/changelog.md b/changelog.md index 853034f0..50f0f743 100644 --- a/changelog.md +++ b/changelog.md @@ -21,6 +21,7 @@ Saves from 6.x are not compatible with 7.0. * **[New Game Wizard]** Choices for some options will be remembered for the next new game. Not all settings will be preserved, as many are campaign dependent. * **[New Game Wizard]** Lua plugins can now be set while creating a new game. * **[New Game Wizard]** Squadrons can be directly replaced with a preset during air wing configuration rather than needing to remove and create a new squadron. +* **[New Game Wizard]** Squadron liveries can now be selected during air wing configuration. * **[Squadrons]** Squadron-specific mission capability lists no longer restrict players from assigning missions outside the squadron's preferences. ## Fixes diff --git a/qt_ui/widgets/combos/liveryselector.py b/qt_ui/widgets/combos/liveryselector.py new file mode 100644 index 00000000..38c4a55f --- /dev/null +++ b/qt_ui/widgets/combos/liveryselector.py @@ -0,0 +1,31 @@ +from __future__ import annotations + +from PySide6.QtWidgets import QComboBox +from dcs.liveries.livery import Livery + +from game.squadrons import Squadron + + +class LiverySelector(QComboBox): + def __init__(self, squadron: Squadron) -> None: + super().__init__() + self.setSizeAdjustPolicy(QComboBox.SizeAdjustPolicy.AdjustToContents) + self.set_squadron(squadron) + + @property + def selected_livery(self) -> Livery | None: + return self.currentData() + + def set_squadron(self, squadron: Squadron) -> None: + selected_idx: int | None = None + self.clear() + self.addItem("Default", None) + for idx, livery in enumerate( + squadron.aircraft.dcs_unit_type.iter_liveries_for_country(squadron.country) + ): + self.addItem(livery.name, livery) + if squadron.livery == livery.id: + selected_idx = idx + if selected_idx is not None: + self.setCurrentIndex(selected_idx) + self.update() diff --git a/qt_ui/windows/AirWingConfigurationDialog.py b/qt_ui/windows/AirWingConfigurationDialog.py index b7f21466..feb16bf7 100644 --- a/qt_ui/windows/AirWingConfigurationDialog.py +++ b/qt_ui/windows/AirWingConfigurationDialog.py @@ -39,6 +39,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.liveryselector import LiverySelector from qt_ui.widgets.combos.primarytaskselector import PrimaryTaskSelector @@ -188,6 +189,10 @@ class SquadronConfigurationBox(QGroupBox): reroll_nickname_button.clicked.connect(self.reroll_nickname) nickname_edit_layout.addWidget(reroll_nickname_button, 1, 1, Qt.AlignTop) + left_column.addWidget(QLabel("Livery:")) + self.livery_selector = LiverySelector(self.squadron) + left_column.addWidget(self.livery_selector) + task_and_size_row = QHBoxLayout() left_column.addLayout(task_and_size_row) @@ -254,6 +259,7 @@ class SquadronConfigurationBox(QGroupBox): try: self.name_edit.setText(self.squadron.name) self.nickname_edit.setText(self.squadron.nickname) + self.livery_selector.set_squadron(self.squadron) self.primary_task_selector.setCurrentText(self.squadron.primary_task.value) self.max_size_selector.setValue(self.squadron.max_size) self.base_selector.setCurrentText(self.squadron.location.name) @@ -327,6 +333,8 @@ class SquadronConfigurationBox(QGroupBox): def apply(self) -> Squadron: self.squadron.name = self.name_edit.text() self.squadron.nickname = self.nickname_edit.text() + if (livery := self.livery_selector.selected_livery) is not None: + self.squadron.livery = livery.id self.squadron.max_size = self.max_size_selector.value() if (primary_task := self.primary_task_selector.selected_task) is not None: self.squadron.primary_task = primary_task