summaryrefslogtreecommitdiff
path: root/callbacks.lua
diff options
context:
space:
mode:
authorZefram <zefram@fysh.org>2014-04-29 19:36:52 +0100
committerZefram <zefram@fysh.org>2014-04-29 19:36:52 +0100
commit01297996a6afbbd92c10d4de32d372d46bb8a80c (patch)
tree27176b4e1e0635d74f9cf2e14836ccc632b4b623 /callbacks.lua
parent20cf4748864269a56c385137163c9a54139df40d (diff)
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 <return>.
Diffstat (limited to 'callbacks.lua')
-rw-r--r--callbacks.lua10
1 files changed, 9 insertions, 1 deletions
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",