Allow setting CV routes in the new UI.

This is a pretty janky system until we get add context menu support. For
now the destination is set by dragging the CV marker and cleared by
right clicking the destination marker. Once we have a context menu a
context action will begin setting the destination the way it did in the
old UI, and the destination marker will be draggable.
This commit is contained in:
Dan Albert
2021-05-15 03:33:55 -07:00
parent 4a096cb728
commit 31fa2d866f
2 changed files with 147 additions and 14 deletions

View File

@@ -16,6 +16,7 @@ from game.theater import (
ControlPoint,
TheaterGroundObject,
FrontLine,
LatLon,
)
from game.utils import meters, nautical_miles
from gen.ato import AirTaskingOrder
@@ -57,6 +58,8 @@ class ControlPointJs(QObject):
nameChanged = Signal()
blueChanged = Signal()
positionChanged = Signal()
mobileChanged = Signal()
destinationChanged = Signal(list)
def __init__(
self,
@@ -83,6 +86,42 @@ class ControlPointJs(QObject):
ll = self.theater.point_to_ll(self.control_point.position)
return [ll.latitude, ll.longitude]
@Property(bool, notify=mobileChanged)
def mobile(self) -> bool:
return self.control_point.moveable and self.control_point.captured
@Property(list, notify=destinationChanged)
def destination(self) -> LeafletLatLon:
if self.control_point.target_position is None:
# Qt seems to convert None to [] for list Properties :(
return []
return self.theater.point_to_ll(self.control_point.target_position).as_list()
@Slot(list, result=str)
def setDestination(self, destination: LeafletLatLon) -> str:
if not self.control_point.moveable:
return f"{self.control_point} is not mobile"
if not self.control_point.captured:
return f"{self.control_point} is not owned by player"
point = self.theater.ll_to_point(LatLon(*destination))
from qt_ui.widgets.map.QLiberationMap import MAX_SHIP_DISTANCE
move_distance = meters(point.distance_to_point(self.control_point.position))
if move_distance > MAX_SHIP_DISTANCE:
return (
f"Cannot move {self.control_point} more than "
f"{MAX_SHIP_DISTANCE.nautical_miles}nm. Attempted "
f"{move_distance.nautical_miles}nm"
)
self.control_point.target_position = point
self.destinationChanged.emit(destination)
return ""
@Slot()
def cancelTravel(self) -> None:
self.control_point.target_position = None
self.destinationChanged.emit([])
@Slot()
def showInfoDialog(self) -> None:
if self.dialog is None: