add content_config
This commit is contained in:
parent
794e38507a
commit
2018b2f8a4
@ -1,15 +1,23 @@
|
|||||||
|
|
||||||
<container size='1000,580' color='#0F1E2DB2' interval='5' context='menu'>
|
<container size='1000,580' color='#0F1E2DB2' interval='5' context='menu'>
|
||||||
<panel id='contents' pos='15,15' size='440,490' color='0' max-length='455' scrollable='true'>
|
<panel id='contents' pos='15,15' size='440,490' color='0' max-length='455' scrollable='true'>
|
||||||
<!-- content is generated in script -->
|
<!-- content is generated in script -->
|
||||||
</panel>
|
</panel>
|
||||||
<button pos='15,525' size='440,40' onclick='menu:back()'>@Back</button>
|
<button pos='15,525' size='440,40' onclick='menu:back()'>@Back</button>
|
||||||
<button pos='485,525' size='500,40' onclick='core.open_folder("user:content")'>@Open content folder</button>
|
|
||||||
|
|
||||||
<panel id='search_panel' size='440,35' pos='15,485' interval='1' color='#0000004C'>
|
<panel id='search_panel' size='440,35' pos='15,485' interval='1' color='#0000004C'>
|
||||||
<textbox id='search_textbox' multiline='false' size='440,25' sub-consumer='function(x) refresh_search() end'></textbox>
|
<textbox id='search_textbox' multiline='false' size='440,25' sub-consumer='function(x) refresh_search() end'></textbox>
|
||||||
</panel>
|
</panel>
|
||||||
|
|
||||||
<panel id='content_info' pos='485,15' size='440,406' color='0' max-length='406' scrollable='true'>
|
<image onclick='core.open_folder("user:content")' interactive='true' src='gui/folder_icon'
|
||||||
|
size='32' margin='0,0,10,15' gravity='bottom-right'
|
||||||
|
color='#FFFFFF50' hover-color='#FFFFFF10'/>
|
||||||
|
|
||||||
|
<image id="open_config" onclick='open_config()' interactive='true' src='gui/settings_icon'
|
||||||
|
size='32' margin='0,0,52,15' gravity='bottom-right'
|
||||||
|
color='#FFFFFF50' hover-color='#FFFFFF10'/>
|
||||||
|
|
||||||
|
<panel id='content_info' pos='485,15' size='440,506' color='0' max-length='506' scrollable='true'>
|
||||||
<label>@Creator</label>
|
<label>@Creator</label>
|
||||||
<label id='author' multiline="true" color='#8C8C8C'>None</label>
|
<label id='author' multiline="true" color='#8C8C8C'>None</label>
|
||||||
<label></label>
|
<label></label>
|
||||||
@ -25,4 +33,8 @@
|
|||||||
<label>@Dependencies</label>
|
<label>@Dependencies</label>
|
||||||
<label id='dependencies' multiline="true" color='#8C8C8C'>None</label>
|
<label id='dependencies' multiline="true" color='#8C8C8C'>None</label>
|
||||||
</panel>
|
</panel>
|
||||||
|
|
||||||
|
<panel id='configs' visible='false' pos='485,15' size='440,506' color='0' max-length='506' scrollable='true'>
|
||||||
|
<!-- content is generated in script -->
|
||||||
|
</panel>
|
||||||
</container>
|
</container>
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
local packs_installed = {}
|
local packs_installed = {}
|
||||||
|
local pack_open = {}
|
||||||
|
|
||||||
function on_open(params)
|
function on_open(params)
|
||||||
refresh()
|
refresh()
|
||||||
@ -41,9 +42,140 @@ function refresh_search()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function create_checkbox(id, name, cheaked)
|
||||||
|
document.configs:add(string.format(
|
||||||
|
"<checkbox id='%s' consumer='function(x) set_value(\"%s\", \"%s\", x) end' checked='%s'>%s</checkbox>",
|
||||||
|
id, name, id, cheaked, name
|
||||||
|
))
|
||||||
|
end
|
||||||
|
|
||||||
|
local function create_textbox(id, name, text)
|
||||||
|
document.configs:add(string.format(
|
||||||
|
"<label id='%s'>%s</label>",
|
||||||
|
id .. "_label", name
|
||||||
|
))
|
||||||
|
document.configs:add(string.format(
|
||||||
|
"<textbox id='%s' consumer='function(x) set_value(\"%s\", \"%s\", x) end' hint='%s'>%s</textbox>",
|
||||||
|
id, name, id, name, text
|
||||||
|
))
|
||||||
|
end
|
||||||
|
|
||||||
|
local function create_trackbar(id, name, val)
|
||||||
|
document.configs:add(string.format(
|
||||||
|
"<label id='%s'>%s (%s)</label>",
|
||||||
|
id .. "_label", name, val
|
||||||
|
))
|
||||||
|
document.configs:add(string.format(
|
||||||
|
"<trackbar id='%s' consumer='function(x) set_value(\"%s\", \"%s\", x) end' value='%s' min='0' max='1000' step='10'>%s</trackbar>",
|
||||||
|
id, name, id, val, name
|
||||||
|
))
|
||||||
|
end
|
||||||
|
|
||||||
|
local function create_label(id, text, color)
|
||||||
|
if id then
|
||||||
|
document.configs:add(string.format(
|
||||||
|
"<label id='%s' color='%s'>%s</label>",
|
||||||
|
id, color, text
|
||||||
|
))
|
||||||
|
else
|
||||||
|
document.configs:add(string.format(
|
||||||
|
"<label>%s</label>",
|
||||||
|
text
|
||||||
|
))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function create_config(i, config, name, path)
|
||||||
|
create_label(name, '[' .. name .. ']', "#008000")
|
||||||
|
pack_open[2][i] = {{}, path = path}
|
||||||
|
for _, a in ipairs(config.checkboxes) do
|
||||||
|
create_checkbox(i .. '_' .. a[1], a[1], a[2])
|
||||||
|
pack_open[2][i][1][a[1]] = type(a[2])
|
||||||
|
end
|
||||||
|
create_label(nil, '', 0)
|
||||||
|
for _, a in ipairs(config.trackbars) do
|
||||||
|
create_trackbar(i .. '_' .. a[1], a[1], a[2])
|
||||||
|
create_label(nil, '', 0)
|
||||||
|
pack_open[2][i][1][a[1]] = type(a[2])
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, a in ipairs(config.textboxes) do
|
||||||
|
create_textbox(i .. '_' .. a[1], a[1], a[2])
|
||||||
|
create_label(nil, '', 0)
|
||||||
|
pack_open[2][i][1][a[1]] = type(a[2])
|
||||||
|
end
|
||||||
|
create_label(nil, '', 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function load_config_file(path)
|
||||||
|
local extension = path:match("%.(%w+)$")
|
||||||
|
|
||||||
|
if not extension or file.isdir(path) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local value = file.read(path)
|
||||||
|
|
||||||
|
if extension == "toml" then
|
||||||
|
return toml.parse(value), extension
|
||||||
|
elseif extension == "json" then
|
||||||
|
return json.parse(value), extension
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function load_config(path)
|
||||||
|
if file.exists(path) then
|
||||||
|
local value = load_config_file(path)
|
||||||
|
local config = {checkboxes = {},
|
||||||
|
trackbars = {},
|
||||||
|
textboxes = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if not value then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
for i, v in pairs(value) do
|
||||||
|
if type(v) == "string" then
|
||||||
|
table.insert(config.textboxes, {i, v})
|
||||||
|
elseif type(v) == "boolean" then
|
||||||
|
table.insert(config.checkboxes, {i, v})
|
||||||
|
elseif type(v) == "number" then
|
||||||
|
table.insert(config.trackbars, {i, v})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return config
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function set_value(name, id, value)
|
||||||
|
local config_id = tonumber(id:match("^(%w+)_"))
|
||||||
|
local elem_id = id:match("^[^_]+_(.+)$")
|
||||||
|
local type_val = pack_open[2][config_id][1][elem_id]
|
||||||
|
|
||||||
|
if type_val == 'number' then
|
||||||
|
document[id .. '_label'].text = string.format("%s (%s)", elem_id, value)
|
||||||
|
end
|
||||||
|
|
||||||
|
local path = pack_open[2][config_id].path
|
||||||
|
local config, extension = load_config_file(path)
|
||||||
|
config[name] = value
|
||||||
|
|
||||||
|
if extension == "toml" then
|
||||||
|
file.write(path, toml.tostring(config))
|
||||||
|
elseif extension == "json" then
|
||||||
|
file.write(path, json.tostring(config))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function open_pack(id)
|
function open_pack(id)
|
||||||
local packinfo = pack.get_info(id)
|
local packinfo = pack.get_info(id)
|
||||||
|
pack_open = {id, {}}
|
||||||
|
|
||||||
|
document.configs.visible = false
|
||||||
|
document.content_info.visible = true
|
||||||
|
|
||||||
if packinfo['dependencies'] == nil then document.dependencies.text = 'None' else document.dependencies.text = table.tostring(packinfo['dependencies']) end
|
if packinfo['dependencies'] == nil then document.dependencies.text = 'None' else document.dependencies.text = table.tostring(packinfo['dependencies']) end
|
||||||
if packinfo['creator'] == '' then document.author.text = 'None' else document.author.text = packinfo['creator'] end
|
if packinfo['creator'] == '' then document.author.text = 'None' else document.author.text = packinfo['creator'] end
|
||||||
@ -51,11 +183,35 @@ function open_pack(id)
|
|||||||
if packinfo['description'] == nil then document.description.text = 'None' else document.description.text = packinfo['description'] end
|
if packinfo['description'] == nil then document.description.text = 'None' else document.description.text = packinfo['description'] end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function open_config()
|
||||||
|
local id = pack_open[1]
|
||||||
|
if (not document.configs.visible and id) and
|
||||||
|
(file.exists("config:" .. id) and #file.list("config:" .. id) > 0) then
|
||||||
|
|
||||||
|
document.configs:clear()
|
||||||
|
document.configs.visible = true
|
||||||
|
document.content_info.visible = false
|
||||||
|
local configs = file.list("config:" .. id)
|
||||||
|
for i, c in ipairs(configs) do
|
||||||
|
local name = c:match("([^/]+)$")
|
||||||
|
name = name:match("([^%.]+)")
|
||||||
|
local config = load_config(c)
|
||||||
|
|
||||||
|
if config then
|
||||||
|
create_config(i, config, name, c)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
document.configs.visible = false
|
||||||
|
document.content_info.visible = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function refresh()
|
function refresh()
|
||||||
local packs_available = pack.get_available()
|
local packs_available = pack.get_available()
|
||||||
packs_installed = pack.get_installed()
|
packs_installed = pack.get_installed()
|
||||||
|
|
||||||
for i,k in ipairs(packs_available) do
|
for _, k in ipairs(packs_available) do
|
||||||
table.insert(packs_installed, k)
|
table.insert(packs_installed, k)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,9 @@
|
|||||||
"gui/warning",
|
"gui/warning",
|
||||||
"gui/error",
|
"gui/error",
|
||||||
"gui/cross",
|
"gui/cross",
|
||||||
"gui/refresh"
|
"gui/refresh",
|
||||||
|
"gui/folder_icon",
|
||||||
|
"gui/settings_icon"
|
||||||
],
|
],
|
||||||
"fonts": [
|
"fonts": [
|
||||||
{
|
{
|
||||||
|
|||||||
BIN
res/textures/gui/folder_icon.png
Normal file
BIN
res/textures/gui/folder_icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 181 B |
BIN
res/textures/gui/settings_icon.png
Normal file
BIN
res/textures/gui/settings_icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 258 B |
Loading…
x
Reference in New Issue
Block a user