refact search
This commit is contained in:
parent
dc83e9b466
commit
6c3dd941ce
@ -52,6 +52,11 @@ table.shuffle(t: table) -> table
|
|||||||
|
|
||||||
Перемешивает значения в таблице.
|
Перемешивает значения в таблице.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
table.merge(t1: table, t2: table) -> table
|
||||||
|
```
|
||||||
|
|
||||||
|
Возвращает объединённую таблицу t1 с t2.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
table.tostring(t: table) -> string
|
table.tostring(t: table) -> string
|
||||||
|
|||||||
@ -34,34 +34,60 @@ function apply()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function refresh_search()
|
function reposition_func(pack)
|
||||||
|
local INTERVAL = 2
|
||||||
|
local STEP = -1
|
||||||
|
local SIZE = 80
|
||||||
|
|
||||||
|
local tbl = packs_excluded
|
||||||
|
if table.has(packs_included, pack) then
|
||||||
|
tbl = packs_included
|
||||||
|
end
|
||||||
|
|
||||||
|
local indx = table.index(tbl, pack) - 1
|
||||||
|
local pos = {0, (SIZE + INTERVAL) * indx - STEP}
|
||||||
|
|
||||||
|
return pos
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function refresh_search()
|
||||||
local search_text = document.search_textbox.text:lower()
|
local search_text = document.search_textbox.text:lower()
|
||||||
local interval = 2
|
|
||||||
local step = -1
|
|
||||||
|
|
||||||
for _, packs in ipairs({packs_excluded, packs_included}) do
|
local new_included = table.copy(packs_included)
|
||||||
local visible = 0
|
local new_excluded = table.copy(packs_excluded)
|
||||||
|
|
||||||
for i, v in ipairs(packs) do
|
local function score(package_name)
|
||||||
local info = packs_info[v]
|
if package_name:lower():find(search_text) then
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
local id = info[1]
|
local function sorting(a, b)
|
||||||
local title = info[2]
|
local score_a = score(packs_info[a][2])
|
||||||
|
local score_b = score(packs_info[b][2])
|
||||||
|
|
||||||
local content = document["pack_" .. id]
|
if score_a ~= score_b then
|
||||||
local pos = content.pos
|
return score_a > score_b
|
||||||
local size = content.size
|
else
|
||||||
|
return packs_info[a][2] < packs_info[b][2]
|
||||||
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
|
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
|
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()
|
refresh_search()
|
||||||
@ -126,7 +152,7 @@ function move_right()
|
|||||||
refresh_changes()
|
refresh_changes()
|
||||||
end
|
end
|
||||||
|
|
||||||
function place_pack(panel, packinfo, callback)
|
function place_pack(panel, packinfo, callback, position_func)
|
||||||
if packinfo.error then
|
if packinfo.error then
|
||||||
callback = nil
|
callback = nil
|
||||||
end
|
end
|
||||||
@ -136,6 +162,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
|
||||||
@ -191,22 +218,6 @@ function refresh()
|
|||||||
end
|
end
|
||||||
local packinfos = pack.get_info(packids)
|
local packinfos = pack.get_info(packids)
|
||||||
|
|
||||||
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)
|
|
||||||
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)
|
|
||||||
end
|
|
||||||
|
|
||||||
for _,id in ipairs(base_packs) do
|
for _,id in ipairs(base_packs) do
|
||||||
local packinfo = pack.get_info(id)
|
local packinfo = pack.get_info(id)
|
||||||
packs_info[id] = {packinfo.id, packinfo.title}
|
packs_info[id] = {packinfo.id, packinfo.title}
|
||||||
@ -226,6 +237,22 @@ function refresh()
|
|||||||
if #packs_excluded == 0 then packs_excluded = table.copy(packs_available) 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
|
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")[1],reposition_func("%s")[2]', packinfo.id, 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")[1],reposition_func("%s")[2]', packinfo.id, packinfo.id))
|
||||||
|
end
|
||||||
|
|
||||||
apply_movements(packs_cur, packs_add)
|
apply_movements(packs_cur, packs_add)
|
||||||
refresh_changes()
|
refresh_changes()
|
||||||
end
|
end
|
||||||
|
|||||||
@ -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' z-index="%{index}" position-func="%{position_func}">
|
||||||
<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>
|
||||||
|
|||||||
@ -113,6 +113,18 @@ function table.shuffle(t)
|
|||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function table.merge(t1, t2)
|
||||||
|
for i, v in pairs(t2) do
|
||||||
|
if type(i) == "number" then
|
||||||
|
t1[#t1 + 1] = v
|
||||||
|
elseif t1[i] == nil then
|
||||||
|
t1[i] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return t1
|
||||||
|
end
|
||||||
|
|
||||||
----------------------------------------------
|
----------------------------------------------
|
||||||
|
|
||||||
local pattern_escape_replacements = {
|
local pattern_escape_replacements = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user