From e8df6a3d5434d8e50581c1ea60af0c2de3334765 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Sat, 22 Jul 2023 17:23:43 -0700 Subject: [PATCH] Hide properties that have better controls. The weapon laser codes can be set more easily from the weapon laser code combo box. Setting the properties explicitly here will just cause conflicts and annoying UI bugs. Hide those properties from the UI. --- game/dcs/aircrafttype.py | 10 ++++++++++ game/dcs/lasercodeconfig.py | 11 +++++++++++ .../windows/mission/flight/payload/propertyeditor.py | 3 +++ tests/dcs/test_lasercodeconfig.py | 2 ++ 4 files changed, 26 insertions(+) diff --git a/game/dcs/aircrafttype.py b/game/dcs/aircrafttype.py index ea6c7024..d336f5b3 100644 --- a/game/dcs/aircrafttype.py +++ b/game/dcs/aircrafttype.py @@ -325,9 +325,19 @@ class AircraftType(UnitType[Type[FlyingType]]): def channel_name(self, radio_id: int, channel_id: int) -> str: return self.channel_namer.channel_name(radio_id, channel_id) + @cached_property + def laser_code_prop_ids(self) -> set[str]: + laser_code_props: set[str] = set() + for laser_code_config in self.laser_code_configs: + laser_code_props.update(laser_code_config.iter_prop_ids()) + return laser_code_props + def iter_props(self) -> Iterator[UnitPropertyDescription]: yield from self.dcs_unit_type.properties.values() + def should_show_prop(self, prop_id: str) -> bool: + return prop_id not in self.laser_code_prop_ids + def capable_of(self, task: FlightType) -> bool: return task in self.task_priorities diff --git a/game/dcs/lasercodeconfig.py b/game/dcs/lasercodeconfig.py index 9e8260db..a7bb090f 100644 --- a/game/dcs/lasercodeconfig.py +++ b/game/dcs/lasercodeconfig.py @@ -1,6 +1,7 @@ from __future__ import annotations from abc import ABC, abstractmethod +from collections.abc import Iterator from typing import Any @@ -19,6 +20,10 @@ class LaserCodeConfig(ABC): pylon, [(d["id"], d["digit"]) for d in data["properties"]] ) + @abstractmethod + def iter_prop_ids(self) -> Iterator[str]: + ... + @abstractmethod def property_dict_for_code(self, code: int) -> dict[str, int]: ... @@ -30,6 +35,9 @@ class SinglePropertyLaserCodeConfig(LaserCodeConfig): self.property_id = property_id self.digits = digits + def iter_prop_ids(self) -> Iterator[str]: + yield self.property_id + def property_dict_for_code(self, code: int) -> dict[str, int]: return {self.property_id: code % 10**self.digits} @@ -41,6 +49,9 @@ class MultiplePropertyLaserCodeConfig(LaserCodeConfig): super().__init__(pylon) self.property_digit_mappings = property_digit_mappings + def iter_prop_ids(self) -> Iterator[str]: + yield from (i for i, p in self.property_digit_mappings) + def property_dict_for_code(self, code: int) -> dict[str, int]: d = {} for prop_id, idx in self.property_digit_mappings: diff --git a/qt_ui/windows/mission/flight/payload/propertyeditor.py b/qt_ui/windows/mission/flight/payload/propertyeditor.py index 03355df9..fa825e76 100644 --- a/qt_ui/windows/mission/flight/payload/propertyeditor.py +++ b/qt_ui/windows/mission/flight/payload/propertyeditor.py @@ -37,6 +37,9 @@ class PropertyEditor(QGridLayout): if prop.player_only and not flight.client_count: continue + if not flight.unit_type.should_show_prop(prop.identifier): + continue + try: widget = self.control_for_property(prop) except (MissingPropertyDataError, UnhandledControlTypeError): diff --git a/tests/dcs/test_lasercodeconfig.py b/tests/dcs/test_lasercodeconfig.py index f560f63a..a6acf11f 100644 --- a/tests/dcs/test_lasercodeconfig.py +++ b/tests/dcs/test_lasercodeconfig.py @@ -7,6 +7,7 @@ from game.dcs.lasercodeconfig import ( def test_singlepropertylasercodeproperty() -> None: config = SinglePropertyLaserCodeConfig(0, "code", 3) + assert list(config.iter_prop_ids()) == ["code"] assert config.property_dict_for_code(1688) == {"code": 688} assert config.property_dict_for_code(1000) == {"code": 0} assert config.property_dict_for_code(1234) == {"code": 234} @@ -22,6 +23,7 @@ def test_multiplepropertylasercodeproperty() -> None: ("digit2", 2), ], ) + assert list(config.iter_prop_ids()) == ["digit0", "digit1", "digit2"] assert config.property_dict_for_code(1688) == { "digit0": 8, "digit1": 8,