mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
move menu pages loader to Lua & add gui.load_document, file.ext(), file.prefix() & add core:gui_util module
This commit is contained in:
parent
da471bd4eb
commit
0a1a16299e
16 changed files with 156 additions and 55 deletions
38
res/modules/gui_util.lua
Normal file
38
res/modules/gui_util.lua
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
local gui_util = {}
|
||||
|
||||
--- Parse `pagename?arg1=value1&arg2=value2` queries
|
||||
--- @param query page query string
|
||||
--- @return page_name, args_table
|
||||
function gui_util.parse_query(query)
|
||||
local args = {}
|
||||
local name
|
||||
|
||||
local index = string.find(query, '?')
|
||||
if index then
|
||||
local argstr = string.sub(query, index + 1)
|
||||
name = string.sub(query, 1, index - 1)
|
||||
|
||||
local map = {}
|
||||
for key, value in string.gmatch(argstr, "([^=&]*)=([^&]*)") do
|
||||
map[key] = value
|
||||
end
|
||||
table.insert(args, map)
|
||||
else
|
||||
name = query
|
||||
end
|
||||
return name, args
|
||||
end
|
||||
|
||||
--- @param query page query string
|
||||
--- @return document_id
|
||||
function gui_util.load_page(query)
|
||||
local name, args = gui_util.parse_query(query)
|
||||
local filename = file.find(string.format("layouts/pages/%s.xml", name))
|
||||
if filename then
|
||||
name = file.prefix(filename)..":pages/"..name
|
||||
gui.load_document(filename, name, args)
|
||||
return name
|
||||
end
|
||||
end
|
||||
|
||||
return gui_util
|
||||
|
|
@ -192,6 +192,9 @@ _GUI_ROOT = Document.new("core:root")
|
|||
_MENU = _GUI_ROOT.menu
|
||||
menu = _MENU
|
||||
|
||||
local gui_util = require "core:gui_util"
|
||||
__vc_page_loader = gui_util.load_page
|
||||
|
||||
--- Console library extension ---
|
||||
console.cheats = {}
|
||||
|
||||
|
|
|
|||
|
|
@ -374,3 +374,7 @@ end
|
|||
function file.ext(path)
|
||||
return path:match("%.([^:/\\]+)$")
|
||||
end
|
||||
|
||||
function file.prefix(path)
|
||||
return path:match("^([^:]+)")
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue