Merge pull request #430 from Xertis/main
Redesign of the content addition menu
This commit is contained in:
commit
cbf07a6351
@ -1,13 +1,41 @@
|
|||||||
<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'>
|
<container size='940,600' color='#0F1E2DB2' interval='5' context='menu'>
|
||||||
<!-- content is generated in script -->
|
<button pos='15,545' id='apply_btn' size='440,40' onclick='apply()'>@Apply</button>
|
||||||
</panel>
|
<button pos='485,545' size='440,40' onclick='menu:back()'>@Cancel</button>
|
||||||
<panel id='packs_add' pos='445,2' size='440,406' color='0' max-length='406'>
|
|
||||||
<!-- content is generated in script -->
|
<image id="move_left" src='gui/check_mark'
|
||||||
</panel>
|
size='32' margin='218,2,0,0' gravity='top-left'
|
||||||
<button id='apply_btn' pos='2,410' size='440,40' onclick='apply()'>@Apply</button>
|
color='#FFFFFF50'/>
|
||||||
<button pos='445,410' size='398,40' onclick='menu:back()'>@Cancel</button>
|
|
||||||
<image onclick='refresh()' interactive='true' src='gui/refresh'
|
<image id="move_left" src='gui/cross'
|
||||||
size='32' margin='7' gravity='bottom-right'
|
size='32' margin='0,2,219,0' gravity='top-right'
|
||||||
color='#FFFFFF80' hover-color='#FFFFFF10'/>
|
color='#FFFFFF50'/>
|
||||||
</container>
|
|
||||||
|
<panel id='search_panel' size='440,36' pos='15,504' interval='1' color='#0000004C'>
|
||||||
|
<textbox id='search_textbox' multiline='false' size='440,25' sub-consumer='function(x) refresh_search() end'></textbox>
|
||||||
|
</panel>
|
||||||
|
|
||||||
|
<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='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,34' size='440,507' color='0' max-length='455' scrollable='true'>
|
||||||
|
<!-- content is generated in script -->
|
||||||
|
</panel>
|
||||||
|
|
||||||
|
<panel id='packs_cur' pos='15,34' size='440,507' color='0' max-length='455' scrollable='true'>
|
||||||
|
<!-- content is generated in script -->
|
||||||
|
</panel>
|
||||||
|
</container>
|
||||||
@ -5,9 +5,28 @@ function on_open(params)
|
|||||||
refresh()
|
refresh()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- add - packs to be added to the world (after apply)
|
||||||
|
-- rem - packs that should be removed from the world (after apply)
|
||||||
add_packs = {}
|
add_packs = {}
|
||||||
rem_packs = {}
|
rem_packs = {}
|
||||||
|
|
||||||
|
-- included - connected packs to the world
|
||||||
|
-- excluded - packs that are not connected to the world
|
||||||
|
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()
|
function apply()
|
||||||
core.reconfig_packs(add_packs, rem_packs)
|
core.reconfig_packs(add_packs, rem_packs)
|
||||||
if mode ~= "world" then
|
if mode ~= "world" then
|
||||||
@ -15,8 +34,70 @@ function apply()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function reposition_func(_pack)
|
||||||
|
local INTERVAL = 2
|
||||||
|
local STEP = 1
|
||||||
|
local SIZE = 80
|
||||||
|
|
||||||
|
local tbl = nil
|
||||||
|
if table.has(packs_included, _pack) then
|
||||||
|
tbl = packs_included
|
||||||
|
elseif table.has(packs_excluded, _pack) then
|
||||||
|
tbl = packs_excluded
|
||||||
|
else
|
||||||
|
tbl = packs_excluded
|
||||||
|
local packinfo = pack.get_info(_pack)
|
||||||
|
packinfo[packinfo.id] = {packinfo.id, packinfo.title}
|
||||||
|
table.insert(packs_excluded, packinfo.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
local indx = table.index(tbl, _pack) - 1
|
||||||
|
local pos = {0, (SIZE + INTERVAL) * indx + STEP}
|
||||||
|
|
||||||
|
return pos[1], pos[2]
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function refresh_search()
|
||||||
|
local search_text = document.search_textbox.text:lower()
|
||||||
|
|
||||||
|
local new_included = table.copy(packs_included)
|
||||||
|
local new_excluded = table.copy(packs_excluded)
|
||||||
|
|
||||||
|
local function score(pack_name)
|
||||||
|
if pack_name:lower():find(search_text) then
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
local function sorting(a, b)
|
||||||
|
local score_a = score(packs_info[a][2])
|
||||||
|
local score_b = score(packs_info[b][2])
|
||||||
|
|
||||||
|
if score_a ~= score_b then
|
||||||
|
return score_a > score_b
|
||||||
|
else
|
||||||
|
return packs_info[a][2] < packs_info[b][2]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
table.sort(new_included, sorting)
|
||||||
|
table.sort(new_excluded, sorting)
|
||||||
|
|
||||||
|
packs_included = new_included
|
||||||
|
packs_excluded = new_excluded
|
||||||
|
|
||||||
|
for _, id in ipairs(table.merge(table.copy(packs_included), packs_excluded)) do
|
||||||
|
local content = document["pack_" .. id]
|
||||||
|
content:reposition()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function refresh_changes()
|
function refresh_changes()
|
||||||
document.apply_btn.enabled = (#add_packs>0) or (#rem_packs>0)
|
document.apply_btn.enabled = (#add_packs>0) or (#rem_packs>0)
|
||||||
|
refresh_search()
|
||||||
end
|
end
|
||||||
|
|
||||||
function move_pack(id)
|
function move_pack(id)
|
||||||
@ -24,23 +105,61 @@ function move_pack(id)
|
|||||||
if table.has(add_packs, id) then
|
if table.has(add_packs, id) then
|
||||||
document["pack_"..id]:moveInto(document.packs_add)
|
document["pack_"..id]:moveInto(document.packs_add)
|
||||||
table.remove_value(add_packs, id)
|
table.remove_value(add_packs, id)
|
||||||
|
include(id, false)
|
||||||
-- cancel pack removal
|
-- cancel pack removal
|
||||||
elseif table.has(rem_packs, id) then
|
elseif table.has(rem_packs, id) then
|
||||||
document["pack_"..id]:moveInto(document.packs_cur)
|
document["pack_"..id]:moveInto(document.packs_cur)
|
||||||
table.remove_value(rem_packs, id)
|
table.remove_value(rem_packs, id)
|
||||||
|
include(id, true)
|
||||||
-- add pack
|
-- add pack
|
||||||
elseif table.has(packs_installed, id) then
|
elseif table.has(packs_installed, id) then
|
||||||
document["pack_"..id]:moveInto(document.packs_add)
|
document["pack_"..id]:moveInto(document.packs_add)
|
||||||
table.insert(rem_packs, id)
|
table.insert(rem_packs, id)
|
||||||
|
include(id, false)
|
||||||
-- remove pack
|
-- remove pack
|
||||||
else
|
else
|
||||||
document["pack_"..id]:moveInto(document.packs_cur)
|
document["pack_"..id]:moveInto(document.packs_cur)
|
||||||
table.insert(add_packs, id)
|
table.insert(add_packs, id)
|
||||||
|
include(id, true)
|
||||||
end
|
end
|
||||||
refresh_changes()
|
refresh_changes()
|
||||||
end
|
end
|
||||||
|
|
||||||
function place_pack(panel, packinfo, callback)
|
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, position_func)
|
||||||
if packinfo.error then
|
if packinfo.error then
|
||||||
callback = nil
|
callback = nil
|
||||||
end
|
end
|
||||||
@ -50,6 +169,7 @@ function place_pack(panel, packinfo, callback)
|
|||||||
packinfo.id_verbose = packinfo.id
|
packinfo.id_verbose = packinfo.id
|
||||||
end
|
end
|
||||||
packinfo.callback = callback
|
packinfo.callback = callback
|
||||||
|
packinfo.position_func = position_func or function () end
|
||||||
panel:add(gui.template("pack", packinfo))
|
panel:add(gui.template("pack", packinfo))
|
||||||
if not callback then
|
if not callback then
|
||||||
document["pack_"..packinfo.id].enabled = false
|
document["pack_"..packinfo.id].enabled = false
|
||||||
@ -76,15 +196,30 @@ function check_dependencies(packinfo)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function check_deleted()
|
||||||
|
for i = 1, math.max(#packs_included, #packs_excluded) do
|
||||||
|
local pack = packs_included[i]
|
||||||
|
if pack and not table.has(packs_all, pack) then
|
||||||
|
table.remove(packs_included, i)
|
||||||
|
table.insert(rem_packs, pack)
|
||||||
|
end
|
||||||
|
|
||||||
|
pack = packs_excluded[i]
|
||||||
|
if pack and not table.has(packs_all, pack) then
|
||||||
|
table.remove(packs_excluded, i)
|
||||||
|
table.insert(rem_packs, pack)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function refresh()
|
function refresh()
|
||||||
packs_installed = pack.get_installed()
|
packs_installed = pack.get_installed()
|
||||||
packs_available = pack.get_available()
|
packs_available = pack.get_available()
|
||||||
base_packs = pack.get_base_packs()
|
base_packs = pack.get_base_packs()
|
||||||
packs_all = {unpack(packs_installed)}
|
packs_all = {unpack(packs_installed)}
|
||||||
required = {}
|
required = {}
|
||||||
for i,k in ipairs(packs_available) do
|
|
||||||
table.insert(packs_all, k)
|
table.merge(packs_all, packs_available)
|
||||||
end
|
|
||||||
|
|
||||||
local packs_cur = document.packs_cur
|
local packs_cur = document.packs_cur
|
||||||
local packs_add = document.packs_add
|
local packs_add = document.packs_add
|
||||||
@ -105,20 +240,14 @@ function refresh()
|
|||||||
end
|
end
|
||||||
local packinfos = pack.get_info(packids)
|
local packinfos = pack.get_info(packids)
|
||||||
|
|
||||||
for i,id in ipairs(packs_installed) do
|
for _,id in ipairs(base_packs) do
|
||||||
local packinfo = packinfos[id]
|
local packinfo = pack.get_info(id)
|
||||||
packinfo.index = i
|
packs_info[id] = {packinfo.id, packinfo.title}
|
||||||
callback = not table.has(base_packs, id) and string.format('move_pack("%s")', id) or nil
|
|
||||||
packinfo.error = check_dependencies(packinfo)
|
|
||||||
place_pack(packs_cur, packinfo, callback)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
for i,id in ipairs(packs_available) do
|
for _,id in ipairs(packs_all) do
|
||||||
local packinfo = packinfos[id]
|
local packinfo = pack.get_info(id)
|
||||||
packinfo.index = i
|
packs_info[id] = {packinfo.id, packinfo.title}
|
||||||
callback = string.format('move_pack("%s")', id)
|
|
||||||
packinfo.error = check_dependencies(packinfo)
|
|
||||||
place_pack(packs_add, packinfo, callback)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
for i,id in ipairs(packs_installed) do
|
for i,id in ipairs(packs_installed) do
|
||||||
@ -127,6 +256,26 @@ function refresh()
|
|||||||
end
|
end
|
||||||
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
|
||||||
|
|
||||||
|
for i,id in ipairs(packs_installed) do
|
||||||
|
local packinfo = packinfos[id]
|
||||||
|
packinfo.index = i
|
||||||
|
callback = not table.has(base_packs, id) and string.format('move_pack("%s")', id) or nil
|
||||||
|
packinfo.error = check_dependencies(packinfo)
|
||||||
|
place_pack(packs_cur, packinfo, callback, string.format('reposition_func("%s")', packinfo.id))
|
||||||
|
end
|
||||||
|
|
||||||
|
for i,id in ipairs(packs_available) do
|
||||||
|
local packinfo = packinfos[id]
|
||||||
|
packinfo.index = i
|
||||||
|
callback = string.format('move_pack("%s")', id)
|
||||||
|
packinfo.error = check_dependencies(packinfo)
|
||||||
|
place_pack(packs_add, packinfo, callback, string.format('reposition_func("%s")', packinfo.id))
|
||||||
|
end
|
||||||
|
|
||||||
|
check_deleted()
|
||||||
apply_movements(packs_cur, packs_add)
|
apply_movements(packs_cur, packs_add)
|
||||||
refresh_changes()
|
refresh_changes()
|
||||||
end
|
end
|
||||||
|
|||||||
@ -28,7 +28,8 @@ function on_open()
|
|||||||
document.content_btn.text = string.format(
|
document.content_btn.text = string.format(
|
||||||
"%s [%s]", gui.str("Content", "menu"), #pack.get_installed()
|
"%s [%s]", gui.str("Content", "menu"), #pack.get_installed()
|
||||||
)
|
)
|
||||||
if settings.generator == nil then
|
|
||||||
|
if settings.generator == nil or generation.get_generators()[settings.generator] == nil then
|
||||||
settings.generator = generation.get_default_generator()
|
settings.generator = generation.get_default_generator()
|
||||||
end
|
end
|
||||||
document.generator_btn.text = string.format(
|
document.generator_btn.text = string.format(
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
<container id='pack_%{id}' onclick='%{callback}' size='0,80' color='#00000040' hover-color='#00000080' z-index="%{index}">
|
<container id='pack_%{id}' onclick='%{callback}' size='0,80' color='#00000040' hover-color='#00000080' position-func="%{position_func}" z-index="%{index}">
|
||||||
<label color='#FFFFFF80' size='300,25' align='right' gravity='top-right'>
|
<label color='#FFFFFF80' size='300,25' align='right' gravity='top-right'>
|
||||||
[%{id_verbose}]
|
[%{id_verbose}]
|
||||||
</label>
|
</label>
|
||||||
|
|||||||
@ -19,7 +19,10 @@
|
|||||||
"gui/cross",
|
"gui/cross",
|
||||||
"gui/refresh",
|
"gui/refresh",
|
||||||
"gui/folder_icon",
|
"gui/folder_icon",
|
||||||
"gui/settings_icon"
|
"gui/settings_icon",
|
||||||
|
"gui/check_mark",
|
||||||
|
"gui/left_arrow",
|
||||||
|
"gui/right_arrow"
|
||||||
],
|
],
|
||||||
"fonts": [
|
"fonts": [
|
||||||
{
|
{
|
||||||
|
|||||||
BIN
res/textures/gui/check_mark.png
Normal file
BIN
res/textures/gui/check_mark.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 560 B |
BIN
res/textures/gui/left_arrow.png
Normal file
BIN
res/textures/gui/left_arrow.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 202 B |
BIN
res/textures/gui/loupe.png
Normal file
BIN
res/textures/gui/loupe.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 201 B |
BIN
res/textures/gui/right_arrow.png
Normal file
BIN
res/textures/gui/right_arrow.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 201 B |
Loading…
x
Reference in New Issue
Block a user