From 6232b4f9e86556b5fcb7516aa672fb051a602639 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Wed, 21 Feb 2024 22:54:50 +0300 Subject: [PATCH] Reimplement the Settings window as a normal window (#7845, #7870) --- apps/openmw/mwbase/windowmanager.hpp | 3 ++- apps/openmw/mwgui/mainmenu.cpp | 8 +++++- apps/openmw/mwgui/settingswindow.cpp | 4 +-- apps/openmw/mwgui/settingswindow.hpp | 2 +- apps/openmw/mwgui/windowmanagerimp.cpp | 27 ++++++++++++++++--- apps/openmw/mwgui/windowmanagerimp.hpp | 3 ++- apps/openmw/mwinput/mousemanager.cpp | 4 +-- files/data/mygui/openmw_layers.xml | 1 + .../data/mygui/openmw_settings_window.layout | 2 +- 9 files changed, 39 insertions(+), 15 deletions(-) diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp index c252e0c490..c511ac313d 100644 --- a/apps/openmw/mwbase/windowmanager.hpp +++ b/apps/openmw/mwbase/windowmanager.hpp @@ -136,6 +136,7 @@ namespace MWBase virtual bool isConsoleMode() const = 0; virtual bool isPostProcessorHudVisible() const = 0; + virtual bool isSettingsWindowVisible() const = 0; virtual bool isInteractiveMessageBoxActive() const = 0; virtual void toggleVisible(MWGui::GuiWindow wnd) = 0; @@ -157,7 +158,6 @@ namespace MWBase virtual MWGui::ConfirmationDialog* getConfirmationDialog() = 0; virtual MWGui::TradeWindow* getTradeWindow() = 0; virtual MWGui::PostProcessorHud* getPostProcessorHud() = 0; - virtual MWGui::SettingsWindow* getSettingsWindow() = 0; /// Make the player use an item, while updating GUI state accordingly virtual void useItem(const MWWorld::Ptr& item, bool force = false) = 0; @@ -342,6 +342,7 @@ namespace MWBase virtual void toggleConsole() = 0; virtual void toggleDebugWindow() = 0; virtual void togglePostProcessorHud() = 0; + virtual void toggleSettingsWindow() = 0; /// Cycle to next or previous spell virtual void cycleSpell(bool next) = 0; diff --git a/apps/openmw/mwgui/mainmenu.cpp b/apps/openmw/mwgui/mainmenu.cpp index d0c55f432e..be3700342a 100644 --- a/apps/openmw/mwgui/mainmenu.cpp +++ b/apps/openmw/mwgui/mainmenu.cpp @@ -99,7 +99,7 @@ namespace MWGui } else if (name == "options") { - winMgr->getSettingsWindow()->setVisible(true); + winMgr->toggleSettingsWindow(); } else if (name == "credits") winMgr->playVideo("mw_credits.bik", true); @@ -212,6 +212,12 @@ namespace MWGui bool MainMenu::exit() { + if (MWBase::Environment::get().getWindowManager()->isSettingsWindowVisible()) + { + MWBase::Environment::get().getWindowManager()->toggleSettingsWindow(); + return false; + } + return MWBase::Environment::get().getStateManager()->getState() == MWBase::StateManager::State_Running; } diff --git a/apps/openmw/mwgui/settingswindow.cpp b/apps/openmw/mwgui/settingswindow.cpp index 6c6a34595e..b569132141 100644 --- a/apps/openmw/mwgui/settingswindow.cpp +++ b/apps/openmw/mwgui/settingswindow.cpp @@ -241,7 +241,7 @@ namespace MWGui } SettingsWindow::SettingsWindow() - : WindowModal("openmw_settings_window.layout") + : WindowBase("openmw_settings_window.layout") , mKeyboardMode(true) , mCurrentPage(-1) { @@ -1042,8 +1042,6 @@ namespace MWGui void SettingsWindow::onOpen() { - WindowModal::onOpen(); - highlightCurrentResolution(); updateControlsBox(); updateLightSettings(); diff --git a/apps/openmw/mwgui/settingswindow.hpp b/apps/openmw/mwgui/settingswindow.hpp index 47951ef121..1f96f7de54 100644 --- a/apps/openmw/mwgui/settingswindow.hpp +++ b/apps/openmw/mwgui/settingswindow.hpp @@ -7,7 +7,7 @@ namespace MWGui { - class SettingsWindow : public WindowModal + class SettingsWindow : public WindowBase { public: SettingsWindow(); diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index b8c92d761e..ab5e23eeac 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -914,6 +914,9 @@ namespace MWGui if (isConsoleMode()) mConsole->onFrame(frameDuration); + if (isSettingsWindowVisible()) + mSettingsWindow->onFrame(frameDuration); + if (!gameRunning) return; @@ -1473,10 +1476,6 @@ namespace MWGui { return mPostProcessorHud; } - MWGui::SettingsWindow* WindowManager::getSettingsWindow() - { - return mSettingsWindow; - } void WindowManager::useItem(const MWWorld::Ptr& item, bool bypassBeastRestrictions) { @@ -1552,6 +1551,11 @@ namespace MWGui return mPostProcessorHud && mPostProcessorHud->isVisible(); } + bool WindowManager::isSettingsWindowVisible() const + { + return mSettingsWindow && mSettingsWindow->isVisible(); + } + bool WindowManager::isInteractiveMessageBoxActive() const { return mMessageBoxManager && mMessageBoxManager->isInteractiveMessageBox(); @@ -2133,6 +2137,21 @@ namespace MWGui updateVisible(); } + void WindowManager::toggleSettingsWindow() + { + bool visible = mSettingsWindow->isVisible(); + + if (!visible && !mGuiModes.empty()) + mKeyboardNavigation->saveFocus(mGuiModes.back()); + + mSettingsWindow->setVisible(!visible); + + if (visible && !mGuiModes.empty()) + mKeyboardNavigation->restoreFocus(mGuiModes.back()); + + updateVisible(); + } + void WindowManager::cycleSpell(bool next) { if (!isGuiMode()) diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index 3445ebdb9a..ddc9e1c5e0 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -162,6 +162,7 @@ namespace MWGui bool isConsoleMode() const override; bool isPostProcessorHudVisible() const override; + bool isSettingsWindowVisible() const override; bool isInteractiveMessageBoxActive() const override; void toggleVisible(GuiWindow wnd) override; @@ -183,7 +184,6 @@ namespace MWGui MWGui::ConfirmationDialog* getConfirmationDialog() override; MWGui::TradeWindow* getTradeWindow() override; MWGui::PostProcessorHud* getPostProcessorHud() override; - MWGui::SettingsWindow* getSettingsWindow() override; /// Make the player use an item, while updating GUI state accordingly void useItem(const MWWorld::Ptr& item, bool bypassBeastRestrictions = false) override; @@ -364,6 +364,7 @@ namespace MWGui void toggleConsole() override; void toggleDebugWindow() override; void togglePostProcessorHud() override; + void toggleSettingsWindow() override; /// Cycle to next or previous spell void cycleSpell(bool next) override; diff --git a/apps/openmw/mwinput/mousemanager.cpp b/apps/openmw/mwinput/mousemanager.cpp index f18ec2ac87..9a8cada25b 100644 --- a/apps/openmw/mwinput/mousemanager.cpp +++ b/apps/openmw/mwinput/mousemanager.cpp @@ -166,9 +166,7 @@ namespace MWInput // Don't trigger any mouse bindings while in settings menu, otherwise rebinding controls becomes impossible // Also do not trigger bindings when input controls are disabled, e.g. during save loading - const MWGui::SettingsWindow* settingsWindow - = MWBase::Environment::get().getWindowManager()->getSettingsWindow(); - if ((!settingsWindow || !settingsWindow->isVisible()) && !input->controlsDisabled()) + if (!MWBase::Environment::get().getWindowManager()->isSettingsWindowVisible() && !input->controlsDisabled()) { mBindingsManager->mousePressed(arg, id); } diff --git a/files/data/mygui/openmw_layers.xml b/files/data/mygui/openmw_layers.xml index 045fb1cdc2..459db3fcb9 100644 --- a/files/data/mygui/openmw_layers.xml +++ b/files/data/mygui/openmw_layers.xml @@ -13,6 +13,7 @@ + diff --git a/files/data/mygui/openmw_settings_window.layout b/files/data/mygui/openmw_settings_window.layout index 27298b9756..9e2f707ef5 100644 --- a/files/data/mygui/openmw_settings_window.layout +++ b/files/data/mygui/openmw_settings_window.layout @@ -1,6 +1,6 @@  - +