mirror of
https://github.com/minetest-mods/unified_inventory.git
synced 2024-12-30 20:50:23 +01:00
Fix error on invalid item_button_ fields
Also reduce the player inventory sending by one. If a formspec is sent, it'll also take the newest known search text
This commit is contained in:
parent
774674d0f5
commit
04b1cb9e7d
@ -47,6 +47,15 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
refill:set_size("main", 1)
|
refill:set_size("main", 1)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
local function apply_new_filter(player, search_text, new_dir)
|
||||||
|
local player_name = player:get_player_name()
|
||||||
|
minetest.sound_play("click", {to_player=player_name, gain = 0.1})
|
||||||
|
unified_inventory.apply_filter(player, search_text, new_dir)
|
||||||
|
unified_inventory.current_searchbox[player_name] = search_text
|
||||||
|
unified_inventory.set_inventory_formspec(player,
|
||||||
|
unified_inventory.current_page[player_name])
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
|
|
||||||
@ -60,7 +69,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
if fields.searchbox
|
if fields.searchbox
|
||||||
and fields.searchbox ~= unified_inventory.current_searchbox[player_name] then
|
and fields.searchbox ~= unified_inventory.current_searchbox[player_name] then
|
||||||
unified_inventory.current_searchbox[player_name] = fields.searchbox
|
unified_inventory.current_searchbox[player_name] = fields.searchbox
|
||||||
unified_inventory.set_inventory_formspec(player, unified_inventory.current_page[player_name])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
for i, def in pairs(unified_inventory.buttons) do
|
for i, def in pairs(unified_inventory.buttons) do
|
||||||
@ -112,21 +120,18 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
unified_inventory.current_page[player_name])
|
unified_inventory.current_page[player_name])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Check clicked item image button
|
||||||
local clicked_item
|
local clicked_item
|
||||||
for name, value in pairs(fields) do
|
for name, value in pairs(fields) do
|
||||||
if string.sub(name, 1, 12) == "item_button_" then
|
|
||||||
local new_dir, mangled_item = string.match(name, "^item_button_([a-z]+)_(.*)$")
|
local new_dir, mangled_item = string.match(name, "^item_button_([a-z]+)_(.*)$")
|
||||||
|
if new_dir and mangled_item then
|
||||||
clicked_item = unified_inventory.demangle_for_formspec(mangled_item)
|
clicked_item = unified_inventory.demangle_for_formspec(mangled_item)
|
||||||
if string.sub(clicked_item, 1, 6) == "group:" then
|
if string.sub(clicked_item, 1, 6) == "group:" then
|
||||||
minetest.sound_play("click", {to_player=player_name, gain = 0.1})
|
-- Change search filter to this group
|
||||||
unified_inventory.apply_filter(player, clicked_item, new_dir)
|
apply_new_filter(player, clicked_item, new_dir)
|
||||||
unified_inventory.current_searchbox[player_name] = clicked_item
|
|
||||||
unified_inventory.set_inventory_formspec(player,
|
|
||||||
unified_inventory.current_page[player_name])
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if new_dir == "recipe"
|
if new_dir == "recipe" or new_dir == "usage" then
|
||||||
or new_dir == "usage" then
|
|
||||||
unified_inventory.current_craft_direction[player_name] = new_dir
|
unified_inventory.current_craft_direction[player_name] = new_dir
|
||||||
end
|
end
|
||||||
break
|
break
|
||||||
@ -145,6 +150,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
unified_inventory.alternate[player_name] = 1
|
unified_inventory.alternate[player_name] = 1
|
||||||
unified_inventory.set_inventory_formspec(player, "craftguide")
|
unified_inventory.set_inventory_formspec(player, "craftguide")
|
||||||
elseif player_creative then
|
elseif player_creative then
|
||||||
|
-- Creative page: Add entire stack to inventory
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
local stack = ItemStack(clicked_item)
|
local stack = ItemStack(clicked_item)
|
||||||
stack:set_count(stack:get_stack_max())
|
stack:set_count(stack:get_stack_max())
|
||||||
@ -162,12 +168,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
minetest.sound_play("paperflip2",
|
minetest.sound_play("paperflip2",
|
||||||
{to_player=player_name, gain = 1.0})
|
{to_player=player_name, gain = 1.0})
|
||||||
elseif fields.searchresetbutton then
|
elseif fields.searchresetbutton then
|
||||||
unified_inventory.apply_filter(player, "", "nochange")
|
apply_new_filter(player, "", "nochange")
|
||||||
unified_inventory.current_searchbox[player_name] = ""
|
|
||||||
unified_inventory.set_inventory_formspec(player,
|
|
||||||
unified_inventory.current_page[player_name])
|
|
||||||
minetest.sound_play("click",
|
|
||||||
{to_player=player_name, gain = 0.1})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- alternate buttons
|
-- alternate buttons
|
||||||
|
Loading…
Reference in New Issue
Block a user