mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +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]):
|
def setGame(self, game: Optional[Game]):
|
||||||
self.game = game
|
self.game = game
|
||||||
logging.debug("Reloading Map Canvas")
|
|
||||||
if self.game is not None:
|
if self.game is not None:
|
||||||
|
logging.debug("Reloading Map Canvas")
|
||||||
self.reload_scene()
|
self.reload_scene()
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
|
import traceback
|
||||||
import webbrowser
|
import webbrowser
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
@ -16,7 +17,7 @@ from PySide2.QtWidgets import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
import qt_ui.uiconstants as CONST
|
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.dialogs import Dialog
|
||||||
from qt_ui.displayoptions import DisplayGroup, DisplayOptions, DisplayRule
|
from qt_ui.displayoptions import DisplayGroup, DisplayOptions, DisplayRule
|
||||||
from qt_ui.models import GameModel
|
from qt_ui.models import GameModel
|
||||||
@ -40,10 +41,9 @@ class QLiberationWindow(QMainWindow):
|
|||||||
self.game: Optional[Game] = None
|
self.game: Optional[Game] = None
|
||||||
self.game_model = GameModel()
|
self.game_model = GameModel()
|
||||||
Dialog.set_game(self.game_model)
|
Dialog.set_game(self.game_model)
|
||||||
self.ato_panel = None
|
self.ato_panel = QAirTaskingOrderPanel(self.game_model)
|
||||||
self.info_panel = None
|
self.info_panel = QInfoPanel(self.game)
|
||||||
self.liberation_map = None
|
self.liberation_map = QLiberationMap(self.game_model)
|
||||||
self.setGame(persistency.restore_game())
|
|
||||||
|
|
||||||
self.setGeometry(300, 100, 270, 100)
|
self.setGeometry(300, 100, 270, 100)
|
||||||
self.setWindowTitle(f"DCS Liberation - v{VERSION}")
|
self.setWindowTitle(f"DCS Liberation - v{VERSION}")
|
||||||
@ -55,17 +55,14 @@ class QLiberationWindow(QMainWindow):
|
|||||||
self.initMenuBar()
|
self.initMenuBar()
|
||||||
self.initToolbar()
|
self.initToolbar()
|
||||||
self.connectSignals()
|
self.connectSignals()
|
||||||
self.onGameGenerated(self.game)
|
|
||||||
|
|
||||||
screen = QDesktopWidget().screenGeometry()
|
screen = QDesktopWidget().screenGeometry()
|
||||||
self.setGeometry(0, 0, screen.width(), screen.height())
|
self.setGeometry(0, 0, screen.width(), screen.height())
|
||||||
self.setWindowState(Qt.WindowMaximized)
|
self.setWindowState(Qt.WindowMaximized)
|
||||||
|
|
||||||
def initUi(self):
|
self.onGameGenerated(persistency.restore_game())
|
||||||
self.ato_panel = QAirTaskingOrderPanel(self.game_model)
|
|
||||||
self.liberation_map = QLiberationMap(self.game_model)
|
|
||||||
self.info_panel = QInfoPanel(self.game)
|
|
||||||
|
|
||||||
|
def initUi(self):
|
||||||
hbox = QSplitter(Qt.Horizontal)
|
hbox = QSplitter(Qt.Horizontal)
|
||||||
vbox = QSplitter(Qt.Vertical)
|
vbox = QSplitter(Qt.Vertical)
|
||||||
hbox.addWidget(self.ato_panel)
|
hbox.addWidget(self.ato_panel)
|
||||||
@ -193,8 +190,7 @@ class QLiberationWindow(QMainWindow):
|
|||||||
filter="*.liberation")
|
filter="*.liberation")
|
||||||
if file is not None:
|
if file is not None:
|
||||||
game = persistency.load_game(file[0])
|
game = persistency.load_game(file[0])
|
||||||
self.setGame(game)
|
GameUpdateSignal.get_instance().updateGame(game)
|
||||||
GameUpdateSignal.get_instance().updateGame(self.game)
|
|
||||||
|
|
||||||
def saveGame(self):
|
def saveGame(self):
|
||||||
logging.info("Saving game")
|
logging.info("Saving game")
|
||||||
@ -217,6 +213,7 @@ class QLiberationWindow(QMainWindow):
|
|||||||
GameUpdateSignal.get_instance().updateGame(self.game)
|
GameUpdateSignal.get_instance().updateGame(self.game)
|
||||||
|
|
||||||
def setGame(self, game: Optional[Game]):
|
def setGame(self, game: Optional[Game]):
|
||||||
|
try:
|
||||||
if game is not None:
|
if game is not None:
|
||||||
game.on_load()
|
game.on_load()
|
||||||
self.game = game
|
self.game = game
|
||||||
@ -225,6 +222,18 @@ class QLiberationWindow(QMainWindow):
|
|||||||
self.game_model.set(self.game)
|
self.game_model.set(self.game)
|
||||||
if self.liberation_map is not None:
|
if self.liberation_map is not None:
|
||||||
self.liberation_map.setGame(game)
|
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):
|
def showAboutDialog(self):
|
||||||
text = "<h3>DCS Liberation " + VERSION + "</h3>" + \
|
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*/
|
||||||
QMenuBar {
|
QMenuBar {
|
||||||
spacing: 2px; /* spacing between menu bar items */
|
spacing: 2px; /* spacing between menu bar items */
|
||||||
|
|||||||
@ -1,3 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
windows basis styles
|
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