Allow deleting waypoints.

In almost every case this leaves us with a flight plan we can't reason
about, so it gets degraded to `CustomFlightPlan`. The exception is when
deleting a target point when there are other target points remaining.
This probably gets people using this feature back to what they want
though, which is essentially the 2.1 behavior.

Fixes https://github.com/Khopa/dcs_liberation/issues/393
This commit is contained in:
Dan Albert
2020-11-18 23:40:18 -08:00
parent 2d56ae1cb6
commit a816877d08
2 changed files with 36 additions and 8 deletions

View File

@@ -12,8 +12,12 @@ from PySide2.QtWidgets import (
from game import Game
from gen.ato import Package
from gen.flights.flight import Flight, FlightType
from gen.flights.flightplan import FlightPlanBuilder
from gen.flights.flight import Flight, FlightType, FlightWaypoint
from gen.flights.flightplan import (
CustomFlightPlan,
FlightPlanBuilder,
StrikeFlightPlan,
)
from qt_ui.windows.mission.flight.waypoints.QFlightWaypointList import \
QFlightWaypointList
from qt_ui.windows.mission.flight.waypoints\
@@ -103,10 +107,30 @@ class QFlightWaypointTab(QFrame):
def on_delete_waypoint(self):
wpt = self.flight_waypoint_list.selectionModel().currentIndex().row()
if wpt > 0:
del self.flight.points[wpt-1]
self.delete_waypoint(self.flight.flight_plan.waypoints[wpt])
self.flight_waypoint_list.update_list()
self.on_change()
def delete_waypoint(self, waypoint: FlightWaypoint) -> None:
# Need to degrade to a custom flight plan and remove the waypoint.
# If the waypoint is a target waypoint and is not the last target
# waypoint, we don't need to degrade.
flight_plan = self.flight.flight_plan
if isinstance(flight_plan, StrikeFlightPlan):
if waypoint in flight_plan.targets and len(flight_plan.targets) > 1:
flight_plan.targets.remove(waypoint)
return
if not isinstance(flight_plan, CustomFlightPlan):
flight_plan = CustomFlightPlan(
package=self.flight.package,
flight=self.flight,
custom_waypoints=flight_plan.waypoints
)
flight_plan.waypoints.remove(waypoint)
self.flight.flight_plan = flight_plan
def on_fast_waypoint(self):
self.subwindow = QPredefinedWaypointSelectionWindow(self.game, self.flight, self.flight_waypoint_list)
self.subwindow.finished.connect(self.on_change)