Replace mission planning UI.

Mission planning has been completely redone. Missions are now planned
by right clicking the target area and choosing "New package".

A package can include multiple flights for the same objective. Right
now the automatic flight planner is only fragging single-flight
packages in the same manner that it used to, but that can be improved
now.

The air tasking order (ATO) is now the left bar of the main UI. This
shows every fragged package, and the flights in the selected package.
The info bar that was previously on the left is now a smaller bar at
the bottom of the screen. The old "Mission Planning" button is now
just the "Take Off" button.

The flight plan display no longer shows enemy flight plans. That could
be re-added if needed, probably with a difficulty/cheat option.

Aircraft inventories have been disassociated from the Planner class.
Aircraft inventories are now stored globally in the Game object.

Save games made prior to this update will not be compatible do to the
changes in how aircraft inventories and planned flights are stored.
This commit is contained in:
Dan Albert
2020-09-13 14:32:47 -07:00
parent 0eee5747af
commit ff083942e8
38 changed files with 1807 additions and 695 deletions

View File

@@ -0,0 +1,13 @@
"""Spin box for selecting the number of aircraft in a flight."""
from PySide2.QtWidgets import QSpinBox
class QFlightSizeSpinner(QSpinBox):
"""Spin box for selecting the number of aircraft in a flight."""
def __init__(self, min_size: int = 1, max_size: int = 4,
default_size: int = 2) -> None:
super().__init__()
self.setMinimum(min_size)
self.setMaximum(max_size)
self.setValue(default_size)

View File

@@ -0,0 +1,17 @@
"""A layout containing a widget with an associated label."""
from PySide2.QtCore import Qt
from PySide2.QtWidgets import QHBoxLayout, QLabel, QWidget
class QLabeledWidget(QHBoxLayout):
"""A layout containing a widget with an associated label.
Best used for vertical forms, where the given widget is the input and the
label is used to name the input.
"""
def __init__(self, text: str, widget: QWidget) -> None:
super().__init__()
self.addWidget(QLabel(text))
self.addStretch()
self.addWidget(widget, alignment=Qt.AlignRight)

View File

@@ -1,16 +1,15 @@
from PySide2.QtWidgets import QFrame, QHBoxLayout, QPushButton, QVBoxLayout, QGroupBox
from game import Game
from qt_ui.widgets.QBudgetBox import QBudgetBox
from qt_ui.widgets.QFactionsInfos import QFactionsInfos
from qt_ui.windows.finances.QFinancesMenu import QFinancesMenu
from qt_ui.windows.stats.QStatsWindow import QStatsWindow
from qt_ui.widgets.QTurnCounter import QTurnCounter
from PySide2.QtWidgets import QFrame, QGroupBox, QHBoxLayout, QPushButton
import qt_ui.uiconstants as CONST
from game import Game
from game.event import CAP, CAS, FrontlineAttackEvent
from qt_ui.widgets.QBudgetBox import QBudgetBox
from qt_ui.widgets.QFactionsInfos import QFactionsInfos
from qt_ui.widgets.QTurnCounter import QTurnCounter
from qt_ui.windows.GameUpdateSignal import GameUpdateSignal
from qt_ui.windows.mission.QMissionPlanning import QMissionPlanning
from qt_ui.windows.settings.QSettingsWindow import QSettingsWindow
from qt_ui.windows.stats.QStatsWindow import QStatsWindow
from qt_ui.windows.QWaitingForMissionResultWindow import QWaitingForMissionResultWindow
class QTopPanel(QFrame):
@@ -33,10 +32,10 @@ class QTopPanel(QFrame):
self.passTurnButton.setProperty("style", "btn-primary")
self.passTurnButton.clicked.connect(self.passTurn)
self.proceedButton = QPushButton("Mission Planning")
self.proceedButton = QPushButton("Take off")
self.proceedButton.setIcon(CONST.ICONS["Proceed"])
self.proceedButton.setProperty("style", "btn-success")
self.proceedButton.clicked.connect(self.proceed)
self.proceedButton.setProperty("style", "start-button")
self.proceedButton.clicked.connect(self.launch_mission)
if self.game and self.game.turn == 0:
self.proceedButton.setEnabled(False)
@@ -100,9 +99,31 @@ class QTopPanel(QFrame):
GameUpdateSignal.get_instance().updateGame(self.game)
self.proceedButton.setEnabled(True)
def proceed(self):
self.subwindow = QMissionPlanning(self.game)
self.subwindow.show()
def launch_mission(self):
"""Finishes planning and waits for mission completion."""
# TODO: Refactor this nonsense.
game_event = None
for event in self.game.events:
if isinstance(event,
FrontlineAttackEvent) and event.is_player_attacking:
game_event = event
if game_event is None:
game_event = FrontlineAttackEvent(
self.game,
self.game.theater.controlpoints[0],
self.game.theater.controlpoints[0],
self.game.theater.controlpoints[0].position,
self.game.player_name,
self.game.enemy_name)
game_event.is_awacs_enabled = True
game_event.ca_slots = 1
game_event.departure_cp = self.game.theater.controlpoints[0]
game_event.player_attacking({CAS: {}, CAP: {}})
game_event.depart_from = self.game.theater.controlpoints[0]
self.game.initiate_event(game_event)
waiting = QWaitingForMissionResultWindow(game_event, self.game)
waiting.show()
def budget_update(self, game:Game):
self.budgetBox.setGame(game)

249
qt_ui/widgets/ato.py Normal file
View File

@@ -0,0 +1,249 @@
"""Widgets for displaying air tasking orders."""
import logging
from typing import Optional
from PySide2.QtCore import QItemSelectionModel, QModelIndex, QSize, Qt
from PySide2.QtWidgets import (
QAbstractItemView,
QGroupBox,
QHBoxLayout,
QListView,
QPushButton,
QSplitter,
QVBoxLayout,
)
from gen.ato import Package
from gen.flights.flight import Flight
from ..models import AtoModel, GameModel, NullListModel, PackageModel
class QFlightList(QListView):
"""List view for displaying the flights of a package."""
def __init__(self, model: Optional[PackageModel]) -> None:
super().__init__()
self.package_model = model
self.set_package(model)
self.setIconSize(QSize(91, 24))
self.setSelectionBehavior(QAbstractItemView.SelectItems)
def set_package(self, model: Optional[PackageModel]) -> None:
"""Sets the package model to display."""
if model is None:
self.disconnect_model()
else:
self.package_model = model
self.setModel(model)
# noinspection PyUnresolvedReferences
model.deleted.connect(self.disconnect_model)
self.selectionModel().setCurrentIndex(
model.index(0, 0, QModelIndex()),
QItemSelectionModel.Select
)
def disconnect_model(self) -> None:
"""Clears the listview of any model attachments.
Displays an empty list until set_package is called with a valid model.
"""
model = self.model()
if model is not None and isinstance(model, PackageModel):
model.deleted.disconnect(self.disconnect_model)
self.setModel(NullListModel())
@property
def selected_item(self) -> Optional[Flight]:
"""Returns the selected flight, if any."""
index = self.currentIndex()
if not index.isValid():
return None
return self.package_model.flight_at_index(index)
class QFlightPanel(QGroupBox):
"""The flight display portion of the ATO panel.
Displays the flights assigned to the selected package, and includes edit and
delete buttons for flight management.
"""
def __init__(self, game_model: GameModel,
package_model: Optional[PackageModel] = None) -> None:
super().__init__("Flights")
self.game_model = game_model
self.package_model = package_model
self.vbox = QVBoxLayout()
self.setLayout(self.vbox)
self.flight_list = QFlightList(package_model)
self.vbox.addWidget(self.flight_list)
self.button_row = QHBoxLayout()
self.vbox.addLayout(self.button_row)
self.edit_button = QPushButton("Edit")
self.edit_button.clicked.connect(self.on_edit)
self.button_row.addWidget(self.edit_button)
self.delete_button = QPushButton("Delete")
# noinspection PyTypeChecker
self.delete_button.setProperty("style", "btn-danger")
self.delete_button.clicked.connect(self.on_delete)
self.button_row.addWidget(self.delete_button)
self.selection_changed.connect(self.on_selection_changed)
self.on_selection_changed()
def set_package(self, model: Optional[PackageModel]) -> None:
"""Sets the package model to display."""
self.package_model = model
self.flight_list.set_package(model)
self.on_selection_changed()
@property
def selection_changed(self):
"""Returns the signal emitted when the flight selection changes."""
return self.flight_list.selectionModel().selectionChanged
def on_selection_changed(self) -> None:
"""Updates the status of the edit and delete buttons."""
index = self.flight_list.currentIndex()
enabled = index.isValid()
self.edit_button.setEnabled(enabled)
self.delete_button.setEnabled(enabled)
def on_edit(self) -> None:
"""Opens the flight edit dialog."""
index = self.flight_list.currentIndex()
if not index.isValid():
logging.error(f"Cannot edit flight when no flight is selected.")
return
from qt_ui.dialogs import Dialog
Dialog.open_edit_flight_dialog(
self.package_model.flight_at_index(index)
)
def on_delete(self) -> None:
"""Removes the selected flight from the package."""
index = self.flight_list.currentIndex()
if not index.isValid():
logging.error(f"Cannot delete flight when no flight is selected.")
return
self.game_model.game.aircraft_inventory.return_from_flight(
self.flight_list.selected_item)
self.package_model.delete_flight_at_index(index)
class QPackageList(QListView):
"""List view for displaying the packages of an ATO."""
def __init__(self, model: AtoModel) -> None:
super().__init__()
self.ato_model = model
self.setModel(model)
self.setIconSize(QSize(91, 24))
self.setSelectionBehavior(QAbstractItemView.SelectItems)
@property
def selected_item(self) -> Optional[Package]:
"""Returns the selected package, if any."""
index = self.currentIndex()
if not index.isValid():
return None
return self.ato_model.package_at_index(index)
class QPackagePanel(QGroupBox):
"""The package display portion of the ATO panel.
Displays the package assigned to the player's ATO, and includes edit and
delete buttons for package management.
"""
def __init__(self, model: AtoModel) -> None:
super().__init__("Packages")
self.ato_model = model
self.ato_model.layoutChanged.connect(self.on_selection_changed)
self.vbox = QVBoxLayout()
self.setLayout(self.vbox)
self.package_list = QPackageList(self.ato_model)
self.vbox.addWidget(self.package_list)
self.button_row = QHBoxLayout()
self.vbox.addLayout(self.button_row)
self.edit_button = QPushButton("Edit")
self.edit_button.clicked.connect(self.on_edit)
self.button_row.addWidget(self.edit_button)
self.delete_button = QPushButton("Delete")
# noinspection PyTypeChecker
self.delete_button.setProperty("style", "btn-danger")
self.delete_button.clicked.connect(self.on_delete)
self.button_row.addWidget(self.delete_button)
self.selection_changed.connect(self.on_selection_changed)
self.on_selection_changed()
@property
def selection_changed(self):
"""Returns the signal emitted when the flight selection changes."""
return self.package_list.selectionModel().selectionChanged
def on_selection_changed(self) -> None:
"""Updates the status of the edit and delete buttons."""
index = self.package_list.currentIndex()
enabled = index.isValid()
self.edit_button.setEnabled(enabled)
self.delete_button.setEnabled(enabled)
def on_edit(self) -> None:
"""Opens the package edit dialog."""
index = self.package_list.currentIndex()
if not index.isValid():
logging.error(f"Cannot edit package when no package is selected.")
return
from qt_ui.dialogs import Dialog
Dialog.open_edit_package_dialog(self.ato_model.get_package_model(index))
def on_delete(self) -> None:
"""Removes the package from the ATO."""
index = self.package_list.currentIndex()
if not index.isValid():
logging.error(f"Cannot delete package when no package is selected.")
return
self.ato_model.delete_package_at_index(index)
class QAirTaskingOrderPanel(QSplitter):
"""A split panel for displaying the packages and flights of an ATO.
Used as the left-bar of the main UI. The top half of the panel displays the
packages of the player's ATO, and the bottom half displays the flights of
the selected package.
"""
def __init__(self, game_model: GameModel) -> None:
super().__init__(Qt.Vertical)
self.ato_model = game_model.ato_model
self.package_panel = QPackagePanel(self.ato_model)
self.package_panel.selection_changed.connect(self.on_package_change)
self.ato_model.rowsInserted.connect(self.on_package_change)
self.addWidget(self.package_panel)
self.flight_panel = QFlightPanel(game_model)
self.addWidget(self.flight_panel)
def on_package_change(self) -> None:
"""Sets the newly selected flight for display in the bottom panel."""
index = self.package_panel.package_list.currentIndex()
if index.isValid():
self.flight_panel.set_package(
self.ato_model.get_package_model(index)
)
else:
self.flight_panel.set_package(None)

