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

60
qt_ui/dialogs.py Normal file
View File

@@ -0,0 +1,60 @@
"""Application-wide dialog management."""
from typing import Optional
from gen.flights.flight import Flight
from theater.missiontarget import MissionTarget
from .models import GameModel, PackageModel
from .windows.mission.QEditFlightDialog import QEditFlightDialog
from .windows.mission.QPackageDialog import (
QEditPackageDialog,
QNewPackageDialog,
)
class Dialog:
"""Dialog management singleton.
Opens dialogs and keeps references to dialog windows so that their creators
do not need to worry about the lifetime of the dialog object, and can open
dialogs without needing to have their own reference to common data like the
game model.
"""
#: The game model. Is only None before initialization, as the game model
#: itself is responsible for handling the case where no game is loaded.
game_model: Optional[GameModel] = None
new_package_dialog: Optional[QNewPackageDialog] = None
edit_package_dialog: Optional[QEditPackageDialog] = None
edit_flight_dialog: Optional[QEditFlightDialog] = None
@classmethod
def set_game(cls, game_model: GameModel) -> None:
"""Sets the game model."""
cls.game_model = game_model
@classmethod
def open_new_package_dialog(cls, mission_target: MissionTarget):
"""Opens the dialog to create a new package with the given target."""
cls.new_package_dialog = QNewPackageDialog(
cls.game_model.game,
cls.game_model.ato_model,
mission_target
)
cls.new_package_dialog.show()
@classmethod
def open_edit_package_dialog(cls, package_model: PackageModel):
"""Opens the dialog to edit the given package."""
cls.edit_package_dialog = QEditPackageDialog(
cls.game_model.game,
cls.game_model.ato_model,
package_model
)
cls.edit_package_dialog.show()
@classmethod
def open_edit_flight_dialog(cls, flight: Flight):
"""Opens the dialog to edit the given flight."""
cls.edit_flight_dialog = QEditFlightDialog(cls.game_model.game, flight)
cls.edit_flight_dialog.show()

268
qt_ui/models.py Normal file
View File

@@ -0,0 +1,268 @@
"""Qt data models for game objects."""
from typing import Any, Callable, Dict, Iterator, TypeVar, Optional
from PySide2.QtCore import (
QAbstractListModel,
QModelIndex,
Qt,
Signal,
)
from PySide2.QtGui import QIcon
from game import db
from game.game import Game
from gen.ato import AirTaskingOrder, Package
from gen.flights.flight import Flight
from qt_ui.uiconstants import AIRCRAFT_ICONS
from theater.missiontarget import MissionTarget
class DeletableChildModelManager:
"""Manages lifetimes for child models.
Qt's data models don't have a good way of modeling related data aside from
lists, tables, or trees of similar objects. We could build one monolithic
GameModel that tracks all of the data in the game and use the parent/child
relationships of that model to index down into the ATO, packages, flights,
etc, but doing so is error prone because it requires us to manually manage
that relationship tree and keep our own mappings from row/column into
specific members.
However, creating child models outside of the tree means that removing an
item from the parent will not signal the child's deletion to any views, so
we must track this explicitly.
Any model which has child data types should use this class to track the
deletion of child models. All child model types must define a signal named
`deleted`. This signal will be emitted when the child model is being
deleted. Any views displaying such data should subscribe to those events and
update their display accordingly.
"""
#: The type of data owned by models created by this class.
DataType = TypeVar("DataType")
#: The type of model managed by this class.
ModelType = TypeVar("ModelType")
ModelDict = Dict[DataType, ModelType]
def __init__(self, create_model: Callable[[DataType], ModelType]) -> None:
self.create_model = create_model
self.models: DeletableChildModelManager.ModelDict = {}
def acquire(self, data: DataType) -> ModelType:
"""Returns a model for the given child data.
If a model has already been created for the given data, it will be
returned. The data type must be hashable.
"""
if data in self.models:
return self.models[data]
model = self.create_model(data)
self.models[data] = model
return model
def release(self, data: DataType) -> None:
"""Releases the model matching the given data, if one exists.
If the given data has had a model created for it, that model will be
deleted and its `deleted` signal will be emitted.
"""
if data in self.models:
model = self.models[data]
del self.models[data]
model.deleted.emit()
def clear(self) -> None:
"""Deletes all managed models."""
for data in list(self.models.keys()):
self.release(data)
class NullListModel(QAbstractListModel):
"""Generic empty list model."""
def rowCount(self, parent: QModelIndex = QModelIndex()) -> int:
return 0
def data(self, index: QModelIndex, role: int = Qt.DisplayRole) -> Any:
return None
class PackageModel(QAbstractListModel):
"""The model for an ATO package."""
#: Emitted when this package is being deleted from the ATO.
deleted = Signal()
def __init__(self, package: Package) -> None:
super().__init__()
self.package = package
def rowCount(self, parent: QModelIndex = QModelIndex()) -> int:
return len(self.package.flights)
def data(self, index: QModelIndex, role: int = Qt.DisplayRole) -> Any:
if not index.isValid():
return None
flight = self.flight_at_index(index)
if role == Qt.DisplayRole:
return self.text_for_flight(flight)
if role == Qt.DecorationRole:
return self.icon_for_flight(flight)
return None
@staticmethod
def text_for_flight(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
origin = flight.from_cp.name
return f"[{task}] {count} x {name} from {origin} in {delay} minutes"
@staticmethod
def icon_for_flight(flight: Flight) -> Optional[QIcon]:
"""Returns the icon that should be displayed for the flight."""
name = db.unit_type_name(flight.unit_type)
if name in AIRCRAFT_ICONS:
return QIcon(AIRCRAFT_ICONS[name])
return None
def add_flight(self, flight: Flight) -> None:
"""Adds the given flight to the package."""
self.beginInsertRows(QModelIndex(), self.rowCount(), self.rowCount())
self.package.add_flight(flight)
self.endInsertRows()
def delete_flight_at_index(self, index: QModelIndex) -> None:
"""Removes the flight at the given index from the package."""
self.delete_flight(self.flight_at_index(index))
def delete_flight(self, flight: Flight) -> None:
"""Removes the given flight from the package.
If the flight is using claimed inventory, the caller is responsible for
returning that inventory.
"""
index = self.package.flights.index(flight)
self.beginRemoveRows(QModelIndex(), index, index)
self.package.remove_flight(flight)
self.endRemoveRows()
def flight_at_index(self, index: QModelIndex) -> Flight:
"""Returns the flight located at the given index."""
return self.package.flights[index.row()]
@property
def mission_target(self) -> MissionTarget:
"""Returns the mission target of the package."""
package = self.package
target = package.target
return target
@property
def description(self) -> str:
"""Returns the description of the package."""
return self.package.package_description
@property
def flights(self) -> Iterator[Flight]:
"""Iterates over the flights in the package."""
for flight in self.package.flights:
yield flight
class AtoModel(QAbstractListModel):
"""The model for an AirTaskingOrder."""
def __init__(self, game: Optional[Game], ato: AirTaskingOrder) -> None:
super().__init__()
self.game = game
self.ato = ato
self.package_models = DeletableChildModelManager(PackageModel)
def rowCount(self, parent: QModelIndex = QModelIndex()) -> int:
return len(self.ato.packages)
def data(self, index: QModelIndex, role: int = Qt.DisplayRole) -> Any:
if not index.isValid():
return None
if role == Qt.DisplayRole:
package = self.ato.packages[index.row()]
return f"{package.package_description} {package.target.name}"
return None
def add_package(self, package: Package) -> None:
"""Adds a package to the ATO."""
self.beginInsertRows(QModelIndex(), self.rowCount(), self.rowCount())
self.ato.add_package(package)
self.endInsertRows()
def delete_package_at_index(self, index: QModelIndex) -> None:
"""Removes the package at the given index from the ATO."""
self.delete_package(self.package_at_index(index))
def delete_package(self, package: Package) -> None:
"""Removes the given package from the ATO."""
self.package_models.release(package)
index = self.ato.packages.index(package)
self.beginRemoveRows(QModelIndex(), index, index)
self.ato.remove_package(package)
for flight in package.flights:
self.game.aircraft_inventory.return_from_flight(flight)
self.endRemoveRows()
def package_at_index(self, index: QModelIndex) -> Package:
"""Returns the package at the given index."""
return self.ato.packages[index.row()]
def replace_from_game(self, game: Optional[Game]) -> None:
"""Updates the ATO object to match the updated game object.
If the game is None (as is the case when no game has been loaded), an
empty ATO will be used.
"""
self.beginResetModel()
self.game = game
self.package_models.clear()
if self.game is not None:
self.ato = game.blue_ato
else:
self.ato = AirTaskingOrder()
self.endResetModel()
def get_package_model(self, index: QModelIndex) -> PackageModel:
"""Returns a model for the package at the given index."""
return self.package_models.acquire(self.package_at_index(index))
@property
def packages(self) -> Iterator[PackageModel]:
"""Iterates over all the packages in the ATO."""
for package in self.ato.packages:
yield self.package_models.acquire(package)
class GameModel:
"""A model for the Game object.
This isn't a real Qt data model, but simplifies management of the game and
its ATO objects.
"""
def __init__(self) -> None:
self.game: Optional[Game] = None
# TODO: Add red ATO model, add cheat option to show red flight plan.
self.ato_model = AtoModel(self.game, AirTaskingOrder())
def set(self, game: Optional[Game]) -> None:
"""Updates the managed Game object.
The argument will be None when no game has been loaded. In this state,
much of the UI is still visible and needs to handle that behavior. To
simplify that case, the AtoModel will model an empty ATO when no game is
loaded.
"""
self.game = game
self.ato_model.replace_from_game(self.game)

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)

