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 // 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); void removeSettingsPage(const sol::table& options);
} }
#endif // !OPENMW_LUAUI_REGISTERSCRIPTSETTINGS #endif // !OPENMW_LUAUI_REGISTERSCRIPTSETTINGS

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

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

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

Loading…
Cancel
Save