View File

@@ -0,0 +1,16 @@
"""Combo box for selecting aircraft types."""
from typing import Iterable
from PySide2.QtWidgets import QComboBox
from dcs.planes import PlaneType
class QAircraftTypeSelector(QComboBox):
"""Combo box for selecting among the given aircraft types."""
def __init__(self, aircraft_types: Iterable[PlaneType]) -> None:
super().__init__()
for aircraft in aircraft_types:
self.addItem(f"{aircraft.id}", userData=aircraft)
self.model().sort(0)

View File

@@ -0,0 +1,22 @@
"""Combo box for selecting a flight's task type."""
from PySide2.QtWidgets import QComboBox
from gen.flights.flight import FlightType
class QFlightTypeComboBox(QComboBox):
"""Combo box for selecting a flight task type."""
def __init__(self) -> None:
super().__init__()
self.addItem("CAP [Combat Air Patrol]", userData=FlightType.CAP)
self.addItem("BARCAP [Barrier Combat Air Patrol]", userData=FlightType.BARCAP)
self.addItem("TARCAP [Target Combat Air Patrol]", userData=FlightType.TARCAP)
self.addItem("INTERCEPT [Interception]", userData=FlightType.INTERCEPTION)
self.addItem("CAS [Close Air Support]", userData=FlightType.CAS)
self.addItem("BAI [Battlefield Interdiction]", userData=FlightType.BAI)
self.addItem("SEAD [Suppression of Enemy Air Defenses]", userData=FlightType.SEAD)
self.addItem("DEAD [Destruction of Enemy Air Defenses]", userData=FlightType.DEAD)
self.addItem("STRIKE [Strike]", userData=FlightType.STRIKE)
self.addItem("ANTISHIP [Antiship Attack]", userData=FlightType.ANTISHIP)
self.model().sort(0)

