From a1910f49a811daad94357a26c4337a98d25c89fa Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Tue, 13 Jul 2021 17:49:10 -0700 Subject: [PATCH] Color navmesh zones based on threat. --- qt_ui/widgets/map/mapmodel.py | 32 ++++++++++++++++++++++++++++---- resources/ui/map/map.js | 7 +++++-- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/qt_ui/widgets/map/mapmodel.py b/qt_ui/widgets/map/mapmodel.py index c6c5e70b..02eadd9f 100644 --- a/qt_ui/widgets/map/mapmodel.py +++ b/qt_ui/widgets/map/mapmodel.py @@ -12,7 +12,7 @@ from shapely.geometry import LineString, Point as ShapelyPoint, Polygon, MultiPo from game import Game from game.dcs.groundunittype import GroundUnitType -from game.navmesh import NavMesh +from game.navmesh import NavMesh, NavMeshPoly from game.profiling import logged_duration from game.theater import ( ConflictTheater, @@ -646,11 +646,35 @@ class ThreatZoneContainerJs(QObject): return self._red +class NavMeshPolyJs(QObject): + polyChanged = Signal() + threatenedChanged = Signal() + + def __init__(self, poly: LeafletPoly, threatened: bool) -> None: + super().__init__() + self._poly = poly + self._threatened = threatened + + @Property(list, notify=polyChanged) + def poly(self) -> LeafletPoly: + return self._poly + + @Property(bool, notify=threatenedChanged) + def threatened(self) -> bool: + return self._threatened + + @classmethod + def from_navmesh(cls, poly: NavMeshPoly, theater: ConflictTheater) -> NavMeshPolyJs: + return NavMeshPolyJs( + shapely_poly_to_leaflet_points(poly.poly, theater), poly.threatened + ) + + class NavMeshJs(QObject): blueChanged = Signal() redChanged = Signal() - def __init__(self, blue: list[LeafletPoly], red: list[LeafletPoly]) -> None: + def __init__(self, blue: list[NavMeshPolyJs], red: list[NavMeshPolyJs]) -> None: super().__init__() self._blue = blue self._red = red @@ -667,10 +691,10 @@ class NavMeshJs(QObject): return self._red @staticmethod - def to_polys(navmesh: NavMesh, theater: ConflictTheater) -> list[LeafletPoly]: + def to_polys(navmesh: NavMesh, theater: ConflictTheater) -> list[NavMeshPolyJs]: polys = [] for poly in navmesh.polys: - polys.append(shapely_poly_to_leaflet_points(poly.poly, theater)) + polys.append(NavMeshPolyJs.from_navmesh(poly, theater)) return polys @classmethod diff --git a/resources/ui/map/map.js b/resources/ui/map/map.js index 141fe2ef..6cae9ae2 100644 --- a/resources/ui/map/map.js +++ b/resources/ui/map/map.js @@ -904,10 +904,13 @@ function drawThreatZones() { function drawNavmesh(zones, layer) { for (const zone of zones) { - L.polyline(zone, { + L.polyline(zone.poly, { color: "#000000", weight: 1, - fill: false, + fillColor: zone.threatened ? "#ff0000" : "#00ff00", + fill: true, + fillOpacity: 0.1, + noClip: true, interactive: false, }).addTo(layer); }