1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-12 13:13:27 +00:00

Merge branch 'lua_settings_duplication' into 'master'

Fix #7831

Closes #7831

See merge request OpenMW/openmw!3883
This commit is contained in:
psi29a 2024-02-20 08:47:04 +00:00
commit 4de326a2b0

View File

@ -268,7 +268,7 @@ local function generateSearchHints(page)
return table.concat(hints, ' ')
end
local function renderPage(page)
local function renderPage(page, options)
local l10n = core.l10n(page.l10n)
local sortedGroups = {}
for _, group in pairs(groups[page.key]) do
@ -329,11 +329,10 @@ local function renderPage(page)
bigSpacer,
},
}
return {
name = l10n(page.name),
element = ui.create(layout),
searchHints = generateSearchHints(page),
}
if options.element then options.element:destroy() end
options.name = l10n(page.name)
options.element = ui.create(layout)
options.searchHints = generateSearchHints(page)
end
local function onSettingChanged(global)
@ -341,8 +340,12 @@ local function onSettingChanged(global)
local group = common.getSection(global, common.groupSectionKey):get(groupKey)
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 groupsLayout = element.layout.content.groups
local groupLayout = groupsLayout.content[groupLayoutName(group.key, global)]
@ -385,15 +388,8 @@ local function onGroupRegistered(global, key)
groups[group.page][pageGroup.key] = pageGroup
if not pages[group.page] then return end
if pageOptions[group.page] then
pageOptions[group.page].element:destroy()
else
pageOptions[group.page] = {}
end
local renderedOptions = renderPage(pages[group.page])
for k, v in pairs(renderedOptions) do
pageOptions[group.page][k] = v
end
pageOptions[group.page] = pageOptions[group.page] or {}
renderPage(pages[group.page], pageOptions[group.page])
end
local function updateGroups(global)
@ -411,10 +407,7 @@ local function updateGroups(global)
end
end))
end
local updatePlayerGroups = function() updateGroups(false) end
updatePlayerGroups()
local updateGlobalGroups = function() updateGroups(true) end
local menuGroups = {}
@ -423,22 +416,22 @@ local menuPages = {}
local function resetPlayerGroups()
local playerGroupsSection = storage.playerSection(common.groupSectionKey)
for pageKey, page in pairs(groups) do
for groupKey, group in pairs(page) do
if not menuGroups[groupKey] and not group.global then
for groupKey in pairs(page) do
if not menuGroups[groupKey] then
page[groupKey] = nil
playerGroupsSection:set(groupKey, nil)
end
end
if pageOptions[pageKey] then
pageOptions[pageKey].element:destroy()
local options = pageOptions[pageKey]
if options then
if not menuPages[pageKey] then
ui.removeSettingsPage(pageOptions[pageKey])
if options.element then
options.element:destroy()
end
ui.removeSettingsPage(options)
pageOptions[pageKey] = nil
else
local renderedOptions = renderPage(pages[pageKey])
for k, v in pairs(renderedOptions) do
pageOptions[pageKey][k] = v
end
renderPage(pages[pageKey], options)
end
end
end
@ -472,13 +465,15 @@ local function registerPage(options)
pageOptions[page.key].element:destroy()
end
pageOptions[page.key] = pageOptions[page.key] or {}
local renderedOptions = renderPage(page)
for k, v in pairs(renderedOptions) do
pageOptions[page.key][k] = v
end
renderPage(page, pageOptions[page.key])
ui.registerSettingsPage(pageOptions[page.key])
end
updatePlayerGroups()
if menu.getState() == menu.STATE.Running then -- handle reloadlua correctly
updateGlobalGroups()
end
return {
interfaceName = 'Settings',
interface = {