View File

@@ -1,22 +1,36 @@
import logging
import sys
import webbrowser
from typing import Optional
from PySide2.QtCore import Qt
from PySide2.QtGui import QIcon
from PySide2.QtWidgets import QWidget, QVBoxLayout, QMainWindow, QAction, QMessageBox, QDesktopWidget, \
QSplitter, QFileDialog
from PySide2.QtWidgets import (
QAction,
QDesktopWidget,
QFileDialog,
QMainWindow,
QMessageBox,
QSplitter,
QVBoxLayout,
QWidget,
)
import qt_ui.uiconstants as CONST
from game import Game
from game.inventory import GlobalAircraftInventory
from qt_ui.dialogs import Dialog
from qt_ui.models import GameModel
from qt_ui.uiconstants import URLS
from qt_ui.widgets.QTopPanel import QTopPanel
from qt_ui.widgets.ato import QAirTaskingOrderPanel
from qt_ui.widgets.map.QLiberationMap import QLiberationMap
from qt_ui.windows.GameUpdateSignal import GameUpdateSignal, DebriefingSignal
from qt_ui.windows.GameUpdateSignal import DebriefingSignal, GameUpdateSignal
from qt_ui.windows.QDebriefingWindow import QDebriefingWindow
from qt_ui.windows.newgame.QNewGameWizard import NewGameWizard
from qt_ui.windows.infos.QInfoPanel import QInfoPanel
from qt_ui.windows.preferences.QLiberationPreferencesWindow import QLiberationPreferencesWindow
from qt_ui.windows.newgame.QNewGameWizard import NewGameWizard
from qt_ui.windows.preferences.QLiberationPreferencesWindow import \
QLiberationPreferencesWindow
from userdata import persistency
@@ -25,6 +39,10 @@ class QLiberationWindow(QMainWindow):
def __init__(self):
super(QLiberationWindow, self).__init__()
self.game: Optional[Game] = None
self.game_model = GameModel()
Dialog.set_game(self.game_model)
self.ato_panel = None
self.info_panel = None
self.setGame(persistency.restore_game())
@@ -44,16 +62,19 @@ class QLiberationWindow(QMainWindow):
self.setGeometry(0, 0, screen.width(), screen.height())
self.setWindowState(Qt.WindowMaximized)
def initUi(self):
self.liberation_map = QLiberationMap(self.game)
self.ato_panel = QAirTaskingOrderPanel(self.game_model)
self.liberation_map = QLiberationMap(self.game_model)
self.info_panel = QInfoPanel(self.game)
hbox = QSplitter(Qt.Horizontal)
hbox.addWidget(self.info_panel)
hbox.addWidget(self.liberation_map)
hbox.setSizes([2, 8])
vbox = QSplitter(Qt.Vertical)
hbox.addWidget(self.ato_panel)
hbox.addWidget(vbox)
vbox.addWidget(self.liberation_map)
vbox.addWidget(self.info_panel)
hbox.setSizes([100, 600])
vbox.setSizes([600, 100])
vbox = QVBoxLayout()
vbox.setMargin(0)
@@ -210,10 +231,11 @@ class QLiberationWindow(QMainWindow):
def exit(self):
sys.exit(0)
def setGame(self, game: Game):
def setGame(self, game: Optional[Game]):
self.game = game
if self.info_panel:
self.info_panel.setGame(game)
self.game_model.set(self.game)
def showAboutDialog(self):
text = "<h3>DCS Liberation " + CONST.VERSION_STRING + "</h3>" + \

View File

@@ -1,9 +1,9 @@
from PySide2.QtCore import Qt
from PySide2.QtGui import QCloseEvent, QPixmap
from PySide2.QtWidgets import QHBoxLayout, QLabel, QWidget, QDialog, QGridLayout
from PySide2.QtWidgets import QDialog, QGridLayout, QHBoxLayout, QLabel, QWidget
from game import Game
from game.event import ControlPointType
from qt_ui.models import GameModel
from qt_ui.uiconstants import EVENT_ICONS
from qt_ui.windows.GameUpdateSignal import GameUpdateSignal
from qt_ui.windows.basemenu.QBaseMenuTabs import QBaseMenuTabs
@@ -13,19 +13,20 @@ from theater import ControlPoint
class QBaseMenu2(QDialog):
def __init__(self, parent, cp: ControlPoint, game: Game):
def __init__(self, parent, cp: ControlPoint, game_model: GameModel):
super(QBaseMenu2, self).__init__(parent)
# Attrs
self.cp = cp
self.game = game
self.game_model = game_model
self.is_carrier = self.cp.cptype in [ControlPointType.AIRCRAFT_CARRIER_GROUP, ControlPointType.LHA_GROUP]
self.objectName = "menuDialogue"
# Widgets
self.qbase_menu_tab = QBaseMenuTabs(cp, game)
self.qbase_menu_tab = QBaseMenuTabs(cp, self.game_model)
try:
game = self.game_model.game
self.airport = game.theater.terrain.airport_by_id(self.cp.id)
except:
self.airport = None
@@ -70,7 +71,9 @@ class QBaseMenu2(QDialog):
self.mainLayout.addWidget(header, 0, 0)
self.mainLayout.addWidget(self.topLayoutWidget, 1, 0)
self.mainLayout.addWidget(self.qbase_menu_tab, 2, 0)
totalBudget = QLabel(QRecruitBehaviour.BUDGET_FORMAT.format(self.game.budget))
totalBudget = QLabel(
QRecruitBehaviour.BUDGET_FORMAT.format(self.game_model.game.budget)
)
totalBudget.setObjectName("budgetField")
totalBudget.setAlignment(Qt.AlignRight | Qt.AlignBottom)
totalBudget.setProperty("style", "budget-label")
@@ -78,7 +81,7 @@ class QBaseMenu2(QDialog):
self.setLayout(self.mainLayout)
def closeEvent(self, closeEvent:QCloseEvent):
GameUpdateSignal.get_instance().updateGame(self.game)
GameUpdateSignal.get_instance().updateGame(self.game_model.game)
def get_base_image(self):
if self.cp.cptype == ControlPointType.AIRCRAFT_CARRIER_GROUP:

View File

@@ -1,6 +1,6 @@
from PySide2.QtWidgets import QTabWidget, QFrame, QGridLayout, QLabel
from PySide2.QtWidgets import QFrame, QGridLayout, QLabel, QTabWidget
from game import Game
from qt_ui.models import GameModel
from qt_ui.windows.basemenu.airfield.QAirfieldCommand import QAirfieldCommand
from qt_ui.windows.basemenu.base_defenses.QBaseDefensesHQ import QBaseDefensesHQ
from qt_ui.windows.basemenu.ground_forces.QGroundForcesHQ import QGroundForcesHQ
@@ -10,29 +10,29 @@ from theater import ControlPoint
class QBaseMenuTabs(QTabWidget):
def __init__(self, cp: ControlPoint, game: Game):
def __init__(self, cp: ControlPoint, game_model: GameModel):
super(QBaseMenuTabs, self).__init__()
self.cp = cp
if cp:
if not cp.captured:
self.intel = QIntelInfo(cp, game)
self.intel = QIntelInfo(cp, game_model.game)
self.addTab(self.intel, "Intel")
if not cp.is_carrier:
self.base_defenses_hq = QBaseDefensesHQ(cp, game)
self.base_defenses_hq = QBaseDefensesHQ(cp, game_model.game)
self.addTab(self.base_defenses_hq, "Base Defenses")
else:
if cp.has_runway():
self.airfield_command = QAirfieldCommand(cp, game)
self.airfield_command = QAirfieldCommand(cp, game_model)
self.addTab(self.airfield_command, "Airfield Command")
if not cp.is_carrier:
self.ground_forces_hq = QGroundForcesHQ(cp, game)
self.ground_forces_hq = QGroundForcesHQ(cp, game_model)
self.addTab(self.ground_forces_hq, "Ground Forces HQ")
self.base_defenses_hq = QBaseDefensesHQ(cp, game)
self.base_defenses_hq = QBaseDefensesHQ(cp, game_model.game)
self.addTab(self.base_defenses_hq, "Base Defenses")
else:
self.base_defenses_hq = QBaseDefensesHQ(cp, game)
self.base_defenses_hq = QBaseDefensesHQ(cp, game_model.game)
self.addTab(self.base_defenses_hq, "Fleet")
else:

View File

@@ -1,25 +1,34 @@
from PySide2.QtWidgets import QLabel, QPushButton, \
QSizePolicy, QSpacerItem, QGroupBox, QHBoxLayout
from PySide2.QtWidgets import (
QGroupBox,
QHBoxLayout,
QLabel,
QPushButton,
QSizePolicy,
QSpacerItem,
)
from dcs.unittype import UnitType
from theater import db
class QRecruitBehaviour:
game = None
cp = None
deliveryEvent = None
existing_units_labels = None
bought_amount_labels = None
class QRecruitBehaviour:
BUDGET_FORMAT = "Available Budget: <b>${}M</b>"
def __init__(self):
def __init__(self) -> None:
self.deliveryEvent = None
self.bought_amount_labels = {}
self.existing_units_labels = {}
self.update_available_budget()
def add_purchase_row(self, unit_type, layout, row):
@property
def budget(self) -> int:
return self.game_model.game.budget
@budget.setter
def budget(self, value: int) -> None:
self.game_model.game.budget = value
def add_purchase_row(self, unit_type, layout, row):
exist = QGroupBox()
exist.setProperty("style", "buy-box")
exist.setMaximumHeight(36)
@@ -98,27 +107,28 @@ class QRecruitBehaviour:
parent = parent.parent()
for child in parent.children():
if child.objectName() == "budgetField":
child.setText(QRecruitBehaviour.BUDGET_FORMAT.format(self.game.budget))
child.setText(
QRecruitBehaviour.BUDGET_FORMAT.format(self.budget))
def buy(self, unit_type):
price = db.PRICES[unit_type]
if self.game.budget >= price:
if self.budget >= price:
self.deliveryEvent.deliver({unit_type: 1})
self.game.budget -= price
self.budget -= price
self._update_count_label(unit_type)
self.update_available_budget()
def sell(self, unit_type):
if self.deliveryEvent.units.get(unit_type, 0) > 0:
price = db.PRICES[unit_type]
self.game.budget += price
self.budget += price
self.deliveryEvent.units[unit_type] = self.deliveryEvent.units[unit_type] - 1
if self.deliveryEvent.units[unit_type] == 0:
del self.deliveryEvent.units[unit_type]
elif self.cp.base.total_units_of_type(unit_type) > 0:
price = db.PRICES[unit_type]
self.game.budget += price
self.budget += price
self.cp.base.commit_losses({unit_type: 1})
self._update_count_label(unit_type)

View File

@@ -1,27 +1,35 @@
from PySide2.QtCore import Qt
from PySide2.QtWidgets import QVBoxLayout, QGridLayout, QGroupBox, QScrollArea, QFrame, QWidget
from typing import Optional
from game.event import UnitsDeliveryEvent
from PySide2.QtCore import Qt
from PySide2.QtWidgets import (
QFrame,
QGridLayout,
QScrollArea,
QVBoxLayout,
QWidget,
)
from game.event.event import UnitsDeliveryEvent
from qt_ui.models import GameModel
from qt_ui.windows.basemenu.QRecruitBehaviour import QRecruitBehaviour
from theater import ControlPoint, CAP, CAS, db
from game import Game
from theater import CAP, CAS, ControlPoint, db
class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
def __init__(self, cp:ControlPoint, game:Game):
def __init__(self, cp: ControlPoint, game_model: GameModel) -> None:
QFrame.__init__(self)
self.cp = cp
self.game = game
self.game_model = game_model
self.deliveryEvent: Optional[UnitsDeliveryEvent] = None
self.bought_amount_labels = {}
self.existing_units_labels = {}
for event in self.game.events:
for event in self.game_model.game.events:
if event.__class__ == UnitsDeliveryEvent and event.from_cp == self.cp:
self.deliveryEvent = event
if not self.deliveryEvent:
self.deliveryEvent = self.game.units_delivery_event(self.cp)
self.deliveryEvent = self.game_model.game.units_delivery_event(self.cp)
self.init_ui()
@@ -29,8 +37,8 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
main_layout = QVBoxLayout()
units = {
CAP: db.find_unittype(CAP, self.game.player_name),
CAS: db.find_unittype(CAS, self.game.player_name),
CAP: db.find_unittype(CAP, self.game_model.game.player_name),
CAS: db.find_unittype(CAS, self.game_model.game.player_name),
}
scroll_content = QWidget()
@@ -39,7 +47,8 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
for task_type in units.keys():
units_column = list(set(units[task_type]))
if len(units_column) == 0: continue
if len(units_column) == 0:
continue
units_column.sort(key=lambda x: db.PRICES[x])
for unit_type in units_column:
if self.cp.is_carrier and not unit_type in db.CARRIER_CAPABLE:

View File

@@ -1,27 +1,30 @@
from PySide2.QtWidgets import QFrame, QGridLayout, QLabel, QHBoxLayout, QGroupBox, QVBoxLayout
from game import Game
from qt_ui.widgets.base.QAirportInformation import QAirportInformation
from qt_ui.windows.basemenu.airfield.QAircraftRecruitmentMenu import QAircraftRecruitmentMenu
from PySide2.QtWidgets import QFrame, QGridLayout, QGroupBox, QVBoxLayout
from qt_ui.models import GameModel
from qt_ui.windows.basemenu.airfield.QAircraftRecruitmentMenu import \
QAircraftRecruitmentMenu
from qt_ui.windows.mission.QPlannedFlightsView import QPlannedFlightsView
from theater import ControlPoint
class QAirfieldCommand(QFrame):
def __init__(self, cp:ControlPoint, game:Game):
def __init__(self, cp:ControlPoint, game_model: GameModel):
super(QAirfieldCommand, self).__init__()
self.cp = cp
self.game = game
self.game_model = game_model
self.init_ui()
def init_ui(self):
layout = QGridLayout()
layout.addWidget(QAircraftRecruitmentMenu(self.cp, self.game), 0, 0)
layout.addWidget(QAircraftRecruitmentMenu(self.cp, self.game_model), 0, 0)
try:
planned = QGroupBox("Planned Flights")
planned_layout = QVBoxLayout()
planned_layout.addWidget(QPlannedFlightsView(self.game.planners[self.cp.id]))
planned_layout.addWidget(
QPlannedFlightsView(self.game_model, self.cp)
)
planned.setLayout(planned_layout)
layout.addWidget(planned, 0, 1)
except:

View File

@@ -1,27 +1,33 @@
from PySide2.QtCore import Qt
from PySide2.QtWidgets import QVBoxLayout, QGridLayout, QGroupBox, QFrame, QWidget, QScrollArea
from PySide2.QtWidgets import (
QFrame,
QGridLayout,
QScrollArea,
QVBoxLayout,
QWidget,
)
from game import Game
from game.event import UnitsDeliveryEvent
from qt_ui.models import GameModel
from qt_ui.windows.basemenu.QRecruitBehaviour import QRecruitBehaviour
from theater import ControlPoint, PinpointStrike, db
class QArmorRecruitmentMenu(QFrame, QRecruitBehaviour):
def __init__(self, cp:ControlPoint, game:Game):
def __init__(self, cp: ControlPoint, game_model: GameModel):
QFrame.__init__(self)
self.cp = cp
self.game = game
self.game_model = game_model
self.bought_amount_labels = {}
self.existing_units_labels = {}
for event in self.game.events:
for event in self.game_model.game.events:
if event.__class__ == UnitsDeliveryEvent and event.from_cp == self.cp:
self.deliveryEvent = event
if not self.deliveryEvent:
self.deliveryEvent = self.game.units_delivery_event(self.cp)
self.deliveryEvent = self.game_model.game.units_delivery_event(self.cp)
self.init_ui()
@@ -29,7 +35,8 @@ class QArmorRecruitmentMenu(QFrame, QRecruitBehaviour):
main_layout = QVBoxLayout()
units = {
PinpointStrike: db.find_unittype(PinpointStrike, self.game.player_name),
PinpointStrike: db.find_unittype(PinpointStrike,
self.game_model.game.player_name),
}
scroll_content = QWidget()

View File

@@ -1,21 +1,24 @@
from PySide2.QtWidgets import QFrame, QGridLayout
from game import Game
from qt_ui.windows.basemenu.ground_forces.QArmorRecruitmentMenu import QArmorRecruitmentMenu
from qt_ui.windows.basemenu.ground_forces.QGroundForcesStrategy import QGroundForcesStrategy
from qt_ui.models import GameModel
from qt_ui.windows.basemenu.ground_forces.QArmorRecruitmentMenu import \
QArmorRecruitmentMenu
from qt_ui.windows.basemenu.ground_forces.QGroundForcesStrategy import \
QGroundForcesStrategy
from theater import ControlPoint
class QGroundForcesHQ(QFrame):
def __init__(self, cp:ControlPoint, game:Game):
def __init__(self, cp: ControlPoint, game_model: GameModel) -> None:
super(QGroundForcesHQ, self).__init__()
self.cp = cp
self.game = game
self.game_model = game_model
self.init_ui()
def init_ui(self):
layout = QGridLayout()
layout.addWidget(QArmorRecruitmentMenu(self.cp, self.game), 0, 0)
layout.addWidget(QGroundForcesStrategy(self.cp, self.game), 0, 1)
layout.addWidget(QArmorRecruitmentMenu(self.cp, self.game_model), 0, 0)
layout.addWidget(QGroundForcesStrategy(self.cp, self.game_model.game),
0, 1)
self.setLayout(layout)

View File

@@ -0,0 +1,29 @@
"""Dialog window for editing flights."""
from PySide2.QtWidgets import (
QDialog,
QVBoxLayout,
)
from game import Game
from gen.flights.flight import Flight
from qt_ui.uiconstants import EVENT_ICONS
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, flight: Flight) -> None:
super().__init__()
self.game = game
self.setWindowTitle("Create flight")
self.setWindowIcon(EVENT_ICONS["strike"])
layout = QVBoxLayout()
self.flight_planner = QFlightPlanner(flight, game)
layout.addWidget(self.flight_planner)
self.setLayout(layout)

View File

