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.
This commit is contained in:
Dan Albert 2023-07-22 17:23:43 -07:00
parent e901d1f538
commit e8df6a3d54
4 changed files with 26 additions and 0 deletions

View File

@ -325,9 +325,19 @@ class AircraftType(UnitType[Type[FlyingType]]):
def channel_name(self, radio_id: int, channel_id: int) -> str: def channel_name(self, radio_id: int, channel_id: int) -> str:
return self.channel_namer.channel_name(radio_id, channel_id) 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]: def iter_props(self) -> Iterator[UnitPropertyDescription]:
yield from self.dcs_unit_type.properties.values() 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: def capable_of(self, task: FlightType) -> bool:
return task in self.task_priorities return task in self.task_priorities

View File

@ -1,6 +1,7 @@
from __future__ import annotations from __future__ import annotations
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from collections.abc import Iterator
from typing import Any from typing import Any
@ -19,6 +20,10 @@ class LaserCodeConfig(ABC):
pylon, [(d["id"], d["digit"]) for d in data["properties"]] pylon, [(d["id"], d["digit"]) for d in data["properties"]]
) )
@abstractmethod
def iter_prop_ids(self) -> Iterator[str]:
...
@abstractmethod @abstractmethod
def property_dict_for_code(self, code: int) -> dict[str, int]: def property_dict_for_code(self, code: int) -> dict[str, int]:
... ...
@ -30,6 +35,9 @@ class SinglePropertyLaserCodeConfig(LaserCodeConfig):
self.property_id = property_id self.property_id = property_id
self.digits = digits 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]: def property_dict_for_code(self, code: int) -> dict[str, int]:
return {self.property_id: code % 10**self.digits} return {self.property_id: code % 10**self.digits}
@ -41,6 +49,9 @@ class MultiplePropertyLaserCodeConfig(LaserCodeConfig):
super().__init__(pylon) super().__init__(pylon)
self.property_digit_mappings = property_digit_mappings 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]: def property_dict_for_code(self, code: int) -> dict[str, int]:
d = {} d = {}
for prop_id, idx in self.property_digit_mappings: for prop_id, idx in self.property_digit_mappings:

View File

@ -37,6 +37,9 @@ class PropertyEditor(QGridLayout):
if prop.player_only and not flight.client_count: if prop.player_only and not flight.client_count:
continue continue
if not flight.unit_type.should_show_prop(prop.identifier):
continue
try: try:
widget = self.control_for_property(prop) widget = self.control_for_property(prop)
except (MissingPropertyDataError, UnhandledControlTypeError): except (MissingPropertyDataError, UnhandledControlTypeError):

View File

@ -7,6 +7,7 @@ from game.dcs.lasercodeconfig import (
def test_singlepropertylasercodeproperty() -> None: def test_singlepropertylasercodeproperty() -> None:
config = SinglePropertyLaserCodeConfig(0, "code", 3) 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(1688) == {"code": 688}
assert config.property_dict_for_code(1000) == {"code": 0} assert config.property_dict_for_code(1000) == {"code": 0}
assert config.property_dict_for_code(1234) == {"code": 234} assert config.property_dict_for_code(1234) == {"code": 234}
@ -22,6 +23,7 @@ def test_multiplepropertylasercodeproperty() -> None:
("digit2", 2), ("digit2", 2),
], ],
) )
assert list(config.iter_prop_ids()) == ["digit0", "digit1", "digit2"]
assert config.property_dict_for_code(1688) == { assert config.property_dict_for_code(1688) == {
"digit0": 8, "digit0": 8,
"digit1": 8, "digit1": 8,