mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Add livery selector in SquadronDialog
This commit is contained in:
parent
ef0bc31b8c
commit
4b4ec8d9ad
45
qt_ui/widgets/combos/QSquadronLiverySelector.py
Normal file
45
qt_ui/widgets/combos/QSquadronLiverySelector.py
Normal file
@ -0,0 +1,45 @@
|
||||
import logging
|
||||
|
||||
from PySide2.QtWidgets import QComboBox
|
||||
|
||||
from game.squadrons import Squadron
|
||||
|
||||
|
||||
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 = set(self.aircraft_type.dcs_unit_type.iter_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)
|
||||
faction = squadron.coalition.faction
|
||||
overrides = [
|
||||
x
|
||||
for x in faction.liveries_overrides.get(self.aircraft_type, [])
|
||||
if x in [y.id.lower() for y in liveries]
|
||||
]
|
||||
if len(overrides) > 0:
|
||||
self.addItem("Use livery overrides", userData=None)
|
||||
for livery in sorted(liveries):
|
||||
self.addItem(livery.name, userData=livery.id)
|
||||
if selected_livery is not None:
|
||||
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)
|
||||
@ -1,4 +1,3 @@
|
||||
import logging
|
||||
from collections import defaultdict
|
||||
from typing import Iterable, Iterator, Optional
|
||||
|
||||
@ -42,6 +41,7 @@ from game.squadrons.squadrondef import SquadronDef
|
||||
from game.theater import ControlPoint, ParkingType
|
||||
from game.theater.start_generator import GeneratorSettings
|
||||
from qt_ui.uiconstants import AIRCRAFT_ICONS, ICONS
|
||||
from qt_ui.widgets.combos.QSquadronLiverySelector import SquadronLiverySelector
|
||||
from qt_ui.widgets.combos.primarytaskselector import PrimaryTaskSelector
|
||||
|
||||
|
||||
@ -132,46 +132,6 @@ 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 = set(self.aircraft_type.dcs_unit_type.iter_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)
|
||||
faction = squadron.coalition.faction
|
||||
overrides = [
|
||||
x
|
||||
for x in faction.liveries_overrides.get(self.aircraft_type, [])
|
||||
if x in [y.id.lower() for y in liveries]
|
||||
]
|
||||
if len(overrides) > 0:
|
||||
self.addItem("Use livery overrides", userData=None)
|
||||
for livery in sorted(liveries):
|
||||
self.addItem(livery.name, userData=livery.id)
|
||||
if selected_livery is not None:
|
||||
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)
|
||||
|
||||
|
||||
class SquadronSizeSpinner(QSpinBox):
|
||||
def __init__(self, starting_size: int, parent: QWidget | None) -> None:
|
||||
super().__init__(parent)
|
||||
|
||||
@ -30,6 +30,7 @@ from game.theater import ConflictTheater, ControlPoint, ParkingType
|
||||
from qt_ui.delegates import TwoColumnRowDelegate
|
||||
from qt_ui.errorreporter import report_errors
|
||||
from qt_ui.models import AtoModel, SquadronModel
|
||||
from qt_ui.widgets.combos.QSquadronLiverySelector import SquadronLiverySelector
|
||||
from qt_ui.widgets.combos.primarytaskselector import PrimaryTaskSelector
|
||||
|
||||
|
||||
@ -257,6 +258,11 @@ class SquadronDialog(QDialog):
|
||||
)
|
||||
left_column.addWidget(self.primary_task_selector)
|
||||
|
||||
left_column.addWidget(QLabel("Livery"))
|
||||
self.livery_selector = SquadronLiverySelector(self.squadron_model.squadron)
|
||||
self.livery_selector.currentIndexChanged.connect(self.on_livery_changed)
|
||||
left_column.addWidget(self.livery_selector)
|
||||
|
||||
auto_assigned_tasks = AutoAssignedTaskControls(squadron_model)
|
||||
left_column.addLayout(auto_assigned_tasks)
|
||||
|
||||
@ -400,3 +406,6 @@ class SquadronDialog(QDialog):
|
||||
if task is None:
|
||||
raise RuntimeError("Selected task cannot be None")
|
||||
self.squadron.primary_task = task
|
||||
|
||||
def on_livery_changed(self) -> None:
|
||||
self.squadron.livery = self.livery_selector.currentData()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user