From 7dd379c5c3a68c731f38dce7288db42b9f0521fd Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Sun, 16 May 2021 12:57:42 -0700 Subject: [PATCH] Show active supply routes in the new UI. --- qt_ui/widgets/map/mapmodel.py | 42 +++++++++++++++++++++++++++++++++++ resources/ui/map/map.js | 13 +++++++++-- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/qt_ui/widgets/map/mapmodel.py b/qt_ui/widgets/map/mapmodel.py index 4a406183..3bb471c9 100644 --- a/qt_ui/widgets/map/mapmodel.py +++ b/qt_ui/widgets/map/mapmodel.py @@ -20,6 +20,7 @@ from game.theater import ( FrontLine, LatLon, ) +from game.transfers import MultiGroupTransport, TransportMap from game.utils import meters, nautical_miles from gen.ato import AirTaskingOrder from gen.flights.flight import Flight, FlightWaypoint, FlightWaypointType @@ -254,6 +255,7 @@ class SupplyRouteJs(QObject): frontActiveChanged = Signal() isSeaChanged = Signal() blueChanged = Signal() + activeTransportsChanged = Signal() def __init__( self, @@ -261,12 +263,50 @@ class SupplyRouteJs(QObject): b: ControlPoint, points: List[LeafletLatLon], sea_route: bool, + game: Game, ) -> None: super().__init__() self.control_point_a = a self.control_point_b = b self._points = points self.sea_route = sea_route + self.game = game + + def find_in_transport_map( + self, transport_map: TransportMap + ) -> List[MultiGroupTransport]: + transports = [] + transport = transport_map.find_transport( + self.control_point_a, self.control_point_b + ) + if transport is not None: + transports.append(transport) + transport = transport_map.find_transport( + self.control_point_b, self.control_point_a + ) + if transport is not None: + transports.append(transport) + return transports + + def find_transports(self) -> List[MultiGroupTransport]: + if self.sea_route: + return self.find_in_transport_map(self.game.transfers.cargo_ships) + return self.find_in_transport_map(self.game.transfers.convoys) + + @Property(list, notify=activeTransportsChanged) + def activeTransports(self) -> List[str]: + transports = self.find_transports() + if not transports: + return [] + + descriptions = [] + for transport in transports: + units = "units" if transport.size > 1 else "unit" + descriptions.append( + f"{transport.size} {units} transferring from {transport.origin} to " + f"{transport.destination}" + ) + return descriptions @Property(list, notify=pointsChanged) def points(self) -> List[LeafletLatLon]: @@ -638,6 +678,7 @@ class MapModel(QObject): for p in convoy_route ], sea_route=False, + game=self.game, ) ) for destination, shipping_lane in control_point.shipping_lanes.items(): @@ -653,6 +694,7 @@ class MapModel(QObject): for p in shipping_lane ], sea_route=True, + game=self.game, ) ) self.supplyRoutesChanged.emit() diff --git a/resources/ui/map/map.js b/resources/ui/map/map.js index cc8e1f98..fc7f2b82 100644 --- a/resources/ui/map/map.js +++ b/resources/ui/map/map.js @@ -6,7 +6,6 @@ * - Navmeshes * - Time of day/weather themeing * - Exclusion zones - * - Supply route status * - "Actual" front line * - Debug flight plan drawing * - Icon variety @@ -384,10 +383,20 @@ function drawSupplyRoutes() { } else { color = "#8c1414"; } - L.polyline(route.points, { + const line = L.polyline(route.points, { color: color, weight: route.isSea ? 4 : 6, }).addTo(supplyRoutesLayer); + const activeTransports = route.activeTransports; + if (activeTransports.length > 0) { + line.bindTooltip(activeTransports.join("
")); + L.polyline(route.points, { + color: "#ffffff", + weight: 2, + }).addTo(supplyRoutesLayer); + } else { + line.bindTooltip("This supply route is inactive."); + } }); }