redesign content

This commit is contained in:
Xertis 2025-01-02 23:16:53 +03:00
parent fc5e751f68
commit e5cb5a5689
2 changed files with 125 additions and 9 deletions

View File

@ -1,13 +1,34 @@
<container size='887,454' color='#0F1E2DB2' padding='8' interval='5' context='menu'>
<panel id='packs_cur' pos='2' size='440,406' color='0' max-length='406'>
<!-- content is generated in script -->
<container size='940,580' color='#0F1E2DB2' interval='5' context='menu'>
<button pos='15,525' id='apply_btn' size='440,40' onclick='apply()'>@Apply</button>
<button pos='485,525' size='440,40' onclick='menu:back()'>@Cancel</button>
<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>
</panel>
<panel id='packs_add' pos='445,2' size='440,406' color='0' max-length='406'>
<!-- content is generated in script -->
</panel>
<button id='apply_btn' pos='2,410' size='440,40' onclick='apply()'>@Apply</button>
<button pos='445,410' size='398,40' onclick='menu:back()'>@Cancel</button>
<image onclick='core.open_folder("user:content")' interactive='true' src='gui/folder_icon'
size='32' margin='0,0,18,66' gravity='bottom-right'
color='#FFFFFF50' hover-color='#FFFFFF10'/>
<image onclick='refresh()' interactive='true' src='gui/refresh'
size='32' margin='7' gravity='bottom-right'
size='32' margin='0,0,65,66' gravity='bottom-right'
color='#FFFFFF80' hover-color='#FFFFFF10'/>
<image id="move_right" onclick='move_right()' interactive='true' src='gui/right_arrow'
size='32' margin='0,0,380,64' gravity='bottom-right'
color='#FFFFFF50' hover-color='#FFFFFF10'/>
<image id="move_left" onclick='move_left()' interactive='true' src='gui/left_arrow'
size='32' margin='0,0,425,64' gravity='bottom-right'
color='#FFFFFF50' hover-color='#FFFFFF10'/>
<panel id='packs_add' pos='485,15' size='440,506' color='0' max-length='455' scrollable='true'>
<!-- content is generated in script -->
</panel>
<panel id='packs_cur' pos='15,15' size='440,506' color='0' max-length='455' scrollable='true'>
<!-- content is generated in script -->
</panel>
</container>

View File

@ -8,6 +8,21 @@ end
add_packs = {}
rem_packs = {}
packs_included = {}
packs_excluded = {}
packs_info = {}
local function include(id, is_include)
if is_include then
table.insert(packs_included, id)
table.remove_value(packs_excluded, id)
else
table.insert(packs_excluded, id)
table.remove_value(packs_included, id)
end
end
function apply()
core.reconfig_packs(add_packs, rem_packs)
if mode ~= "world" then
@ -15,8 +30,37 @@ function apply()
end
end
function refresh_search()
local search_text = document.search_textbox.text:lower()
local interval = 2
local step = -1
for _, packs in ipairs({packs_excluded, packs_included}) do
local visible = 0
for i, v in ipairs(packs) do
local info = packs_info[v]
local id = info[1]
local title = info[2]
local content = document["pack_" .. id]
local pos = content.pos
local size = content.size
if title:lower():find(search_text) or search_text == '' then
content.pos = {pos[1], visible * (size[2] + interval) - step}
visible = visible + 1
else
content.pos = {pos[1], (visible + #packs - i) * (size[2] + interval) - step}
end
end
end
end
function refresh_changes()
document.apply_btn.enabled = (#add_packs>0) or (#rem_packs>0)
refresh_search()
end
function move_pack(id)
@ -24,22 +68,60 @@ function move_pack(id)
if table.has(add_packs, id) then
document["pack_"..id]:moveInto(document.packs_add)
table.remove_value(add_packs, id)
include(id, false)
-- cancel pack removal
elseif table.has(rem_packs, id) then
document["pack_"..id]:moveInto(document.packs_cur)
table.remove_value(rem_packs, id)
include(id, true)
-- add pack
elseif table.has(packs_installed, id) then
document["pack_"..id]:moveInto(document.packs_add)
table.insert(rem_packs, id)
include(id, false)
-- remove pack
else
document["pack_"..id]:moveInto(document.packs_cur)
table.insert(add_packs, id)
include(id, true)
end
refresh_changes()
end
function move_left()
for _, id in pairs(table.copy(packs_excluded)) do
if not document["pack_"..id].enabled then goto continue end
include(id, true)
table.insert(add_packs, id)
table.remove_value(rem_packs, id)
document["pack_"..id]:moveInto(document.packs_cur)
::continue::
end
refresh_changes()
end
function move_right()
for _, id in pairs(table.copy(packs_included)) do
if not document["pack_"..id].enabled then goto continue end
include(id, false)
if table.has(packs_installed, id) then
table.insert(rem_packs, id)
end
table.remove_value(add_packs, id)
document["pack_"..id]:moveInto(document.packs_add)
::continue::
end
refresh_changes()
end
function place_pack(panel, packinfo, callback)
if packinfo.error then
callback = nil
@ -115,12 +197,25 @@ function refresh()
place_pack(packs_add, packinfo, callback)
end
for _,id in ipairs(base_packs) do
local packinfo = pack.get_info(id)
packs_info[id] = {packinfo.id, packinfo.title}
end
for _,id in ipairs(packs_all) do
local packinfo = pack.get_info(id)
packs_info[id] = {packinfo.id, packinfo.title}
end
for i,id in ipairs(packs_installed) do
if table.has(required, id) then
document["pack_"..id].enabled = false
end
end
if #packs_excluded == 0 then packs_excluded = table.copy(packs_available) end
if #packs_included == 0 then packs_included = table.copy(packs_installed) end
apply_movements(packs_cur, packs_add)
refresh_changes()
end