Checkpoint game before sim, auto-revert on abort.

An alternative to
https://github.com/dcs-liberation/dcs_liberation/pull/2891 that I ended
up liking much better (I had assumed some part of the UI would fail or
at least look terrible with this approach, but it seems to work quite
well).

On by default now since it's far less frightening than the previous
thing.

Fixes https://github.com/dcs-liberation/dcs_liberation/issues/2735.
This commit is contained in:
Dan Albert
2023-05-19 17:25:13 -07:00
parent f10350dac4
commit 24e72475b4
12 changed files with 84 additions and 36 deletions

View File

@@ -133,7 +133,14 @@ class QLiberationWindow(QMainWindow):
vbox = QVBoxLayout()
vbox.setContentsMargins(0, 0, 0, 0)
vbox.addWidget(QTopPanel(self.game_model, self.sim_controller, ui_flags))
vbox.addWidget(
QTopPanel(
self.game_model,
self.sim_controller,
ui_flags,
self.reset_to_pre_sim_checkpoint,
)
)
vbox.addWidget(hbox)
central_widget = QWidget()
@@ -340,6 +347,23 @@ class QLiberationWindow(QMainWindow):
except Exception:
logging.exception("Error loading save game %s", file[0])
def reset_to_pre_sim_checkpoint(self) -> None:
"""Loads the game that was saved before pressing the take-off button.
A checkpoint will be saved when the player presses take-off to save their state
before the mission simulation begins. If the mission is aborted, we usually want
to reset to the pre-simulation state to allow players to effectively "rewind",
since they probably aborted so that they could make changes. Implementing rewind
for real is impractical, but checkpoints are easy.
"""
if self.game is None:
raise RuntimeError(
"Cannot reset to pre-sim checkpoint when no game is loaded"
)
GameUpdateSignal.get_instance().game_loaded.emit(
self.game.save_manager.load_pre_sim_checkpoint()
)
def saveGame(self):
logging.info("Saving game")

View File

@@ -2,7 +2,7 @@ from __future__ import annotations
import logging
from pathlib import Path
from typing import Optional
from typing import Optional, Callable
from PySide6 import QtCore
from PySide6.QtCore import QObject, Signal
@@ -52,12 +52,14 @@ class QWaitingForMissionResultWindow(QDialog):
self,
game: Game,
sim_controller: SimController,
reset_to_pre_sim_checkpoint: Callable[[], None],
parent: Optional[QWidget] = None,
) -> None:
super(QWaitingForMissionResultWindow, self).__init__(parent=parent)
self.setWindowModality(QtCore.Qt.WindowModal)
self.game = game
self.sim_controller = sim_controller
self.reset_to_pre_sim_checkpoint = reset_to_pre_sim_checkpoint
self.setWindowTitle("Waiting for mission completion.")
self.setWindowIcon(QIcon("./resources/icon.png"))
self.setMinimumHeight(570)
@@ -134,8 +136,8 @@ class QWaitingForMissionResultWindow(QDialog):
self.setLayout(self.layout)
def reject(self) -> None:
if self.game.settings.reset_simulation_on_abort:
self.sim_controller.reset_simulation()
if self.game.settings.reload_pre_sim_checkpoint_on_abort:
self.reset_to_pre_sim_checkpoint()
super().reject()
@staticmethod