mirror of
https://github.com/minetest-mods/i3.git
synced 2025-06-30 15:40:24 +02:00
Inventory sorting: Add option for rejecting items
This commit is contained in:
@ -446,12 +446,32 @@ local function compress_items(list, start_i)
|
||||
return new_inv
|
||||
end
|
||||
|
||||
local function reject_items(player, inv, list, rej)
|
||||
for i = 1, #list do
|
||||
local stack = list[i]
|
||||
local name = stack:get_name()
|
||||
|
||||
for _, it in ipairs(rej) do
|
||||
if name == it then
|
||||
spawn_item(player, stack)
|
||||
inv:set_stack("main", i, ItemStack(""))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return inv:get_list("main")
|
||||
end
|
||||
|
||||
local function sort_inventory(player, data)
|
||||
local inv = player:get_inventory()
|
||||
local list = inv:get_list("main")
|
||||
local size = inv:get_size("main")
|
||||
local start_i = data.ignore_hotbar and 10 or 1
|
||||
|
||||
if true_table(data.reject_items) then
|
||||
list = reject_items(player, inv, list, data.reject_items)
|
||||
end
|
||||
|
||||
if data.inv_compress then
|
||||
list = compress_items(list, start_i)
|
||||
else
|
||||
|
@ -475,6 +475,15 @@ local function show_popup(fs, data)
|
||||
fs("checkbox", 2.4, 10.5, "cb_reverse_sorting", "Reverse sorting", tostring(data.reverse_sorting))
|
||||
fs("checkbox", 2.4, 10.95, "cb_auto_sorting", "Automatic sorting", tostring(data.auto_sorting))
|
||||
fs("checkbox", 5.4, 10.05, "cb_ignore_hotbar", "Ignore hotbar", tostring(data.ignore_hotbar))
|
||||
|
||||
for _ = 1, 3 do
|
||||
fs("box", 5.4, 10.68, 2.4, 0.45, "#707070")
|
||||
end
|
||||
|
||||
fs("style[reject_items;font_size=15;font=mono;textcolor=#bddeff]")
|
||||
fs(fmt("field[5.4,10.68;2.4,0.45;reject_items;Reject items:;%s]",
|
||||
ESC(concat(data.reject_items or {}, ","))))
|
||||
fs("field_close_on_enter[reject_items;false]")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -3,7 +3,7 @@ local _, get_inventory_fs = i3.files.gui()
|
||||
local S, clr = i3.get("S", "clr")
|
||||
local min, ceil, random = i3.get("min", "ceil", "random")
|
||||
local reg_items, reg_aliases = i3.get("reg_items", "reg_aliases")
|
||||
local fmt, find, match, sub, lower = i3.get("fmt", "find", "match", "sub", "lower")
|
||||
local fmt, find, match, sub, lower, split = i3.get("fmt", "find", "match", "sub", "lower", "split")
|
||||
local vec_new, vec_eq, vec_round = i3.get("vec_new", "vec_eq", "vec_round")
|
||||
local sort, copy, insert, remove, indexof = i3.get("sort", "copy", "insert", "remove", "indexof")
|
||||
|
||||
@ -55,6 +55,11 @@ i3.new_tab {
|
||||
skins.set_player_skin(player, _skins[id])
|
||||
end
|
||||
|
||||
if fields.reject_items then
|
||||
local items = split(fields.reject_items, ",")
|
||||
data.reject_items = items
|
||||
end
|
||||
|
||||
for field in pairs(fields) do
|
||||
if sub(field, 1, 4) == "btn_" then
|
||||
data.subcat = indexof(i3.SUBCAT, sub(field, 5))
|
||||
|
Reference in New Issue
Block a user