mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Further improvements to livery-selector
Unlocking the full potential, i.e. allowing users to switch back & forth between livery-sets, livery-overrides and normal liveries, including support for overriding flight/flight-member specific liveries.
This commit is contained in:
@@ -4,6 +4,8 @@ from PySide6.QtWidgets import QComboBox
|
||||
|
||||
from game.squadrons import Squadron
|
||||
|
||||
LIVERY_SET_TEXT = "Use livery-set from squadron's yaml"
|
||||
|
||||
|
||||
class SquadronLiverySelector(QComboBox):
|
||||
"""
|
||||
@@ -11,15 +13,17 @@ class SquadronLiverySelector(QComboBox):
|
||||
The combo box will automatically be populated with all available liveries.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self, squadron: Squadron, full_list_view_override: bool = False
|
||||
) -> None:
|
||||
def __init__(self, squadron: Squadron, update_squadron: bool = True) -> None:
|
||||
super().__init__()
|
||||
self.setSizeAdjustPolicy(QComboBox.SizeAdjustPolicy.AdjustToContents)
|
||||
|
||||
self.squadron = squadron
|
||||
self.aircraft_type = squadron.aircraft
|
||||
selected_livery = squadron.livery
|
||||
|
||||
if update_squadron:
|
||||
self.currentTextChanged.connect(self.on_change)
|
||||
|
||||
liveries = set()
|
||||
cc = squadron.coalition.faction.country.shortname
|
||||
aircraft_liveries = set(self.aircraft_type.dcs_unit_type.iter_liveries())
|
||||
@@ -35,23 +39,32 @@ class SquadronLiverySelector(QComboBox):
|
||||
for x in faction.liveries_overrides.get(self.aircraft_type, [])
|
||||
if x in [y.id.lower() for y in liveries]
|
||||
]
|
||||
if (
|
||||
selected_livery is None
|
||||
and squadron.livery_set
|
||||
and not full_list_view_override
|
||||
):
|
||||
self.addItem("Using livery-set from squadron's yaml", userData=None)
|
||||
self.setEnabled(False)
|
||||
return
|
||||
if selected_livery is None and squadron.aircraft.default_livery:
|
||||
selected_livery = squadron.aircraft.default_livery
|
||||
if squadron.livery_set:
|
||||
self.addItem(LIVERY_SET_TEXT, userData=None)
|
||||
if len(overrides) > 0:
|
||||
self.addItem("Use livery overrides", userData=None)
|
||||
if (
|
||||
selected_livery is None
|
||||
and not squadron.livery_set
|
||||
and squadron.aircraft.default_livery
|
||||
):
|
||||
selected_livery = squadron.aircraft.default_livery
|
||||
for livery in sorted(liveries):
|
||||
self.addItem(livery.name, userData=livery.id)
|
||||
if selected_livery is not None:
|
||||
if selected_livery is not None and not squadron.livery_set:
|
||||
if selected_livery.lower() == livery.id:
|
||||
self.setCurrentText(livery.name)
|
||||
if len(liveries) == 0:
|
||||
self.addItem("No available liveries (using DCS default)")
|
||||
self.setEnabled(False)
|
||||
|
||||
@property
|
||||
def using_livery_set(self) -> bool:
|
||||
return self.currentText() == LIVERY_SET_TEXT
|
||||
|
||||
def on_change(self, text: str) -> None:
|
||||
self.squadron.livery = self.currentData()
|
||||
if text == LIVERY_SET_TEXT:
|
||||
self.squadron.use_livery_set = True
|
||||
else:
|
||||
self.squadron.use_livery_set = False
|
||||
|
||||
Reference in New Issue
Block a user