mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-22 23:11:33 +00:00
Remove settings pages in Lua
This commit is contained in:
parent
c6a27d06b0
commit
79deb5f559
8 changed files with 40 additions and 9 deletions
|
@ -18,6 +18,7 @@
|
||||||
#include <components/l10n/manager.hpp>
|
#include <components/l10n/manager.hpp>
|
||||||
|
|
||||||
#include <components/lua_ui/content.hpp>
|
#include <components/lua_ui/content.hpp>
|
||||||
|
#include <components/lua_ui/registerscriptsettings.hpp>
|
||||||
#include <components/lua_ui/util.hpp>
|
#include <components/lua_ui/util.hpp>
|
||||||
|
|
||||||
#include "../mwbase/windowmanager.hpp"
|
#include "../mwbase/windowmanager.hpp"
|
||||||
|
@ -62,6 +63,11 @@ namespace MWLua
|
||||||
mGlobalScripts.setSerializer(mGlobalSerializer.get());
|
mGlobalScripts.setSerializer(mGlobalSerializer.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LuaManager::~LuaManager()
|
||||||
|
{
|
||||||
|
LuaUi::clearSettings();
|
||||||
|
}
|
||||||
|
|
||||||
void LuaManager::initConfiguration()
|
void LuaManager::initConfiguration()
|
||||||
{
|
{
|
||||||
mConfiguration.init(MWBase::Environment::get().getESMStore()->getLuaScriptsCfg());
|
mConfiguration.init(MWBase::Environment::get().getESMStore()->getLuaScriptsCfg());
|
||||||
|
@ -551,6 +557,7 @@ namespace MWLua
|
||||||
|
|
||||||
LuaUi::clearGameInterface();
|
LuaUi::clearGameInterface();
|
||||||
LuaUi::clearMenuInterface();
|
LuaUi::clearMenuInterface();
|
||||||
|
LuaUi::clearSettings();
|
||||||
MWBase::Environment::get().getWindowManager()->setConsoleMode("");
|
MWBase::Environment::get().getWindowManager()->setConsoleMode("");
|
||||||
MWBase::Environment::get().getL10nManager()->dropCache();
|
MWBase::Environment::get().getL10nManager()->dropCache();
|
||||||
mUiResourceManager.clear();
|
mUiResourceManager.clear();
|
||||||
|
|
|
@ -35,6 +35,7 @@ namespace MWLua
|
||||||
LuaManager(const VFS::Manager* vfs, const std::filesystem::path& libsDir);
|
LuaManager(const VFS::Manager* vfs, const std::filesystem::path& libsDir);
|
||||||
LuaManager(const LuaManager&) = delete;
|
LuaManager(const LuaManager&) = delete;
|
||||||
LuaManager(LuaManager&&) = delete;
|
LuaManager(LuaManager&&) = delete;
|
||||||
|
~LuaManager();
|
||||||
|
|
||||||
// Called by engine.cpp when the environment is fully initialized.
|
// Called by engine.cpp when the environment is fully initialized.
|
||||||
void init();
|
void init();
|
||||||
|
|
|
@ -247,6 +247,7 @@ namespace MWLua
|
||||||
{ "Center", LuaUi::Alignment::Center }, { "End", LuaUi::Alignment::End } }));
|
{ "Center", LuaUi::Alignment::Center }, { "End", LuaUi::Alignment::End } }));
|
||||||
|
|
||||||
api["registerSettingsPage"] = &LuaUi::registerSettingsPage;
|
api["registerSettingsPage"] = &LuaUi::registerSettingsPage;
|
||||||
|
api["removeSettingsPage"] = &LuaUi::registerSettingsPage;
|
||||||
|
|
||||||
api["texture"] = [luaManager = context.mLuaManager](const sol::table& options) {
|
api["texture"] = [luaManager = context.mLuaManager](const sol::table& options) {
|
||||||
LuaUi::TextureData data;
|
LuaUi::TextureData data;
|
||||||
|
|
|
@ -8,6 +8,7 @@ namespace LuaUi
|
||||||
// implemented in scriptsettings.cpp
|
// implemented in scriptsettings.cpp
|
||||||
void registerSettingsPage(const sol::table& options);
|
void registerSettingsPage(const sol::table& options);
|
||||||
void clearSettings();
|
void clearSettings();
|
||||||
|
void removeSettingsPage(std::string_view key);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // !OPENMW_LUAUI_REGISTERSCRIPTSETTINGS
|
#endif // !OPENMW_LUAUI_REGISTERSCRIPTSETTINGS
|
||||||
|
|
|
@ -40,6 +40,11 @@ namespace LuaUi
|
||||||
allPages.push_back(options);
|
allPages.push_back(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void removeSettingsPage(const sol::table& options)
|
||||||
|
{
|
||||||
|
std::erase_if(allPages, [options](const sol::table& it) { return it == options; });
|
||||||
|
}
|
||||||
|
|
||||||
void clearSettings()
|
void clearSettings()
|
||||||
{
|
{
|
||||||
allPages.clear();
|
allPages.clear();
|
||||||
|
@ -47,10 +52,10 @@ namespace LuaUi
|
||||||
|
|
||||||
void attachPageAt(size_t index, LuaAdapter* adapter)
|
void attachPageAt(size_t index, LuaAdapter* adapter)
|
||||||
{
|
{
|
||||||
|
adapter->detach();
|
||||||
if (index < allPages.size())
|
if (index < allPages.size())
|
||||||
{
|
{
|
||||||
ScriptSettingsPage page = parse(allPages[index]);
|
ScriptSettingsPage page = parse(allPages[index]);
|
||||||
adapter->detach();
|
|
||||||
if (page.mElement.get())
|
if (page.mElement.get())
|
||||||
adapter->attach(page.mElement);
|
adapter->attach(page.mElement);
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,8 +46,6 @@ namespace LuaUi
|
||||||
|
|
||||||
void clearGameInterface()
|
void clearGameInterface()
|
||||||
{
|
{
|
||||||
// TODO: move settings clearing logic to Lua?
|
|
||||||
clearSettings();
|
|
||||||
while (!Element::sGameElements.empty())
|
while (!Element::sGameElements.empty())
|
||||||
Element::sGameElements.begin()->second->destroy();
|
Element::sGameElements.begin()->second->destroy();
|
||||||
}
|
}
|
||||||
|
|
|
@ -423,17 +423,27 @@ local function updateGlobalGroups()
|
||||||
end
|
end
|
||||||
|
|
||||||
local menuGroups = {}
|
local menuGroups = {}
|
||||||
|
local menuPages = {}
|
||||||
|
|
||||||
local function resetGroups()
|
local function reset()
|
||||||
for pageKey, page in pairs(groups) do
|
for pageKey, page in pairs(groups) do
|
||||||
for groupKey in pairs(page) do
|
for groupKey in pairs(page) do
|
||||||
if not menuGroups[groupKey] then
|
if not menuGroups[groupKey] then
|
||||||
page[groupKey] = nil
|
page[groupKey] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local renderedOptions = renderPage(pages[pageKey])
|
if pageOptions[pageKey] then
|
||||||
for k, v in pairs(renderedOptions) do
|
pageOptions[pageKey].element.destroy()
|
||||||
pageOptions[pageKey][k] = v
|
if not menuPages[pageKey] then
|
||||||
|
pageOptions[pageKey].element.destroy()
|
||||||
|
ui.removeSettingsPage(pageOptions[pageKey])
|
||||||
|
pageOptions[pageKey] = nil
|
||||||
|
else
|
||||||
|
local renderedOptions = renderPage(pages[pageKey])
|
||||||
|
for k, v in pairs(renderedOptions) do
|
||||||
|
pageOptions[pageKey][k] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -477,7 +487,10 @@ return {
|
||||||
interfaceName = 'Settings',
|
interfaceName = 'Settings',
|
||||||
interface = {
|
interface = {
|
||||||
version = 1,
|
version = 1,
|
||||||
registerPage = registerPage,
|
registerPage = function(options)
|
||||||
|
registerPage(options)
|
||||||
|
menuPages[options] = true
|
||||||
|
end,
|
||||||
registerRenderer = registerRenderer,
|
registerRenderer = registerRenderer,
|
||||||
registerGroup = function(options)
|
registerGroup = function(options)
|
||||||
common.registerGroup(options)
|
common.registerGroup(options)
|
||||||
|
@ -492,7 +505,7 @@ return {
|
||||||
if menu.getState() == menu.STATE.Running then
|
if menu.getState() == menu.STATE.Running then
|
||||||
updateGlobalGroups()
|
updateGlobalGroups()
|
||||||
else
|
else
|
||||||
resetGroups()
|
reset()
|
||||||
end
|
end
|
||||||
updatePlayerGroups()
|
updatePlayerGroups()
|
||||||
end,
|
end,
|
||||||
|
|
|
@ -93,6 +93,11 @@
|
||||||
-- @function [parent=#ui] registerSettingsPage
|
-- @function [parent=#ui] registerSettingsPage
|
||||||
-- @param #SettingsPageOptions page
|
-- @param #SettingsPageOptions page
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Removes the settings page
|
||||||
|
-- @function [parent=#ui] removeSettingsPage
|
||||||
|
-- @param #SettingsPageOptions page must be the exact same table of options as the one passed to registerSettingsPage
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Table with settings page options, passed as an argument to ui.registerSettingsPage
|
-- Table with settings page options, passed as an argument to ui.registerSettingsPage
|
||||||
-- @type SettingsPageOptions
|
-- @type SettingsPageOptions
|
||||||
|
|
Loading…
Reference in a new issue