mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Use the new data from pydcs to improve the properties UI: * Use human readable names * Use appropriate control types * Limit min and max values as appropriate for each property * Show labels Fixes https://github.com/dcs-liberation/dcs_liberation/issues/3090.
30 lines
1.0 KiB
Python
30 lines
1.0 KiB
Python
from PySide6.QtWidgets import QComboBox
|
|
from dcs.unitpropertydescription import UnitPropertyDescription
|
|
|
|
from game.ato import Flight
|
|
from .missingpropertydataerror import MissingPropertyDataError
|
|
|
|
|
|
class PropertyComboBox(QComboBox):
|
|
def __init__(self, flight: Flight, prop: UnitPropertyDescription) -> None:
|
|
super().__init__()
|
|
self.flight = flight
|
|
self.prop = prop
|
|
|
|
if prop.values is None:
|
|
raise MissingPropertyDataError("values cannot be None")
|
|
if prop.default is None:
|
|
raise MissingPropertyDataError("default cannot be None")
|
|
|
|
current_value = self.flight.props.get(self.prop.identifier, self.prop.default)
|
|
|
|
for ident, text in self.prop.values.items():
|
|
self.addItem(text, ident)
|
|
if ident == current_value:
|
|
self.setCurrentText(text)
|
|
|
|
self.currentIndexChanged.connect(self.on_selection_changed)
|
|
|
|
def on_selection_changed(self, _index: int) -> None:
|
|
self.flight.props[self.prop.identifier] = self.currentData()
|