diff --git a/qt_ui/widgets/map/mapmodel.py b/qt_ui/widgets/map/mapmodel.py index 1651db67..dd821202 100644 --- a/qt_ui/widgets/map/mapmodel.py +++ b/qt_ui/widgets/map/mapmodel.py @@ -606,6 +606,14 @@ class FlightJs(QObject): def selected(self) -> bool: return self._selected + @Slot(result=bool) + def flightIsInAto(self) -> bool: + if self.flight.package not in self.flight.squadron.coalition.ato.packages: + return False + if self.flight not in self.flight.package.flights: + return False + return True + def set_selected(self, value: bool) -> None: self._selected = value self.selectedChanged.emit() @@ -1186,19 +1194,14 @@ class MapModel(QObject): ) return flights - def _get_selected_flight(self) -> Optional[Flight]: - for p_idx, package in enumerate(self.game.blue.ato.packages): - for f_idx, flight in enumerate(package.flights): - if (p_idx, f_idx) == self._selected_flight_index: - return flight - return None - def reset_atos(self) -> None: self._flights = self._flights_in_ato( self.game.blue.ato, blue=True ) | self._flights_in_ato(self.game.red.ato, blue=False) self.flightsChanged.emit() - selected_flight = self._get_selected_flight() + selected_flight = None + if self._selected_flight is not None: + selected_flight = self._selected_flight.flight if selected_flight is None: self._ip_zones = IpZonesJs.empty() self._join_zones = JoinZonesJs.empty() diff --git a/resources/ui/map/map.js b/resources/ui/map/map.js index 7e7e2fba..620c95e6 100644 --- a/resources/ui/map/map.js +++ b/resources/ui/map/map.js @@ -892,20 +892,34 @@ class Flight { } drawFlightPlan() { - const path = []; - this.flightPlan.forEach((waypoint) => { - if (waypoint.includeInPath()) { - path.push(waypoint.position()); + this.flight.flightIsInAto().then((inAto) => { + if (!inAto) { + // HACK: The signal to redraw the ATO following package/flight deletion + // and the signal to change flight/package selection due to UI selection + // change come in an arbitrary order. If redraw signal comes first the UI + // will clear the map and redraw, but then when the UI updates selection + // away from the (now deleted) flight/package it calls deselect, which + // redraws the deleted flight plan in its deselected state. + // + // Avoid this by checking that the flight is still in the coalition's ATO + // before drawing. + return; } - if (this.shouldMark(waypoint)) { - waypoint.marker - .addTo(selectedFlightPlansLayer) - .addTo(this.flightPlanLayer()) - .addTo(allFlightPlansLayer); - } - }); + const path = []; + this.flightPlan.forEach((waypoint) => { + if (waypoint.includeInPath()) { + path.push(waypoint.position()); + } + if (this.shouldMark(waypoint)) { + waypoint.marker + .addTo(selectedFlightPlansLayer) + .addTo(this.flightPlanLayer()) + .addTo(allFlightPlansLayer); + } + }); - this.drawPath(path); + this.drawPath(path); + }); } }