content menu moved to xml (no icons yet)

This commit is contained in:
MihailRis
2024-04-18 22:15:23 +03:00
parent 49d57b307b
commit 64820020f8
14 changed files with 91 additions and 172 deletions
+6
View File
@@ -0,0 +1,6 @@
<panel size='550' color='0' padding='8' interval='5'>
<panel id='packs_panel' size='540,10' color='0,0,0,50' max-length='400'>
<!-- content is generated in script -->
</panel>
<button onclick='menu:back()' padding='10'>@Back</button>
</panel>
+14
View File
@@ -0,0 +1,14 @@
function add_pack(packid, packinfo)
local callback = string.format('core.add_packs({%q})', packid)
packinfo.id = packid
packinfo.callback = callback
packinfo.icon = "gui/no_icon"
document.packs_panel:add(gui.template("pack", packinfo))
end
function on_open()
local packs = pack.get_available()
for i,id in ipairs(packs) do
add_pack(id, pack.get_info(id))
end
end
+2 -1
View File
@@ -1,6 +1,7 @@
<panel size='550' color='0' padding='8' interval='5'>
<panel id='packs_panel' size='540,10' color='0,0,0,50' max-length='400'>
<!-- content is generated in script -->
<!-- content is generated in script -->
</panel>
<button onclick='menu.page = "add_packs"' padding='10'>@Add</button>
<button onclick='menu:back()' padding='10'>@Back</button>
</panel>
+11 -8
View File
@@ -1,12 +1,15 @@
function add_pack(packid, packinfo)
document.packs_panel:add(gui.template("pack", {
id=packid,
title=packinfo.title,
description=packinfo.description,
icon="gui/no_icon",
creator=packinfo.creator,
remover='0'
}))
local remover = ''
if packid ~= "base" then
remover = string.format('core.remove_packs({%q})', packid)
end
if packinfo.has_indices then
packid = packid.."*"
end
packinfo.id = packid
packinfo.remover = remover
packinfo.icon = "gui/no_icon"
document.packs_panel:add(gui.template("pack", packinfo))
end
function on_open()
+2 -1
View File
@@ -204,7 +204,8 @@ end
function gui.template(name, params)
local text = file.read(file.find("layouts/templates/"..name..".xml"))
for k,v in pairs(params) do
text = text:gsub("(%%{"..k.."})", tostring(v))
local arg = tostring(v):gsub("'", "\\'"):gsub('"', '\\"')
text = text:gsub("(%%{"..k.."})", arg)
end
text = text:gsub("if%s*=%s*'%%{%w+}'", "if=''")
text = text:gsub("if%s*=%s*\"%%{%w+}\"", "if=\"\"")