@@ -1,159 +0,0 @@
from PySide2.QtCore import Qt, Slot, QItemSelectionModel, QPoint
from PySide2.QtWidgets import QDialog, QGridLayout, QScrollArea, QVBoxLayout, QPushButton, QHBoxLayout, QMessageBox
from game import Game
from game.event import CAP, CAS, FrontlineAttackEvent
from qt_ui.uiconstants import EVENT_ICONS
from qt_ui.windows.QWaitingForMissionResultWindow import QWaitingForMissionResultWindow
from qt_ui.windows.mission.QPlannedFlightsView import QPlannedFlightsView
from qt_ui.windows.mission.QChooseAirbase import QChooseAirbase
from qt_ui.windows.mission.flight.QFlightCreator import QFlightCreator
from qt_ui.windows.mission.flight.QFlightPlanner import QFlightPlanner
class QMissionPlanning(QDialog):
def __init__(self, game: Game):
super(QMissionPlanning, self).__init__()
self.game = game
self.setWindowFlags(Qt.WindowStaysOnTopHint)
self.setMinimumSize(1000, 440)
self.setWindowTitle("Mission Preparation")
self.setWindowIcon(EVENT_ICONS["strike"])
self.init_ui()
print("DONE")
def init_ui(self):
self.captured_cp = [cp for cp in self.game.theater.controlpoints if cp.captured]
self.layout = QGridLayout()
self.left_bar_layout = QVBoxLayout()
self.select_airbase = QChooseAirbase(self.game)
self.select_airbase.selected_airbase_changed.connect(self.on_departure_cp_changed)
self.planned_flight_view = QPlannedFlightsView(None)
self.available_aircraft_at_selected_location = {}
if self.captured_cp[0].id in self.game.planners.keys():
self.planner = self.game.planners[self.captured_cp[0].id]
self.planned_flight_view.set_flight_planner(self.planner)
self.selected_cp = self.captured_cp[0]
self.available_aircraft_at_selected_location = self.planner.get_available_aircraft()
self.planned_flight_view.selectionModel().setCurrentIndex(self.planned_flight_view.indexAt(QPoint(1, 1)), QItemSelectionModel.Rows)
self.planned_flight_view.selectionModel().selectionChanged.connect(self.on_flight_selection_change)
if len(self.planned_flight_view.flight_planner.flights) > 0:
self.flight_planner = QFlightPlanner(self.planned_flight_view.flight_planner.flights[0], self.game, self.planned_flight_view.flight_planner, 0)
self.flight_planner.on_planned_flight_changed.connect(self.update_planned_flight_view)
else:
self.flight_planner = QFlightPlanner(None, self.game, self.planned_flight_view.flight_planner, 0)
self.flight_planner.on_planned_flight_changed.connect(self.update_planned_flight_view)
self.add_flight_button = QPushButton("Add Flight")
self.add_flight_button.clicked.connect(self.on_add_flight)
self.delete_flight_button = QPushButton("Delete Selected")
self.delete_flight_button.setProperty("style", "btn-danger")
self.delete_flight_button.clicked.connect(self.on_delete_flight)
self.button_layout = QHBoxLayout()
self.button_layout.addStretch()
self.button_layout.addWidget(self.delete_flight_button)
self.button_layout.addWidget(self.add_flight_button)
self.mission_start_button = QPushButton("Take Off")
self.mission_start_button.setProperty("style", "start-button")
self.mission_start_button.clicked.connect(self.on_start)
self.left_bar_layout.addWidget(self.select_airbase)
self.left_bar_layout.addWidget(self.planned_flight_view)
self.left_bar_layout.addLayout(self.button_layout)
self.layout.addLayout(self.left_bar_layout, 0, 0)
self.layout.addWidget(self.flight_planner, 0, 1)
self.layout.addWidget(self.mission_start_button, 1, 1, alignment=Qt.AlignRight)
self.setLayout(self.layout)
@Slot(str)
def on_departure_cp_changed(self, cp_name):
cps = [cp for cp in self.game.theater.controlpoints if cp.name == cp_name]
print(cps)
if len(cps) == 1:
self.selected_cp = cps[0]
self.planner = self.game.planners[cps[0].id]
self.available_aircraft_at_selected_location = self.planner.get_available_aircraft()
self.planned_flight_view.set_flight_planner(self.planner)
else:
self.available_aircraft_at_selected_location = {}
self.planned_flight_view.set_flight_planner(None)
def on_flight_selection_change(self):
print("On flight selection change")
index = self.planned_flight_view.selectionModel().currentIndex().row()
self.planned_flight_view.repaint()
if self.flight_planner is not None:
self.flight_planner.on_planned_flight_changed.disconnect()
self.flight_planner.clearTabs()
try:
flight = self.planner.flights[index]
except IndexError:
flight = None
self.flight_planner = QFlightPlanner(flight, self.game, self.planner, self.flight_planner.currentIndex())
self.flight_planner.on_planned_flight_changed.connect(self.update_planned_flight_view)
self.layout.addWidget(self.flight_planner, 0, 1)
def update_planned_flight_view(self):
self.planned_flight_view.update_content()
def on_add_flight(self):
possible_aircraft_type = list(self.selected_cp.base.aircraft.keys())
if len(possible_aircraft_type) == 0:
msg = QMessageBox()
msg.setIcon(QMessageBox.Information)
msg.setText("No more aircraft are available on " + self.selected_cp.name + " airbase.")
msg.setWindowTitle("No more aircraft")
msg.setStandardButtons(QMessageBox.Ok)
msg.setWindowFlags(Qt.WindowStaysOnTopHint)
msg.exec_()
else:
self.subwindow = QFlightCreator(self.game, self.selected_cp, possible_aircraft_type, self.planned_flight_view)
self.subwindow.show()
def on_delete_flight(self):
index = self.planned_flight_view.selectionModel().currentIndex().row()
self.planner.remove_flight(index)
self.planned_flight_view.set_flight_planner(self.planner, index)
def on_start(self):
# TODO : refactor this nonsense
self.gameEvent = None
for event in self.game.events:
if isinstance(event, FrontlineAttackEvent) and event.is_player_attacking:
self.gameEvent = event
if self.gameEvent is None:
self.gameEvent = 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)
#if self.awacs_checkbox.isChecked() == 1:
# self.gameEvent.is_awacs_enabled = True
# self.game.awacs_expense_commit()
#else:
# self.gameEvent.is_awacs_enabled = False
self.gameEvent.is_awacs_enabled = True
self.gameEvent.ca_slots = 1
self.gameEvent.departure_cp = self.game.theater.controlpoints[0]
self.gameEvent.player_attacking({CAS:{}, CAP:{}})
self.gameEvent.depart_from = self.game.theater.controlpoints[0]
self.game.initiate_event(self.gameEvent)
waiting = QWaitingForMissionResultWindow(self.gameEvent, self.game)
waiting.show()
self.close()

View File