View File

@@ -0,0 +1,41 @@
"""Combo box for selecting a departure airfield."""
from typing import Iterable
from PySide2.QtWidgets import QComboBox
from dcs.planes import PlaneType
from game.inventory import GlobalAircraftInventory
from theater.controlpoint import ControlPoint
class QOriginAirfieldSelector(QComboBox):
"""A combo box for selecting a flight's departure airfield.
The combo box will automatically be populated with all departure airfields
that have unassigned inventory of the given aircraft type.
"""
def __init__(self, global_inventory: GlobalAircraftInventory,
origins: Iterable[ControlPoint],
aircraft: PlaneType) -> None:
super().__init__()
self.global_inventory = global_inventory
self.origins = list(origins)
self.aircraft = aircraft
self.rebuild_selector()
def change_aircraft(self, aircraft: PlaneType) -> None:
if self.aircraft == aircraft:
return
self.aircraft = aircraft
self.rebuild_selector()
def rebuild_selector(self) -> None:
self.clear()
for origin in self.origins:
inventory = self.global_inventory.for_control_point(origin)
available = inventory.available(self.aircraft)
if available:
self.addItem(f"{origin.name} ({available} available)", origin)
self.model().sort(0)
self.update()

View File

@@ -17,6 +17,7 @@ from game import Game, db
from game.data.radar_db import UNITS_WITH_RADAR
from gen import Conflict
from gen.flights.flight import Flight
from qt_ui.models import GameModel
from qt_ui.widgets.map.QLiberationScene import QLiberationScene
from qt_ui.widgets.map.QMapControlPoint import QMapControlPoint
from qt_ui.widgets.map.QMapGroundObject import QMapGroundObject
@@ -37,9 +38,10 @@ class QLiberationMap(QGraphicsView):
"flight_paths": False
}
def __init__(self, game: Game):
def __init__(self, game_model: GameModel):
super(QLiberationMap, self).__init__()
QLiberationMap.instance = self
self.game_model = game_model
self.frontline_vector_cache = {}
@@ -50,7 +52,7 @@ class QLiberationMap(QGraphicsView):
self.factorized = 1
self.init_scene()
self.connectSignals()
self.setGame(game)
self.setGame(game_model.game)
def init_scene(self):
scene = QLiberationScene(self)
@@ -129,8 +131,10 @@ class QLiberationMap(QGraphicsView):
pos = self._transform_point(cp.position)
scene.addItem(QMapControlPoint(self, pos[0] - CONST.CP_SIZE / 2, pos[1] - CONST.CP_SIZE / 2, CONST.CP_SIZE,
CONST.CP_SIZE, cp, self.game))
scene.addItem(QMapControlPoint(self, pos[0] - CONST.CP_SIZE / 2,
pos[1] - CONST.CP_SIZE / 2,
CONST.CP_SIZE,
CONST.CP_SIZE, cp, self.game_model))
if cp.captured:
pen = QPen(brush=CONST.COLORS[playerColor])
@@ -185,11 +189,9 @@ class QLiberationMap(QGraphicsView):
text.setPos(pos[0] + CONST.CP_SIZE + 1, pos[1] - CONST.CP_SIZE / 2 + 1)
def draw_flight_plans(self, scene) -> None:
for cp in self.game.theater.controlpoints:
if cp.id in self.game.planners:
planner = self.game.planners[cp.id]
for flight in planner.flights:
self.draw_flight_plan(scene, flight)
for package in self.game_model.ato_model.packages:
for flight in package.flights:
self.draw_flight_plan(scene, flight)
def draw_flight_plan(self, scene: QGraphicsScene, flight: Flight) -> None:
is_player = flight.from_cp.captured

