mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Redraw flight plans when they change.
This commit is contained in:
parent
1e041b6249
commit
aa309af015
@ -16,6 +16,7 @@ from PySide2.QtWidgets import (
|
|||||||
from gen.ato import Package
|
from gen.ato import Package
|
||||||
from gen.flights.flight import Flight
|
from gen.flights.flight import Flight
|
||||||
from ..models import AtoModel, GameModel, NullListModel, PackageModel
|
from ..models import AtoModel, GameModel, NullListModel, PackageModel
|
||||||
|
from qt_ui.windows.GameUpdateSignal import GameUpdateSignal
|
||||||
|
|
||||||
|
|
||||||
class QFlightList(QListView):
|
class QFlightList(QListView):
|
||||||
@ -134,6 +135,7 @@ class QFlightPanel(QGroupBox):
|
|||||||
self.game_model.game.aircraft_inventory.return_from_flight(
|
self.game_model.game.aircraft_inventory.return_from_flight(
|
||||||
self.flight_list.selected_item)
|
self.flight_list.selected_item)
|
||||||
self.package_model.delete_flight_at_index(index)
|
self.package_model.delete_flight_at_index(index)
|
||||||
|
GameUpdateSignal.get_instance().redraw_flight_paths()
|
||||||
|
|
||||||
|
|
||||||
class QPackageList(QListView):
|
class QPackageList(QListView):
|
||||||
@ -217,6 +219,7 @@ class QPackagePanel(QGroupBox):
|
|||||||
logging.error(f"Cannot delete package when no package is selected.")
|
logging.error(f"Cannot delete package when no package is selected.")
|
||||||
return
|
return
|
||||||
self.ato_model.delete_package_at_index(index)
|
self.ato_model.delete_package_at_index(index)
|
||||||
|
GameUpdateSignal.get_instance().redraw_flight_paths()
|
||||||
|
|
||||||
|
|
||||||
class QAirTaskingOrderPanel(QSplitter):
|
class QAirTaskingOrderPanel(QSplitter):
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import typing
|
from typing import Dict, List, Tuple
|
||||||
from typing import Dict, Tuple
|
|
||||||
|
|
||||||
from PySide2.QtCore import Qt
|
from PySide2.QtCore import Qt
|
||||||
from PySide2.QtGui import QBrush, QColor, QPen, QPixmap, QWheelEvent
|
from PySide2.QtGui import QBrush, QColor, QPen, QPixmap, QWheelEvent
|
||||||
from PySide2.QtWidgets import (
|
from PySide2.QtWidgets import (
|
||||||
QFrame,
|
QFrame,
|
||||||
|
QGraphicsItem,
|
||||||
QGraphicsOpacityEffect,
|
QGraphicsOpacityEffect,
|
||||||
QGraphicsScene,
|
QGraphicsScene,
|
||||||
QGraphicsView,
|
QGraphicsView,
|
||||||
@ -44,6 +44,8 @@ class QLiberationMap(QGraphicsView):
|
|||||||
QLiberationMap.instance = self
|
QLiberationMap.instance = self
|
||||||
self.game_model = game_model
|
self.game_model = game_model
|
||||||
|
|
||||||
|
self.flight_path_items: List[QGraphicsItem] = []
|
||||||
|
|
||||||
self.setMinimumSize(800,600)
|
self.setMinimumSize(800,600)
|
||||||
self.setMaximumHeight(2160)
|
self.setMaximumHeight(2160)
|
||||||
self._zoom = 0
|
self._zoom = 0
|
||||||
@ -53,6 +55,10 @@ class QLiberationMap(QGraphicsView):
|
|||||||
self.connectSignals()
|
self.connectSignals()
|
||||||
self.setGame(game_model.game)
|
self.setGame(game_model.game)
|
||||||
|
|
||||||
|
GameUpdateSignal.get_instance().flight_paths_changed.connect(
|
||||||
|
lambda: self.draw_flight_plans(self.scene())
|
||||||
|
)
|
||||||
|
|
||||||
def init_scene(self):
|
def init_scene(self):
|
||||||
scene = QLiberationScene(self)
|
scene = QLiberationScene(self)
|
||||||
self.setScene(scene)
|
self.setScene(scene)
|
||||||
@ -176,8 +182,7 @@ class QLiberationMap(QGraphicsView):
|
|||||||
if self.get_display_rule("lines"):
|
if self.get_display_rule("lines"):
|
||||||
self.scene_create_lines_for_cp(cp, playerColor, enemyColor)
|
self.scene_create_lines_for_cp(cp, playerColor, enemyColor)
|
||||||
|
|
||||||
if self.get_display_rule("flight_paths"):
|
self.draw_flight_plans(scene)
|
||||||
self.draw_flight_plans(scene)
|
|
||||||
|
|
||||||
for cp in self.game.theater.controlpoints:
|
for cp in self.game.theater.controlpoints:
|
||||||
pos = self._transform_point(cp.position)
|
pos = self._transform_point(cp.position)
|
||||||
@ -188,6 +193,15 @@ class QLiberationMap(QGraphicsView):
|
|||||||
text.setPos(pos[0] + CONST.CP_SIZE + 1, pos[1] - CONST.CP_SIZE / 2 + 1)
|
text.setPos(pos[0] + CONST.CP_SIZE + 1, pos[1] - CONST.CP_SIZE / 2 + 1)
|
||||||
|
|
||||||
def draw_flight_plans(self, scene) -> None:
|
def draw_flight_plans(self, scene) -> None:
|
||||||
|
for item in self.flight_path_items:
|
||||||
|
try:
|
||||||
|
scene.removeItem(item)
|
||||||
|
except RuntimeError:
|
||||||
|
# Something may have caused those items to already be removed.
|
||||||
|
pass
|
||||||
|
self.flight_path_items.clear()
|
||||||
|
if not self.get_display_rule("flight_paths"):
|
||||||
|
return
|
||||||
for package in self.game_model.ato_model.packages:
|
for package in self.game_model.ato_model.packages:
|
||||||
for flight in package.flights:
|
for flight in package.flights:
|
||||||
self.draw_flight_plan(scene, flight)
|
self.draw_flight_plan(scene, flight)
|
||||||
@ -209,17 +223,21 @@ class QLiberationMap(QGraphicsView):
|
|||||||
player: bool) -> None:
|
player: bool) -> None:
|
||||||
waypoint_pen = self.waypoint_pen(player)
|
waypoint_pen = self.waypoint_pen(player)
|
||||||
waypoint_brush = self.waypoint_brush(player)
|
waypoint_brush = self.waypoint_brush(player)
|
||||||
scene.addEllipse(position[0], position[1], self.WAYPOINT_SIZE,
|
self.flight_path_items.append(scene.addEllipse(
|
||||||
self.WAYPOINT_SIZE, waypoint_pen, waypoint_brush)
|
position[0], position[1], self.WAYPOINT_SIZE,
|
||||||
|
self.WAYPOINT_SIZE, waypoint_pen, waypoint_brush
|
||||||
|
))
|
||||||
|
|
||||||
def draw_flight_path(self, scene: QGraphicsScene, pos0: Tuple[int, int],
|
def draw_flight_path(self, scene: QGraphicsScene, pos0: Tuple[int, int],
|
||||||
pos1: Tuple[int, int], player: bool):
|
pos1: Tuple[int, int], player: bool):
|
||||||
flight_path_pen = self.flight_path_pen(player)
|
flight_path_pen = self.flight_path_pen(player)
|
||||||
# Draw the line to the *middle* of the waypoint.
|
# Draw the line to the *middle* of the waypoint.
|
||||||
offset = self.WAYPOINT_SIZE // 2
|
offset = self.WAYPOINT_SIZE // 2
|
||||||
scene.addLine(pos0[0] + offset, pos0[1] + offset,
|
self.flight_path_items.append(scene.addLine(
|
||||||
pos1[0] + offset, pos1[1] + offset,
|
pos0[0] + offset, pos0[1] + offset,
|
||||||
flight_path_pen)
|
pos1[0] + offset, pos1[1] + offset,
|
||||||
|
flight_path_pen
|
||||||
|
))
|
||||||
|
|
||||||
def scene_create_lines_for_cp(self, cp: ControlPoint, playerColor, enemyColor):
|
def scene_create_lines_for_cp(self, cp: ControlPoint, playerColor, enemyColor):
|
||||||
scene = self.scene()
|
scene = self.scene()
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from PySide2.QtCore import QObject, Signal
|
from PySide2.QtCore import QObject, Signal
|
||||||
|
|
||||||
from game import Game
|
from game import Game
|
||||||
@ -19,21 +21,31 @@ class GameUpdateSignal(QObject):
|
|||||||
budgetupdated = Signal(Game)
|
budgetupdated = Signal(Game)
|
||||||
debriefingReceived = Signal(DebriefingSignal)
|
debriefingReceived = Signal(DebriefingSignal)
|
||||||
|
|
||||||
|
flight_paths_changed = Signal()
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(GameUpdateSignal, self).__init__()
|
super(GameUpdateSignal, self).__init__()
|
||||||
GameUpdateSignal.instance = self
|
GameUpdateSignal.instance = self
|
||||||
|
|
||||||
|
def redraw_flight_paths(self) -> None:
|
||||||
|
# noinspection PyUnresolvedReferences
|
||||||
|
self.flight_paths_changed.emit()
|
||||||
|
|
||||||
def updateGame(self, game: Game):
|
def updateGame(self, game: Game):
|
||||||
|
# noinspection PyUnresolvedReferences
|
||||||
self.gameupdated.emit(game)
|
self.gameupdated.emit(game)
|
||||||
|
|
||||||
def updateBudget(self, game: Game):
|
def updateBudget(self, game: Game):
|
||||||
|
# noinspection PyUnresolvedReferences
|
||||||
self.budgetupdated.emit(game)
|
self.budgetupdated.emit(game)
|
||||||
|
|
||||||
def sendDebriefing(self, game: Game, gameEvent: Event, debriefing: Debriefing):
|
def sendDebriefing(self, game: Game, gameEvent: Event, debriefing: Debriefing):
|
||||||
sig = DebriefingSignal(game, gameEvent, debriefing)
|
sig = DebriefingSignal(game, gameEvent, debriefing)
|
||||||
|
# noinspection PyUnresolvedReferences
|
||||||
self.gameupdated.emit(game)
|
self.gameupdated.emit(game)
|
||||||
|
# noinspection PyUnresolvedReferences
|
||||||
self.debriefingReceived.emit(sig)
|
self.debriefingReceived.emit(sig)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_instance():
|
def get_instance() -> GameUpdateSignal:
|
||||||
return GameUpdateSignal.instance
|
return GameUpdateSignal.instance
|
||||||
|
|||||||
@ -7,6 +7,7 @@ from PySide2.QtWidgets import (
|
|||||||
from game import Game
|
from game import Game
|
||||||
from gen.flights.flight import Flight
|
from gen.flights.flight import Flight
|
||||||
from qt_ui.uiconstants import EVENT_ICONS
|
from qt_ui.uiconstants import EVENT_ICONS
|
||||||
|
from qt_ui.windows.GameUpdateSignal import GameUpdateSignal
|
||||||
from qt_ui.windows.mission.flight.QFlightPlanner import QFlightPlanner
|
from qt_ui.windows.mission.flight.QFlightPlanner import QFlightPlanner
|
||||||
|
|
||||||
|
|
||||||
@ -27,3 +28,8 @@ class QEditFlightDialog(QDialog):
|
|||||||
layout.addWidget(self.flight_planner)
|
layout.addWidget(self.flight_planner)
|
||||||
|
|
||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
|
self.finished.connect(self.on_close)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def on_close(_result) -> None:
|
||||||
|
GameUpdateSignal.get_instance().redraw_flight_paths()
|
||||||
|
|||||||
@ -17,6 +17,7 @@ from gen.flights.flight import Flight
|
|||||||
from qt_ui.models import AtoModel, PackageModel
|
from qt_ui.models import AtoModel, PackageModel
|
||||||
from qt_ui.uiconstants import EVENT_ICONS
|
from qt_ui.uiconstants import EVENT_ICONS
|
||||||
from qt_ui.widgets.ato import QFlightList
|
from qt_ui.widgets.ato import QFlightList
|
||||||
|
from qt_ui.windows.GameUpdateSignal import GameUpdateSignal
|
||||||
from qt_ui.windows.mission.flight.QFlightCreator import QFlightCreator
|
from qt_ui.windows.mission.flight.QFlightCreator import QFlightCreator
|
||||||
from theater.missiontarget import MissionTarget
|
from theater.missiontarget import MissionTarget
|
||||||
|
|
||||||
@ -86,6 +87,12 @@ class QPackageDialog(QDialog):
|
|||||||
|
|
||||||
self.setLayout(self.layout)
|
self.setLayout(self.layout)
|
||||||
|
|
||||||
|
self.finished.connect(self.on_close)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def on_close(_result) -> None:
|
||||||
|
GameUpdateSignal.get_instance().redraw_flight_paths()
|
||||||
|
|
||||||
def on_selection_changed(self, selected: QItemSelection,
|
def on_selection_changed(self, selected: QItemSelection,
|
||||||
_deselected: QItemSelection) -> None:
|
_deselected: QItemSelection) -> None:
|
||||||
"""Updates the state of the delete button."""
|
"""Updates the state of the delete button."""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user