@@ -0,0 +1,198 @@
"""Dialogs for creating and editing ATO packages."""
import logging
from typing import Optional
from PySide2.QtCore import QItemSelection, Signal
from PySide2.QtWidgets import (
QDialog,
QHBoxLayout,
QLabel,
QPushButton,
QVBoxLayout,
)
from game.game import Game
from gen.ato import Package
from gen.flights.flight import Flight
from qt_ui.models import AtoModel, PackageModel
from qt_ui.uiconstants import EVENT_ICONS
from qt_ui.widgets.ato import QFlightList
from qt_ui.windows.mission.flight.QFlightCreator import QFlightCreator
from theater.missiontarget import MissionTarget
class QPackageDialog(QDialog):
"""Base package management dialog.
The dialogs for creating a new package and editing an existing dialog are
very similar, and this implements the shared behavior.
"""
#: Emitted when a change is made to the package.
package_changed = Signal()
#: Emitted when a flight is added to the package.
flight_added = Signal(Flight)
#: Emitted when a flight is removed from the package.
flight_removed = Signal(Flight)
def __init__(self, game: Game, model: PackageModel) -> None:
super().__init__()
self.game = game
self.package_model = model
self.add_flight_dialog: Optional[QFlightCreator] = None
self.setMinimumSize(1000, 440)
self.setWindowTitle(
f"Mission Package: {self.package_model.mission_target.name}"
)
self.setWindowIcon(EVENT_ICONS["strike"])
self.layout = QVBoxLayout()
self.summary_row = QHBoxLayout()
self.layout.addLayout(self.summary_row)
self.package_type_label = QLabel("Package Type:")
self.package_type_text = QLabel(self.package_model.description)
# noinspection PyUnresolvedReferences
self.package_changed.connect(lambda: self.package_type_text.setText(
self.package_model.description
))
self.summary_row.addWidget(self.package_type_label)
self.summary_row.addWidget(self.package_type_text)
self.package_view = QFlightList(self.package_model)
self.package_view.selectionModel().selectionChanged.connect(
self.on_selection_changed
)
self.layout.addWidget(self.package_view)
self.button_layout = QHBoxLayout()
self.layout.addLayout(self.button_layout)
self.add_flight_button = QPushButton("Add Flight")
self.add_flight_button.clicked.connect(self.on_add_flight)
self.button_layout.addWidget(self.add_flight_button)
self.delete_flight_button = QPushButton("Delete Selected")
self.delete_flight_button.setProperty("style", "btn-danger")
self.delete_flight_button.clicked.connect(self.on_delete_flight)
self.delete_flight_button.setEnabled(False)
self.button_layout.addWidget(self.delete_flight_button)
self.button_layout.addStretch()
self.setLayout(self.layout)
def on_selection_changed(self, selected: QItemSelection,
_deselected: QItemSelection) -> None:
"""Updates the state of the delete button."""
self.delete_flight_button.setEnabled(not selected.empty())
def on_add_flight(self) -> None:
"""Opens the new flight dialog."""
self.add_flight_dialog = QFlightCreator(
self.game, self.package_model.package
)
self.add_flight_dialog.created.connect(self.add_flight)
self.add_flight_dialog.show()
def add_flight(self, flight: Flight) -> None:
"""Adds the new flight to the package."""
self.package_model.add_flight(flight)
# noinspection PyUnresolvedReferences
self.package_changed.emit()
# noinspection PyUnresolvedReferences
self.flight_added.emit(flight)
def on_delete_flight(self) -> None:
"""Removes the selected flight from the package."""
flight = self.package_view.selected_item
if flight is None:
logging.error(f"Cannot delete flight when no flight is selected.")
return
self.package_model.delete_flight(flight)
# noinspection PyUnresolvedReferences
self.package_changed.emit()
# noinspection PyUnresolvedReferences
self.flight_removed.emit(flight)
class QNewPackageDialog(QPackageDialog):
"""Dialog window for creating a new package.
New packages do not affect the ATO model until they are saved.
"""
def __init__(self, game: Game, model: AtoModel,
target: MissionTarget) -> None:
super().__init__(game, PackageModel(Package(target)))
self.ato_model = model
self.save_button = QPushButton("Save")
self.save_button.setProperty("style", "start-button")
self.save_button.clicked.connect(self.on_save)
self.button_layout.addWidget(self.save_button)
self.delete_flight_button.clicked.connect(self.on_delete_flight)
def on_save(self) -> None:
"""Saves the created package.
Empty packages may be created. They can be modified later, and will have
no effect if empty when the mission is generated.
"""
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)
self.close()
class QEditPackageDialog(QPackageDialog):
"""Dialog window for editing an existing package.
Changes to existing packages occur immediately.
"""
def __init__(self, game: Game, model: AtoModel,
package: PackageModel) -> None:
super().__init__(game, package)
self.ato_model = model
self.delete_button = QPushButton("Delete package")
self.delete_button.setProperty("style", "btn-danger")
self.delete_button.clicked.connect(self.on_delete)
self.button_layout.addWidget(self.delete_button)
self.done_button = QPushButton("Done")
self.done_button.setProperty("style", "start-button")
self.done_button.clicked.connect(self.on_done)
self.button_layout.addWidget(self.done_button)
# noinspection PyUnresolvedReferences
self.flight_added.connect(self.on_flight_added)
# noinspection PyUnresolvedReferences
self.flight_removed.connect(self.on_flight_removed)
# TODO: Make the new package dialog do this too, return on cancel.
# Not claiming the aircraft when they are added to the planner means that
# inventory counts are not updated until after the new package is updated,
# so you can add an infinite number of aircraft to a new package in the UI,
# which will crash when the flight package is saved.
def on_flight_added(self, flight: Flight) -> None:
self.game.aircraft_inventory.claim_for_flight(flight)
def on_flight_removed(self, flight: Flight) -> None:
self.game.aircraft_inventory.return_from_flight(flight)
def on_done(self) -> None:
"""Closes the window."""
self.close()
def on_delete(self) -> None:
"""Removes the viewed package from the ATO."""
# The ATO model returns inventory for us when deleting a package.
self.ato_model.delete_package(self.package_model.package)
self.close()

View File

@@ -1,37 +1,36 @@
from PySide2.QtCore import QSize, QItemSelectionModel, QPoint
from PySide2.QtCore import QItemSelectionModel, QSize
from PySide2.QtGui import QStandardItemModel
from PySide2.QtWidgets import QListView, QAbstractItemView
from PySide2.QtWidgets import QAbstractItemView, QListView
from gen.flights.ai_flight_planner import FlightPlanner
from qt_ui.models import GameModel
from qt_ui.windows.mission.QFlightItem import QFlightItem
from theater.controlpoint import ControlPoint
class QPlannedFlightsView(QListView):
def __init__(self, flight_planner: FlightPlanner):
def __init__(self, game_model: GameModel, cp: ControlPoint) -> None:
super(QPlannedFlightsView, self).__init__()
self.game_model = game_model
self.cp = cp
self.model = QStandardItemModel(self)
self.setModel(self.model)
self.flightitems = []
self.flight_items = []
self.setIconSize(QSize(91, 24))
self.setSelectionBehavior(QAbstractItemView.SelectItems)
if flight_planner:
self.set_flight_planner(flight_planner)
self.set_flight_planner()
def update_content(self):
for i, f in enumerate(self.flight_planner.flights):
self.flightitems[i].update(f)
def setup_content(self):
self.flight_items = []
for package in self.game_model.ato_model.packages:
for flight in package.flights:
if flight.from_cp == self.cp:
item = QFlightItem(flight)
self.model.appendRow(item)
self.flight_items.append(item)
self.set_selected_flight(0)
def setup_content(self, row=0):
self.flightitems = []
for i, f in enumerate(self.flight_planner.flights):
item = QFlightItem(f)
self.model.appendRow(item)
self.flightitems.append(item)
self.setSelectedFlight(row)
self.repaint()
def setSelectedFlight(self, row):
def set_selected_flight(self, row):
self.selectionModel().clearSelection()
index = self.model.index(row, 0)
if not index.isValid():
@@ -42,8 +41,6 @@ class QPlannedFlightsView(QListView):
def clear_layout(self):
self.model.removeRows(0, self.model.rowCount())
def set_flight_planner(self, flight_planner: FlightPlanner, row=0):
def set_flight_planner(self) -> None:
self.clear_layout()
self.flight_planner = flight_planner
if self.flight_planner:
self.setup_content(row)
self.setup_content()

View File

