From 1ab205cb460409de430c8b2b3922bbede99358a4 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Thu, 13 May 2021 00:44:47 -0700 Subject: [PATCH] Add tooltips for TGOs. --- game/theater/theatergroundobject.py | 11 +++++++ qt_ui/widgets/map/mapmodel.py | 47 +++++++++++++++++++++++++++-- resources/ui/map/map.js | 6 ++-- 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/game/theater/theatergroundobject.py b/game/theater/theatergroundobject.py index ec12bf08..b084b614 100644 --- a/game/theater/theatergroundobject.py +++ b/game/theater/theatergroundobject.py @@ -128,6 +128,17 @@ class TheaterGroundObject(MissionTarget): """ return list(itertools.chain.from_iterable([g.units for g in self.groups])) + @property + def dead_units(self) -> List[Unit]: + """ + :return: all the dead units at this location + """ + return list( + itertools.chain.from_iterable( + [getattr(g, "units_losts", []) for g in self.groups] + ) + ) + @property def group_name(self) -> str: """The name of the unit group.""" diff --git a/qt_ui/widgets/map/mapmodel.py b/qt_ui/widgets/map/mapmodel.py index 18e76b26..9e057722 100644 --- a/qt_ui/widgets/map/mapmodel.py +++ b/qt_ui/widgets/map/mapmodel.py @@ -4,8 +4,10 @@ from typing import List, Optional, Tuple from PySide2.QtCore import Property, QObject, Signal, Slot from dcs import Point +from dcs.vehicles import vehicle_map +from dcs.unit import Unit -from game import Game +from game import Game, db from game.profiling import logged_duration from game.theater import ( ConflictTheater, @@ -55,10 +57,42 @@ class ControlPointJs(QObject): class GroundObjectJs(QObject): - def __init__(self, tgo: TheaterGroundObject, theater: ConflictTheater) -> None: + def __init__( + self, tgo: TheaterGroundObject, theater: ConflictTheater, country: str + ) -> None: super().__init__() self.tgo = tgo self.theater = theater + self.country = country + + @Property(str) + def name(self) -> str: + return self.tgo.name + + def make_unit_name(self, unit: Unit, dead: bool) -> str: + dead_label = " [DEAD]" if dead else "" + unit_display_name = unit.type + unit_type = vehicle_map.get(unit.type) + if unit_type is not None: + unit_display_name = db.unit_get_expanded_info( + self.country, unit_type, "name" + ) + return f"Unit #{unit.id} - {unit_display_name}{dead_label}" + + @Property(list) + def units(self) -> List[str]: + units = [] + if self.tgo.groups: + for unit in self.tgo.units: + units.append(self.make_unit_name(unit, dead=False)) + for unit in self.tgo.dead_units: + units.append(self.make_unit_name(unit, dead=True)) + else: + buildings = self.theater.find_ground_objects_by_obj_name(self.tgo.obj_name) + for building in buildings: + dead = " [DEAD]" if building.is_dead else "" + units.append(f"{building.dcs_identifier}{dead}") + return units @Property(bool) def blue(self) -> bool: @@ -315,12 +349,19 @@ class MapModel(QObject): seen = set() self._ground_objects = [] for cp in self.game.theater.controlpoints: + if cp.captured: + country = self.game.player_country + else: + country = self.game.enemy_country + for tgo in cp.ground_objects: if tgo.name in seen: continue seen.add(tgo.name) - self._ground_objects.append(GroundObjectJs(tgo, self.game.theater)) + self._ground_objects.append( + GroundObjectJs(tgo, self.game.theater, country) + ) self.groundObjectsChanged.emit() @Property(list, notify=groundObjectsChanged) diff --git a/resources/ui/map/map.js b/resources/ui/map/map.js index 23abb3e9..e2cb2eb2 100644 --- a/resources/ui/map/map.js +++ b/resources/ui/map/map.js @@ -166,9 +166,9 @@ function drawGroundObjects() { blueSamThreatLayer.clearLayers(); redSamThreatLayer.clearLayers(); game.groundObjects.forEach((tgo) => { - L.marker(tgo.position, { icon: iconFor(tgo.blue) }).addTo( - groundObjectsLayer - ); + L.marker(tgo.position, { icon: iconFor(tgo.blue) }) + .bindTooltip(`${tgo.name}
${tgo.units.join("
")}`) + .addTo(groundObjectsLayer); drawSamThreatsAt(tgo); }); }