mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Make waypoints draggable.
This commit is contained in:
@@ -177,8 +177,6 @@ class PackageModel(QAbstractListModel):
|
||||
def set_tot(self, tot: datetime.timedelta) -> None:
|
||||
self.package.time_over_target = tot
|
||||
self.update_tot()
|
||||
# For some reason this is needed to make the UI update quickly.
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def set_asap(self, asap: bool) -> None:
|
||||
self.package.auto_asap = asap
|
||||
@@ -188,6 +186,8 @@ class PackageModel(QAbstractListModel):
|
||||
if self.package.auto_asap:
|
||||
self.package.set_tot_asap()
|
||||
self.tot_changed.emit()
|
||||
# For some reason this is needed to make the UI update quickly.
|
||||
self.layoutChanged.emit()
|
||||
|
||||
@property
|
||||
def mission_target(self) -> MissionTarget:
|
||||
@@ -291,6 +291,12 @@ class AtoModel(QAbstractListModel):
|
||||
"""Returns a model for the package at the given index."""
|
||||
return self.package_models.acquire(self.package_at_index(index))
|
||||
|
||||
def find_matching_package_model(self, package: Package) -> Optional[PackageModel]:
|
||||
for model in self.packages:
|
||||
if model.package == package:
|
||||
return model
|
||||
return None
|
||||
|
||||
@property
|
||||
def packages(self) -> Iterator[PackageModel]:
|
||||
"""Iterates over all the packages in the ATO."""
|
||||
@@ -376,6 +382,11 @@ class GameModel:
|
||||
self.ato_model = AtoModel(self, self.game.blue_ato)
|
||||
self.red_ato_model = AtoModel(self, self.game.red_ato)
|
||||
|
||||
def ato_model_for(self, player: bool) -> AtoModel:
|
||||
if player:
|
||||
return self.ato_model
|
||||
return self.red_ato_model
|
||||
|
||||
def set(self, game: Optional[Game]) -> None:
|
||||
"""Updates the managed Game object.
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ from gen.ato import AirTaskingOrder
|
||||
from gen.flights.flight import Flight, FlightWaypoint, FlightWaypointType
|
||||
from gen.flights.flightplan import FlightPlan, PatrollingFlightPlan
|
||||
from qt_ui.dialogs import Dialog
|
||||
from qt_ui.models import GameModel
|
||||
from qt_ui.models import GameModel, AtoModel
|
||||
from qt_ui.windows.GameUpdateSignal import GameUpdateSignal
|
||||
from qt_ui.windows.basemenu.QBaseMenu2 import QBaseMenu2
|
||||
from qt_ui.windows.groundobject.QGroundObjectMenu import QGroundObjectMenu
|
||||
@@ -316,20 +316,27 @@ class WaypointJs(QObject):
|
||||
altitudeReferenceChanged = Signal()
|
||||
nameChanged = Signal()
|
||||
timingChanged = Signal()
|
||||
isTakeoffChanged = Signal()
|
||||
isDivertChanged = Signal()
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
waypoint: FlightWaypoint,
|
||||
number: int,
|
||||
flight_plan: FlightPlan,
|
||||
flight: Flight,
|
||||
theater: ConflictTheater,
|
||||
ato_model: AtoModel,
|
||||
) -> None:
|
||||
super().__init__()
|
||||
self.waypoint = waypoint
|
||||
self._number = number
|
||||
self.flight_plan = flight_plan
|
||||
self.flight = flight
|
||||
self.theater = theater
|
||||
self.ato_model = ato_model
|
||||
|
||||
@property
|
||||
def flight_plan(self) -> FlightPlan:
|
||||
return self.flight.flight_plan
|
||||
|
||||
@Property(int, notify=numberChanged)
|
||||
def number(self) -> int:
|
||||
@@ -363,10 +370,26 @@ class WaypointJs(QObject):
|
||||
return ""
|
||||
return f"{prefix} T+{timedelta(seconds=int(time.total_seconds()))}"
|
||||
|
||||
@Property(bool, notify=isTakeoffChanged)
|
||||
def isTakeoff(self) -> bool:
|
||||
return self.waypoint.waypoint_type is FlightWaypointType.TAKEOFF
|
||||
|
||||
@Property(bool, notify=isDivertChanged)
|
||||
def isDivert(self) -> bool:
|
||||
return self.waypoint.waypoint_type is FlightWaypointType.DIVERT
|
||||
|
||||
@Slot(list, result=str)
|
||||
def setPosition(self, position: LeafletLatLon) -> str:
|
||||
point = self.theater.ll_to_point(LatLon(*position))
|
||||
self.waypoint.x = point.x
|
||||
self.waypoint.y = point.y
|
||||
package = self.ato_model.find_matching_package_model(self.flight.package)
|
||||
if package is None:
|
||||
return "Could not find package model containing modified flight"
|
||||
package.update_tot()
|
||||
self.positionChanged.emit()
|
||||
return ""
|
||||
|
||||
|
||||
class FlightJs(QObject):
|
||||
flightPlanChanged = Signal()
|
||||
@@ -375,16 +398,26 @@ class FlightJs(QObject):
|
||||
commitBoundaryChanged = Signal()
|
||||
|
||||
def __init__(
|
||||
self, flight: Flight, selected: bool, theater: ConflictTheater, faction: Faction
|
||||
self,
|
||||
flight: Flight,
|
||||
selected: bool,
|
||||
theater: ConflictTheater,
|
||||
faction: Faction,
|
||||
ato_model: AtoModel,
|
||||
) -> None:
|
||||
super().__init__()
|
||||
self.flight = flight
|
||||
self._selected = selected
|
||||
self.theater = theater
|
||||
self.faction = faction
|
||||
self.ato_model = ato_model
|
||||
self._waypoints = self.make_waypoints()
|
||||
self._commit_boundary = self.make_commit_boundary()
|
||||
|
||||
def update_waypoints(self) -> None:
|
||||
for waypoint in self._waypoints:
|
||||
waypoint.timingChanged.emit()
|
||||
|
||||
def make_waypoints(self) -> List[WaypointJs]:
|
||||
departure = FlightWaypoint(
|
||||
FlightWaypointType.TAKEOFF,
|
||||
@@ -393,10 +426,12 @@ class FlightJs(QObject):
|
||||
meters(0),
|
||||
)
|
||||
departure.alt_type = "RADIO"
|
||||
return [
|
||||
WaypointJs(p, i, self.flight.flight_plan, self.theater)
|
||||
for i, p in enumerate([departure] + self.flight.points)
|
||||
]
|
||||
waypoints = []
|
||||
for idx, point in enumerate([departure] + self.flight.points):
|
||||
waypoint = WaypointJs(point, idx, self.flight, self.theater, self.ato_model)
|
||||
waypoint.positionChanged.connect(self.update_waypoints)
|
||||
waypoints.append(waypoint)
|
||||
return waypoints
|
||||
|
||||
def make_commit_boundary(self) -> Optional[List[LeafletLatLon]]:
|
||||
if not isinstance(self.flight.flight_plan, PatrollingFlightPlan):
|
||||
@@ -533,6 +568,7 @@ class MapModel(QObject):
|
||||
selected=blue and (p_idx, f_idx) == self._selected_flight_index,
|
||||
theater=self.game.theater,
|
||||
faction=self.game.faction_for(blue),
|
||||
ato_model=self.game_model.ato_model_for(blue),
|
||||
)
|
||||
)
|
||||
return flights
|
||||
|
||||
Reference in New Issue
Block a user