diff --git a/engines/stark/services/userinterface.cpp b/engines/stark/services/userinterface.cpp index 85dc93ae2dd..8de99762b22 100644 --- a/engines/stark/services/userinterface.cpp +++ b/engines/stark/services/userinterface.cpp @@ -70,13 +70,13 @@ UserInterface::UserInterface(Gfx::Driver *gfx) : _exitGame(false), _quitToMainMenu(false), _shouldToggleSubtitle(false), + _shouldGoBackToPreviousScreen(false), _fmvScreen(nullptr), _gameScreen(nullptr), _interactive(true), _interactionAttemptDenied(false), _currentScreen(nullptr), - _gameWindowThumbnail(nullptr), - _prevScreenNameStack() { + _gameWindowThumbnail(nullptr) { } UserInterface::~UserInterface() { @@ -151,12 +151,12 @@ void UserInterface::handleDoubleClick() { } void UserInterface::handleEscape() { - bool handled = false; + bool handled = StarkGameInterface->skipCurrentSpeeches(); - handled = StarkGameInterface->skipCurrentSpeeches(); if (!handled) { handled = skipFMV(); } + if (!handled) { Screen::Name curScreenName = _currentScreen->getName(); if (curScreenName != Screen::kScreenGame && curScreenName != Screen::kScreenMainMenu) { @@ -195,7 +195,7 @@ void UserInterface::requestFMVPlayback(const Common::String &name) { } void UserInterface::onFMVStopped() { - backPrevScreen(); + _shouldGoBackToPreviousScreen = true; } void UserInterface::changeScreen(Screen::Name screenName) { @@ -218,17 +218,8 @@ void UserInterface::backPrevScreen() { _prevScreenNameStack.pop(); } -void UserInterface::performQuitToMainMenu() { - assert(_quitToMainMenu); - - changeScreen(Screen::kScreenGame); - StarkResourceProvider->shutdown(); - changeScreen(Screen::kScreenMainMenu); - _prevScreenNameStack.clear(); - _quitToMainMenu = false; -} - void UserInterface::restoreScreenHistory() { + _shouldGoBackToPreviousScreen = false; _prevScreenNameStack.clear(); _prevScreenNameStack.push(Screen::kScreenMainMenu); } @@ -465,4 +456,19 @@ void UserInterface::toggleExitDisplay() { _gameScreen->getGameWindow()->toggleExitDisplay(); } +void UserInterface::doQueuedScreenChange() { + if (_quitToMainMenu) { + changeScreen(Screen::kScreenGame); + StarkResourceProvider->shutdown(); + changeScreen(Screen::kScreenMainMenu); + _prevScreenNameStack.clear(); + _quitToMainMenu = false; + } + + if (_shouldGoBackToPreviousScreen) { + backPrevScreen(); + _shouldGoBackToPreviousScreen = false; + } +} + } // End of namespace Stark diff --git a/engines/stark/services/userinterface.h b/engines/stark/services/userinterface.h index b29fab245c0..0195e1a9ea4 100644 --- a/engines/stark/services/userinterface.h +++ b/engines/stark/services/userinterface.h @@ -101,10 +101,11 @@ public: /** Back to the previous displayed screen */ void backPrevScreen(); + /** Apply the scheduled screen change if any */ + void doQueuedScreenChange(); + /** Back to the main menu screen and rest resources */ void requestQuitToMainMenu() { _quitToMainMenu = true; } - bool hasQuitToMainMenuRequest() { return _quitToMainMenu; } - void performQuitToMainMenu(); /** Restore the screen travelling history to the initial state*/ void restoreScreenHistory(); @@ -231,6 +232,9 @@ private: bool _shouldToggleSubtitle; + // TODO: Generalize to all screen changes + bool _shouldGoBackToPreviousScreen; + Graphics::Surface *_gameWindowThumbnail; }; diff --git a/engines/stark/stark.cpp b/engines/stark/stark.cpp index 21eec091792..935117e56a6 100644 --- a/engines/stark/stark.cpp +++ b/engines/stark/stark.cpp @@ -184,9 +184,7 @@ void StarkEngine::mainLoop() { break; } - if (_userInterface->hasQuitToMainMenuRequest()) { - _userInterface->performQuitToMainMenu(); - } + _userInterface->doQueuedScreenChange(); if (_resourceProvider->hasLocationChangeRequest()) { _global->setNormalSpeed();