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 committed by Raffson
parent 51f578b9e3
commit dc22e0a577
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99
4 changed files with 26 additions and 0 deletions

View File

@ -331,9 +331,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

View File

@ -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:

View File

@ -42,6 +42,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):

View File

@ -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,