View File

@@ -1,29 +1,23 @@
from typing import Optional
from PySide2.QtGui import QColor, QPainter
from PySide2.QtWidgets import (
QAction,
QGraphicsSceneContextMenuEvent,
QMenu,
)
import qt_ui.uiconstants as const
from game import Game
from qt_ui.models import GameModel
from qt_ui.windows.basemenu.QBaseMenu2 import QBaseMenu2
from theater import ControlPoint
from .QMapObject import QMapObject
class QMapControlPoint(QMapObject):
def __init__(self, parent, x: float, y: float, w: float, h: float,
model: ControlPoint, game: Game) -> None:
super().__init__(x, y, w, h)
self.model = model
self.game = game
control_point: ControlPoint, game_model: GameModel) -> None:
super().__init__(x, y, w, h, mission_target=control_point)
self.game_model = game_model
self.control_point = control_point
self.parent = parent
self.setZValue(1)
self.setToolTip(self.model.name)
self.setToolTip(self.control_point.name)
self.base_details_dialog: Optional[QBaseMenu2] = None
def paint(self, painter, option, widget=None) -> None:
@@ -33,7 +27,7 @@ class QMapControlPoint(QMapObject):
painter.setBrush(self.brush_color)
painter.setPen(self.pen_color)
if self.model.has_runway():
if self.control_point.has_runway():
if self.isUnderMouse():
painter.setBrush(const.COLORS["white"])
painter.setPen(self.pen_color)
@@ -44,22 +38,9 @@ class QMapControlPoint(QMapObject):
# Either don't draw them at all, or perhaps use a sunk ship icon.
painter.restore()
def contextMenuEvent(self, event: QGraphicsSceneContextMenuEvent) -> None:
if self.model.captured:
text = "Open base menu"
else:
text = "Open intel menu"
open_menu = QAction(text)
open_menu.triggered.connect(self.on_click)
menu = QMenu("Menu", self.parent)
menu.addAction(open_menu)
menu.exec_(event.screenPos())
@property
def brush_color(self) -> QColor:
if self.model.captured:
if self.control_point.captured:
return const.COLORS["blue"]
else:
return const.COLORS["super_red"]
@@ -68,10 +49,17 @@ class QMapControlPoint(QMapObject):
def pen_color(self) -> QColor:
return const.COLORS["white"]
@property
def object_dialog_text(self) -> str:
if self.control_point.captured:
return "Open base menu"
else:
return "Open intel menu"
def on_click(self) -> None:
self.base_details_dialog = QBaseMenu2(
self.window(),
self.model,
self.game
self.control_point,
self.game_model
)
self.base_details_dialog.show()

