mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Defer game load to after UI initialization.
This removes both the double load that happens on startup and also makes it possible to get the UI to create a new game if the existing default.liberation is not compatible.
This commit is contained in:
parent
3fd5e1bae7
commit
4cf406aefa
@ -121,8 +121,8 @@ class QLiberationMap(QGraphicsView):
|
||||
|
||||
def setGame(self, game: Optional[Game]):
|
||||
self.game = game
|
||||
logging.debug("Reloading Map Canvas")
|
||||
if self.game is not None:
|
||||
logging.debug("Reloading Map Canvas")
|
||||
self.reload_scene()
|
||||
|
||||
"""
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import logging
|
||||
import traceback
|
||||
import webbrowser
|
||||
from typing import Optional
|
||||
|
||||
@ -16,7 +17,7 @@ from PySide2.QtWidgets import (
|
||||
)
|
||||
|
||||
import qt_ui.uiconstants as CONST
|
||||
from game import Game, persistency, VERSION
|
||||
from game import Game, VERSION, persistency
|
||||
from qt_ui.dialogs import Dialog
|
||||
from qt_ui.displayoptions import DisplayGroup, DisplayOptions, DisplayRule
|
||||
from qt_ui.models import GameModel
|
||||
@ -40,10 +41,9 @@ class QLiberationWindow(QMainWindow):
|
||||
self.game: Optional[Game] = None
|
||||
self.game_model = GameModel()
|
||||
Dialog.set_game(self.game_model)
|
||||
self.ato_panel = None
|
||||
self.info_panel = None
|
||||
self.liberation_map = None
|
||||
self.setGame(persistency.restore_game())
|
||||
self.ato_panel = QAirTaskingOrderPanel(self.game_model)
|
||||
self.info_panel = QInfoPanel(self.game)
|
||||
self.liberation_map = QLiberationMap(self.game_model)
|
||||
|
||||
self.setGeometry(300, 100, 270, 100)
|
||||
self.setWindowTitle(f"DCS Liberation - v{VERSION}")
|
||||
@ -55,17 +55,14 @@ class QLiberationWindow(QMainWindow):
|
||||
self.initMenuBar()
|
||||
self.initToolbar()
|
||||
self.connectSignals()
|
||||
self.onGameGenerated(self.game)
|
||||
|
||||
screen = QDesktopWidget().screenGeometry()
|
||||
self.setGeometry(0, 0, screen.width(), screen.height())
|
||||
self.setWindowState(Qt.WindowMaximized)
|
||||
|
||||
def initUi(self):
|
||||
self.ato_panel = QAirTaskingOrderPanel(self.game_model)
|
||||
self.liberation_map = QLiberationMap(self.game_model)
|
||||
self.info_panel = QInfoPanel(self.game)
|
||||
self.onGameGenerated(persistency.restore_game())
|
||||
|
||||
def initUi(self):
|
||||
hbox = QSplitter(Qt.Horizontal)
|
||||
vbox = QSplitter(Qt.Vertical)
|
||||
hbox.addWidget(self.ato_panel)
|
||||
@ -193,8 +190,7 @@ class QLiberationWindow(QMainWindow):
|
||||
filter="*.liberation")
|
||||
if file is not None:
|
||||
game = persistency.load_game(file[0])
|
||||
self.setGame(game)
|
||||
GameUpdateSignal.get_instance().updateGame(self.game)
|
||||
GameUpdateSignal.get_instance().updateGame(game)
|
||||
|
||||
def saveGame(self):
|
||||
logging.info("Saving game")
|
||||
@ -217,14 +213,27 @@ class QLiberationWindow(QMainWindow):
|
||||
GameUpdateSignal.get_instance().updateGame(self.game)
|
||||
|
||||
def setGame(self, game: Optional[Game]):
|
||||
if game is not None:
|
||||
game.on_load()
|
||||
self.game = game
|
||||
if self.info_panel is not None:
|
||||
self.info_panel.setGame(game)
|
||||
self.game_model.set(self.game)
|
||||
if self.liberation_map is not None:
|
||||
self.liberation_map.setGame(game)
|
||||
try:
|
||||
if game is not None:
|
||||
game.on_load()
|
||||
self.game = game
|
||||
if self.info_panel is not None:
|
||||
self.info_panel.setGame(game)
|
||||
self.game_model.set(self.game)
|
||||
if self.liberation_map is not None:
|
||||
self.liberation_map.setGame(game)
|
||||
except AttributeError:
|
||||
logging.exception("Incompatible save game")
|
||||
QMessageBox.critical(
|
||||
self,
|
||||
"Could not load save game",
|
||||
"The save game you have loaded is incompatible with this "
|
||||
"version of DCS Liberation.\n"
|
||||
"\n"
|
||||
f"{traceback.format_exc()}",
|
||||
QMessageBox.Ok
|
||||
)
|
||||
GameUpdateSignal.get_instance().updateGame(None)
|
||||
|
||||
def showAboutDialog(self):
|
||||
text = "<h3>DCS Liberation " + VERSION + "</h3>" + \
|
||||
|
||||
@ -19,6 +19,14 @@ grey text -------------------- #B7C0C6
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
* Makes all message box text selectable.
|
||||
* https://stackoverflow.com/a/32595502/632035
|
||||
*/
|
||||
QMessageBox {
|
||||
messagebox-text-interaction-flags: 5;
|
||||
}
|
||||
|
||||
/*QMenuBar*/
|
||||
QMenuBar {
|
||||
spacing: 2px; /* spacing between menu bar items */
|
||||
|
||||
@ -1,3 +1,11 @@
|
||||
/*
|
||||
windows basis styles
|
||||
*/
|
||||
|
||||
/*
|
||||
* Makes all message box text selectable.
|
||||
* https://stackoverflow.com/a/32595502/632035
|
||||
*/
|
||||
QMessageBox {
|
||||
messagebox-text-interaction-flags: 5;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user