1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2024-12-28 00:15:06 +00:00

Merge branch 'windows_typed_settings' into 'master'

Use typed settings storage for windows (#6876)

See merge request OpenMW/openmw!2921
This commit is contained in:
psi29a 2023-04-16 19:36:27 +00:00
commit a82b7cb872
10 changed files with 458 additions and 159 deletions

View File

@ -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

View File

@ -16,7 +16,7 @@
#include <components/myguiplatform/myguitexture.hpp>
#include <components/settings/settings.hpp>
#include <components/settings/values.hpp>
#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<MyGUI::Window>();
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<int>(Settings::Manager::getFloat(setting + " x", "Windows") * viewSize.width),
static_cast<int>(Settings::Manager::getFloat(setting + " y", "Windows") * viewSize.height));
MyGUI::IntSize size(static_cast<int>(Settings::Manager::getFloat(setting + " w", "Windows") * viewSize.width),
static_cast<int>(Settings::Manager::getFloat(setting + " h", "Windows") * viewSize.height));
MyGUI::IntPoint pos(static_cast<int>(rect.mX * viewSize.width), static_cast<int>(rect.mY * viewSize.height));
MyGUI::IntSize size(static_cast<int>(rect.mW * viewSize.width), static_cast<int>(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<float>(viewSize.width));
settings.mRegular.mY.set(_sender->getPosition().top / static_cast<float>(viewSize.height));
settings.mRegular.mW.set(_sender->getSize().width / static_cast<float>(viewSize.width));
settings.mRegular.mH.set(_sender->getSize().height / static_cast<float>(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);
}

View File

@ -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);

View File

@ -16,7 +16,7 @@
#include <components/esm3/esmwriter.hpp>
#include <components/esm3/globalmap.hpp>
#include <components/myguiplatform/myguitexture.hpp>
#include <components/settings/settings.hpp>
#include <components/settings/values.hpp>
#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);
}

View File

@ -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,
};
}
}

View File

@ -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<float>& mX;
Settings::SettingValue<float>& mY;
Settings::SettingValue<float>& mW;
Settings::SettingValue<float>& mH;
};
struct WindowSettingValues
{
WindowRectSettingValues mRegular;
WindowRectSettingValues mMaximized;
Settings::SettingValue<bool>& 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

View File

@ -6,7 +6,7 @@
#include <components/esm3/loadbsgn.hpp>
#include <components/esm3/loadrace.hpp>
#include <components/misc/strings/format.hpp>
#include <components/settings/settings.hpp>
#include <components/settings/values.hpp>
#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);
}

View File

@ -15,7 +15,7 @@
#include <components/esm3/loadgmst.hpp>
#include <components/esm3/loadrace.hpp>
#include <components/settings/settings.hpp>
#include <components/settings/values.hpp>
#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);
}

View File

@ -52,6 +52,8 @@
#include <components/lua_ui/util.hpp>
#include <components/settings/values.hpp>
#include "../mwbase/inputmanager.hpp"
#include "../mwbase/luamanager.hpp"
#include "../mwbase/soundmanager.hpp"
@ -120,6 +122,26 @@
namespace MWGui
{
namespace
{
Settings::SettingValue<bool>* 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<StatsWindow>(mDragAndDrop.get());
mStatsWindow = statsWindow.get();
mWindows.push_back(std::move(statsWindow));
trackWindow(mStatsWindow, "stats");
trackWindow(mStatsWindow, makeStatsWindowSettingValues());
auto inventoryWindow = std::make_unique<InventoryWindow>(
mDragAndDrop.get(), mViewer->getSceneData()->asGroup(), mResourceSystem);
@ -325,7 +347,7 @@ namespace MWGui
auto spellWindow = std::make_unique<SpellWindow>(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<TradeWindow>();
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<Console>(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<DialogueWindow>();
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<ContainerWindow>(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<HUD>(mCustomMarkers, mDragAndDrop.get(), mLocalMapRender.get());
@ -399,7 +421,7 @@ namespace MWGui
auto settingsWindow = std::make_unique<SettingsWindow>();
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<ConfirmationDialog>();
@ -407,7 +429,7 @@ namespace MWGui
mWindows.push_back(std::move(confirmationDialog));
auto alchemyWindow = std::make_unique<AlchemyWindow>();
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<SoulgemDialog>(mMessageBoxManager.get());
auto companionWindow = std::make_unique<CompanionWindow>(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<PostProcessorHud>();
mPostProcessorHud = postProcessorHud.get();
mWindows.push_back(std::move(postProcessorHud));
trackWindow(mPostProcessorHud, "postprocessor");
trackWindow(mPostProcessorHud, makePostprocessorWindowSettingValues());
mInputBlocker = MyGUI::Gui::getInstance().createWidget<MyGUI::Widget>(
"", 0, 0, w, h, MyGUI::Align::Stretch, "InputBlocker");
@ -1192,19 +1214,11 @@ namespace MWGui
if (!mHud)
return; // UI not initialized yet
for (std::map<MyGUI::Window*, std::string>::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<int>(Settings::Manager::getFloat(settingName + " x", "Windows") * x),
static_cast<int>(Settings::Manager::getFloat(settingName + " y", "Windows") * y));
MyGUI::IntSize size(static_cast<int>(Settings::Manager::getFloat(settingName + " w", "Windows") * x),
static_cast<int>(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<int>(rect.mX * x), static_cast<int>(rect.mY * y)));
window->setSize(MyGUI::IntSize(static_cast<int>(rect.mW * x), static_cast<int>(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<bool>* 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<int>(Settings::Manager::getFloat(settingName + " x", "Windows") * viewSize.width),
static_cast<int>(Settings::Manager::getFloat(settingName + " y", "Windows") * viewSize.height));
MyGUI::IntSize size(
static_cast<int>(Settings::Manager::getFloat(settingName + " w", "Windows") * viewSize.width),
static_cast<int>(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<int>(rect.mX * viewSize.width), static_cast<int>(rect.mY * viewSize.height)));
layout->mMainWidget->setSize(
MyGUI::IntSize(static_cast<int>(rect.mW * viewSize.width), static_cast<int>(rect.mH * viewSize.height)));
MyGUI::Window* window = layout->mMainWidget->castType<MyGUI::Window>();
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<MyGUI::Window>();
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<float>(viewSize.width));
settings.mRegular.mY.set(window->getPosition().top / static_cast<float>(viewSize.height));
settings.mRegular.mW.set(window->getSize().width / static_cast<float>(viewSize.width));
settings.mRegular.mH.set(window->getSize().height / static_cast<float>(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);
}

View File

@ -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<MyGUI::Window*, std::string> mTrackedWindows;
void trackWindow(Layout* layout, const std::string& name);
std::map<MyGUI::Window*, WindowSettingValues> mTrackedWindows;
void trackWindow(Layout* layout, const WindowSettingValues& settings);
void onWindowChangeCoord(MyGUI::Window* _sender);
ESM::RefId mSelectedSpell;