mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
This commit is contained in:
parent
8dab64f4c3
commit
74142536e9
11
game/game.py
11
game/game.py
@ -387,16 +387,17 @@ class Game:
|
||||
for_red: True if opfor should be re-initialized.
|
||||
for_blue: True if the player coalition should be re-initialized.
|
||||
"""
|
||||
# Check for win or loss condition FIRST!
|
||||
turn_state = self.check_win_loss()
|
||||
if turn_state in (TurnState.LOSS, TurnState.WIN):
|
||||
return self.process_win_loss(turn_state)
|
||||
|
||||
# Update bullseye positions for blue & red
|
||||
self.set_bullseye()
|
||||
|
||||
# Update statistics
|
||||
self.game_stats.update(self)
|
||||
|
||||
# Check for win or loss condition
|
||||
turn_state = self.check_win_loss()
|
||||
if turn_state in (TurnState.LOSS, TurnState.WIN):
|
||||
return self.process_win_loss(turn_state)
|
||||
|
||||
# Plan flights & combat for next turn
|
||||
with logged_duration("Threat zone computation"):
|
||||
self.compute_threat_zones(events)
|
||||
|
||||
@ -11,6 +11,7 @@ from PySide2.QtWidgets import (
|
||||
|
||||
import qt_ui.uiconstants as CONST
|
||||
from game import Game, persistency
|
||||
from game.game import TurnState
|
||||
from game.ato.package import Package
|
||||
from game.profiling import logged_duration
|
||||
from game.utils import meters
|
||||
@ -78,14 +79,24 @@ class QTopPanel(QFrame):
|
||||
self.buttonBoxLayout.addWidget(self.transfers)
|
||||
self.buttonBox.setLayout(self.buttonBoxLayout)
|
||||
|
||||
self.simSpeedControls = SimSpeedControls(sim_controller)
|
||||
|
||||
self.proceedBox = QGroupBox("Proceed")
|
||||
self.proceedBoxLayout = QHBoxLayout()
|
||||
self.proceedBoxLayout.addLayout(SimSpeedControls(sim_controller))
|
||||
self.proceedBoxLayout.addLayout(self.simSpeedControls)
|
||||
self.proceedBoxLayout.addLayout(MaxPlayerCount(self.game_model.ato_model))
|
||||
self.proceedBoxLayout.addWidget(self.passTurnButton)
|
||||
self.proceedBoxLayout.addWidget(self.proceedButton)
|
||||
self.proceedBox.setLayout(self.proceedBoxLayout)
|
||||
|
||||
self.controls = [
|
||||
self.air_wing,
|
||||
self.transfers,
|
||||
self.simSpeedControls,
|
||||
self.passTurnButton,
|
||||
self.proceedButton,
|
||||
]
|
||||
|
||||
self.layout = QHBoxLayout()
|
||||
|
||||
self.layout.addWidget(self.factionsInfos)
|
||||
@ -127,15 +138,16 @@ class QTopPanel(QFrame):
|
||||
self.budgetBox.setGame(game)
|
||||
self.factionsInfos.setGame(game)
|
||||
|
||||
self.passTurnButton.setEnabled(True)
|
||||
if game and game.turn > 0:
|
||||
self.passTurnButton.setText("Pass Turn")
|
||||
self.setControls(True)
|
||||
|
||||
if game and game.turn == 0:
|
||||
if game.turn > 0:
|
||||
self.passTurnButton.setText("Pass Turn")
|
||||
elif game.turn == 0:
|
||||
self.passTurnButton.setText("Begin Campaign")
|
||||
self.proceedButton.setEnabled(False)
|
||||
self.simSpeedControls.setEnabled(False)
|
||||
else:
|
||||
self.proceedButton.setEnabled(True)
|
||||
raise RuntimeError(f"game.turn out of bounds!\n value = {game.turn}")
|
||||
|
||||
def open_air_wing(self):
|
||||
self.dialog = AirWingDialog(self.game_model, self.window())
|
||||
@ -291,3 +303,7 @@ class QTopPanel(QFrame):
|
||||
|
||||
def budget_update(self, game: Game):
|
||||
self.budgetBox.setGame(game)
|
||||
|
||||
def setControls(self, enabled: bool):
|
||||
for controller in self.controls:
|
||||
controller.setEnabled(enabled)
|
||||
|
||||
@ -33,3 +33,8 @@ class SimSpeedControls(QHBoxLayout):
|
||||
|
||||
def on_sim_speed_reset(self, speed_setting: SimSpeedSetting) -> None:
|
||||
self.buttons[speed_setting].setChecked(True)
|
||||
|
||||
def setEnabled(self, enabled: bool) -> None:
|
||||
super().setEnabled(enabled)
|
||||
for button in self.button_group.buttons():
|
||||
button.setEnabled(enabled)
|
||||
|
||||
@ -5,6 +5,7 @@ from typing import Optional
|
||||
from PySide2.QtCore import QObject, Signal
|
||||
|
||||
from game import Game
|
||||
from game.game import TurnState
|
||||
from game.debriefing import Debriefing
|
||||
|
||||
|
||||
@ -13,6 +14,7 @@ class GameUpdateSignal(QObject):
|
||||
instance = None
|
||||
gameupdated = Signal(Game)
|
||||
budgetupdated = Signal(Game)
|
||||
game_state_changed = Signal(TurnState)
|
||||
debriefingReceived = Signal(Debriefing)
|
||||
|
||||
game_loaded = Signal(Game)
|
||||
@ -35,6 +37,11 @@ class GameUpdateSignal(QObject):
|
||||
# noinspection PyUnresolvedReferences
|
||||
self.debriefingReceived.emit(debriefing)
|
||||
|
||||
def gameStateChanged(self, state: TurnState):
|
||||
if state in (TurnState.WIN, TurnState.LOSS):
|
||||
# noinspection PyUnresolvedReferences
|
||||
self.game_state_changed.emit(state)
|
||||
|
||||
@staticmethod
|
||||
def get_instance() -> GameUpdateSignal:
|
||||
return GameUpdateSignal.instance
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import logging
|
||||
from typing import Callable, Dict, TypeVar
|
||||
|
||||
from PySide2.QtGui import QIcon, QPixmap
|
||||
from PySide2.QtGui import QIcon, QPixmap, QCloseEvent
|
||||
from PySide2.QtWidgets import (
|
||||
QDialog,
|
||||
QGridLayout,
|
||||
@ -12,6 +12,8 @@ from PySide2.QtWidgets import (
|
||||
)
|
||||
|
||||
from game.debriefing import Debriefing
|
||||
from game.game import TurnState
|
||||
from qt_ui.windows.GameUpdateSignal import GameUpdateSignal
|
||||
|
||||
|
||||
T = TypeVar("T")
|
||||
@ -86,3 +88,8 @@ class QDebriefingWindow(QDialog):
|
||||
okay = QPushButton("Okay")
|
||||
okay.clicked.connect(self.close)
|
||||
layout.addWidget(okay)
|
||||
|
||||
def closeEvent(self, event: QCloseEvent) -> None:
|
||||
super().closeEvent(event)
|
||||
state = self.debriefing.game.check_win_loss()
|
||||
GameUpdateSignal.get_instance().gameStateChanged(state)
|
||||
|
||||
@ -21,6 +21,7 @@ from PySide2.QtWidgets import (
|
||||
import qt_ui.uiconstants as CONST
|
||||
from game import Game, VERSION, persistency
|
||||
from game.debriefing import Debriefing
|
||||
from game.game import TurnState
|
||||
from game.layout import LAYOUTS
|
||||
from game.server import EventStream, GameContext
|
||||
from game.server.dependencies import QtCallbacks, QtContext
|
||||
@ -129,9 +130,10 @@ class QLiberationWindow(QMainWindow):
|
||||
hbox.setSizes([1, 10000000])
|
||||
vbox.setSizes([600, 100])
|
||||
|
||||
self.top_panel = QTopPanel(self.game_model, self.sim_controller)
|
||||
vbox = QVBoxLayout()
|
||||
vbox.setMargin(0)
|
||||
vbox.addWidget(QTopPanel(self.game_model, self.sim_controller))
|
||||
vbox.addWidget(self.top_panel)
|
||||
vbox.addWidget(hbox)
|
||||
|
||||
central_widget = QWidget()
|
||||
@ -141,6 +143,7 @@ class QLiberationWindow(QMainWindow):
|
||||
def connectSignals(self):
|
||||
GameUpdateSignal.get_instance().gameupdated.connect(self.setGame)
|
||||
GameUpdateSignal.get_instance().debriefingReceived.connect(self.onDebriefing)
|
||||
GameUpdateSignal.get_instance().game_state_changed.connect(self.onEndGame)
|
||||
|
||||
def initActions(self):
|
||||
self.newGameAction = QAction("&New Game", self)
|
||||
@ -368,6 +371,32 @@ class QLiberationWindow(QMainWindow):
|
||||
self.game = game
|
||||
GameUpdateSignal.get_instance().game_loaded.emit(self.game)
|
||||
|
||||
def onEndGame(self, state: TurnState):
|
||||
if state == TurnState.CONTINUE:
|
||||
return
|
||||
|
||||
for window in QApplication.topLevelWidgets():
|
||||
if window is not self:
|
||||
window.close()
|
||||
|
||||
GameUpdateSignal.get_instance().updateGame(None)
|
||||
|
||||
self.top_panel.setControls(False)
|
||||
|
||||
title = "Victory!" if TurnState.WIN else "Defeat!"
|
||||
msgvar = "won" if TurnState.WIN else "lost"
|
||||
msg = f"You have {msgvar} the campaign, do you wish to start a new one?"
|
||||
result = QMessageBox.information(
|
||||
QApplication.focusWidget(),
|
||||
title,
|
||||
msg,
|
||||
QMessageBox.Yes,
|
||||
QMessageBox.No,
|
||||
)
|
||||
|
||||
if result is not None and result == QMessageBox.Yes:
|
||||
self.newGame()
|
||||
|
||||
def setGame(self, game: Optional[Game]):
|
||||
try:
|
||||
self.game = game
|
||||
@ -522,6 +551,7 @@ class QLiberationWindow(QMainWindow):
|
||||
self._save_window_geometry()
|
||||
super().closeEvent(event)
|
||||
self.dialog = None
|
||||
self.debriefing = None
|
||||
for window in QApplication.topLevelWidgets():
|
||||
window.close()
|
||||
else:
|
||||
|
||||
@ -14,6 +14,7 @@ from dcs.ships import Stennis, KUZNECOW
|
||||
from game import Game
|
||||
from game.ato.flighttype import FlightType
|
||||
from game.config import RUNWAY_REPAIR_COST
|
||||
from game.game import TurnState
|
||||
from game.server import EventStream
|
||||
from game.sim import GameUpdateEvents
|
||||
from game.theater import (
|
||||
@ -126,6 +127,8 @@ class QBaseMenu2(QDialog):
|
||||
self.game_model.game.initialize_turn(events)
|
||||
EventStream.put_nowait(events)
|
||||
GameUpdateSignal.get_instance().updateGame(self.game_model.game)
|
||||
state = self.game_model.game.check_win_loss()
|
||||
GameUpdateSignal.get_instance().gameStateChanged(state)
|
||||
|
||||
@property
|
||||
def has_transfer_destinations(self) -> bool:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user