@@ -1,122 +1,169 @@
from typing import List
import logging
from typing import Optional
from PySide2.QtCore import Qt
from PySide2.QtWidgets import QDialog, QGridLayout, QLabel, QComboBox, QHBoxLayout, QVBoxLayout, QPushButton, QSpinBox, \
QMessageBox
from dcs import Point
from dcs.unittype import UnitType
from PySide2.QtCore import Qt, Signal
from PySide2.QtWidgets import (
QDialog,
QMessageBox,
QPushButton,
QVBoxLayout,
)
from dcs.planes import PlaneType
from game import Game
from gen.ato import Package
from gen.flights.ai_flight_planner import FlightPlanner
from gen.flights.flight import Flight, FlightWaypoint, FlightType
from gen.flights.flight import Flight, FlightType
from qt_ui.uiconstants import EVENT_ICONS
from qt_ui.windows.mission.flight.waypoints.QFlightWaypointInfoBox import QFlightWaypointInfoBox
from theater import ControlPoint
PREDEFINED_WAYPOINT_CATEGORIES = [
"Frontline (CAS AREA)",
"Building",
"Units",
"Airbase"
]
from qt_ui.widgets.QFlightSizeSpinner import QFlightSizeSpinner
from qt_ui.widgets.QLabeledWidget import QLabeledWidget
from qt_ui.widgets.combos.QAircraftTypeSelector import QAircraftTypeSelector
from qt_ui.widgets.combos.QFlightTypeComboBox import QFlightTypeComboBox
from qt_ui.widgets.combos.QOriginAirfieldSelector import QOriginAirfieldSelector
from theater import ControlPoint, TheaterGroundObject
class QFlightCreator(QDialog):
created = Signal(Flight)
def __init__(self, game: Game, package: Package) -> None:
super().__init__()
def __init__(self, game: Game, from_cp:ControlPoint, possible_aircraft_type:List[UnitType], flight_view=None):
super(QFlightCreator, self).__init__()
self.game = game
self.from_cp = from_cp
self.flight_view = flight_view
self.planner = self.game.planners[from_cp.id]
self.available = self.planner.get_available_aircraft()
self.package = package
self.setWindowFlags(Qt.WindowStaysOnTopHint)
self.setModal(True)
self.setWindowTitle("Create flight")
self.setWindowIcon(EVENT_ICONS["strike"])
self.select_type_aircraft = QComboBox()
for aircraft_type in self.planner.get_available_aircraft().keys():
print(aircraft_type)
print(aircraft_type.name)
if self.available[aircraft_type] > 0:
self.select_type_aircraft.addItem(aircraft_type.id, userData=aircraft_type)
self.select_type_aircraft.setCurrentIndex(0)
self.select_flight_type = QComboBox()
self.select_flight_type.addItem("CAP [Combat Air Patrol]", userData=FlightType.CAP)
self.select_flight_type.addItem("BARCAP [Barrier Combat Air Patrol]", userData=FlightType.BARCAP)
self.select_flight_type.addItem("TARCAP [Target Combat Air Patrol]", userData=FlightType.TARCAP)
self.select_flight_type.addItem("INTERCEPT [Interception]", userData=FlightType.INTERCEPTION)
self.select_flight_type.addItem("CAS [Close Air Support]", userData=FlightType.CAS)
self.select_flight_type.addItem("BAI [Battlefield Interdiction]", userData=FlightType.BAI)
self.select_flight_type.addItem("SEAD [Suppression of Enemy Air Defenses]", userData=FlightType.SEAD)
self.select_flight_type.addItem("DEAD [Destruction of Enemy Air Defenses]", userData=FlightType.DEAD)
self.select_flight_type.addItem("STRIKE [Strike]", userData=FlightType.STRIKE)
self.select_flight_type.addItem("ANTISHIP [Antiship Attack]", userData=FlightType.ANTISHIP)
self.select_flight_type.setCurrentIndex(0)
self.select_count_of_aircraft = QSpinBox()
self.select_count_of_aircraft.setMinimum(1)
self.select_count_of_aircraft.setMaximum(4)
self.select_count_of_aircraft.setValue(2)
aircraft_type = self.select_type_aircraft.currentData()
if aircraft_type is not None:
self.select_count_of_aircraft.setValue(min(self.available[aircraft_type], 2))
self.select_count_of_aircraft.setMaximum(min(self.available[aircraft_type], 4))
self.add_button = QPushButton("Add")
self.add_button.clicked.connect(self.create_flight)
self.init_ui()
def init_ui(self):
layout = QVBoxLayout()
type_layout = QHBoxLayout()
type_layout.addWidget(QLabel("Type of Aircraft : "))
type_layout.addStretch()
type_layout.addWidget(self.select_type_aircraft, alignment=Qt.AlignRight)
# TODO: Limit task selection to those valid for the target type.
self.task_selector = QFlightTypeComboBox()
self.task_selector.setCurrentIndex(0)
layout.addLayout(QLabeledWidget("Task:", self.task_selector))
count_layout = QHBoxLayout()
count_layout.addWidget(QLabel("Count : "))
count_layout.addStretch()
count_layout.addWidget(self.select_count_of_aircraft, alignment=Qt.AlignRight)
self.aircraft_selector = QAircraftTypeSelector(
self.game.aircraft_inventory.available_types_for_player
)
self.aircraft_selector.setCurrentIndex(0)
self.aircraft_selector.currentIndexChanged.connect(
self.on_aircraft_changed)
layout.addLayout(QLabeledWidget("Aircraft:", self.aircraft_selector))
flight_type_layout = QHBoxLayout()
flight_type_layout.addWidget(QLabel("Task : "))
flight_type_layout.addStretch()
flight_type_layout.addWidget(self.select_flight_type, alignment=Qt.AlignRight)
self.airfield_selector = QOriginAirfieldSelector(
self.game.aircraft_inventory,
[cp for cp in game.theater.controlpoints if cp.captured],
self.aircraft_selector.currentData()
)
layout.addLayout(QLabeledWidget("Airfield:", self.airfield_selector))
self.flight_size_spinner = QFlightSizeSpinner()
layout.addLayout(QLabeledWidget("Count:", self.flight_size_spinner))
layout.addLayout(type_layout)
layout.addLayout(count_layout)
layout.addLayout(flight_type_layout)
layout.addStretch()
layout.addWidget(self.add_button, alignment=Qt.AlignRight)
self.create_button = QPushButton("Create")
self.create_button.clicked.connect(self.create_flight)
layout.addWidget(self.create_button, alignment=Qt.AlignRight)
self.setLayout(layout)
def create_flight(self):
aircraft_type = self.select_type_aircraft.currentData()
count = self.select_count_of_aircraft.value()
def verify_form(self) -> Optional[str]:
aircraft: PlaneType = self.aircraft_selector.currentData()
origin: ControlPoint = self.airfield_selector.currentData()
size: int = self.flight_size_spinner.value()
if not origin.captured:
return f"{origin.name} is not owned by your coalition."
available = origin.base.aircraft.get(aircraft, 0)
if not available:
return f"{origin.name} has no {aircraft.id} available."
if size > available:
return f"{origin.name} has only {available} {aircraft.id} available."
return None
if self.available[aircraft_type] < count:
msg = QMessageBox()
msg.setIcon(QMessageBox.Information)
msg.setText("Not enough aircraft of this type are available. Only " + str(self.available[aircraft_type]) + " available.")
msg.setWindowTitle("Not enough aircraft")
msg.setStandardButtons(QMessageBox.Ok)
msg.setWindowFlags(Qt.WindowStaysOnTopHint)
msg.exec_()
def create_flight(self) -> None:
error = self.verify_form()
if error is not None:
self.error_box("Could not create flight", error)
return
else:
flight = Flight(aircraft_type, count, self.from_cp, self.select_flight_type.currentData())
self.planner.flights.append(flight)
self.planner.custom_flights.append(flight)
if self.flight_view is not None:
self.flight_view.set_flight_planner(self.planner, len(self.planner.flights)-1)
self.close()
task = self.task_selector.currentData()
aircraft = self.aircraft_selector.currentData()
origin = self.airfield_selector.currentData()
size = self.flight_size_spinner.value()
flight = Flight(aircraft, size, origin, task)
self.populate_flight_plan(flight, task)
# noinspection PyUnresolvedReferences
self.created.emit(flight)
self.close()
def on_aircraft_changed(self, index: int) -> None:
new_aircraft = self.aircraft_selector.itemData(index)
self.airfield_selector.change_aircraft(new_aircraft)
@property
def planner(self) -> FlightPlanner:
return self.game.planners[self.airfield_selector.currentData().id]
def populate_flight_plan(self, flight: Flight, task: FlightType) -> None:
# TODO: Flesh out mission types.
# Probably most important to add, since it's a regression, is CAS. Right
# now it's not possible to frag a package on a front line though, and
# that's the only location where CAS missions are valid.
if task == FlightType.ANTISHIP:
logging.error("Anti-ship flight plan generation not implemented")
elif task == FlightType.BAI:
logging.error("BAI flight plan generation not implemented")
elif task == FlightType.BARCAP:
self.generate_cap(flight)
elif task == FlightType.CAP:
self.generate_cap(flight)
elif task == FlightType.CAS:
logging.error("CAS flight plan generation not implemented")
elif task == FlightType.DEAD:
self.generate_sead(flight)
elif task == FlightType.ELINT:
logging.error("ELINT flight plan generation not implemented")
elif task == FlightType.EVAC:
logging.error("Evac flight plan generation not implemented")
elif task == FlightType.EWAR:
logging.error("EWar flight plan generation not implemented")
elif task == FlightType.INTERCEPTION:
logging.error("Intercept flight plan generation not implemented")
elif task == FlightType.LOGISTICS:
logging.error("Logistics flight plan generation not implemented")
elif task == FlightType.RECON:
logging.error("Recon flight plan generation not implemented")
elif task == FlightType.SEAD:
self.generate_sead(flight)
elif task == FlightType.STRIKE:
self.generate_strike(flight)
elif task == FlightType.TARCAP:
self.generate_cap(flight)
elif task == FlightType.TROOP_TRANSPORT:
logging.error(
"Troop transport flight plan generation not implemented"
)
def generate_cap(self, flight: Flight) -> None:
if not isinstance(self.package.target, ControlPoint):
logging.error(
"Could not create flight plan: CAP missions for strike targets "
"not implemented"
)
return
self.planner.generate_barcap(flight, self.package.target)
def generate_sead(self, flight: Flight) -> None:
self.planner.generate_sead(flight, self.package.target)
def generate_strike(self, flight: Flight) -> None:
if not isinstance(self.package.target, TheaterGroundObject):
logging.error(
"Could not create flight plan: strike missions for capture "
"points not implemented"
)
return
self.planner.generate_strike(flight, self.package.target)

