mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-30 05:47:57 +03:00
Generate search hints
This commit is contained in:
parent
5e90b1db0d
commit
1b62dda9f6
1 changed files with 27 additions and 12 deletions
|
@ -11,6 +11,7 @@ local function registerRenderer(name, renderFunction)
|
||||||
renderers[name] = renderFunction
|
renderers[name] = renderFunction
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local pages = {}
|
||||||
local groups = {}
|
local groups = {}
|
||||||
local pageOptions = {}
|
local pageOptions = {}
|
||||||
|
|
||||||
|
@ -160,6 +161,25 @@ local function pageGroupComparator(a, b)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function generateSearchHints(page)
|
||||||
|
local hints = {}
|
||||||
|
local l10n = core.l10n(page.l10n)
|
||||||
|
table.insert(hints, l10n(page.name))
|
||||||
|
table.insert(hints, l10n(page.description))
|
||||||
|
local pageGroups = groups[page.key]
|
||||||
|
for _, pageGroup in pairs(pageGroups) do
|
||||||
|
local group = common.getSection(pageGroup.global, common.groupSectionKey):get(pageGroup.key)
|
||||||
|
local l10n = core.l10n(group.l10n)
|
||||||
|
table.insert(hints, l10n(group.name))
|
||||||
|
table.insert(hints, l10n(group.description))
|
||||||
|
for _, setting in pairs(group.settings) do
|
||||||
|
table.insert(hints, l10n(setting.name))
|
||||||
|
table.insert(hints, l10n(setting.description))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return table.concat(hints, ' ')
|
||||||
|
end
|
||||||
|
|
||||||
local function renderPage(page)
|
local function renderPage(page)
|
||||||
local l10n = core.l10n(page.l10n)
|
local l10n = core.l10n(page.l10n)
|
||||||
local layout = {
|
local layout = {
|
||||||
|
@ -214,7 +234,7 @@ local function renderPage(page)
|
||||||
return {
|
return {
|
||||||
name = l10n(page.name),
|
name = l10n(page.name),
|
||||||
element = ui.create(layout),
|
element = ui.create(layout),
|
||||||
searchHints = '',
|
searchHints = generateSearchHints(page),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -242,18 +262,12 @@ local function onGroupRegistered(global, key)
|
||||||
table.insert(groups[group.page], pageGroup)
|
table.insert(groups[group.page], pageGroup)
|
||||||
common.getSection(global, group.key):subscribe(onSettingChanged(global))
|
common.getSection(global, group.key):subscribe(onSettingChanged(global))
|
||||||
|
|
||||||
local index = 1
|
if not pages[group.page] then return end
|
||||||
for _, g in ipairs(groups[group.page]) do
|
local options = renderPage(pages[group.page])
|
||||||
if pageGroupComparator(pageGroup, g) then
|
pageOptions[group.page].element:destroy()
|
||||||
index = index + 1
|
for k, v in pairs(options) do
|
||||||
end
|
pageOptions[group.page][k] = v
|
||||||
end
|
end
|
||||||
|
|
||||||
if not pageOptions[group.page] then return end
|
|
||||||
local element = pageOptions[group.page].element
|
|
||||||
local groupsLayout = element.layout.content.groups
|
|
||||||
groupsLayout.content:insert(index, renderGroup(group, global))
|
|
||||||
element:update()
|
|
||||||
end
|
end
|
||||||
local globalGroups = storage.globalSection(common.groupSectionKey)
|
local globalGroups = storage.globalSection(common.groupSectionKey)
|
||||||
for groupKey in pairs(globalGroups:asTable()) do
|
for groupKey in pairs(globalGroups:asTable()) do
|
||||||
|
@ -288,6 +302,7 @@ local function registerPage(options)
|
||||||
name = options.name,
|
name = options.name,
|
||||||
description = options.description,
|
description = options.description,
|
||||||
}
|
}
|
||||||
|
pages[page.key] = page
|
||||||
groups[page.key] = groups[page.key] or {}
|
groups[page.key] = groups[page.key] or {}
|
||||||
pageOptions[page.key] = renderPage(page)
|
pageOptions[page.key] = renderPage(page)
|
||||||
ui.registerSettingsPage(pageOptions[page.key])
|
ui.registerSettingsPage(pageOptions[page.key])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue