diff --git a/changelog.md b/changelog.md index 976b08db..47e0ae3a 100644 --- a/changelog.md +++ b/changelog.md @@ -21,6 +21,7 @@ Saves from 5.x are not compatible with 6.0. * **[UI]** Added options to the loadout editor for setting properties such as HMD choice. * **[UI]** Added separate images for the different carrier types. * **[UI]** Add Accept/Reset buttons to Air Wing Configurator screen. +* **[UI]** Add livery selector to Air Wing Configurator's squadrons. * **[Campaign]** Allow campaign designers to define default values for the economy settings (starting budget and multiplier). * **[Plugins]** Allow full support of the SkynetIADS plugin with all advanced features (connection nodes, power sources, command centers) if campaign supports it. * **[Plugins]** Added support for the CTLD script by ciribob with many possible customization options and updated the JTAC Autolase to the CTLD included script. diff --git a/game/coalition.py b/game/coalition.py index 1f20b3de..0ad296f7 100644 --- a/game/coalition.py +++ b/game/coalition.py @@ -74,6 +74,10 @@ class Coalition: def country_name(self) -> str: return self.faction.country + @property + def country_shortname(self) -> str: + return self.faction.country_shortname + @property def opponent(self) -> Coalition: assert self._opponent is not None diff --git a/game/factions/faction.py b/game/factions/faction.py index 2de77a28..561d7446 100644 --- a/game/factions/faction.py +++ b/game/factions/faction.py @@ -46,6 +46,9 @@ class Faction: # Country used by this faction country: str = field(default="") + # Country's short name used by this faction + country_shortname: str = field(default="") + # Nice name of the faction name: str = field(default="") @@ -172,13 +175,22 @@ class Faction: faction = Faction(locales=json.get("locales")) faction.country = json.get("country", "/") - if faction.country not in [c.name for c in country_dict.values()]: + + country = None + for c in country_dict.values(): + if c.name == faction.country: + country = c + break + + if country is None: raise AssertionError( 'Faction\'s country ("{}") is not a valid DCS country ID'.format( faction.country ) ) + faction.country_shortname = country.shortname + faction.name = json.get("name", "") if not faction.name: raise AssertionError("Faction has no valid name") diff --git a/qt_ui/windows/AirWingConfigurationDialog.py b/qt_ui/windows/AirWingConfigurationDialog.py index 72325181..64200835 100644 --- a/qt_ui/windows/AirWingConfigurationDialog.py +++ b/qt_ui/windows/AirWingConfigurationDialog.py @@ -1,3 +1,4 @@ +import logging from typing import Iterable, Optional, Iterator from PySide2.QtCore import ( @@ -26,7 +27,6 @@ from PySide2.QtWidgets import ( QPushButton, QGridLayout, QToolButton, - QMessageBox, ) from game import Game from game.ato.flighttype import FlightType @@ -137,6 +137,38 @@ class SquadronBaseSelector(QComboBox): self.update() +class SquadronLiverySelector(QComboBox): + """ + A combo box for selecting a squadron's livery. + The combo box will automatically be populated with all available liveries. + """ + + def __init__(self, squadron: Squadron) -> None: + super().__init__() + self.setSizeAdjustPolicy(self.AdjustToContents) + + self.aircraft_type = squadron.aircraft + selected_livery = squadron.livery + + liveries = set() + cc = squadron.coalition.faction.country_shortname + aircraft_liveries = self.aircraft_type.dcs_unit_type.Liveries + if len(aircraft_liveries) == 0: + logging.info(f"Liveries for {self.aircraft_type} is empty!") + for livery in aircraft_liveries: + valid_livery = livery.countries is None or cc in livery.countries + if valid_livery or cc in ["BLUE", "RED"]: + liveries.add(livery) + for livery in sorted(liveries): + self.addItem(livery.name, userData=livery.id) + if selected_livery is not None: + if selected_livery == livery.id: + self.setCurrentText(livery.name) + if len(liveries) == 0: + self.addItem("No available liveries (using DCS default)") + self.setEnabled(False) + + class SquadronConfigurationBox(QGroupBox): remove_squadron_signal = Signal(Squadron) @@ -169,6 +201,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 = SquadronLiverySelector(squadron) + left_column.addWidget(self.livery_selector) + left_column.addWidget(QLabel("Base:")) self.base_selector = SquadronBaseSelector( theater.control_points_for(squadron.player), @@ -224,6 +260,7 @@ class SquadronConfigurationBox(QGroupBox): if base is None: raise RuntimeError("Base cannot be none") self.squadron.assign_to_base(base) + self.squadron.livery = self.livery_selector.currentData() player_names = self.player_list.toPlainText().splitlines() # Prepend player pilots so they get set active first.