View File

@@ -14,11 +14,12 @@ from .QMapObject import QMapObject
class QMapGroundObject(QMapObject):
def __init__(self, parent, x: float, y: float, w: float, h: float,
cp: ControlPoint, model: TheaterGroundObject, game: Game,
control_point: ControlPoint,
ground_object: TheaterGroundObject, game: Game,
buildings: Optional[List[TheaterGroundObject]] = None) -> None:
super().__init__(x, y, w, h)
self.model = model
self.cp = cp
super().__init__(x, y, w, h, mission_target=ground_object)
self.ground_object = ground_object
self.control_point = control_point
self.parent = parent
self.game = game
self.setZValue(2)
@@ -26,21 +27,20 @@ class QMapGroundObject(QMapObject):
self.setFlag(QGraphicsItem.ItemIgnoresTransformations, False)
self.ground_object_dialog: Optional[QGroundObjectMenu] = None
if len(self.model.groups) > 0:
if self.ground_object.groups:
units = {}
for g in self.model.groups:
print(g)
for g in self.ground_object.groups:
for u in g.units:
if u.type in units:
units[u.type] = units[u.type]+1
else:
units[u.type] = 1
tooltip = "[" + self.model.obj_name + "]" + "\n"
tooltip = "[" + self.ground_object.obj_name + "]" + "\n"
for unit in units.keys():
tooltip = tooltip + str(unit) + "x" + str(units[unit]) + "\n"
self.setToolTip(tooltip[:-1])
else:
tooltip = "[" + self.model.obj_name + "]" + "\n"
tooltip = "[" + self.ground_object.obj_name + "]" + "\n"
for building in buildings:
if not building.is_dead:
tooltip = tooltip + str(building.dcs_identifier) + "\n"
@@ -53,20 +53,20 @@ class QMapGroundObject(QMapObject):
if self.parent.get_display_rule("go"):
painter.save()
cat = self.model.category
if cat == "aa" and self.model.sea_object:
cat = self.ground_object.category
if cat == "aa" and self.ground_object.sea_object:
cat = "ship"
rect = QRect(option.rect.x() + 2, option.rect.y(),
option.rect.width() - 2, option.rect.height())
is_dead = self.model.is_dead
is_dead = self.ground_object.is_dead
for building in self.buildings:
if not building.is_dead:
is_dead = False
break
if not is_dead and not self.cp.captured:
if not is_dead and not self.control_point.captured:
painter.drawPixmap(rect, const.ICONS[cat + enemy_icons])
elif not is_dead:
painter.drawPixmap(rect, const.ICONS[cat + player_icons])
@@ -80,7 +80,7 @@ class QMapGroundObject(QMapObject):
units_alive = 0
units_dead = 0
if len(self.model.groups) == 0:
if len(self.ground_object.groups) == 0:
for building in self.buildings:
if building.dcs_identifier in FORTIFICATION_BUILDINGS:
continue
@@ -89,7 +89,7 @@ class QMapGroundObject(QMapObject):
else:
units_alive += 1
for g in self.model.groups:
for g in self.ground_object.groups:
units_alive += len(g.units)
if hasattr(g, "units_losts"):
units_dead += len(g.units_losts)
@@ -106,9 +106,9 @@ class QMapGroundObject(QMapObject):
def on_click(self) -> None:
self.ground_object_dialog = QGroundObjectMenu(
self.window(),
self.model,
self.ground_object,
self.buildings,
self.cp,
self.control_point,
self.game
)
self.ground_object_dialog.show()

