From 5ce942c9a05ae0c692c01326e5dae58174861e2a Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Wed, 7 Oct 2020 17:09:57 -0700 Subject: [PATCH] Confirm mission start when no client slots exist. Especially considering the button in this position used to be how players added client slots, confirm that they in fact want to launch an AI-only mission before launching, and guide them toward the new UI. --- qt_ui/widgets/QTopPanel.py | 39 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/qt_ui/widgets/QTopPanel.py b/qt_ui/widgets/QTopPanel.py index fae3a11d..f75826ad 100644 --- a/qt_ui/widgets/QTopPanel.py +++ b/qt_ui/widgets/QTopPanel.py @@ -1,6 +1,12 @@ from typing import Optional -from PySide2.QtWidgets import QFrame, QGroupBox, QHBoxLayout, QPushButton +from PySide2.QtWidgets import ( + QFrame, + QGroupBox, + QHBoxLayout, + QMessageBox, + QPushButton, +) import qt_ui.uiconstants as CONST from game import Game @@ -9,9 +15,10 @@ 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.QWaitingForMissionResultWindow import \ + QWaitingForMissionResultWindow 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): @@ -101,8 +108,36 @@ class QTopPanel(QFrame): GameUpdateSignal.get_instance().updateGame(self.game) self.proceedButton.setEnabled(True) + def ato_has_clients(self) -> bool: + for package in self.game.blue_ato.packages: + for flight in package.flights: + if flight.client_count > 0: + return True + return False + + def confirm_no_client_launch(self) -> bool: + result = QMessageBox.question( + self, + "Continue without client slots?", + ("No client slots have been created for players. Continuing will " + "allow the AI to perform the mission, but players will be unable " + "to participate.
" + "
" + "To add client slots for players, select a package from the " + "Packages panel on the left of the main window, and then a flight " + "from the Flights panel below the Packages panel. The edit button " + "below the Flights panel will allow you to edit the number of " + "client slots in the flight. Each client slot allows one player."), + QMessageBox.No, + QMessageBox.Yes + ) + return result == QMessageBox.Yes + def launch_mission(self): """Finishes planning and waits for mission completion.""" + if not self.ato_has_clients() and not self.confirm_no_client_launch(): + return + # TODO: Refactor this nonsense. game_event = None for event in self.game.events: