mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Add tooltips for TGOs.
This commit is contained in:
parent
eb26d54ac1
commit
1ab205cb46
@ -128,6 +128,17 @@ class TheaterGroundObject(MissionTarget):
|
|||||||
"""
|
"""
|
||||||
return list(itertools.chain.from_iterable([g.units for g in self.groups]))
|
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
|
@property
|
||||||
def group_name(self) -> str:
|
def group_name(self) -> str:
|
||||||
"""The name of the unit group."""
|
"""The name of the unit group."""
|
||||||
|
|||||||
@ -4,8 +4,10 @@ from typing import List, Optional, Tuple
|
|||||||
|
|
||||||
from PySide2.QtCore import Property, QObject, Signal, Slot
|
from PySide2.QtCore import Property, QObject, Signal, Slot
|
||||||
from dcs import Point
|
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.profiling import logged_duration
|
||||||
from game.theater import (
|
from game.theater import (
|
||||||
ConflictTheater,
|
ConflictTheater,
|
||||||
@ -55,10 +57,42 @@ class ControlPointJs(QObject):
|
|||||||
|
|
||||||
|
|
||||||
class GroundObjectJs(QObject):
|
class GroundObjectJs(QObject):
|
||||||
def __init__(self, tgo: TheaterGroundObject, theater: ConflictTheater) -> None:
|
def __init__(
|
||||||
|
self, tgo: TheaterGroundObject, theater: ConflictTheater, country: str
|
||||||
|
) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.tgo = tgo
|
self.tgo = tgo
|
||||||
self.theater = theater
|
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)
|
@Property(bool)
|
||||||
def blue(self) -> bool:
|
def blue(self) -> bool:
|
||||||
@ -315,12 +349,19 @@ class MapModel(QObject):
|
|||||||
seen = set()
|
seen = set()
|
||||||
self._ground_objects = []
|
self._ground_objects = []
|
||||||
for cp in self.game.theater.controlpoints:
|
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:
|
for tgo in cp.ground_objects:
|
||||||
if tgo.name in seen:
|
if tgo.name in seen:
|
||||||
continue
|
continue
|
||||||
seen.add(tgo.name)
|
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()
|
self.groundObjectsChanged.emit()
|
||||||
|
|
||||||
@Property(list, notify=groundObjectsChanged)
|
@Property(list, notify=groundObjectsChanged)
|
||||||
|
|||||||
@ -166,9 +166,9 @@ function drawGroundObjects() {
|
|||||||
blueSamThreatLayer.clearLayers();
|
blueSamThreatLayer.clearLayers();
|
||||||
redSamThreatLayer.clearLayers();
|
redSamThreatLayer.clearLayers();
|
||||||
game.groundObjects.forEach((tgo) => {
|
game.groundObjects.forEach((tgo) => {
|
||||||
L.marker(tgo.position, { icon: iconFor(tgo.blue) }).addTo(
|
L.marker(tgo.position, { icon: iconFor(tgo.blue) })
|
||||||
groundObjectsLayer
|
.bindTooltip(`${tgo.name}<br />${tgo.units.join("<br />")}`)
|
||||||
);
|
.addTo(groundObjectsLayer);
|
||||||
drawSamThreatsAt(tgo);
|
drawSamThreatsAt(tgo);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user