View File

@@ -1,11 +1,20 @@
"""Common base for objects drawn on the game map."""
from typing import Optional
from PySide2.QtCore import Qt
from PySide2.QtWidgets import (
QAction,
QGraphicsRectItem,
QGraphicsSceneContextMenuEvent,
QGraphicsSceneHoverEvent,
QGraphicsSceneMouseEvent,
QMenu,
)
from qt_ui.dialogs import Dialog
from qt_ui.windows.mission.QPackageDialog import QNewPackageDialog
from theater.missiontarget import MissionTarget
class QMapObject(QGraphicsRectItem):
"""Base class for objects drawn on the game map.
@@ -13,8 +22,12 @@ class QMapObject(QGraphicsRectItem):
Game map objects have an on_click behavior that triggers on left click, and
change the mouse cursor on hover.
"""
def __init__(self, x: float, y: float, w: float, h: float):
def __init__(self, x: float, y: float, w: float, h: float,
mission_target: MissionTarget) -> None:
super().__init__(x, y, w, h)
self.mission_target = mission_target
self.new_package_dialog: Optional[QNewPackageDialog] = None
self.setAcceptHoverEvents(True)
def hoverEnterEvent(self, event: QGraphicsSceneHoverEvent):
@@ -24,5 +37,39 @@ class QMapObject(QGraphicsRectItem):
if event.button() == Qt.LeftButton:
self.on_click()
def contextMenuEvent(self, event: QGraphicsSceneContextMenuEvent) -> None:
menu = QMenu("Menu", self.parent)
object_details_action = QAction(self.object_dialog_text)
object_details_action.triggered.connect(self.on_click)
menu.addAction(object_details_action)
new_package_action = QAction(f"New package")
new_package_action.triggered.connect(self.open_new_package_dialog)
menu.addAction(new_package_action)
menu.exec_(event.screenPos())
@property
def object_dialog_text(self) -> str:
"""Text to for the object's dialog in the context menu.
Right clicking a map object will open a context menu and the first item
will open the details dialog for this object. This menu action has the
same behavior as the on_click event.
Return:
The text that should be displayed for the menu item.
"""
return "Details"
def on_click(self) -> None:
"""The action to take when this map object is left-clicked.
Typically this should open a details view of the object.
"""
raise NotImplementedError
def open_new_package_dialog(self) -> None:
"""Opens the dialog for planning a new mission package."""
Dialog.open_new_package_dialog(self.mission_target)