View File

@@ -1,42 +1,31 @@
from PySide2.QtCore import Signal
from PySide2.QtWidgets import QTabWidget, QFrame, QGridLayout, QLabel
from PySide2.QtWidgets import QTabWidget
from gen.flights.flight import Flight
from game import Game
from qt_ui.windows.mission.flight.payload.QFlightPayloadTab import QFlightPayloadTab
from qt_ui.windows.mission.flight.settings.QGeneralFlightSettingsTab import QGeneralFlightSettingsTab
from qt_ui.windows.mission.flight.waypoints.QFlightWaypointTab import QFlightWaypointTab
from gen.flights.flight import Flight
from qt_ui.windows.mission.flight.payload.QFlightPayloadTab import \
QFlightPayloadTab
from qt_ui.windows.mission.flight.settings.QGeneralFlightSettingsTab import \
QGeneralFlightSettingsTab
from qt_ui.windows.mission.flight.waypoints.QFlightWaypointTab import \
QFlightWaypointTab
class QFlightPlanner(QTabWidget):
on_planned_flight_changed = Signal()
def __init__(self, flight: Flight, game: Game, planner, selected_tab):
super(QFlightPlanner, self).__init__()
def __init__(self, flight: Flight, game: Game):
super().__init__()
print(selected_tab)
self.tabCount = 0
if flight:
self.general_settings_tab = QGeneralFlightSettingsTab(flight, game, planner)
self.general_settings_tab.on_flight_settings_changed.connect(lambda: self.on_planned_flight_changed.emit())
self.payload_tab = QFlightPayloadTab(flight, game)
self.waypoint_tab = QFlightWaypointTab(game, flight)
self.waypoint_tab.on_flight_changed.connect(lambda: self.on_planned_flight_changed.emit())
self.addTab(self.general_settings_tab, "General Flight settings")
self.addTab(self.payload_tab, "Payload")
self.addTab(self.waypoint_tab, "Waypoints")
self.tabCount = 3
self.setCurrentIndex(selected_tab)
else:
tabError = QFrame()
l = QGridLayout()
l.addWidget(QLabel("No flight selected"))
tabError.setLayout(l)
self.addTab(tabError, "No flight")
self.tabCount = 1
def clearTabs(self):
for i in range(self.tabCount):
self.removeTab(i)
self.general_settings_tab = QGeneralFlightSettingsTab(game, flight)
self.general_settings_tab.on_flight_settings_changed.connect(
lambda: self.on_planned_flight_changed.emit())
self.payload_tab = QFlightPayloadTab(flight, game)
self.waypoint_tab = QFlightWaypointTab(game, flight)
self.waypoint_tab.on_flight_changed.connect(
lambda: self.on_planned_flight_changed.emit())
self.addTab(self.general_settings_tab, "General Flight settings")
self.addTab(self.payload_tab, "Payload")
self.addTab(self.waypoint_tab, "Waypoints")
self.setCurrentIndex(0)

View File

@@ -6,12 +6,14 @@ class QFlightSlotEditor(QGroupBox):
changed = Signal()
def __init__(self, flight, game, planner):
def __init__(self, flight, game):
super(QFlightSlotEditor, self).__init__("Slots")
self.flight = flight
self.game = game
self.planner = planner
self.available = self.planner.get_available_aircraft()
inventory = self.game.aircraft_inventory.for_control_point(
flight.from_cp
)
self.available = inventory.all_aircraft
if self.flight.unit_type not in self.available:
max = self.flight.count
else:

View File

@@ -12,18 +12,15 @@ from qt_ui.windows.mission.flight.settings.QFlightTypeTaskInfo import QFlightTyp
class QGeneralFlightSettingsTab(QFrame):
on_flight_settings_changed = Signal()
def __init__(self, flight: Flight, game: Game, planner):
def __init__(self, game: Game, flight: Flight):
super(QGeneralFlightSettingsTab, self).__init__()
self.flight = flight
self.game = game
self.planner = planner
self.init_ui()
def init_ui(self):
layout = QGridLayout()
flight_info = QFlightTypeTaskInfo(self.flight)
flight_departure = QFlightDepartureEditor(self.flight)
flight_slots = QFlightSlotEditor(self.flight, self.game, self.planner)
flight_slots = QFlightSlotEditor(self.flight, self.game)
flight_start_type = QFlightStartType(self.flight)
layout.addWidget(flight_info, 0, 0)
layout.addWidget(flight_departure, 1, 0)
@@ -35,5 +32,7 @@ class QGeneralFlightSettingsTab(QFrame):
self.setLayout(layout)
flight_start_type.setEnabled(self.flight.client_count > 0)
flight_slots.changed.connect(lambda: flight_start_type.setEnabled(self.flight.client_count > 0))
flight_departure.changed.connect(lambda: self.on_flight_settings_changed.emit())
flight_slots.changed.connect(
lambda: flight_start_type.setEnabled(self.flight.client_count > 0))
flight_departure.changed.connect(
lambda: self.on_flight_settings_changed.emit())