mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-01 15:06:41 +00:00
Optimize setting group rendering by rendering them as separate elements, support element-rendered setting renderers
This commit is contained in:
parent
9ae61f1932
commit
a11e553de4
1 changed files with 50 additions and 20 deletions
|
@ -6,8 +6,11 @@ local core = require('openmw.core')
|
||||||
local storage = require('openmw.storage')
|
local storage = require('openmw.storage')
|
||||||
local I = require('openmw.interfaces')
|
local I = require('openmw.interfaces')
|
||||||
|
|
||||||
|
local auxUi = require('openmw_aux.ui')
|
||||||
|
|
||||||
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):setLifeTime(storage.LIFE_TIME.GameSession)
|
||||||
|
-- need to :reset() on reloadlua as well as game session end
|
||||||
common.getSection(false, common.groupSectionKey):reset()
|
common.getSection(false, common.groupSectionKey):reset()
|
||||||
|
|
||||||
local renderers = {}
|
local renderers = {}
|
||||||
|
@ -21,6 +24,7 @@ local interfaceL10n = core.l10n('Interface')
|
||||||
local pages = {}
|
local pages = {}
|
||||||
local groups = {}
|
local groups = {}
|
||||||
local pageOptions = {}
|
local pageOptions = {}
|
||||||
|
local groupElements = {}
|
||||||
|
|
||||||
local interval = { template = I.MWUI.templates.interval }
|
local interval = { template = I.MWUI.templates.interval }
|
||||||
local growingIntreval = {
|
local growingIntreval = {
|
||||||
|
@ -116,6 +120,11 @@ local function renderSetting(group, setting, value, global)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
local argument = common.getArgumentSection(global, group.key):get(setting.key)
|
local argument = common.getArgumentSection(global, group.key):get(setting.key)
|
||||||
|
local ok, rendererResult = pcall(renderFunction, value, set, argument)
|
||||||
|
if not ok then
|
||||||
|
print(string.format('Setting %s renderer "%s" error: %s', setting.key, setting.renderer, rendererResult))
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name = setting.key,
|
name = setting.key,
|
||||||
type = ui.TYPE.Flex,
|
type = ui.TYPE.Flex,
|
||||||
|
@ -129,7 +138,7 @@ local function renderSetting(group, setting, value, global)
|
||||||
content = ui.content {
|
content = ui.content {
|
||||||
titleLayout,
|
titleLayout,
|
||||||
growingIntreval,
|
growingIntreval,
|
||||||
renderFunction(value, set, argument),
|
ok and rendererResult or {}, -- TODO: display error?
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -245,10 +254,12 @@ end
|
||||||
|
|
||||||
local function generateSearchHints(page)
|
local function generateSearchHints(page)
|
||||||
local hints = {}
|
local hints = {}
|
||||||
local l10n = core.l10n(page.l10n)
|
do
|
||||||
table.insert(hints, l10n(page.name))
|
local l10n = core.l10n(page.l10n)
|
||||||
if page.description then
|
table.insert(hints, l10n(page.name))
|
||||||
table.insert(hints, l10n(page.description))
|
if page.description then
|
||||||
|
table.insert(hints, l10n(page.description))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
local pageGroups = groups[page.key]
|
local pageGroups = groups[page.key]
|
||||||
for _, pageGroup in pairs(pageGroups) do
|
for _, pageGroup in pairs(pageGroups) do
|
||||||
|
@ -281,7 +292,15 @@ local function renderPage(page, options)
|
||||||
if not group then
|
if not group then
|
||||||
error(string.format('%s group "%s" was not found', pageGroup.global and 'Global' or 'Player', pageGroup.key))
|
error(string.format('%s group "%s" was not found', pageGroup.global and 'Global' or 'Player', pageGroup.key))
|
||||||
end
|
end
|
||||||
table.insert(groupLayouts, renderGroup(group, pageGroup.global))
|
local groupElement = groupElements[page.key][group.key]
|
||||||
|
if not groupElement or not groupElement.layout then
|
||||||
|
groupElement = ui.create(renderGroup(group, pageGroup.global))
|
||||||
|
end
|
||||||
|
if groupElement.layout == nil then
|
||||||
|
error(string.format('Destroyed group element for %s %s', page.key, group.key))
|
||||||
|
end
|
||||||
|
groupElements[page.key][group.key] = groupElement
|
||||||
|
table.insert(groupLayouts, groupElement)
|
||||||
end
|
end
|
||||||
local groupsLayout = {
|
local groupsLayout = {
|
||||||
name = 'groups',
|
name = 'groups',
|
||||||
|
@ -344,18 +363,23 @@ 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 groupElement = groupElements[group.page][group.key]
|
||||||
|
|
||||||
if not settingKey then
|
if not settingKey then
|
||||||
renderPage(pages[group.page], pageOptions[group.page])
|
if groupElement then
|
||||||
|
groupElement.layout = renderGroup(group)
|
||||||
|
groupElement:update()
|
||||||
|
else
|
||||||
|
renderPage(pages[group.page], pageOptions[group.page])
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local value = common.getSection(global, group.key):get(settingKey)
|
local value = common.getSection(global, group.key):get(settingKey)
|
||||||
local element = pageOptions[group.page].element
|
local settingsContent = groupElement.layout.content.settings.content
|
||||||
local groupsLayout = element.layout.content.groups
|
auxUi.deepDestroy(settingsContent[settingKey]) -- support setting renderers which return UI elements
|
||||||
local groupLayout = groupsLayout.content[groupLayoutName(group.key, global)]
|
settingsContent[settingKey] = renderSetting(group, group.settings[settingKey], value)
|
||||||
local settingsContent = groupLayout.content.settings.content
|
groupElement:update()
|
||||||
settingsContent[settingKey] = renderSetting(group, group.settings[settingKey], value, global)
|
|
||||||
element:update()
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -364,6 +388,8 @@ local function onGroupRegistered(global, key)
|
||||||
if not group then return end
|
if not group then return end
|
||||||
|
|
||||||
groups[group.page] = groups[group.page] or {}
|
groups[group.page] = groups[group.page] or {}
|
||||||
|
groupElements[group.page] = groupElements[group.page] or {}
|
||||||
|
|
||||||
local pageGroup = {
|
local pageGroup = {
|
||||||
key = group.key,
|
key = group.key,
|
||||||
global = global,
|
global = global,
|
||||||
|
@ -380,11 +406,9 @@ local function onGroupRegistered(global, key)
|
||||||
|
|
||||||
local value = common.getSection(global, group.key):get(settingKey)
|
local value = common.getSection(global, group.key):get(settingKey)
|
||||||
|
|
||||||
local element = pageOptions[group.page].element
|
local element = groupElements[group.page][group.key]
|
||||||
local groupsLayout = element.layout.content.groups
|
local settingsContent = element.layout.content.settings.content
|
||||||
local groupLayout = groupsLayout.content[groupLayoutName(group.key, global)]
|
settingsContent[settingKey] = renderSetting(group, group.settings[settingKey], value)
|
||||||
local settingsContent = groupLayout.content.settings.content
|
|
||||||
settingsContent[settingKey] = renderSetting(group, group.settings[settingKey], value, global)
|
|
||||||
element:update()
|
element:update()
|
||||||
end))
|
end))
|
||||||
end
|
end
|
||||||
|
@ -422,6 +446,11 @@ 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 in pairs(page) do
|
||||||
if not menuGroups[groupKey] then
|
if not menuGroups[groupKey] then
|
||||||
|
if groupElements[pageKey][groupKey] then
|
||||||
|
groupElements[pageKey][groupKey]:destroy()
|
||||||
|
print(string.format('destroyed group element %s %s', pageKey, groupKey))
|
||||||
|
groupElements[pageKey][groupKey] = nil
|
||||||
|
end
|
||||||
page[groupKey] = nil
|
page[groupKey] = nil
|
||||||
playerGroupsSection:set(groupKey, nil)
|
playerGroupsSection:set(groupKey, nil)
|
||||||
end
|
end
|
||||||
|
@ -430,7 +459,8 @@ local function resetPlayerGroups()
|
||||||
if options then
|
if options then
|
||||||
if not menuPages[pageKey] then
|
if not menuPages[pageKey] then
|
||||||
if options.element then
|
if options.element then
|
||||||
options.element:destroy()
|
auxUi.deepDestroy(options.element)
|
||||||
|
options.element = nil
|
||||||
end
|
end
|
||||||
ui.removeSettingsPage(options)
|
ui.removeSettingsPage(options)
|
||||||
pageOptions[pageKey] = nil
|
pageOptions[pageKey] = nil
|
||||||
|
|
Loading…
Reference in a new issue