mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-09-08 20:05:19 -04:00
Merge branch 'master' into 'master'
Save user settings when closing windows Closes #8077 See merge request OpenMW/openmw!4367
This commit is contained in:
commit
d1b03734b3
@ -88,6 +88,8 @@ namespace MWBase
|
||||
virtual void executeAction(int action) = 0;
|
||||
|
||||
virtual bool controlsDisabled() = 0;
|
||||
|
||||
virtual void saveBindings() = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef GAME_MWBASE_LUAMANAGER_H
|
||||
#define GAME_MWBASE_LUAMANAGER_H
|
||||
|
||||
#include <filesystem>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
@ -75,6 +76,7 @@ namespace MWBase
|
||||
virtual void questUpdated(const ESM::RefId& questId, int stage) = 0;
|
||||
// `arg` is either forwarded from MWGui::pushGuiMode or empty
|
||||
virtual void uiModeChanged(const MWWorld::Ptr& arg) = 0;
|
||||
virtual void savePermanentStorage(const std::filesystem::path& userConfigPath) = 0;
|
||||
|
||||
// TODO: notify LuaManager about other events
|
||||
// virtual void objectOnHit(const MWWorld::Ptr &ptr, float damage, bool ishealth, const MWWorld::Ptr &object,
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <MyGUI_WidgetInput.h>
|
||||
#include <MyGUI_Window.h>
|
||||
|
||||
#include <components/files/configurationmanager.hpp>
|
||||
#include <components/fx/technique.hpp>
|
||||
#include <components/fx/widgets.hpp>
|
||||
|
||||
@ -50,8 +51,9 @@ namespace MWGui
|
||||
MyGUI::ListBox::onKeyButtonPressed(key, ch);
|
||||
}
|
||||
|
||||
PostProcessorHud::PostProcessorHud()
|
||||
PostProcessorHud::PostProcessorHud(Files::ConfigurationManager& cfgMgr)
|
||||
: WindowBase("openmw_postprocessor_hud.layout")
|
||||
, mCfgMgr(cfgMgr)
|
||||
{
|
||||
getWidget(mActiveList, "ActiveList");
|
||||
getWidget(mInactiveList, "InactiveList");
|
||||
@ -243,6 +245,8 @@ namespace MWGui
|
||||
|
||||
void PostProcessorHud::onClose()
|
||||
{
|
||||
Settings::ShaderManager::get().save();
|
||||
Settings::Manager::saveUser(mCfgMgr.getUserConfigPath() / "settings.cfg");
|
||||
toggleMode(Settings::ShaderManager::Mode::Normal);
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include <MyGUI_ListBox.h>
|
||||
|
||||
#include <components/files/configurationmanager.hpp>
|
||||
#include <components/settings/shadermanager.hpp>
|
||||
#include <components/vfs/pathutil.hpp>
|
||||
|
||||
@ -32,7 +33,7 @@ namespace MWGui
|
||||
};
|
||||
|
||||
public:
|
||||
PostProcessorHud();
|
||||
PostProcessorHud(Files::ConfigurationManager& cfgMgr);
|
||||
|
||||
void onOpen() override;
|
||||
|
||||
@ -99,6 +100,8 @@ namespace MWGui
|
||||
std::string mOverrideHint;
|
||||
|
||||
int mOffset = 0;
|
||||
|
||||
Files::ConfigurationManager& mCfgMgr;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <SDL_video.h>
|
||||
|
||||
#include <components/debug/debuglog.hpp>
|
||||
#include <components/files/configurationmanager.hpp>
|
||||
#include <components/l10n/manager.hpp>
|
||||
#include <components/lua_ui/scriptsettings.hpp>
|
||||
#include <components/misc/constants.hpp>
|
||||
@ -39,6 +40,7 @@
|
||||
#include "../mwbase/soundmanager.hpp"
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
#include "../mwbase/world.hpp"
|
||||
#include "../mwlua/luamanagerimp.hpp"
|
||||
|
||||
#include "confirmationdialog.hpp"
|
||||
|
||||
@ -247,10 +249,11 @@ namespace MWGui
|
||||
}
|
||||
}
|
||||
|
||||
SettingsWindow::SettingsWindow()
|
||||
SettingsWindow::SettingsWindow(Files::ConfigurationManager& cfgMgr)
|
||||
: WindowBase("openmw_settings_window.layout")
|
||||
, mKeyboardMode(true)
|
||||
, mCurrentPage(-1)
|
||||
, mCfgMgr(cfgMgr)
|
||||
{
|
||||
const bool terrain = Settings::terrain().mDistantTerrain;
|
||||
const std::string_view widgetName = terrain ? "RenderingDistanceSlider" : "LargeRenderingDistanceSlider";
|
||||
@ -1092,6 +1095,14 @@ namespace MWGui
|
||||
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mOkButton);
|
||||
}
|
||||
|
||||
void SettingsWindow::onClose()
|
||||
{
|
||||
// Save user settings
|
||||
Settings::Manager::saveUser(mCfgMgr.getUserConfigPath() / "settings.cfg");
|
||||
MWBase::Environment::get().getLuaManager()->savePermanentStorage(mCfgMgr.getUserConfigPath());
|
||||
MWBase::Environment::get().getInputManager()->saveBindings();
|
||||
}
|
||||
|
||||
void SettingsWindow::onWindowResize(MyGUI::Window* _sender)
|
||||
{
|
||||
layoutControlsBox();
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef MWGUI_SETTINGS_H
|
||||
#define MWGUI_SETTINGS_H
|
||||
|
||||
#include <components/files/configurationmanager.hpp>
|
||||
#include <components/lua_ui/adapter.hpp>
|
||||
|
||||
#include "windowbase.hpp"
|
||||
@ -10,10 +11,12 @@ namespace MWGui
|
||||
class SettingsWindow : public WindowBase
|
||||
{
|
||||
public:
|
||||
SettingsWindow();
|
||||
SettingsWindow(Files::ConfigurationManager& cfgMgr);
|
||||
|
||||
void onOpen() override;
|
||||
|
||||
void onClose() override;
|
||||
|
||||
void onFrame(float duration) override;
|
||||
|
||||
void updateControlsBox();
|
||||
@ -120,6 +123,7 @@ namespace MWGui
|
||||
|
||||
private:
|
||||
void resetScrollbars();
|
||||
Files::ConfigurationManager& mCfgMgr;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -409,7 +409,7 @@ namespace MWGui
|
||||
mCountDialog = countDialog.get();
|
||||
mWindows.push_back(std::move(countDialog));
|
||||
|
||||
auto settingsWindow = std::make_unique<SettingsWindow>();
|
||||
auto settingsWindow = std::make_unique<SettingsWindow>(mCfgMgr);
|
||||
mSettingsWindow = settingsWindow.get();
|
||||
mWindows.push_back(std::move(settingsWindow));
|
||||
trackWindow(mSettingsWindow, makeSettingsWindowSettingValues());
|
||||
@ -503,7 +503,7 @@ namespace MWGui
|
||||
mWindows.push_back(std::move(debugWindow));
|
||||
trackWindow(mDebugWindow, makeDebugWindowSettingValues());
|
||||
|
||||
auto postProcessorHud = std::make_unique<PostProcessorHud>();
|
||||
auto postProcessorHud = std::make_unique<PostProcessorHud>(mCfgMgr);
|
||||
mPostProcessorHud = postProcessorHud.get();
|
||||
mWindows.push_back(std::move(postProcessorHud));
|
||||
trackWindow(mPostProcessorHud, makePostprocessorWindowSettingValues());
|
||||
|
@ -196,23 +196,7 @@ namespace MWInput
|
||||
|
||||
BindingsManager::~BindingsManager()
|
||||
{
|
||||
const std::string newFileName = Files::pathToUnicodeString(mUserFile) + ".new";
|
||||
try
|
||||
{
|
||||
if (mInputBinder->save(newFileName))
|
||||
{
|
||||
std::filesystem::rename(Files::pathFromUnicodeString(newFileName), mUserFile);
|
||||
Log(Debug::Info) << "Saved input bindings: " << mUserFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log(Debug::Error) << "Failed to save input bindings to " << newFileName;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
Log(Debug::Error) << "Failed to save input bindings to " << newFileName << ": " << e.what();
|
||||
}
|
||||
saveBindings();
|
||||
}
|
||||
|
||||
void BindingsManager::update(float dt)
|
||||
@ -715,4 +699,25 @@ namespace MWInput
|
||||
if (previousValue <= 0.6 && currentValue > 0.6)
|
||||
manager->executeAction(action);
|
||||
}
|
||||
|
||||
void BindingsManager::saveBindings()
|
||||
{
|
||||
const std::string newFileName = Files::pathToUnicodeString(mUserFile) + ".new";
|
||||
try
|
||||
{
|
||||
if (mInputBinder->save(newFileName))
|
||||
{
|
||||
std::filesystem::rename(Files::pathFromUnicodeString(newFileName), mUserFile);
|
||||
Log(Debug::Info) << "Saved input bindings: " << mUserFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log(Debug::Error) << "Failed to save input bindings to " << newFileName;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
Log(Debug::Error) << "Failed to save input bindings to " << newFileName << ": " << e.what();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -65,6 +65,8 @@ namespace MWInput
|
||||
|
||||
void actionValueChanged(int action, float currentValue, float previousValue);
|
||||
|
||||
void saveBindings();
|
||||
|
||||
private:
|
||||
void setupSDLKeyMappings();
|
||||
|
||||
|
@ -246,4 +246,9 @@ namespace MWInput
|
||||
{
|
||||
mActionManager->executeAction(action);
|
||||
}
|
||||
|
||||
void InputManager::saveBindings()
|
||||
{
|
||||
mBindingsManager->saveBindings();
|
||||
}
|
||||
}
|
||||
|
@ -106,6 +106,8 @@ namespace MWInput
|
||||
private:
|
||||
bool mControlsDisabled;
|
||||
|
||||
void saveBindings() override;
|
||||
|
||||
std::unique_ptr<SDLUtil::InputWrapper> mInputWrapper;
|
||||
std::unique_ptr<BindingsManager> mBindingsManager;
|
||||
std::unique_ptr<ControlSwitch> mControlSwitch;
|
||||
|
@ -43,7 +43,7 @@ namespace MWLua
|
||||
void init();
|
||||
|
||||
void loadPermanentStorage(const std::filesystem::path& userConfigPath);
|
||||
void savePermanentStorage(const std::filesystem::path& userConfigPath);
|
||||
void savePermanentStorage(const std::filesystem::path& userConfigPath) override;
|
||||
|
||||
// \brief Executes lua handlers. Defaults to running in parallel with OSG Cull.
|
||||
//
|
||||
|
Loading…
x
Reference in New Issue
Block a user