Allow searching for groups.
Also make "group buttons" apply the filter to that group.
This commit is contained in:
parent
b69fc35c88
commit
d560bcd6f0
@ -118,6 +118,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
if string.sub(name, 1, 12) == "item_button_" then
|
if string.sub(name, 1, 12) == "item_button_" then
|
||||||
clicked_item = string.sub(name, 13)
|
clicked_item = string.sub(name, 13)
|
||||||
break
|
break
|
||||||
|
elseif string.sub(name, 1, 11) == "item_group_" then
|
||||||
|
minetest.sound_play("click",
|
||||||
|
{to_player=player_name, gain = 0.1})
|
||||||
|
unified_inventory.apply_filter(player, "group:"..string.sub(name, 12))
|
||||||
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if clicked_item then
|
if clicked_item then
|
||||||
|
38
internal.lua
38
internal.lua
@ -97,18 +97,36 @@ function unified_inventory.apply_filter(player, filter)
|
|||||||
lfilter = ""
|
lfilter = ""
|
||||||
end
|
end
|
||||||
unified_inventory.filtered_items_list[player_name]={}
|
unified_inventory.filtered_items_list[player_name]={}
|
||||||
for name, def in pairs(minetest.registered_items) do
|
if lfilter:sub(1, 6) == "group:" then
|
||||||
if (not def.groups.not_in_creative_inventory or
|
local groups = lfilter:sub(7):split(",")
|
||||||
def.groups.not_in_creative_inventory == 0)
|
for name, def in pairs(minetest.registered_items) do
|
||||||
and def.description and def.description ~= "" then
|
if def.groups then
|
||||||
local lname = string.lower(name)
|
local all = true
|
||||||
local ldesc = string.lower(def.description)
|
for _, group in ipairs(groups) do
|
||||||
if string.find(lname, lfilter) or string.find(ldesc, lfilter) then
|
if not (def.groups[group] and (def.groups[group] > 0)) then
|
||||||
table.insert(unified_inventory.filtered_items_list[player_name], name)
|
all = false
|
||||||
size = size + 1
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if all then
|
||||||
|
table.insert(unified_inventory.filtered_items_list[player_name], name)
|
||||||
|
size = size + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
for name, def in pairs(minetest.registered_items) do
|
||||||
|
if (not def.groups.not_in_creative_inventory or
|
||||||
|
def.groups.not_in_creative_inventory == 0)
|
||||||
|
and def.description and def.description ~= "" then
|
||||||
|
local lname = string.lower(name)
|
||||||
|
local ldesc = string.lower(def.description)
|
||||||
|
if string.find(lname, lfilter) or string.find(ldesc, lfilter) then
|
||||||
|
table.insert(unified_inventory.filtered_items_list[player_name], name)
|
||||||
|
size = size + 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
table.sort(unified_inventory.filtered_items_list[player_name])
|
table.sort(unified_inventory.filtered_items_list[player_name])
|
||||||
unified_inventory.filtered_items_list_size[player_name] = size
|
unified_inventory.filtered_items_list_size[player_name] = size
|
||||||
|
@ -213,7 +213,8 @@ unified_inventory.register_page("craftguide", {
|
|||||||
local group = string.sub(item, 7)
|
local group = string.sub(item, 7)
|
||||||
formspec = formspec.."image_button["
|
formspec = formspec.."image_button["
|
||||||
..(1.0 + x)..","..(0.0 + y)..";1.1,1.1;"
|
..(1.0 + x)..","..(0.0 + y)..";1.1,1.1;"
|
||||||
.."ui_group.png;;"
|
.."ui_group.png;"
|
||||||
|
.."item_group_"..minetest.formspec_escape(group)..";"
|
||||||
..minetest.formspec_escape(group).."]"
|
..minetest.formspec_escape(group).."]"
|
||||||
else
|
else
|
||||||
formspec = formspec.."item_image_button["
|
formspec = formspec.."item_image_button["
|
||||||
|
Loading…
Reference in New Issue
Block a user