mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Merge remote-tracking branch 'upstream/develop' into new-plugin-system
This commit is contained in:
@@ -58,7 +58,7 @@ class Dialog:
|
||||
flight: Flight) -> None:
|
||||
"""Opens the dialog to edit the given flight."""
|
||||
cls.edit_flight_dialog = QEditFlightDialog(
|
||||
cls.game_model.game,
|
||||
cls.game_model,
|
||||
package_model.package,
|
||||
flight
|
||||
)
|
||||
|
||||
65
qt_ui/displayoptions.py
Normal file
65
qt_ui/displayoptions.py
Normal file
@@ -0,0 +1,65 @@
|
||||
"""Visibility options for the game map."""
|
||||
from dataclasses import dataclass
|
||||
from typing import Iterator, Optional, Union
|
||||
|
||||
|
||||
@dataclass
|
||||
class DisplayRule:
|
||||
name: str
|
||||
_value: bool
|
||||
|
||||
@property
|
||||
def menu_text(self) -> str:
|
||||
return self.name
|
||||
|
||||
@property
|
||||
def value(self) -> bool:
|
||||
return self._value
|
||||
|
||||
@value.setter
|
||||
def value(self, value: bool) -> None:
|
||||
from qt_ui.widgets.map.QLiberationMap import QLiberationMap
|
||||
self._value = value
|
||||
QLiberationMap.instance.reload_scene()
|
||||
QLiberationMap.instance.update()
|
||||
|
||||
def __bool__(self) -> bool:
|
||||
return self.value
|
||||
|
||||
|
||||
class DisplayGroup:
|
||||
def __init__(self, name: Optional[str]) -> None:
|
||||
self.name = name
|
||||
|
||||
def __iter__(self) -> Iterator[DisplayRule]:
|
||||
# Python 3.6 enforces that __dict__ is order preserving by default.
|
||||
for value in self.__dict__.values():
|
||||
if isinstance(value, DisplayRule):
|
||||
yield value
|
||||
|
||||
|
||||
class FlightPathOptions(DisplayGroup):
|
||||
def __init__(self) -> None:
|
||||
super().__init__("Flight Paths")
|
||||
self.hide = DisplayRule("Hide Flight Paths", False)
|
||||
self.only_selected = DisplayRule("Show Selected Flight Path", False)
|
||||
self.all = DisplayRule("Show All Flight Paths", True)
|
||||
|
||||
|
||||
class DisplayOptions:
|
||||
ground_objects = DisplayRule("Ground Objects", True)
|
||||
control_points = DisplayRule("Control Points", True)
|
||||
lines = DisplayRule("Lines", True)
|
||||
events = DisplayRule("Events", True)
|
||||
sam_ranges = DisplayRule("SAM Ranges", True)
|
||||
waypoint_info = DisplayRule("Waypoint Information", True)
|
||||
flight_paths = FlightPathOptions()
|
||||
|
||||
@classmethod
|
||||
def menu_items(cls) -> Iterator[Union[DisplayGroup, DisplayRule]]:
|
||||
# Python 3.6 enforces that __dict__ is order preserving by default.
|
||||
for value in cls.__dict__.values():
|
||||
if isinstance(value, DisplayRule):
|
||||
yield value
|
||||
elif isinstance(value, DisplayGroup):
|
||||
yield value
|
||||
@@ -1,7 +1,6 @@
|
||||
"""Qt data models for game objects."""
|
||||
import datetime
|
||||
from enum import auto, IntEnum
|
||||
from typing import Any, Callable, Dict, Iterator, TypeVar, Optional
|
||||
from typing import Any, Callable, Dict, Iterator, Optional, TypeVar
|
||||
|
||||
from PySide2.QtCore import (
|
||||
QAbstractListModel,
|
||||
@@ -15,6 +14,7 @@ from game import db
|
||||
from game.game import Game
|
||||
from gen.ato import AirTaskingOrder, Package
|
||||
from gen.flights.flight import Flight
|
||||
from gen.flights.traveltime import TotEstimator
|
||||
from qt_ui.uiconstants import AIRCRAFT_ICONS
|
||||
from theater.missiontarget import MissionTarget
|
||||
|
||||
@@ -95,6 +95,8 @@ class NullListModel(QAbstractListModel):
|
||||
class PackageModel(QAbstractListModel):
|
||||
"""The model for an ATO package."""
|
||||
|
||||
FlightRole = Qt.UserRole
|
||||
|
||||
#: Emitted when this package is being deleted from the ATO.
|
||||
deleted = Signal()
|
||||
|
||||
@@ -113,17 +115,19 @@ class PackageModel(QAbstractListModel):
|
||||
return self.text_for_flight(flight)
|
||||
if role == Qt.DecorationRole:
|
||||
return self.icon_for_flight(flight)
|
||||
elif role == PackageModel.FlightRole:
|
||||
return flight
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def text_for_flight(flight: Flight) -> str:
|
||||
def text_for_flight(self, flight: Flight) -> str:
|
||||
"""Returns the text that should be displayed for the flight."""
|
||||
task = flight.flight_type.name
|
||||
count = flight.count
|
||||
name = db.unit_type_name(flight.unit_type)
|
||||
delay = flight.scheduled_in
|
||||
estimator = TotEstimator(self.package)
|
||||
delay = datetime.timedelta(seconds=estimator.mission_start_time(flight))
|
||||
origin = flight.from_cp.name
|
||||
return f"[{task}] {count} x {name} from {origin} in {delay} minutes"
|
||||
return f"[{task}] {count} x {name} from {origin} in {delay}"
|
||||
|
||||
@staticmethod
|
||||
def icon_for_flight(flight: Flight) -> Optional[QIcon]:
|
||||
@@ -185,6 +189,8 @@ class AtoModel(QAbstractListModel):
|
||||
|
||||
PackageRole = Qt.UserRole
|
||||
|
||||
client_slots_changed = Signal()
|
||||
|
||||
def __init__(self, game: Optional[Game], ato: AirTaskingOrder) -> None:
|
||||
super().__init__()
|
||||
self.game = game
|
||||
|
||||
@@ -31,14 +31,20 @@ COLORS: Dict[str, QColor] = {
|
||||
"white_transparent": QColor(255, 255, 255, 35),
|
||||
"grey_transparent": QColor(150, 150, 150, 30),
|
||||
|
||||
"light_red": QColor(231, 92, 83, 90),
|
||||
"red": QColor(200, 80, 80),
|
||||
"dark_red": QColor(140, 20, 20),
|
||||
"red_transparent": QColor(227, 32, 0, 20),
|
||||
"transparent": QColor(255, 255, 255, 0),
|
||||
|
||||
"light_blue": QColor(105, 182, 240, 90),
|
||||
"blue": QColor(0, 132, 255),
|
||||
"dark_blue": QColor(45, 62, 80),
|
||||
"blue_transparent": QColor(0, 132, 255, 20),
|
||||
|
||||
"purple": QColor(187, 137, 255),
|
||||
"yellow": QColor(238, 225, 123),
|
||||
|
||||
"bright_red": QColor(150, 80, 80),
|
||||
"super_red": QColor(227, 32, 0),
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
"""A layout containing a widget with an associated label."""
|
||||
from typing import Optional
|
||||
|
||||
from PySide2.QtCore import Qt
|
||||
from PySide2.QtWidgets import QHBoxLayout, QLabel, QWidget
|
||||
|
||||
@@ -10,8 +12,13 @@ class QLabeledWidget(QHBoxLayout):
|
||||
label is used to name the input.
|
||||
"""
|
||||
|
||||
def __init__(self, text: str, widget: QWidget) -> None:
|
||||
def __init__(self, text: str, widget: QWidget,
|
||||
tooltip: Optional[str] = None) -> None:
|
||||
super().__init__()
|
||||
self.addWidget(QLabel(text))
|
||||
label = QLabel(text)
|
||||
self.addWidget(label)
|
||||
self.addStretch()
|
||||
self.addWidget(widget, alignment=Qt.AlignRight)
|
||||
if tooltip is not None:
|
||||
label.setToolTip(tooltip)
|
||||
widget.setToolTip(tooltip)
|
||||
|
||||
@@ -11,9 +11,11 @@ from PySide2.QtWidgets import (
|
||||
import qt_ui.uiconstants as CONST
|
||||
from game import Game
|
||||
from game.event import CAP, CAS, FrontlineAttackEvent
|
||||
from qt_ui.models import GameModel
|
||||
from qt_ui.widgets.QBudgetBox import QBudgetBox
|
||||
from qt_ui.widgets.QFactionsInfos import QFactionsInfos
|
||||
from qt_ui.widgets.QTurnCounter import QTurnCounter
|
||||
from qt_ui.widgets.clientslots import MaxPlayerCount
|
||||
from qt_ui.windows.GameUpdateSignal import GameUpdateSignal
|
||||
from qt_ui.windows.QWaitingForMissionResultWindow import \
|
||||
QWaitingForMissionResultWindow
|
||||
@@ -23,14 +25,18 @@ from qt_ui.windows.stats.QStatsWindow import QStatsWindow
|
||||
|
||||
class QTopPanel(QFrame):
|
||||
|
||||
def __init__(self, game: Game):
|
||||
def __init__(self, game_model: GameModel):
|
||||
super(QTopPanel, self).__init__()
|
||||
self.game = game
|
||||
self.game_model = game_model
|
||||
self.setMaximumHeight(70)
|
||||
self.init_ui()
|
||||
GameUpdateSignal.get_instance().gameupdated.connect(self.setGame)
|
||||
GameUpdateSignal.get_instance().budgetupdated.connect(self.budget_update)
|
||||
|
||||
@property
|
||||
def game(self) -> Optional[Game]:
|
||||
return self.game_model.game
|
||||
|
||||
def init_ui(self):
|
||||
|
||||
self.turnCounter = QTurnCounter()
|
||||
@@ -68,6 +74,8 @@ class QTopPanel(QFrame):
|
||||
|
||||
self.proceedBox = QGroupBox("Proceed")
|
||||
self.proceedBoxLayout = QHBoxLayout()
|
||||
self.proceedBoxLayout.addLayout(
|
||||
MaxPlayerCount(self.game_model.ato_model))
|
||||
self.proceedBoxLayout.addWidget(self.passTurnButton)
|
||||
self.proceedBoxLayout.addWidget(self.proceedButton)
|
||||
self.proceedBox.setLayout(self.proceedBoxLayout)
|
||||
@@ -84,16 +92,17 @@ class QTopPanel(QFrame):
|
||||
self.setLayout(self.layout)
|
||||
|
||||
def setGame(self, game: Optional[Game]):
|
||||
self.game = game
|
||||
if game is not None:
|
||||
self.turnCounter.setCurrentTurn(self.game.turn, self.game.current_day)
|
||||
self.budgetBox.setGame(self.game)
|
||||
self.factionsInfos.setGame(self.game)
|
||||
if game is None:
|
||||
return
|
||||
|
||||
if self.game and self.game.turn == 0:
|
||||
self.proceedButton.setEnabled(False)
|
||||
else:
|
||||
self.proceedButton.setEnabled(True)
|
||||
self.turnCounter.setCurrentTurn(game.turn, game.current_day)
|
||||
self.budgetBox.setGame(game)
|
||||
self.factionsInfos.setGame(game)
|
||||
|
||||
if game and game.turn == 0:
|
||||
self.proceedButton.setEnabled(False)
|
||||
else:
|
||||
self.proceedButton.setEnabled(True)
|
||||
|
||||
def openSettings(self):
|
||||
self.subwindow = QSettingsWindow(self.game)
|
||||
@@ -138,6 +147,8 @@ class QTopPanel(QFrame):
|
||||
if not self.ato_has_clients() and not self.confirm_no_client_launch():
|
||||
return
|
||||
|
||||
# TODO: Verify no negative start times.
|
||||
|
||||
# TODO: Refactor this nonsense.
|
||||
game_event = None
|
||||
for event in self.game.events:
|
||||
|
||||
@@ -10,7 +10,7 @@ from PySide2.QtCore import (
|
||||
QSize,
|
||||
Qt,
|
||||
)
|
||||
from PySide2.QtGui import QFont, QFontMetrics, QPainter
|
||||
from PySide2.QtGui import QFont, QFontMetrics, QIcon, QPainter
|
||||
from PySide2.QtWidgets import (
|
||||
QAbstractItemView,
|
||||
QGroupBox,
|
||||
@@ -18,15 +18,115 @@ from PySide2.QtWidgets import (
|
||||
QListView,
|
||||
QPushButton,
|
||||
QSplitter,
|
||||
QStyleOptionViewItem, QStyledItemDelegate, QVBoxLayout,
|
||||
QStyle, QStyleOptionViewItem, QStyledItemDelegate, QVBoxLayout,
|
||||
)
|
||||
|
||||
from game import db
|
||||
from gen.ato import Package
|
||||
from gen.flights.flight import Flight
|
||||
from gen.flights.traveltime import TotEstimator
|
||||
from qt_ui.windows.GameUpdateSignal import GameUpdateSignal
|
||||
from ..models import AtoModel, GameModel, NullListModel, PackageModel
|
||||
|
||||
|
||||
class FlightDelegate(QStyledItemDelegate):
|
||||
FONT_SIZE = 10
|
||||
HMARGIN = 4
|
||||
VMARGIN = 4
|
||||
|
||||
def __init__(self, package: Package) -> None:
|
||||
super().__init__()
|
||||
self.package = package
|
||||
|
||||
def get_font(self, option: QStyleOptionViewItem) -> QFont:
|
||||
font = QFont(option.font)
|
||||
font.setPointSize(self.FONT_SIZE)
|
||||
return font
|
||||
|
||||
@staticmethod
|
||||
def flight(index: QModelIndex) -> Flight:
|
||||
return index.data(PackageModel.FlightRole)
|
||||
|
||||
def first_row_text(self, index: QModelIndex) -> str:
|
||||
flight = self.flight(index)
|
||||
task = flight.flight_type.name
|
||||
count = flight.count
|
||||
name = db.unit_type_name(flight.unit_type)
|
||||
estimator = TotEstimator(self.package)
|
||||
delay = datetime.timedelta(seconds=estimator.mission_start_time(flight))
|
||||
return f"[{task}] {count} x {name} in {delay}"
|
||||
|
||||
def second_row_text(self, index: QModelIndex) -> str:
|
||||
flight = self.flight(index)
|
||||
origin = flight.from_cp.name
|
||||
return f"From {origin}"
|
||||
|
||||
def paint(self, painter: QPainter, option: QStyleOptionViewItem,
|
||||
index: QModelIndex) -> None:
|
||||
# Draw the list item with all the default selection styling, but with an
|
||||
# invalid index so text formatting is left to us.
|
||||
super().paint(painter, option, QModelIndex())
|
||||
|
||||
rect = option.rect.adjusted(self.HMARGIN, self.VMARGIN, -self.HMARGIN,
|
||||
-self.VMARGIN)
|
||||
|
||||
with painter_context(painter):
|
||||
painter.setFont(self.get_font(option))
|
||||
|
||||
icon: Optional[QIcon] = index.data(Qt.DecorationRole)
|
||||
if icon is not None:
|
||||
icon.paint(painter, rect, Qt.AlignLeft | Qt.AlignVCenter,
|
||||
self.icon_mode(option),
|
||||
self.icon_state(option))
|
||||
|
||||
rect = rect.adjusted(self.icon_size(option).width() + self.HMARGIN,
|
||||
0, 0, 0)
|
||||
painter.drawText(rect, Qt.AlignLeft, self.first_row_text(index))
|
||||
line2 = rect.adjusted(0, rect.height() / 2, 0, rect.height() / 2)
|
||||
painter.drawText(line2, Qt.AlignLeft, self.second_row_text(index))
|
||||
|
||||
clients = self.num_clients(index)
|
||||
if clients:
|
||||
painter.drawText(rect, Qt.AlignRight,
|
||||
f"Player Slots: {clients}")
|
||||
|
||||
def num_clients(self, index: QModelIndex) -> int:
|
||||
flight = self.flight(index)
|
||||
return flight.client_count
|
||||
|
||||
@staticmethod
|
||||
def icon_mode(option: QStyleOptionViewItem) -> QIcon.Mode:
|
||||
if not (option.state & QStyle.State_Enabled):
|
||||
return QIcon.Disabled
|
||||
elif option.state & QStyle.State_Selected:
|
||||
return QIcon.Selected
|
||||
elif option.state & QStyle.State_Active:
|
||||
return QIcon.Active
|
||||
return QIcon.Normal
|
||||
|
||||
@staticmethod
|
||||
def icon_state(option: QStyleOptionViewItem) -> QIcon.State:
|
||||
return QIcon.On if option.state & QStyle.State_Open else QIcon.Off
|
||||
|
||||
@staticmethod
|
||||
def icon_size(option: QStyleOptionViewItem) -> QSize:
|
||||
icon_size: Optional[QSize] = option.decorationSize
|
||||
if icon_size is None:
|
||||
return QSize(0, 0)
|
||||
else:
|
||||
return icon_size
|
||||
|
||||
def sizeHint(self, option: QStyleOptionViewItem,
|
||||
index: QModelIndex) -> QSize:
|
||||
left = self.icon_size(option).width() + self.HMARGIN
|
||||
metrics = QFontMetrics(self.get_font(option))
|
||||
first = metrics.size(0, self.first_row_text(index))
|
||||
second = metrics.size(0, self.second_row_text(index))
|
||||
text_width = max(first.width(), second.width())
|
||||
return QSize(left + text_width + 2 * self.HMARGIN,
|
||||
first.height() + second.height() + 2 * self.VMARGIN)
|
||||
|
||||
|
||||
class QFlightList(QListView):
|
||||
"""List view for displaying the flights of a package."""
|
||||
|
||||
@@ -34,6 +134,8 @@ class QFlightList(QListView):
|
||||
super().__init__()
|
||||
self.package_model = model
|
||||
self.set_package(model)
|
||||
if model is not None:
|
||||
self.setItemDelegate(FlightDelegate(model.package))
|
||||
self.setIconSize(QSize(91, 24))
|
||||
self.setSelectionBehavior(QAbstractItemView.SelectItems)
|
||||
|
||||
@@ -43,6 +145,7 @@ class QFlightList(QListView):
|
||||
self.disconnect_model()
|
||||
else:
|
||||
self.package_model = model
|
||||
self.setItemDelegate(FlightDelegate(model.package))
|
||||
self.setModel(model)
|
||||
# noinspection PyUnresolvedReferences
|
||||
model.deleted.connect(self.disconnect_model)
|
||||
@@ -109,6 +212,7 @@ class QFlightPanel(QGroupBox):
|
||||
"""Sets the package model to display."""
|
||||
self.package_model = model
|
||||
self.flight_list.set_package(model)
|
||||
self.selection_changed.connect(self.on_selection_changed)
|
||||
self.on_selection_changed()
|
||||
|
||||
@property
|
||||
@@ -122,6 +226,15 @@ class QFlightPanel(QGroupBox):
|
||||
enabled = index.isValid()
|
||||
self.edit_button.setEnabled(enabled)
|
||||
self.delete_button.setEnabled(enabled)
|
||||
self.change_map_flight_selection(index)
|
||||
|
||||
@staticmethod
|
||||
def change_map_flight_selection(index: QModelIndex) -> None:
|
||||
if not index.isValid():
|
||||
GameUpdateSignal.get_instance().select_flight(None)
|
||||
return
|
||||
|
||||
GameUpdateSignal.get_instance().select_flight(index.row())
|
||||
|
||||
def on_edit(self) -> None:
|
||||
"""Opens the flight edit dialog."""
|
||||
@@ -196,6 +309,15 @@ class PackageDelegate(QStyledItemDelegate):
|
||||
line2 = rect.adjusted(0, rect.height() / 2, 0, rect.height() / 2)
|
||||
painter.drawText(line2, Qt.AlignLeft, self.right_text(index))
|
||||
|
||||
clients = self.num_clients(index)
|
||||
if clients:
|
||||
painter.drawText(rect, Qt.AlignRight,
|
||||
f"Player Slots: {clients}")
|
||||
|
||||
def num_clients(self, index: QModelIndex) -> int:
|
||||
package = self.package(index)
|
||||
return sum(f.client_count for f in package.flights)
|
||||
|
||||
def sizeHint(self, option: QStyleOptionViewItem,
|
||||
index: QModelIndex) -> QSize:
|
||||
metrics = QFontMetrics(self.get_font(option))
|
||||
@@ -270,6 +392,18 @@ class QPackagePanel(QGroupBox):
|
||||
enabled = index.isValid()
|
||||
self.edit_button.setEnabled(enabled)
|
||||
self.delete_button.setEnabled(enabled)
|
||||
self.change_map_package_selection(index)
|
||||
|
||||
def change_map_package_selection(self, index: QModelIndex) -> None:
|
||||
if not index.isValid():
|
||||
GameUpdateSignal.get_instance().select_package(None)
|
||||
return
|
||||
|
||||
package = self.ato_model.get_package_model(index)
|
||||
if package.rowCount() == 0:
|
||||
GameUpdateSignal.get_instance().select_package(None)
|
||||
else:
|
||||
GameUpdateSignal.get_instance().select_package(index.row())
|
||||
|
||||
def on_edit(self) -> None:
|
||||
"""Opens the package edit dialog."""
|
||||
|
||||
28
qt_ui/widgets/clientslots.py
Normal file
28
qt_ui/widgets/clientslots.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""Widgets for displaying client slots."""
|
||||
from PySide2.QtWidgets import QLabel
|
||||
|
||||
from qt_ui.models import AtoModel
|
||||
from qt_ui.widgets.QLabeledWidget import QLabeledWidget
|
||||
|
||||
|
||||
class MaxPlayerCount(QLabeledWidget):
|
||||
def __init__(self, ato_model: AtoModel) -> None:
|
||||
self.ato_model = ato_model
|
||||
self.slots_label = QLabel(str(self.count_client_slots))
|
||||
self.ato_model.client_slots_changed.connect(self.update_count)
|
||||
super().__init__(
|
||||
"Max Players:", self.slots_label,
|
||||
("Total number of client slots. To add client slots, edit a flight "
|
||||
"using the panel on the left.")
|
||||
)
|
||||
|
||||
@property
|
||||
def count_client_slots(self) -> int:
|
||||
slots = 0
|
||||
for package in self.ato_model.packages:
|
||||
for flight in package.flights:
|
||||
slots += flight.client_count
|
||||
return slots
|
||||
|
||||
def update_count(self) -> None:
|
||||
self.slots_label.setText(str(self.count_client_slots))
|
||||
@@ -1,5 +1,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
import logging
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
from typing import List, Optional, Tuple
|
||||
|
||||
from PySide2.QtCore import Qt
|
||||
from PySide2.QtGui import QBrush, QColor, QPen, QPixmap, QWheelEvent
|
||||
@@ -15,14 +18,18 @@ from dcs.mapping import point_from_heading
|
||||
|
||||
import qt_ui.uiconstants as CONST
|
||||
from game import Game, db
|
||||
from game.data.aaa_db import AAA_UNITS
|
||||
from game.data.radar_db import UNITS_WITH_RADAR
|
||||
from gen import Conflict
|
||||
from gen.flights.flight import Flight
|
||||
from game.utils import meter_to_feet
|
||||
from gen import Conflict, PackageWaypointTiming
|
||||
from gen.ato import Package
|
||||
from gen.flights.flight import Flight, FlightWaypoint, FlightWaypointType
|
||||
from qt_ui.displayoptions import DisplayOptions
|
||||
from qt_ui.models import GameModel
|
||||
from qt_ui.widgets.map.QFrontLine import QFrontLine
|
||||
from qt_ui.widgets.map.QLiberationScene import QLiberationScene
|
||||
from qt_ui.widgets.map.QMapControlPoint import QMapControlPoint
|
||||
from qt_ui.widgets.map.QMapGroundObject import QMapGroundObject
|
||||
from qt_ui.widgets.map.QFrontLine import QFrontLine
|
||||
from qt_ui.windows.GameUpdateSignal import GameUpdateSignal
|
||||
from theater import ControlPoint, FrontLine
|
||||
|
||||
@@ -30,15 +37,7 @@ from theater import ControlPoint, FrontLine
|
||||
class QLiberationMap(QGraphicsView):
|
||||
WAYPOINT_SIZE = 4
|
||||
|
||||
instance = None
|
||||
display_rules: Dict[str, bool] = {
|
||||
"cp": True,
|
||||
"go": True,
|
||||
"lines": True,
|
||||
"events": True,
|
||||
"sam": True,
|
||||
"flight_paths": False
|
||||
}
|
||||
instance: Optional[QLiberationMap] = None
|
||||
|
||||
def __init__(self, game_model: GameModel):
|
||||
super(QLiberationMap, self).__init__()
|
||||
@@ -47,6 +46,8 @@ class QLiberationMap(QGraphicsView):
|
||||
self.game: Optional[Game] = game_model.game
|
||||
|
||||
self.flight_path_items: List[QGraphicsItem] = []
|
||||
# A tuple of (package index, flight index), or none.
|
||||
self.selected_flight: Optional[Tuple[int, int]] = None
|
||||
|
||||
self.setMinimumSize(800,600)
|
||||
self.setMaximumHeight(2160)
|
||||
@@ -61,6 +62,25 @@ class QLiberationMap(QGraphicsView):
|
||||
lambda: self.draw_flight_plans(self.scene())
|
||||
)
|
||||
|
||||
def update_package_selection(index: Optional[int]) -> None:
|
||||
self.selected_flight = index, 0
|
||||
self.draw_flight_plans(self.scene())
|
||||
|
||||
GameUpdateSignal.get_instance().package_selection_changed.connect(
|
||||
update_package_selection
|
||||
)
|
||||
|
||||
def update_flight_selection(index: Optional[int]) -> None:
|
||||
if self.selected_flight is None:
|
||||
logging.error("Flight was selected with no package selected")
|
||||
return
|
||||
self.selected_flight = self.selected_flight[0], index
|
||||
self.draw_flight_plans(self.scene())
|
||||
|
||||
GameUpdateSignal.get_instance().flight_selection_changed.connect(
|
||||
update_flight_selection
|
||||
)
|
||||
|
||||
def init_scene(self):
|
||||
scene = QLiberationScene(self)
|
||||
self.setScene(scene)
|
||||
@@ -161,27 +181,44 @@ class QLiberationMap(QGraphicsView):
|
||||
buildings = self.game.theater.find_ground_objects_by_obj_name(ground_object.obj_name)
|
||||
scene.addItem(QMapGroundObject(self, go_pos[0], go_pos[1], 14, 12, cp, ground_object, self.game, buildings))
|
||||
|
||||
if ground_object.category == "aa" and self.get_display_rule("sam"):
|
||||
max_range = 0
|
||||
has_radar = False
|
||||
is_aa = ground_object.category == "aa"
|
||||
if is_aa and DisplayOptions.sam_ranges:
|
||||
threat_range = 0
|
||||
detection_range = 0
|
||||
can_fire = False
|
||||
if ground_object.groups:
|
||||
for g in ground_object.groups:
|
||||
for u in g.units:
|
||||
unit = db.unit_type_from_name(u.type)
|
||||
if unit in UNITS_WITH_RADAR:
|
||||
has_radar = True
|
||||
if unit.threat_range > max_range:
|
||||
max_range = unit.threat_range
|
||||
if has_radar:
|
||||
scene.addEllipse(go_pos[0] - max_range/300.0 + 8, go_pos[1] - max_range/300.0 + 8, max_range/150.0, max_range/150.0, CONST.COLORS["white_transparent"], CONST.COLORS["grey_transparent"])
|
||||
if unit in UNITS_WITH_RADAR or unit in AAA_UNITS:
|
||||
can_fire = True
|
||||
if unit.detection_range > detection_range:
|
||||
detection_range = unit.detection_range
|
||||
if unit.threat_range > threat_range:
|
||||
threat_range = unit.threat_range
|
||||
if can_fire:
|
||||
threat_pos = self._transform_point(Point(ground_object.position.x+threat_range,
|
||||
ground_object.position.y+threat_range))
|
||||
detection_pos = self._transform_point(Point(ground_object.position.x+detection_range,
|
||||
ground_object.position.y+detection_range))
|
||||
threat_radius = Point(*go_pos).distance_to_point(Point(*threat_pos))
|
||||
detection_radius = Point(*go_pos).distance_to_point(Point(*detection_pos))
|
||||
|
||||
# Add detection range circle
|
||||
scene.addEllipse(go_pos[0] - detection_radius/2 + 7, go_pos[1] - detection_radius/2 + 6,
|
||||
detection_radius, detection_radius, self.detection_pen(cp.captured))
|
||||
|
||||
# Add threat range circle
|
||||
scene.addEllipse(go_pos[0] - threat_radius / 2 + 7, go_pos[1] - threat_radius / 2 + 6,
|
||||
threat_radius, threat_radius, self.threat_pen(cp.captured))
|
||||
added_objects.append(ground_object.obj_name)
|
||||
|
||||
for cp in self.game.theater.enemy_points():
|
||||
if self.get_display_rule("lines"):
|
||||
if DisplayOptions.lines:
|
||||
self.scene_create_lines_for_cp(cp, playerColor, enemyColor)
|
||||
|
||||
for cp in self.game.theater.player_points():
|
||||
if self.get_display_rule("lines"):
|
||||
if DisplayOptions.lines:
|
||||
self.scene_create_lines_for_cp(cp, playerColor, enemyColor)
|
||||
|
||||
self.draw_flight_plans(scene)
|
||||
@@ -202,37 +239,94 @@ class QLiberationMap(QGraphicsView):
|
||||
# Something may have caused those items to already be removed.
|
||||
pass
|
||||
self.flight_path_items.clear()
|
||||
if not self.get_display_rule("flight_paths"):
|
||||
if DisplayOptions.flight_paths.hide:
|
||||
return
|
||||
for package in self.game_model.ato_model.packages:
|
||||
for flight in package.flights:
|
||||
self.draw_flight_plan(scene, flight)
|
||||
packages = list(self.game_model.ato_model.packages)
|
||||
for p_idx, package_model in enumerate(packages):
|
||||
for f_idx, flight in enumerate(package_model.flights):
|
||||
selected = (p_idx, f_idx) == self.selected_flight
|
||||
if DisplayOptions.flight_paths.only_selected and not selected:
|
||||
continue
|
||||
self.draw_flight_plan(scene, package_model.package, flight,
|
||||
selected)
|
||||
|
||||
def draw_flight_plan(self, scene: QGraphicsScene, flight: Flight) -> None:
|
||||
def draw_flight_plan(self, scene: QGraphicsScene, package: Package,
|
||||
flight: Flight, selected: bool) -> None:
|
||||
is_player = flight.from_cp.captured
|
||||
pos = self._transform_point(flight.from_cp.position)
|
||||
|
||||
self.draw_waypoint(scene, pos, is_player)
|
||||
self.draw_waypoint(scene, pos, is_player, selected)
|
||||
prev_pos = tuple(pos)
|
||||
for point in flight.points:
|
||||
drew_target = False
|
||||
target_types = (
|
||||
FlightWaypointType.TARGET_GROUP_LOC,
|
||||
FlightWaypointType.TARGET_POINT,
|
||||
FlightWaypointType.TARGET_SHIP,
|
||||
)
|
||||
for idx, point in enumerate(flight.points):
|
||||
new_pos = self._transform_point(Point(point.x, point.y))
|
||||
self.draw_flight_path(scene, prev_pos, new_pos, is_player)
|
||||
self.draw_waypoint(scene, new_pos, is_player)
|
||||
self.draw_flight_path(scene, prev_pos, new_pos, is_player,
|
||||
selected)
|
||||
self.draw_waypoint(scene, new_pos, is_player, selected)
|
||||
if selected and DisplayOptions.waypoint_info:
|
||||
if point.waypoint_type in target_types:
|
||||
if drew_target:
|
||||
# Don't draw dozens of targets over each other.
|
||||
continue
|
||||
drew_target = True
|
||||
self.draw_waypoint_info(scene, idx + 1, point, new_pos, package,
|
||||
flight)
|
||||
prev_pos = tuple(new_pos)
|
||||
self.draw_flight_path(scene, prev_pos, pos, is_player)
|
||||
self.draw_flight_path(scene, prev_pos, pos, is_player, selected)
|
||||
|
||||
def draw_waypoint(self, scene: QGraphicsScene, position: Tuple[int, int],
|
||||
player: bool) -> None:
|
||||
waypoint_pen = self.waypoint_pen(player)
|
||||
waypoint_brush = self.waypoint_brush(player)
|
||||
player: bool, selected: bool) -> None:
|
||||
waypoint_pen = self.waypoint_pen(player, selected)
|
||||
waypoint_brush = self.waypoint_brush(player, selected)
|
||||
self.flight_path_items.append(scene.addEllipse(
|
||||
position[0], position[1], self.WAYPOINT_SIZE,
|
||||
self.WAYPOINT_SIZE, waypoint_pen, waypoint_brush
|
||||
))
|
||||
|
||||
def draw_waypoint_info(self, scene: QGraphicsScene, number: int,
|
||||
waypoint: FlightWaypoint, position: Tuple[int, int],
|
||||
package: Package, flight: Flight) -> None:
|
||||
timing = PackageWaypointTiming.for_package(package)
|
||||
|
||||
altitude = meter_to_feet(waypoint.alt)
|
||||
altitude_type = "AGL" if waypoint.alt_type == "RADIO" else "MSL"
|
||||
|
||||
prefix = "TOT"
|
||||
time = timing.tot_for_waypoint(waypoint)
|
||||
if time is None:
|
||||
prefix = "Depart"
|
||||
time = timing.depart_time_for_waypoint(waypoint, flight)
|
||||
if time is None:
|
||||
tot = ""
|
||||
else:
|
||||
tot = f"{prefix} T+{datetime.timedelta(seconds=time)}"
|
||||
|
||||
pen = QPen(QColor("black"), 0.3)
|
||||
brush = QColor("white")
|
||||
|
||||
def draw_text(text: str, x: int, y: int) -> None:
|
||||
item = scene.addSimpleText(text)
|
||||
item.setBrush(brush)
|
||||
item.setPen(pen)
|
||||
item.moveBy(x, y)
|
||||
item.setZValue(2)
|
||||
self.flight_path_items.append(item)
|
||||
|
||||
draw_text(f"{number} {waypoint.name}", position[0] + 8,
|
||||
position[1] - 15)
|
||||
draw_text(f"{altitude} ft {altitude_type}", position[0] + 8,
|
||||
position[1] - 5)
|
||||
draw_text(tot, position[0] + 8, position[1] + 5)
|
||||
|
||||
def draw_flight_path(self, scene: QGraphicsScene, pos0: Tuple[int, int],
|
||||
pos1: Tuple[int, int], player: bool):
|
||||
flight_path_pen = self.flight_path_pen(player)
|
||||
pos1: Tuple[int, int], player: bool,
|
||||
selected: bool) -> None:
|
||||
flight_path_pen = self.flight_path_pen(player, selected)
|
||||
# Draw the line to the *middle* of the waypoint.
|
||||
offset = self.WAYPOINT_SIZE // 2
|
||||
self.flight_path_items.append(scene.addLine(
|
||||
@@ -321,21 +415,48 @@ class QLiberationMap(QGraphicsView):
|
||||
|
||||
return X > treshold and X or treshold, Y > treshold and Y or treshold
|
||||
|
||||
def highlight_color(self, transparent: Optional[bool] = False) -> QColor:
|
||||
return QColor(255, 255, 0, 20 if transparent else 255)
|
||||
|
||||
def base_faction_color_name(self, player: bool) -> str:
|
||||
if player:
|
||||
return self.game.get_player_color()
|
||||
else:
|
||||
return self.game.get_enemy_color()
|
||||
|
||||
def waypoint_pen(self, player: bool) -> QPen:
|
||||
def waypoint_pen(self, player: bool, selected: bool) -> QColor:
|
||||
if selected and DisplayOptions.flight_paths.all:
|
||||
return self.highlight_color()
|
||||
name = self.base_faction_color_name(player)
|
||||
return QPen(brush=CONST.COLORS[name])
|
||||
return CONST.COLORS[name]
|
||||
|
||||
def waypoint_brush(self, player: bool) -> QColor:
|
||||
def waypoint_brush(self, player: bool, selected: bool) -> QColor:
|
||||
if selected and DisplayOptions.flight_paths.all:
|
||||
return self.highlight_color(transparent=True)
|
||||
name = self.base_faction_color_name(player)
|
||||
return CONST.COLORS[f"{name}_transparent"]
|
||||
|
||||
def flight_path_pen(self, player: bool) -> QPen:
|
||||
def threat_pen(self, player: bool) -> QPen:
|
||||
if player:
|
||||
color = "blue"
|
||||
else:
|
||||
color = "red"
|
||||
qpen = QPen(CONST.COLORS[color])
|
||||
return qpen
|
||||
|
||||
def detection_pen(self, player: bool) -> QPen:
|
||||
if player:
|
||||
color = "purple"
|
||||
else:
|
||||
color = "yellow"
|
||||
qpen = QPen(CONST.COLORS[color])
|
||||
qpen.setStyle(Qt.DotLine)
|
||||
return qpen
|
||||
|
||||
def flight_path_pen(self, player: bool, selected: bool) -> QPen:
|
||||
if selected and DisplayOptions.flight_paths.all:
|
||||
return self.highlight_color()
|
||||
|
||||
name = self.base_faction_color_name(player)
|
||||
color = CONST.COLORS[name]
|
||||
pen = QPen(brush=color)
|
||||
@@ -367,18 +488,3 @@ class QLiberationMap(QGraphicsView):
|
||||
effect = QGraphicsOpacityEffect()
|
||||
effect.setOpacity(0.3)
|
||||
overlay.setGraphicsEffect(effect)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def set_display_rule(rule: str, value: bool):
|
||||
QLiberationMap.display_rules[rule] = value
|
||||
QLiberationMap.instance.reload_scene()
|
||||
QLiberationMap.instance.update()
|
||||
|
||||
@staticmethod
|
||||
def get_display_rules() -> Dict[str, bool]:
|
||||
return QLiberationMap.display_rules
|
||||
|
||||
@staticmethod
|
||||
def get_display_rule(rule) -> bool:
|
||||
return QLiberationMap.display_rules[rule]
|
||||
|
||||
@@ -7,6 +7,7 @@ from qt_ui.models import GameModel
|
||||
from qt_ui.windows.basemenu.QBaseMenu2 import QBaseMenu2
|
||||
from theater import ControlPoint
|
||||
from .QMapObject import QMapObject
|
||||
from ...displayoptions import DisplayOptions
|
||||
|
||||
|
||||
class QMapControlPoint(QMapObject):
|
||||
@@ -21,7 +22,7 @@ class QMapControlPoint(QMapObject):
|
||||
self.base_details_dialog: Optional[QBaseMenu2] = None
|
||||
|
||||
def paint(self, painter, option, widget=None) -> None:
|
||||
if self.parent.get_display_rule("cp"):
|
||||
if DisplayOptions.control_points:
|
||||
painter.save()
|
||||
painter.setRenderHint(QPainter.Antialiasing)
|
||||
painter.setBrush(self.brush_color)
|
||||
|
||||
@@ -8,8 +8,9 @@ import qt_ui.uiconstants as const
|
||||
from game import Game
|
||||
from game.data.building_data import FORTIFICATION_BUILDINGS
|
||||
from qt_ui.windows.groundobject.QGroundObjectMenu import QGroundObjectMenu
|
||||
from theater import TheaterGroundObject, ControlPoint
|
||||
from theater import ControlPoint, TheaterGroundObject
|
||||
from .QMapObject import QMapObject
|
||||
from ...displayoptions import DisplayOptions
|
||||
|
||||
|
||||
class QMapGroundObject(QMapObject):
|
||||
@@ -50,7 +51,7 @@ class QMapGroundObject(QMapObject):
|
||||
player_icons = "_blue"
|
||||
enemy_icons = ""
|
||||
|
||||
if self.parent.get_display_rule("go"):
|
||||
if DisplayOptions.ground_objects:
|
||||
painter.save()
|
||||
|
||||
cat = self.ground_object.category
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional
|
||||
from typing import Optional, Tuple
|
||||
|
||||
from PySide2.QtCore import QObject, Signal
|
||||
|
||||
@@ -24,11 +24,21 @@ class GameUpdateSignal(QObject):
|
||||
debriefingReceived = Signal(DebriefingSignal)
|
||||
|
||||
flight_paths_changed = Signal()
|
||||
package_selection_changed = Signal(int) # Optional[int]
|
||||
flight_selection_changed = Signal(int) # Optional[int]
|
||||
|
||||
def __init__(self):
|
||||
super(GameUpdateSignal, self).__init__()
|
||||
GameUpdateSignal.instance = self
|
||||
|
||||
def select_package(self, index: Optional[int]) -> None:
|
||||
# noinspection PyUnresolvedReferences
|
||||
self.package_selection_changed.emit(index)
|
||||
|
||||
def select_flight(self, index: Optional[int]) -> None:
|
||||
# noinspection PyUnresolvedReferences
|
||||
self.flight_selection_changed.emit(index)
|
||||
|
||||
def redraw_flight_paths(self) -> None:
|
||||
# noinspection PyUnresolvedReferences
|
||||
self.flight_paths_changed.emit()
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import logging
|
||||
import sys
|
||||
import webbrowser
|
||||
from typing import Optional
|
||||
from typing import Optional, Union
|
||||
|
||||
from PySide2.QtCore import Qt
|
||||
from PySide2.QtGui import QIcon
|
||||
from PySide2.QtWidgets import (
|
||||
QAction,
|
||||
QDesktopWidget,
|
||||
QActionGroup, QDesktopWidget,
|
||||
QFileDialog,
|
||||
QMainWindow,
|
||||
QMessageBox,
|
||||
QMenu, QMessageBox,
|
||||
QSplitter,
|
||||
QVBoxLayout,
|
||||
QWidget,
|
||||
@@ -19,6 +19,7 @@ from PySide2.QtWidgets import (
|
||||
import qt_ui.uiconstants as CONST
|
||||
from game import Game, persistency
|
||||
from qt_ui.dialogs import Dialog
|
||||
from qt_ui.displayoptions import DisplayGroup, DisplayOptions, DisplayRule
|
||||
from qt_ui.models import GameModel
|
||||
from qt_ui.uiconstants import URLS
|
||||
from qt_ui.widgets.QTopPanel import QTopPanel
|
||||
@@ -76,7 +77,7 @@ class QLiberationWindow(QMainWindow):
|
||||
|
||||
vbox = QVBoxLayout()
|
||||
vbox.setMargin(0)
|
||||
vbox.addWidget(QTopPanel(self.game))
|
||||
vbox.addWidget(QTopPanel(self.game_model))
|
||||
vbox.addWidget(hbox)
|
||||
|
||||
central_widget = QWidget()
|
||||
@@ -134,48 +135,23 @@ class QLiberationWindow(QMainWindow):
|
||||
file_menu.addSeparator()
|
||||
file_menu.addAction(self.showLiberationPrefDialogAction)
|
||||
file_menu.addSeparator()
|
||||
#file_menu.addAction("Close Current Game", lambda: self.closeGame()) # Not working
|
||||
file_menu.addAction("E&xit" , lambda: self.exit())
|
||||
|
||||
displayMenu = self.menu.addMenu("&Display")
|
||||
|
||||
tg_cp_visibility = QAction('&Control Point', displayMenu)
|
||||
tg_cp_visibility.setCheckable(True)
|
||||
tg_cp_visibility.setChecked(True)
|
||||
tg_cp_visibility.toggled.connect(lambda: QLiberationMap.set_display_rule("cp", tg_cp_visibility.isChecked()))
|
||||
|
||||
tg_go_visibility = QAction('&Ground Objects', displayMenu)
|
||||
tg_go_visibility.setCheckable(True)
|
||||
tg_go_visibility.setChecked(True)
|
||||
tg_go_visibility.toggled.connect(lambda: QLiberationMap.set_display_rule("go", tg_go_visibility.isChecked()))
|
||||
|
||||
tg_line_visibility = QAction('&Lines', displayMenu)
|
||||
tg_line_visibility.setCheckable(True)
|
||||
tg_line_visibility.setChecked(True)
|
||||
tg_line_visibility.toggled.connect(
|
||||
lambda: QLiberationMap.set_display_rule("lines", tg_line_visibility.isChecked()))
|
||||
|
||||
tg_event_visibility = QAction('&Events', displayMenu)
|
||||
tg_event_visibility.setCheckable(True)
|
||||
tg_event_visibility.setChecked(True)
|
||||
tg_event_visibility.toggled.connect(lambda: QLiberationMap.set_display_rule("events", tg_event_visibility.isChecked()))
|
||||
|
||||
tg_sam_visibility = QAction('&SAM Range', displayMenu)
|
||||
tg_sam_visibility.setCheckable(True)
|
||||
tg_sam_visibility.setChecked(True)
|
||||
tg_sam_visibility.toggled.connect(lambda: QLiberationMap.set_display_rule("sam", tg_sam_visibility.isChecked()))
|
||||
|
||||
tg_flight_path_visibility = QAction('&Flight Paths', displayMenu)
|
||||
tg_flight_path_visibility.setCheckable(True)
|
||||
tg_flight_path_visibility.setChecked(False)
|
||||
tg_flight_path_visibility.toggled.connect(lambda: QLiberationMap.set_display_rule("flight_paths", tg_flight_path_visibility.isChecked()))
|
||||
|
||||
displayMenu.addAction(tg_go_visibility)
|
||||
displayMenu.addAction(tg_cp_visibility)
|
||||
displayMenu.addAction(tg_line_visibility)
|
||||
displayMenu.addAction(tg_event_visibility)
|
||||
displayMenu.addAction(tg_sam_visibility)
|
||||
displayMenu.addAction(tg_flight_path_visibility)
|
||||
last_was_group = True
|
||||
for item in DisplayOptions.menu_items():
|
||||
if isinstance(item, DisplayRule):
|
||||
displayMenu.addAction(self.make_display_rule_action(item))
|
||||
last_was_group = False
|
||||
elif isinstance(item, DisplayGroup):
|
||||
if not last_was_group:
|
||||
displayMenu.addSeparator()
|
||||
group = QActionGroup(displayMenu)
|
||||
for display_rule in item:
|
||||
displayMenu.addAction(
|
||||
self.make_display_rule_action(display_rule, group))
|
||||
last_was_group = True
|
||||
|
||||
help_menu = self.menu.addMenu("&Help")
|
||||
help_menu.addAction("&Discord Server", lambda: webbrowser.open_new_tab("https://" + "discord.gg" + "/" + "bKrt" + "rkJ"))
|
||||
@@ -188,6 +164,21 @@ class QLiberationWindow(QMainWindow):
|
||||
help_menu.addSeparator()
|
||||
help_menu.addAction(self.showAboutDialogAction)
|
||||
|
||||
@staticmethod
|
||||
def make_display_rule_action(
|
||||
display_rule, group: Optional[QActionGroup] = None) -> QAction:
|
||||
def make_check_closure():
|
||||
def closure():
|
||||
display_rule.value = action.isChecked()
|
||||
|
||||
return closure
|
||||
|
||||
action = QAction(f"&{display_rule.menu_text}", group)
|
||||
action.setCheckable(True)
|
||||
action.setChecked(display_rule.value)
|
||||
action.toggled.connect(make_check_closure())
|
||||
return action
|
||||
|
||||
def newGame(self):
|
||||
wizard = NewGameWizard(self)
|
||||
wizard.show()
|
||||
|
||||
@@ -4,9 +4,9 @@ from PySide2.QtWidgets import (
|
||||
QVBoxLayout,
|
||||
)
|
||||
|
||||
from game import Game
|
||||
from gen.ato import Package
|
||||
from gen.flights.flight import Flight
|
||||
from qt_ui.models import GameModel
|
||||
from qt_ui.uiconstants import EVENT_ICONS
|
||||
from qt_ui.windows.GameUpdateSignal import GameUpdateSignal
|
||||
from qt_ui.windows.mission.flight.QFlightPlanner import QFlightPlanner
|
||||
@@ -15,22 +15,22 @@ from qt_ui.windows.mission.flight.QFlightPlanner import QFlightPlanner
|
||||
class QEditFlightDialog(QDialog):
|
||||
"""Dialog window for editing flight plans and loadouts."""
|
||||
|
||||
def __init__(self, game: Game, package: Package, flight: Flight) -> None:
|
||||
def __init__(self, game_model: GameModel, package: Package, flight: Flight) -> None:
|
||||
super().__init__()
|
||||
|
||||
self.game = game
|
||||
self.game_model = game_model
|
||||
|
||||
self.setWindowTitle("Create flight")
|
||||
self.setWindowIcon(EVENT_ICONS["strike"])
|
||||
|
||||
layout = QVBoxLayout()
|
||||
|
||||
self.flight_planner = QFlightPlanner(package, flight, game)
|
||||
self.flight_planner = QFlightPlanner(package, flight, game_model.game)
|
||||
layout.addWidget(self.flight_planner)
|
||||
|
||||
self.setLayout(layout)
|
||||
self.finished.connect(self.on_close)
|
||||
|
||||
@staticmethod
|
||||
def on_close(_result) -> None:
|
||||
def on_close(self, _result) -> None:
|
||||
GameUpdateSignal.get_instance().redraw_flight_paths()
|
||||
self.game_model.ato_model.client_slots_changed.emit()
|
||||
|
||||
@@ -1,26 +1,28 @@
|
||||
import datetime
|
||||
|
||||
from PySide2.QtGui import QStandardItem, QIcon
|
||||
|
||||
from game import db
|
||||
from gen.ato import Package
|
||||
from gen.flights.flight import Flight
|
||||
from gen.flights.traveltime import TotEstimator
|
||||
from qt_ui.uiconstants import AIRCRAFT_ICONS
|
||||
|
||||
|
||||
# TODO: Replace with QFlightList.
|
||||
class QFlightItem(QStandardItem):
|
||||
|
||||
def __init__(self, flight:Flight):
|
||||
def __init__(self, package: Package, flight: Flight):
|
||||
super(QFlightItem, self).__init__()
|
||||
self.package = package
|
||||
self.flight = flight
|
||||
|
||||
if db.unit_type_name(self.flight.unit_type).replace("/", " ") in AIRCRAFT_ICONS.keys():
|
||||
icon = QIcon((AIRCRAFT_ICONS[db.unit_type_name(self.flight.unit_type)]))
|
||||
self.setIcon(icon)
|
||||
self.setEditable(False)
|
||||
estimator = TotEstimator(self.package)
|
||||
delay = datetime.timedelta(seconds=estimator.mission_start_time(flight))
|
||||
self.setText("["+str(self.flight.flight_type.name[:6])+"] "
|
||||
+ str(self.flight.count) + " x " + db.unit_type_name(self.flight.unit_type)
|
||||
+ " in " + str(self.flight.scheduled_in) + " minutes")
|
||||
|
||||
def update(self, flight):
|
||||
self.flight = flight
|
||||
self.setText("[" + str(self.flight.flight_type.name[:6]) + "] "
|
||||
+ str(self.flight.count) + " x " + db.unit_type_name(self.flight.unit_type)
|
||||
+ " in " + str(self.flight.scheduled_in) + " minutes")
|
||||
+ " in " + str(delay))
|
||||
|
||||
@@ -116,11 +116,14 @@ class QPackageDialog(QDialog):
|
||||
|
||||
self.finished.connect(self.on_close)
|
||||
|
||||
def on_close(self, _result) -> None:
|
||||
@staticmethod
|
||||
def on_close(_result) -> None:
|
||||
GameUpdateSignal.get_instance().redraw_flight_paths()
|
||||
|
||||
def save_tot(self) -> None:
|
||||
time = self.tot_spinner.time()
|
||||
seconds = time.hour() * 3600 + time.minute() * 60 + time.second()
|
||||
self.package_model.update_tot(seconds)
|
||||
GameUpdateSignal.get_instance().redraw_flight_paths()
|
||||
|
||||
def on_selection_changed(self, selected: QItemSelection,
|
||||
_deselected: QItemSelection) -> None:
|
||||
@@ -182,6 +185,7 @@ class QNewPackageDialog(QPackageDialog):
|
||||
Empty packages may be created. They can be modified later, and will have
|
||||
no effect if empty when the mission is generated.
|
||||
"""
|
||||
self.save_tot()
|
||||
self.ato_model.add_package(self.package_model.package)
|
||||
for flight in self.package_model.package.flights:
|
||||
self.game.aircraft_inventory.claim_for_flight(flight)
|
||||
@@ -227,6 +231,7 @@ class QEditPackageDialog(QPackageDialog):
|
||||
|
||||
def on_done(self) -> None:
|
||||
"""Closes the window."""
|
||||
self.save_tot()
|
||||
self.close()
|
||||
|
||||
def on_delete(self) -> None:
|
||||
|
||||
@@ -90,7 +90,11 @@ class QFlightCreator(QDialog):
|
||||
origin = self.airfield_selector.currentData()
|
||||
size = self.flight_size_spinner.value()
|
||||
|
||||
flight = Flight(aircraft, size, origin, task)
|
||||
if self.game.settings.perf_ai_parking_start:
|
||||
start_type = "Cold"
|
||||
else:
|
||||
start_type = "Warm"
|
||||
flight = Flight(aircraft, size, origin, task, start_type)
|
||||
flight.scheduled_in = self.package.delay
|
||||
|
||||
# noinspection PyUnresolvedReferences
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from PySide2.QtWidgets import QLabel, QHBoxLayout, QGroupBox, QSpinBox
|
||||
|
||||
|
||||
# TODO: Remove?
|
||||
class QFlightDepartureEditor(QGroupBox):
|
||||
|
||||
def __init__(self, flight):
|
||||
@@ -15,7 +16,7 @@ class QFlightDepartureEditor(QGroupBox):
|
||||
self.departure_delta = QSpinBox(self)
|
||||
self.departure_delta.setMinimum(0)
|
||||
self.departure_delta.setMaximum(120)
|
||||
self.departure_delta.setValue(self.flight.scheduled_in)
|
||||
self.departure_delta.setValue(self.flight.scheduled_in // 60)
|
||||
self.departure_delta.valueChanged.connect(self.change_scheduled)
|
||||
|
||||
layout.addWidget(self.depart_from)
|
||||
@@ -27,4 +28,4 @@ class QFlightDepartureEditor(QGroupBox):
|
||||
self.changed = self.departure_delta.valueChanged
|
||||
|
||||
def change_scheduled(self):
|
||||
self.flight.scheduled_in = int(self.departure_delta.value())
|
||||
self.flight.scheduled_in = int(self.departure_delta.value() * 60)
|
||||
|
||||
@@ -2,10 +2,10 @@ from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
import logging
|
||||
from typing import List
|
||||
from typing import List, Optional
|
||||
|
||||
from PySide2 import QtGui, QtWidgets
|
||||
from PySide2.QtCore import QItemSelectionModel, QPoint
|
||||
from PySide2.QtCore import QItemSelectionModel, QPoint, Qt
|
||||
from PySide2.QtWidgets import QVBoxLayout
|
||||
from dcs.task import CAP, CAS
|
||||
|
||||
@@ -63,6 +63,7 @@ class NewGameWizard(QtWidgets.QWizard):
|
||||
no_player_navy = self.field("no_player_navy")
|
||||
no_enemy_navy = self.field("no_enemy_navy")
|
||||
invertMap = self.field("invertMap")
|
||||
starting_money = int(self.field("starting_money"))
|
||||
|
||||
player_name = blueFaction
|
||||
enemy_name = redFaction
|
||||
@@ -76,12 +77,12 @@ class NewGameWizard(QtWidgets.QWizard):
|
||||
settings.do_not_generate_enemy_navy = no_enemy_navy
|
||||
|
||||
self.generatedGame = self.start_new_game(player_name, enemy_name, conflictTheater, midGame, multiplier,
|
||||
timePeriod, settings)
|
||||
timePeriod, settings, starting_money)
|
||||
|
||||
super(NewGameWizard, self).accept()
|
||||
|
||||
def start_new_game(self, player_name: str, enemy_name: str, conflictTheater: ConflictTheater,
|
||||
midgame: bool, multiplier: float, period: datetime, settings:Settings):
|
||||
midgame: bool, multiplier: float, period: datetime, settings:Settings, starting_money: int):
|
||||
|
||||
# Reset name generator
|
||||
namegen.reset()
|
||||
@@ -102,14 +103,10 @@ class NewGameWizard(QtWidgets.QWizard):
|
||||
|
||||
print("-- Game Object generated")
|
||||
start_generator.generate_groundobjects(conflictTheater, game)
|
||||
game.budget = int(game.budget * multiplier)
|
||||
game.budget = starting_money
|
||||
game.settings.multiplier = multiplier
|
||||
game.settings.sams = True
|
||||
game.settings.version = CONST.VERSION_STRING
|
||||
|
||||
if midgame:
|
||||
game.budget = game.budget * 4 * len(list(conflictTheater.conflicts()))
|
||||
|
||||
return game
|
||||
|
||||
|
||||
@@ -298,6 +295,44 @@ class TheaterConfiguration(QtWidgets.QWizardPage):
|
||||
self.setLayout(layout)
|
||||
|
||||
|
||||
class CurrencySpinner(QtWidgets.QSpinBox):
|
||||
def __init__(self, minimum: Optional[int] = None,
|
||||
maximum: Optional[int] = None,
|
||||
initial: Optional[int] = None) -> None:
|
||||
super().__init__()
|
||||
|
||||
if minimum is not None:
|
||||
self.setMinimum(minimum)
|
||||
if maximum is not None:
|
||||
self.setMaximum(maximum)
|
||||
if initial is not None:
|
||||
self.setValue(initial)
|
||||
|
||||
def textFromValue(self, val: int) -> str:
|
||||
return f"${val}"
|
||||
|
||||
|
||||
class BudgetInputs(QtWidgets.QGridLayout):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self.addWidget(QtWidgets.QLabel("Starting money"), 0, 0)
|
||||
|
||||
minimum = 0
|
||||
maximum = 5000
|
||||
initial = 650
|
||||
|
||||
slider = QtWidgets.QSlider(Qt.Horizontal)
|
||||
slider.setMinimum(minimum)
|
||||
slider.setMaximum(maximum)
|
||||
slider.setValue(initial)
|
||||
self.starting_money = CurrencySpinner(minimum, maximum, initial)
|
||||
slider.valueChanged.connect(lambda x: self.starting_money.setValue(x))
|
||||
self.starting_money.valueChanged.connect(lambda x: slider.setValue(x))
|
||||
|
||||
self.addWidget(slider, 1, 0)
|
||||
self.addWidget(self.starting_money, 1, 1)
|
||||
|
||||
|
||||
class MiscOptions(QtWidgets.QWizardPage):
|
||||
def __init__(self, parent=None):
|
||||
super(MiscOptions, self).__init__(parent)
|
||||
@@ -330,6 +365,13 @@ class MiscOptions(QtWidgets.QWizardPage):
|
||||
no_enemy_navy = QtWidgets.QCheckBox()
|
||||
self.registerField('no_enemy_navy', no_enemy_navy)
|
||||
|
||||
layout = QtWidgets.QGridLayout()
|
||||
layout.addWidget(QtWidgets.QLabel("Start at mid game"), 1, 0)
|
||||
layout.addWidget(midGame, 1, 1)
|
||||
layout.addWidget(QtWidgets.QLabel("Ennemy forces multiplier [Disabled for Now]"), 2, 0)
|
||||
layout.addWidget(multiplier, 2, 1)
|
||||
miscSettingsGroup.setLayout(layout)
|
||||
|
||||
generatorLayout = QtWidgets.QGridLayout()
|
||||
generatorLayout.addWidget(QtWidgets.QLabel("No Aircraft Carriers"), 1, 0)
|
||||
generatorLayout.addWidget(no_carrier, 1, 1)
|
||||
@@ -343,16 +385,15 @@ class MiscOptions(QtWidgets.QWizardPage):
|
||||
generatorLayout.addWidget(no_enemy_navy, 5, 1)
|
||||
generatorSettingsGroup.setLayout(generatorLayout)
|
||||
|
||||
layout = QtWidgets.QGridLayout()
|
||||
layout.addWidget(QtWidgets.QLabel("Start at mid game"), 1, 0)
|
||||
layout.addWidget(midGame, 1, 1)
|
||||
layout.addWidget(QtWidgets.QLabel("Ennemy forces multiplier [Disabled for Now]"), 2, 0)
|
||||
layout.addWidget(multiplier, 2, 1)
|
||||
miscSettingsGroup.setLayout(layout)
|
||||
budget_inputs = BudgetInputs()
|
||||
economySettingsGroup = QtWidgets.QGroupBox("Economy")
|
||||
economySettingsGroup.setLayout(budget_inputs)
|
||||
self.registerField('starting_money', budget_inputs.starting_money)
|
||||
|
||||
mlayout = QVBoxLayout()
|
||||
mlayout.addWidget(miscSettingsGroup)
|
||||
mlayout.addWidget(generatorSettingsGroup)
|
||||
mlayout.addWidget(economySettingsGroup)
|
||||
self.setLayout(mlayout)
|
||||
|
||||
|
||||
|
||||
@@ -13,9 +13,8 @@ from PySide2.QtWidgets import (
|
||||
QVBoxLayout,
|
||||
)
|
||||
|
||||
import qt_ui.uiconstants as CONST
|
||||
from qt_ui import liberation_install, liberation_theme
|
||||
from qt_ui.liberation_theme import get_theme_index, set_theme_index
|
||||
from qt_ui.liberation_theme import THEMES, get_theme_index, set_theme_index
|
||||
|
||||
|
||||
class QLiberationPreferences(QFrame):
|
||||
@@ -39,7 +38,7 @@ class QLiberationPreferences(QFrame):
|
||||
self.browse_install_dir = QPushButton("Browse...")
|
||||
self.browse_install_dir.clicked.connect(self.on_browse_installation_dir)
|
||||
self.themeSelect = QComboBox()
|
||||
[self.themeSelect.addItem(y['themeName']) for x, y in CONST.THEMES.items()]
|
||||
[self.themeSelect.addItem(y['themeName']) for x, y in THEMES.items()]
|
||||
|
||||
self.initUi()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user