1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-04-01 22:36:39 +00:00

Handle group resets gracefully

This commit is contained in:
uramer 2024-02-19 19:35:41 +01:00
parent ef730c4395
commit 586706ffe0

View file

@ -268,7 +268,7 @@ local function generateSearchHints(page)
return table.concat(hints, ' ') return table.concat(hints, ' ')
end end
local function renderPage(page) local function renderPage(page, options)
local l10n = core.l10n(page.l10n) local l10n = core.l10n(page.l10n)
local sortedGroups = {} local sortedGroups = {}
for _, group in pairs(groups[page.key]) do for _, group in pairs(groups[page.key]) do
@ -329,11 +329,10 @@ local function renderPage(page)
bigSpacer, bigSpacer,
}, },
} }
return { if options.element then options.element:destroy() end
name = l10n(page.name), options.name = l10n(page.name)
element = ui.create(layout), options.element = ui.create(layout)
searchHints = generateSearchHints(page), options.searchHints = generateSearchHints(page)
}
end end
local function onSettingChanged(global) local function onSettingChanged(global)
@ -341,8 +340,12 @@ local function onSettingChanged(global)
local group = common.getSection(global, common.groupSectionKey):get(groupKey) local group = common.getSection(global, common.groupSectionKey):get(groupKey)
if not group or not pageOptions[group.page] then return end if not group or not pageOptions[group.page] then return end
local value = common.getSection(global, group.key):get(settingKey) if not settingKey then
renderPage(pages[group.page], pageOptions[group.page])
return
end
local value = common.getSection(global, group.key):get(settingKey)
local element = pageOptions[group.page].element local element = pageOptions[group.page].element
local groupsLayout = element.layout.content.groups local groupsLayout = element.layout.content.groups
local groupLayout = groupsLayout.content[groupLayoutName(group.key, global)] local groupLayout = groupsLayout.content[groupLayoutName(group.key, global)]
@ -385,17 +388,8 @@ local function onGroupRegistered(global, key)
groups[group.page][pageGroup.key] = pageGroup groups[group.page][pageGroup.key] = pageGroup
if not pages[group.page] then return end if not pages[group.page] then return end
if pageOptions[group.page] then pageOptions[group.page] = pageOptions[group.page] or {}
if pageOptions[group.page].element then renderPage(pages[group.page], pageOptions[group.page])
pageOptions[group.page].element:destroy()
end
else
pageOptions[group.page] = {}
end
local renderedOptions = renderPage(pages[group.page])
for k, v in pairs(renderedOptions) do
pageOptions[group.page][k] = v
end
end end
local function updateGroups(global) local function updateGroups(global)
@ -433,17 +427,14 @@ local function resetPlayerGroups()
end end
local options = pageOptions[pageKey] local options = pageOptions[pageKey]
if options then if options then
if options.element then
options.element:destroy()
end
if not menuPages[pageKey] then if not menuPages[pageKey] then
if options.element then
options.element:destroy()
end
ui.removeSettingsPage(options) ui.removeSettingsPage(options)
pageOptions[pageKey] = nil pageOptions[pageKey] = nil
else else
local renderedOptions = renderPage(pages[pageKey]) renderPage(pages[pageKey], options)
for k, v in pairs(renderedOptions) do
options[k] = v
end
end end
end end
end end
@ -477,10 +468,7 @@ local function registerPage(options)
pageOptions[page.key].element:destroy() pageOptions[page.key].element:destroy()
end end
pageOptions[page.key] = pageOptions[page.key] or {} pageOptions[page.key] = pageOptions[page.key] or {}
local renderedOptions = renderPage(page) renderPage(page, pageOptions[page.key])
for k, v in pairs(renderedOptions) do
pageOptions[page.key][k] = v
end
ui.registerSettingsPage(pageOptions[page.key]) ui.registerSettingsPage(pageOptions[page.key])
end end