mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Clean up custom loadout interface.
Wraps the pydcs data in a real type so we don't need to spread the reflection all over.
This commit is contained in:
@@ -2,6 +2,7 @@ import inspect
|
||||
|
||||
from PySide2.QtWidgets import QLabel, QHBoxLayout, QGroupBox, QSpinBox, QGridLayout, QVBoxLayout, QSizePolicy
|
||||
|
||||
from game.data.weapons import Pylon
|
||||
from qt_ui.windows.mission.flight.payload.QPylonEditor import QPylonEditor
|
||||
|
||||
|
||||
@@ -19,16 +20,12 @@ class QLoadoutEditor(QGroupBox):
|
||||
hboxLayout = QVBoxLayout(self)
|
||||
layout = QGridLayout(self)
|
||||
|
||||
pylons = [v for v in self.flight.unit_type.__dict__.values() if inspect.isclass(v) and v.__name__.startswith("Pylon")]
|
||||
for i, pylon in enumerate(pylons):
|
||||
label = QLabel("<b>{}</b>".format(pylon.__name__[len("Pylon"):]))
|
||||
label.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))
|
||||
for i, pylon in enumerate(Pylon.iter_pylons(self.flight.unit_type)):
|
||||
label = QLabel(f"<b>{pylon.number}</b>")
|
||||
label.setSizePolicy(
|
||||
QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))
|
||||
layout.addWidget(label, i, 0)
|
||||
try:
|
||||
pylon_number = int(pylon.__name__.split("Pylon")[1])
|
||||
except:
|
||||
pylon_number = i+1
|
||||
layout.addWidget(QPylonEditor(flight, pylon, pylon_number), i, 1)
|
||||
layout.addWidget(QPylonEditor(flight, pylon), i, 1)
|
||||
|
||||
hboxLayout.addLayout(layout)
|
||||
hboxLayout.addStretch()
|
||||
|
||||
@@ -1,38 +1,37 @@
|
||||
import logging
|
||||
import operator
|
||||
from typing import Optional
|
||||
|
||||
from PySide2.QtWidgets import QWidget, QSpinBox, QComboBox
|
||||
from PySide2.QtWidgets import QComboBox
|
||||
|
||||
from game.data.weapons import Pylon, Weapon
|
||||
from gen.flights.flight import Flight
|
||||
|
||||
|
||||
class QPylonEditor(QComboBox):
|
||||
|
||||
def __init__(self, flight, pylon, pylon_number):
|
||||
super(QPylonEditor, self).__init__()
|
||||
self.pylon = pylon
|
||||
self.pylon_number = pylon_number
|
||||
def __init__(self, flight: Flight, pylon: Pylon) -> None:
|
||||
super().__init__()
|
||||
self.flight = flight
|
||||
self.pylon = pylon
|
||||
|
||||
self.possible_loadout = [i for i in self.pylon.__dict__.keys() if i[:2] != '__']
|
||||
current = self.flight.loadout.get(self.pylon.number)
|
||||
|
||||
if not str(self.pylon_number) in self.flight.loadout.keys():
|
||||
self.flight.loadout[str(self.pylon_number)] = ""
|
||||
|
||||
self.addItem("None")
|
||||
for i,k in enumerate(self.possible_loadout):
|
||||
self.addItem(str(self.pylon.__dict__[k][1]["name"]))
|
||||
if self.flight.loadout[str(self.pylon_number)] == str(k):
|
||||
self.addItem("None", None)
|
||||
allowed = sorted(pylon.allowed, key=operator.attrgetter("name"))
|
||||
for i, weapon in enumerate(allowed):
|
||||
self.addItem(weapon.name, weapon)
|
||||
if current == weapon:
|
||||
self.setCurrentIndex(i + 1)
|
||||
|
||||
self.currentTextChanged.connect(self.on_pylon_change)
|
||||
self.currentIndexChanged.connect(self.on_pylon_change)
|
||||
|
||||
def on_pylon_change(self):
|
||||
selected = self.currentText()
|
||||
if selected == "None":
|
||||
logging.info("Pylon " + str(self.pylon_number) + " emptied")
|
||||
self.flight.loadout[str(self.pylon_number)] = ""
|
||||
else:
|
||||
logging.info("Pylon " + str(self.pylon_number) + " changed to " + selected)
|
||||
for i, k in enumerate(self.possible_loadout):
|
||||
if selected == str(self.pylon.__dict__[k][1]["name"]):
|
||||
self.flight.loadout[str(self.pylon_number)] = str(k)
|
||||
break
|
||||
selected: Optional[Weapon] = self.currentData()
|
||||
self.flight.loadout[self.pylon.number] = selected
|
||||
|
||||
if selected is None:
|
||||
logging.debug(f"Pylon {self.pylon.number} emptied")
|
||||
else:
|
||||
logging.debug(
|
||||
f"Pylon {self.pylon.number} changed to {selected.name}")
|
||||
|
||||
Reference in New Issue
Block a user