From 01297996a6afbbd92c10d4de32d372d46bb8a80c Mon Sep 17 00:00:00 2001 From: Zefram Date: Tue, 29 Apr 2014 19:36:52 +0100 Subject: Preserve player's search string Keep the current inventory search string when performing inventory form actions other than searching. This means the player's input is not lost if the player breaks off from entering it to switch pages, or if the player absent-mindedly ends text input with . --- callbacks.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'callbacks.lua') diff --git a/callbacks.lua b/callbacks.lua index d229011..2827c5c 100644 --- a/callbacks.lua +++ b/callbacks.lua @@ -7,6 +7,7 @@ minetest.register_on_joinplayer(function(player) unified_inventory.items_list unified_inventory.activefilter[player_name] = "" unified_inventory.apply_filter(player, "") + unified_inventory.current_searchbox[player_name] = "" unified_inventory.alternate[player_name] = 1 unified_inventory.current_item[player_name] = nil unified_inventory.set_inventory_formspec(player, @@ -54,6 +55,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end local player_name = player:get_player_name() + -- always take new search text, even if not searching on it yet + if fields.searchbox ~= nil and fields.searchbox ~= unified_inventory.current_searchbox[player_name] then + unified_inventory.current_searchbox[player_name] = fields.searchbox + unified_inventory.set_inventory_formspec(player, unified_inventory.current_page[player_name]) + end + for i, def in pairs(unified_inventory.buttons) do if fields[def.name] then def.action(player) @@ -150,7 +157,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end if fields.searchbutton then - unified_inventory.apply_filter(player, fields.searchbox) + unified_inventory.apply_filter(player, unified_inventory.current_searchbox[player_name]) + unified_inventory.current_searchbox[player_name] = "" unified_inventory.set_inventory_formspec(player, unified_inventory.current_page[player_name]) minetest.sound_play("paperflip2", -- cgit v1.2.3