From 62362fc0efd96224720a0443abcf5be44ec8082f Mon Sep 17 00:00:00 2001 From: elsid Date: Wed, 12 Apr 2023 00:33:36 +0200 Subject: [PATCH] Use typed settings storage for windows Group window settings into structs. Include rect sizes in regular and maximized state and maximized flag. Use them instead of manipulations with string names. --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwgui/inventorywindow.cpp | 93 ++++---- apps/openmw/mwgui/inventorywindow.hpp | 2 - apps/openmw/mwgui/mapwindow.cpp | 4 +- apps/openmw/mwgui/settings.cpp | 292 +++++++++++++++++++++++++ apps/openmw/mwgui/settings.hpp | 40 ++++ apps/openmw/mwgui/spellwindow.cpp | 4 +- apps/openmw/mwgui/statswindow.cpp | 4 +- apps/openmw/mwgui/windowmanagerimp.cpp | 171 +++++++-------- apps/openmw/mwgui/windowmanagerimp.hpp | 5 +- 10 files changed, 458 insertions(+), 159 deletions(-) create mode 100644 apps/openmw/mwgui/settings.cpp create mode 100644 apps/openmw/mwgui/settings.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 82dfe1010c..7eb790cf09 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -44,7 +44,7 @@ add_openmw_dir (mwgui tradeitemmodel companionitemmodel pickpocketitemmodel controllers savegamedialog recharge mode videowidget backgroundimage itemwidget screenfader debugwindow spellmodel spellview draganddrop timeadvancer jailscreen itemchargeview keyboardnavigation textcolours statswatcher - postprocessorhud + postprocessorhud settings ) add_openmw_dir (mwdialogue diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 5db7015c21..f6ae36c224 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -16,7 +16,7 @@ #include -#include +#include #include "../mwbase/environment.hpp" #include "../mwbase/mechanicsmanager.hpp" @@ -34,6 +34,7 @@ #include "draganddrop.hpp" #include "inventoryitemmodel.hpp" #include "itemview.hpp" +#include "settings.hpp" #include "sortfilteritemmodel.hpp" #include "tooltips.hpp" #include "tradeitemmodel.hpp" @@ -54,6 +55,23 @@ namespace namespace MWGui { + namespace + { + WindowSettingValues getModeSettings(GuiMode mode) + { + switch (mode) + { + case GM_Container: + return makeInventoryContainerWindowSettingValues(); + case GM_Companion: + return makeInventoryCompanionWindowSettingValues(); + case GM_Barter: + return makeInventoryBarterWindowSettingValues(); + default: + return makeInventoryWindowSettingValues(); + } + } + } InventoryWindow::InventoryWindow( DragAndDrop* dragAndDrop, osg::Group* parent, Resource::ResourceSystem* resourceSystem) @@ -166,24 +184,18 @@ namespace MWGui void InventoryWindow::toggleMaximized() { - std::string setting = getModeSetting(); - - bool maximized = !Settings::Manager::getBool(setting + " maximized", "Windows"); - if (maximized) - setting += " maximized"; + const WindowSettingValues settings = getModeSettings(mGuiMode); + const WindowRectSettingValues& rect = settings.mIsMaximized ? settings.mRegular : settings.mMaximized; MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize(); - float x = Settings::Manager::getFloat(setting + " x", "Windows") * float(viewSize.width); - float y = Settings::Manager::getFloat(setting + " y", "Windows") * float(viewSize.height); - float w = Settings::Manager::getFloat(setting + " w", "Windows") * float(viewSize.width); - float h = Settings::Manager::getFloat(setting + " h", "Windows") * float(viewSize.height); + const float x = rect.mX * viewSize.width; + const float y = rect.mY * viewSize.height; + const float w = rect.mW * viewSize.width; + const float h = rect.mH * viewSize.height; MyGUI::Window* window = mMainWidget->castType(); window->setCoord(x, y, w, h); - if (maximized) - Settings::Manager::setBool(setting, "Windows", maximized); - else - Settings::Manager::setBool(setting + " maximized", "Windows", maximized); + settings.mIsMaximized.set(!settings.mIsMaximized); adjustPanes(); updatePreviewSize(); @@ -192,17 +204,14 @@ namespace MWGui void InventoryWindow::setGuiMode(GuiMode mode) { mGuiMode = mode; - std::string setting = getModeSetting(); + const WindowSettingValues settings = getModeSettings(mGuiMode); setPinButtonVisible(mode == GM_Inventory); - if (Settings::Manager::getBool(setting + " maximized", "Windows")) - setting += " maximized"; + const WindowRectSettingValues& rect = settings.mIsMaximized ? settings.mMaximized : settings.mRegular; MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize(); - MyGUI::IntPoint pos(static_cast(Settings::Manager::getFloat(setting + " x", "Windows") * viewSize.width), - static_cast(Settings::Manager::getFloat(setting + " y", "Windows") * viewSize.height)); - MyGUI::IntSize size(static_cast(Settings::Manager::getFloat(setting + " w", "Windows") * viewSize.width), - static_cast(Settings::Manager::getFloat(setting + " h", "Windows") * viewSize.height)); + MyGUI::IntPoint pos(static_cast(rect.mX * viewSize.width), static_cast(rect.mY * viewSize.height)); + MyGUI::IntSize size(static_cast(rect.mW * viewSize.width), static_cast(rect.mH * viewSize.height)); bool needUpdate = (size.width != mMainWidget->getWidth() || size.height != mMainWidget->getHeight()); @@ -405,44 +414,18 @@ namespace MWGui adjustPanes(); } - std::string InventoryWindow::getModeSetting() const - { - std::string setting = "inventory"; - switch (mGuiMode) - { - case GM_Container: - setting += " container"; - break; - case GM_Companion: - setting += " companion"; - break; - case GM_Barter: - setting += " barter"; - break; - default: - break; - } - - return setting; - } - void InventoryWindow::onWindowResize(MyGUI::Window* _sender) { adjustPanes(); - std::string setting = getModeSetting(); + const WindowSettingValues settings = getModeSettings(mGuiMode); MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize(); - float x = _sender->getPosition().left / float(viewSize.width); - float y = _sender->getPosition().top / float(viewSize.height); - float w = _sender->getSize().width / float(viewSize.width); - float h = _sender->getSize().height / float(viewSize.height); - Settings::Manager::setFloat(setting + " x", "Windows", x); - Settings::Manager::setFloat(setting + " y", "Windows", y); - Settings::Manager::setFloat(setting + " w", "Windows", w); - Settings::Manager::setFloat(setting + " h", "Windows", h); - bool maximized = Settings::Manager::getBool(setting + " maximized", "Windows"); - if (maximized) - Settings::Manager::setBool(setting + " maximized", "Windows", false); + + settings.mRegular.mX.set(_sender->getPosition().left / static_cast(viewSize.width)); + settings.mRegular.mY.set(_sender->getPosition().top / static_cast(viewSize.height)); + settings.mRegular.mW.set(_sender->getSize().width / static_cast(viewSize.width)); + settings.mRegular.mH.set(_sender->getSize().height / static_cast(viewSize.height)); + settings.mIsMaximized.set(false); if (mMainWidget->getSize().width != mLastXSize || mMainWidget->getSize().height != mLastYSize) { @@ -503,7 +486,7 @@ namespace MWGui void InventoryWindow::onPinToggled() { - Settings::Manager::setBool("inventory pin", "Windows", mPinned); + Settings::windows().mInventoryPin.set(mPinned); MWBase::Environment::get().getWindowManager()->setWeaponVisibility(!mPinned); } diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index be331297ed..c302925fba 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -113,8 +113,6 @@ namespace MWGui void onBackgroundSelected(); - std::string getModeSetting() const; - void sellItem(MyGUI::Widget* sender, int count); void dragItem(MyGUI::Widget* sender, int count); diff --git a/apps/openmw/mwgui/mapwindow.cpp b/apps/openmw/mwgui/mapwindow.cpp index abd233b07f..3877ee885d 100644 --- a/apps/openmw/mwgui/mapwindow.cpp +++ b/apps/openmw/mwgui/mapwindow.cpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include "../mwbase/environment.hpp" #include "../mwbase/windowmanager.hpp" @@ -1198,7 +1198,7 @@ namespace MWGui void MapWindow::onPinToggled() { - Settings::Manager::setBool("map pin", "Windows", mPinned); + Settings::windows().mMapPin.set(mPinned); MWBase::Environment::get().getWindowManager()->setMinimapVisibility(!mPinned); } diff --git a/apps/openmw/mwgui/settings.cpp b/apps/openmw/mwgui/settings.cpp new file mode 100644 index 0000000000..fb1068ca41 --- /dev/null +++ b/apps/openmw/mwgui/settings.cpp @@ -0,0 +1,292 @@ +#include "settings.hpp" + +#include "components/settings/values.hpp" + +namespace MWGui +{ + WindowSettingValues makeAlchemyWindowSettingValues() + { + return WindowSettingValues{ + .mRegular = WindowRectSettingValues { + .mX = Settings::windows().mAlchemyX, + .mY = Settings::windows().mAlchemyY, + .mW = Settings::windows().mAlchemyW, + .mH = Settings::windows().mAlchemyH, + }, + .mMaximized = WindowRectSettingValues { + .mX = Settings::windows().mAlchemyMaximizedX, + .mY = Settings::windows().mAlchemyMaximizedY, + .mW = Settings::windows().mAlchemyMaximizedW, + .mH = Settings::windows().mAlchemyMaximizedH, + }, + .mIsMaximized = Settings::windows().mAlchemyMaximized, + }; + } + + WindowSettingValues makeBarterWindowSettingValues() + { + return WindowSettingValues{ + .mRegular = WindowRectSettingValues { + .mX = Settings::windows().mBarterX, + .mY = Settings::windows().mBarterY, + .mW = Settings::windows().mBarterW, + .mH = Settings::windows().mBarterH, + }, + .mMaximized = WindowRectSettingValues { + .mX = Settings::windows().mBarterMaximizedX, + .mY = Settings::windows().mBarterMaximizedY, + .mW = Settings::windows().mBarterMaximizedW, + .mH = Settings::windows().mBarterMaximizedH, + }, + .mIsMaximized = Settings::windows().mBarterMaximized, + }; + } + + WindowSettingValues makeCompanionWindowSettingValues() + { + return WindowSettingValues{ + .mRegular = WindowRectSettingValues { + .mX = Settings::windows().mCompanionX, + .mY = Settings::windows().mCompanionY, + .mW = Settings::windows().mCompanionW, + .mH = Settings::windows().mCompanionH, + }, + .mMaximized = WindowRectSettingValues { + .mX = Settings::windows().mCompanionMaximizedX, + .mY = Settings::windows().mCompanionMaximizedY, + .mW = Settings::windows().mCompanionMaximizedW, + .mH = Settings::windows().mCompanionMaximizedH, + }, + .mIsMaximized = Settings::windows().mCompanionMaximized, + }; + } + + WindowSettingValues makeConsoleWindowSettingValues() + { + return WindowSettingValues{ + .mRegular = WindowRectSettingValues { + .mX = Settings::windows().mConsoleX, + .mY = Settings::windows().mConsoleY, + .mW = Settings::windows().mConsoleW, + .mH = Settings::windows().mConsoleH, + }, + .mMaximized = WindowRectSettingValues { + .mX = Settings::windows().mConsoleMaximizedX, + .mY = Settings::windows().mConsoleMaximizedY, + .mW = Settings::windows().mConsoleMaximizedW, + .mH = Settings::windows().mConsoleMaximizedH, + }, + .mIsMaximized = Settings::windows().mConsoleMaximized, + }; + } + + WindowSettingValues makeContainerWindowSettingValues() + { + return WindowSettingValues{ + .mRegular = WindowRectSettingValues { + .mX = Settings::windows().mContainerX, + .mY = Settings::windows().mContainerY, + .mW = Settings::windows().mContainerW, + .mH = Settings::windows().mContainerH, + }, + .mMaximized = WindowRectSettingValues { + .mX = Settings::windows().mContainerMaximizedX, + .mY = Settings::windows().mContainerMaximizedY, + .mW = Settings::windows().mContainerMaximizedW, + .mH = Settings::windows().mContainerMaximizedH, + }, + .mIsMaximized = Settings::windows().mContainerMaximized, + }; + } + + WindowSettingValues makeDialogueWindowSettingValues() + { + return WindowSettingValues{ + .mRegular = WindowRectSettingValues { + .mX = Settings::windows().mDialogueX, + .mY = Settings::windows().mDialogueY, + .mW = Settings::windows().mDialogueW, + .mH = Settings::windows().mDialogueH, + }, + .mMaximized = WindowRectSettingValues { + .mX = Settings::windows().mDialogueMaximizedX, + .mY = Settings::windows().mDialogueMaximizedY, + .mW = Settings::windows().mDialogueMaximizedW, + .mH = Settings::windows().mDialogueMaximizedH, + }, + .mIsMaximized = Settings::windows().mDialogueMaximized, + }; + } + + WindowSettingValues makeInventoryWindowSettingValues() + { + return WindowSettingValues{ + .mRegular = WindowRectSettingValues { + .mX = Settings::windows().mInventoryX, + .mY = Settings::windows().mInventoryY, + .mW = Settings::windows().mInventoryW, + .mH = Settings::windows().mInventoryH, + }, + .mMaximized = WindowRectSettingValues { + .mX = Settings::windows().mInventoryMaximizedX, + .mY = Settings::windows().mInventoryMaximizedY, + .mW = Settings::windows().mInventoryMaximizedW, + .mH = Settings::windows().mInventoryMaximizedH, + }, + .mIsMaximized = Settings::windows().mInventoryMaximized, + }; + } + + WindowSettingValues makeInventoryBarterWindowSettingValues() + { + return WindowSettingValues{ + .mRegular = WindowRectSettingValues { + .mX = Settings::windows().mInventoryBarterX, + .mY = Settings::windows().mInventoryBarterY, + .mW = Settings::windows().mInventoryBarterW, + .mH = Settings::windows().mInventoryBarterH, + }, + .mMaximized = WindowRectSettingValues { + .mX = Settings::windows().mInventoryBarterMaximizedX, + .mY = Settings::windows().mInventoryBarterMaximizedY, + .mW = Settings::windows().mInventoryBarterMaximizedW, + .mH = Settings::windows().mInventoryBarterMaximizedH, + }, + .mIsMaximized = Settings::windows().mInventoryBarterMaximized, + }; + } + + WindowSettingValues makeInventoryCompanionWindowSettingValues() + { + return WindowSettingValues{ + .mRegular = WindowRectSettingValues { + .mX = Settings::windows().mInventoryCompanionX, + .mY = Settings::windows().mInventoryCompanionY, + .mW = Settings::windows().mInventoryCompanionW, + .mH = Settings::windows().mInventoryCompanionH, + }, + .mMaximized = WindowRectSettingValues { + .mX = Settings::windows().mInventoryCompanionMaximizedX, + .mY = Settings::windows().mInventoryCompanionMaximizedY, + .mW = Settings::windows().mInventoryCompanionMaximizedW, + .mH = Settings::windows().mInventoryCompanionMaximizedH, + }, + .mIsMaximized = Settings::windows().mInventoryCompanionMaximized, + }; + } + + WindowSettingValues makeInventoryContainerWindowSettingValues() + { + return WindowSettingValues{ + .mRegular = WindowRectSettingValues { + .mX = Settings::windows().mInventoryContainerX, + .mY = Settings::windows().mInventoryContainerY, + .mW = Settings::windows().mInventoryContainerW, + .mH = Settings::windows().mInventoryContainerH, + }, + .mMaximized = WindowRectSettingValues { + .mX = Settings::windows().mInventoryContainerMaximizedX, + .mY = Settings::windows().mInventoryContainerMaximizedY, + .mW = Settings::windows().mInventoryContainerMaximizedW, + .mH = Settings::windows().mInventoryContainerMaximizedH, + }, + .mIsMaximized = Settings::windows().mInventoryContainerMaximized, + }; + } + + WindowSettingValues makeMapWindowSettingValues() + { + return WindowSettingValues{ + .mRegular = WindowRectSettingValues { + .mX = Settings::windows().mMapX, + .mY = Settings::windows().mMapY, + .mW = Settings::windows().mMapW, + .mH = Settings::windows().mMapH, + }, + .mMaximized = WindowRectSettingValues { + .mX = Settings::windows().mMapMaximizedX, + .mY = Settings::windows().mMapMaximizedY, + .mW = Settings::windows().mMapMaximizedW, + .mH = Settings::windows().mMapMaximizedH, + }, + .mIsMaximized = Settings::windows().mMapMaximized, + }; + } + + WindowSettingValues makePostprocessorWindowSettingValues() + { + return WindowSettingValues{ + .mRegular = WindowRectSettingValues { + .mX = Settings::windows().mPostprocessorX, + .mY = Settings::windows().mPostprocessorY, + .mW = Settings::windows().mPostprocessorW, + .mH = Settings::windows().mPostprocessorH, + }, + .mMaximized = WindowRectSettingValues { + .mX = Settings::windows().mPostprocessorMaximizedX, + .mY = Settings::windows().mPostprocessorMaximizedY, + .mW = Settings::windows().mPostprocessorMaximizedW, + .mH = Settings::windows().mPostprocessorMaximizedH, + }, + .mIsMaximized = Settings::windows().mPostprocessorMaximized, + }; + } + + WindowSettingValues makeSettingsWindowSettingValues() + { + return WindowSettingValues{ + .mRegular = WindowRectSettingValues { + .mX = Settings::windows().mSettingsX, + .mY = Settings::windows().mSettingsY, + .mW = Settings::windows().mSettingsW, + .mH = Settings::windows().mSettingsH, + }, + .mMaximized = WindowRectSettingValues { + .mX = Settings::windows().mSettingsMaximizedX, + .mY = Settings::windows().mSettingsMaximizedY, + .mW = Settings::windows().mSettingsMaximizedW, + .mH = Settings::windows().mSettingsMaximizedH, + }, + .mIsMaximized = Settings::windows().mSettingsMaximized, + }; + } + + WindowSettingValues makeSpellsWindowSettingValues() + { + return WindowSettingValues{ + .mRegular = WindowRectSettingValues { + .mX = Settings::windows().mSpellsX, + .mY = Settings::windows().mSpellsY, + .mW = Settings::windows().mSpellsW, + .mH = Settings::windows().mSpellsH, + }, + .mMaximized = WindowRectSettingValues { + .mX = Settings::windows().mSpellsMaximizedX, + .mY = Settings::windows().mSpellsMaximizedY, + .mW = Settings::windows().mSpellsMaximizedW, + .mH = Settings::windows().mSpellsMaximizedH, + }, + .mIsMaximized = Settings::windows().mSpellsMaximized, + }; + } + + WindowSettingValues makeStatsWindowSettingValues() + { + return WindowSettingValues{ + .mRegular = WindowRectSettingValues { + .mX = Settings::windows().mStatsX, + .mY = Settings::windows().mStatsY, + .mW = Settings::windows().mStatsW, + .mH = Settings::windows().mStatsH, + }, + .mMaximized = WindowRectSettingValues { + .mX = Settings::windows().mStatsMaximizedX, + .mY = Settings::windows().mStatsMaximizedY, + .mW = Settings::windows().mStatsMaximizedW, + .mH = Settings::windows().mStatsMaximizedH, + }, + .mIsMaximized = Settings::windows().mStatsMaximized, + }; + } + +} diff --git a/apps/openmw/mwgui/settings.hpp b/apps/openmw/mwgui/settings.hpp new file mode 100644 index 0000000000..8d1cda37dd --- /dev/null +++ b/apps/openmw/mwgui/settings.hpp @@ -0,0 +1,40 @@ +#ifndef OPENMW_APPS_OPENMW_MWGUI_SETTINGS_H +#define OPENMW_APPS_OPENMW_MWGUI_SETTINGS_H + +#include "components/settings/settingvalue.hpp" + +namespace MWGui +{ + struct WindowRectSettingValues + { + Settings::SettingValue& mX; + Settings::SettingValue& mY; + Settings::SettingValue& mW; + Settings::SettingValue& mH; + }; + + struct WindowSettingValues + { + WindowRectSettingValues mRegular; + WindowRectSettingValues mMaximized; + Settings::SettingValue& mIsMaximized; + }; + + WindowSettingValues makeAlchemyWindowSettingValues(); + WindowSettingValues makeBarterWindowSettingValues(); + WindowSettingValues makeCompanionWindowSettingValues(); + WindowSettingValues makeConsoleWindowSettingValues(); + WindowSettingValues makeContainerWindowSettingValues(); + WindowSettingValues makeDialogueWindowSettingValues(); + WindowSettingValues makeInventoryWindowSettingValues(); + WindowSettingValues makeInventoryBarterWindowSettingValues(); + WindowSettingValues makeInventoryCompanionWindowSettingValues(); + WindowSettingValues makeInventoryContainerWindowSettingValues(); + WindowSettingValues makeMapWindowSettingValues(); + WindowSettingValues makePostprocessorWindowSettingValues(); + WindowSettingValues makeSettingsWindowSettingValues(); + WindowSettingValues makeSpellsWindowSettingValues(); + WindowSettingValues makeStatsWindowSettingValues(); +} + +#endif diff --git a/apps/openmw/mwgui/spellwindow.cpp b/apps/openmw/mwgui/spellwindow.cpp index cde693f312..847085d4ef 100644 --- a/apps/openmw/mwgui/spellwindow.cpp +++ b/apps/openmw/mwgui/spellwindow.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include "../mwbase/environment.hpp" #include "../mwbase/mechanicsmanager.hpp" @@ -58,7 +58,7 @@ namespace MWGui void SpellWindow::onPinToggled() { - Settings::Manager::setBool("spells pin", "Windows", mPinned); + Settings::windows().mSpellsPin.set(mPinned); MWBase::Environment::get().getWindowManager()->setSpellVisibility(!mPinned); } diff --git a/apps/openmw/mwgui/statswindow.cpp b/apps/openmw/mwgui/statswindow.cpp index c1ee2136a5..d02667940a 100644 --- a/apps/openmw/mwgui/statswindow.cpp +++ b/apps/openmw/mwgui/statswindow.cpp @@ -15,7 +15,7 @@ #include #include -#include +#include #include "../mwbase/environment.hpp" #include "../mwbase/windowmanager.hpp" @@ -717,7 +717,7 @@ namespace MWGui void StatsWindow::onPinToggled() { - Settings::Manager::setBool("stats pin", "Windows", mPinned); + Settings::windows().mStatsPin.set(mPinned); MWBase::Environment::get().getWindowManager()->setHMSVisibility(!mPinned); } diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 33a8bfe62d..9ed822a1f3 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -52,6 +52,8 @@ #include +#include + #include "../mwbase/inputmanager.hpp" #include "../mwbase/luamanager.hpp" #include "../mwbase/soundmanager.hpp" @@ -120,6 +122,26 @@ namespace MWGui { + namespace + { + Settings::SettingValue* findHiddenSetting(GuiWindow window) + { + switch (window) + { + case GW_Inventory: + return &Settings::windows().mInventoryHidden; + case GW_Map: + return &Settings::windows().mMapHidden; + case GW_Magic: + return &Settings::windows().mSpellsHidden; + case GW_Stats: + return &Settings::windows().mStatsHidden; + default: + return nullptr; + } + } + } + WindowManager::WindowManager(SDL_Window* window, osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::ResourceSystem* resourceSystem, SceneUtil::WorkQueue* workQueue, const std::filesystem::path& logpath, bool consoleOnlyScripts, Translation::Storage& translationDataStorage, ToUTF8::FromType encoding, @@ -310,12 +332,12 @@ namespace MWGui mMap = map.get(); mWindows.push_back(std::move(map)); mMap->renderGlobalMap(); - trackWindow(mMap, "map"); + trackWindow(mMap, makeMapWindowSettingValues()); auto statsWindow = std::make_unique(mDragAndDrop.get()); mStatsWindow = statsWindow.get(); mWindows.push_back(std::move(statsWindow)); - trackWindow(mStatsWindow, "stats"); + trackWindow(mStatsWindow, makeStatsWindowSettingValues()); auto inventoryWindow = std::make_unique( mDragAndDrop.get(), mViewer->getSceneData()->asGroup(), mResourceSystem); @@ -325,7 +347,7 @@ namespace MWGui auto spellWindow = std::make_unique(mDragAndDrop.get()); mSpellWindow = spellWindow.get(); mWindows.push_back(std::move(spellWindow)); - trackWindow(mSpellWindow, "spells"); + trackWindow(mSpellWindow, makeSpellsWindowSettingValues()); mGuiModeStates[GM_Inventory] = GuiModeState({ mMap, mInventoryWindow, mSpellWindow, mStatsWindow }); mGuiModeStates[GM_None] = GuiModeState({ mMap, mInventoryWindow, mSpellWindow, mStatsWindow }); @@ -333,13 +355,13 @@ namespace MWGui auto tradeWindow = std::make_unique(); mTradeWindow = tradeWindow.get(); mWindows.push_back(std::move(tradeWindow)); - trackWindow(mTradeWindow, "barter"); + trackWindow(mTradeWindow, makeBarterWindowSettingValues()); mGuiModeStates[GM_Barter] = GuiModeState({ mInventoryWindow, mTradeWindow }); auto console = std::make_unique(w, h, mConsoleOnlyScripts, mCfgMgr); mConsole = console.get(); mWindows.push_back(std::move(console)); - trackWindow(mConsole, "console"); + trackWindow(mConsole, makeConsoleWindowSettingValues()); bool questList = mResourceSystem->getVFS()->exists("textures/tx_menubook_options_over.dds"); auto journal = JournalWindow::create(JournalViewModel::create(), questList, mEncoding); @@ -362,14 +384,14 @@ namespace MWGui auto dialogueWindow = std::make_unique(); mDialogueWindow = dialogueWindow.get(); mWindows.push_back(std::move(dialogueWindow)); - trackWindow(mDialogueWindow, "dialogue"); + trackWindow(mDialogueWindow, makeDialogueWindowSettingValues()); mGuiModeStates[GM_Dialogue] = GuiModeState(mDialogueWindow); mTradeWindow->eventTradeDone += MyGUI::newDelegate(mDialogueWindow, &DialogueWindow::onTradeComplete); auto containerWindow = std::make_unique(mDragAndDrop.get()); mContainerWindow = containerWindow.get(); mWindows.push_back(std::move(containerWindow)); - trackWindow(mContainerWindow, "container"); + trackWindow(mContainerWindow, makeContainerWindowSettingValues()); mGuiModeStates[GM_Container] = GuiModeState({ mContainerWindow, mInventoryWindow }); auto hud = std::make_unique(mCustomMarkers, mDragAndDrop.get(), mLocalMapRender.get()); @@ -399,7 +421,7 @@ namespace MWGui auto settingsWindow = std::make_unique(); mSettingsWindow = settingsWindow.get(); mWindows.push_back(std::move(settingsWindow)); - trackWindow(mSettingsWindow, "settings"); + trackWindow(mSettingsWindow, makeSettingsWindowSettingValues()); mGuiModeStates[GM_Settings] = GuiModeState(mSettingsWindow); auto confirmationDialog = std::make_unique(); @@ -407,7 +429,7 @@ namespace MWGui mWindows.push_back(std::move(confirmationDialog)); auto alchemyWindow = std::make_unique(); - trackWindow(alchemyWindow.get(), "alchemy"); + trackWindow(alchemyWindow.get(), makeAlchemyWindowSettingValues()); mGuiModeStates[GM_Alchemy] = GuiModeState(alchemyWindow.get()); mWindows.push_back(std::move(alchemyWindow)); @@ -448,7 +470,7 @@ namespace MWGui mSoulgemDialog = std::make_unique(mMessageBoxManager.get()); auto companionWindow = std::make_unique(mDragAndDrop.get(), mMessageBoxManager.get()); - trackWindow(companionWindow.get(), "companion"); + trackWindow(companionWindow.get(), makeCompanionWindowSettingValues()); mGuiModeStates[GM_Companion] = GuiModeState({ mInventoryWindow, companionWindow.get() }); mWindows.push_back(std::move(companionWindow)); @@ -492,7 +514,7 @@ namespace MWGui auto postProcessorHud = std::make_unique(); mPostProcessorHud = postProcessorHud.get(); mWindows.push_back(std::move(postProcessorHud)); - trackWindow(mPostProcessorHud, "postprocessor"); + trackWindow(mPostProcessorHud, makePostprocessorWindowSettingValues()); mInputBlocker = MyGUI::Gui::getInstance().createWidget( "", 0, 0, w, h, MyGUI::Align::Stretch, "InputBlocker"); @@ -1192,19 +1214,11 @@ namespace MWGui if (!mHud) return; // UI not initialized yet - for (std::map::iterator it = mTrackedWindows.begin(); it != mTrackedWindows.end(); - ++it) + for (const auto& [window, settings] : mTrackedWindows) { - std::string settingName = it->second; - if (Settings::Manager::getBool(settingName + " maximized", "Windows")) - settingName += " maximized"; - - MyGUI::IntPoint pos(static_cast(Settings::Manager::getFloat(settingName + " x", "Windows") * x), - static_cast(Settings::Manager::getFloat(settingName + " y", "Windows") * y)); - MyGUI::IntSize size(static_cast(Settings::Manager::getFloat(settingName + " w", "Windows") * x), - static_cast(Settings::Manager::getFloat(settingName + " h", "Windows") * y)); - it->first->setPosition(pos); - it->first->setSize(size); + const WindowRectSettingValues& rect = settings.mIsMaximized ? settings.mMaximized : settings.mRegular; + window->setPosition(MyGUI::IntPoint(static_cast(rect.mX * x), static_cast(rect.mY * y))); + window->setSize(MyGUI::IntSize(static_cast(rect.mW * x), static_cast(rect.mH * y))); } for (const auto& window : mWindows) @@ -1511,31 +1525,8 @@ namespace MWGui if (getMode() != GM_Inventory) return; - std::string settingName; - switch (wnd) - { - case GW_Inventory: - settingName = "inventory"; - break; - case GW_Map: - settingName = "map"; - break; - case GW_Magic: - settingName = "spells"; - break; - case GW_Stats: - settingName = "stats"; - break; - default: - break; - } - - if (!settingName.empty()) - { - settingName += " hidden"; - bool hidden = Settings::Manager::getBool(settingName, "Windows"); - Settings::Manager::setBool(settingName, "Windows", !hidden); - } + if (Settings::SettingValue* const hidden = findHiddenSetting(wnd)) + hidden->set(!hidden->get()); mShown = (GuiWindow)(mShown ^ wnd); updateVisible(); @@ -1721,63 +1712,57 @@ namespace MWGui return mCursorVisible && mCursorActive; } - void WindowManager::trackWindow(Layout* layout, const std::string& name) + void WindowManager::trackWindow(Layout* layout, const WindowSettingValues& settings) { - std::string settingName = name; MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize(); - bool isMaximized = Settings::Manager::getBool(name + " maximized", "Windows"); - if (isMaximized) - settingName += " maximized"; - MyGUI::IntPoint pos( - static_cast(Settings::Manager::getFloat(settingName + " x", "Windows") * viewSize.width), - static_cast(Settings::Manager::getFloat(settingName + " y", "Windows") * viewSize.height)); - MyGUI::IntSize size( - static_cast(Settings::Manager::getFloat(settingName + " w", "Windows") * viewSize.width), - static_cast(Settings::Manager::getFloat(settingName + " h", "Windows") * viewSize.height)); - layout->mMainWidget->setPosition(pos); - layout->mMainWidget->setSize(size); + const WindowRectSettingValues& rect = settings.mIsMaximized ? settings.mMaximized : settings.mRegular; + + layout->mMainWidget->setPosition( + MyGUI::IntPoint(static_cast(rect.mX * viewSize.width), static_cast(rect.mY * viewSize.height))); + layout->mMainWidget->setSize( + MyGUI::IntSize(static_cast(rect.mW * viewSize.width), static_cast(rect.mH * viewSize.height))); MyGUI::Window* window = layout->mMainWidget->castType(); window->eventWindowChangeCoord += MyGUI::newDelegate(this, &WindowManager::onWindowChangeCoord); - mTrackedWindows[window] = name; + mTrackedWindows.emplace(window, settings); } void WindowManager::toggleMaximized(Layout* layout) { MyGUI::Window* window = layout->mMainWidget->castType(); - std::string setting = mTrackedWindows[window]; - if (setting.empty()) + const auto it = mTrackedWindows.find(window); + if (it == mTrackedWindows.end()) return; - bool maximized = !Settings::Manager::getBool(setting + " maximized", "Windows"); - if (maximized) - setting += " maximized"; + const WindowSettingValues& settings = it->second; + const WindowRectSettingValues& rect = settings.mIsMaximized ? settings.mRegular : settings.mMaximized; MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize(); - float x = Settings::Manager::getFloat(setting + " x", "Windows") * float(viewSize.width); - float y = Settings::Manager::getFloat(setting + " y", "Windows") * float(viewSize.height); - float w = Settings::Manager::getFloat(setting + " w", "Windows") * float(viewSize.width); - float h = Settings::Manager::getFloat(setting + " h", "Windows") * float(viewSize.height); + const float x = rect.mX * viewSize.width; + const float y = rect.mY * viewSize.height; + const float w = rect.mW * viewSize.width; + const float h = rect.mH * viewSize.height; window->setCoord(x, y, w, h); - Settings::Manager::setBool(mTrackedWindows[window] + " maximized", "Windows", maximized); + + settings.mIsMaximized.set(!settings.mIsMaximized.get()); } - void WindowManager::onWindowChangeCoord(MyGUI::Window* _sender) + void WindowManager::onWindowChangeCoord(MyGUI::Window* window) { - std::string setting = mTrackedWindows[_sender]; + const auto it = mTrackedWindows.find(window); + if (it == mTrackedWindows.end()) + return; + + const WindowSettingValues& settings = it->second; + MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize(); - float x = _sender->getPosition().left / float(viewSize.width); - float y = _sender->getPosition().top / float(viewSize.height); - float w = _sender->getSize().width / float(viewSize.width); - float h = _sender->getSize().height / float(viewSize.height); - Settings::Manager::setFloat(setting + " x", "Windows", x); - Settings::Manager::setFloat(setting + " y", "Windows", y); - Settings::Manager::setFloat(setting + " w", "Windows", w); - Settings::Manager::setFloat(setting + " h", "Windows", h); - bool maximized = Settings::Manager::getBool(setting + " maximized", "Windows"); - if (maximized) - Settings::Manager::setBool(setting + " maximized", "Windows", false); + settings.mRegular.mX.set(window->getPosition().left / static_cast(viewSize.width)); + settings.mRegular.mY.set(window->getPosition().top / static_cast(viewSize.height)); + settings.mRegular.mW.set(window->getSize().width / static_cast(viewSize.width)); + settings.mRegular.mH.set(window->getSize().height / static_cast(viewSize.height)); + + settings.mIsMaximized.set(false); } void WindowManager::clear() @@ -2004,20 +1989,20 @@ namespace MWGui void WindowManager::updatePinnedWindows() { - mInventoryWindow->setPinned(Settings::Manager::getBool("inventory pin", "Windows")); - if (Settings::Manager::getBool("inventory hidden", "Windows")) + mInventoryWindow->setPinned(Settings::windows().mInventoryPin); + if (Settings::windows().mInventoryHidden) mShown = (GuiWindow)(mShown ^ GW_Inventory); - mMap->setPinned(Settings::Manager::getBool("map pin", "Windows")); - if (Settings::Manager::getBool("map hidden", "Windows")) + mMap->setPinned(Settings::windows().mMapPin); + if (Settings::windows().mMapHidden) mShown = (GuiWindow)(mShown ^ GW_Map); - mSpellWindow->setPinned(Settings::Manager::getBool("spells pin", "Windows")); - if (Settings::Manager::getBool("spells hidden", "Windows")) + mSpellWindow->setPinned(Settings::windows().mSpellsPin); + if (Settings::windows().mSpellsHidden) mShown = (GuiWindow)(mShown ^ GW_Magic); - mStatsWindow->setPinned(Settings::Manager::getBool("stats pin", "Windows")); - if (Settings::Manager::getBool("stats hidden", "Windows")) + mStatsWindow->setPinned(Settings::windows().mStatsPin); + if (Settings::windows().mStatsHidden) mShown = (GuiWindow)(mShown ^ GW_Stats); } diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index 100cd21139..dd5ca85547 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -28,6 +28,7 @@ #include "draganddrop.hpp" #include "mapwindow.hpp" #include "messagebox.hpp" +#include "settings.hpp" #include "soulgemdialog.hpp" #include "statswatcher.hpp" #include "textcolours.hpp" @@ -404,8 +405,8 @@ namespace MWGui bool mConsoleOnlyScripts; - std::map mTrackedWindows; - void trackWindow(Layout* layout, const std::string& name); + std::map mTrackedWindows; + void trackWindow(Layout* layout, const WindowSettingValues& settings); void onWindowChangeCoord(MyGUI::Window* _sender); ESM::RefId mSelectedSpell;