Fix Menu Lua settings reset between states

ini_importer_tests
uramer 12 months ago
parent dd09c9b362
commit 7cc0eae461

@ -8,7 +8,7 @@ namespace LuaUi
// implemented in scriptsettings.cpp
void registerSettingsPage(const sol::table& options);
void clearSettings();
void removeSettingsPage(std::string_view key);
void removeSettingsPage(const sol::table& options);
}
#endif // !OPENMW_LUAUI_REGISTERSCRIPTSETTINGS

@ -6,7 +6,6 @@ local argumentSectionPostfix = 'Arguments'
local contextSection = storage.playerSection or storage.globalSection
local groupSection = contextSection(groupSectionKey)
groupSection:removeOnExit()
local function validateSettingOptions(options)
if type(options) ~= 'table' then
@ -109,11 +108,9 @@ end
return {
getSection = function(global, key)
if global then error('Getting global section') end
return (global and storage.globalSection or storage.playerSection)(key)
end,
getArgumentSection = function(global, key)
if global then error('Getting global section') end
return (global and storage.globalSection or storage.playerSection)(key .. argumentSectionPostfix)
end,
updateRendererArgument = function(groupKey, settingKey, argument)

@ -1,6 +1,7 @@
local storage = require('openmw.storage')
local common = require('scripts.omw.settings.common')
common.getSection(true, common.groupSectionKey):removeOnExit()
return {
interfaceName = 'Settings',

@ -7,6 +7,8 @@ local storage = require('openmw.storage')
local I = require('openmw.interfaces')
local common = require('scripts.omw.settings.common')
-- :reset on startup instead of :removeOnExit
common.getSection(false, common.groupSectionKey):reset()
local renderers = {}
local function registerRenderer(name, renderFunction)
@ -276,6 +278,9 @@ local function renderPage(page)
local groupLayouts = {}
for _, pageGroup in ipairs(sortedGroups) do
local group = common.getSection(pageGroup.global, common.groupSectionKey):get(pageGroup.key)
if not group then
error(string.format('%s group "%s" was not found', pageGroup.global and 'Global' or 'Player', pageGroup.key))
end
table.insert(groupLayouts, renderGroup(group, pageGroup.global))
end
local groupsLayout = {
@ -425,17 +430,16 @@ end
local menuGroups = {}
local menuPages = {}
local function reset()
local function resetPlayerGroups()
for pageKey, page in pairs(groups) do
for groupKey in pairs(page) do
if not menuGroups[groupKey] then
for groupKey, group in pairs(page) do
if not menuGroups[groupKey] and not group.global then
page[groupKey] = nil
end
end
if pageOptions[pageKey] then
pageOptions[pageKey].element.destroy()
pageOptions[pageKey].element:destroy()
if not menuPages[pageKey] then
pageOptions[pageKey].element.destroy()
ui.removeSettingsPage(pageOptions[pageKey])
pageOptions[pageKey] = nil
else
@ -483,6 +487,8 @@ local function registerPage(options)
ui.registerSettingsPage(pageOptions[page.key])
end
local lastState
return {
interfaceName = 'Settings',
interface = {
@ -502,15 +508,15 @@ return {
updateRendererArgument = common.updateRendererArgument,
},
engineHandlers = {
onLoad = common.onLoad,
onSave = common.onSave,
onStateChanged = function()
if lastState == menu.STATE.Running then
resetPlayerGroups()
end
updatePlayerGroups()
if menu.getState() == menu.STATE.Running then
updateGlobalGroups()
else
reset()
end
updatePlayerGroups()
lastState = menu.getState()
end,
},
eventHandlers = {

Loading…
Cancel
Save