summaryrefslogtreecommitdiff
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
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>.
-rw-r--r--callbacks.lua10
-rw-r--r--init.lua1
-rw-r--r--internal.lua2
3 files changed, 11 insertions, 2 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",
diff --git a/init.lua b/init.lua
index ec4105f..dcd8ecf 100644
--- a/init.lua
+++ b/init.lua
@@ -8,6 +8,7 @@ unified_inventory = {}
unified_inventory.activefilter = {}
unified_inventory.alternate = {}
unified_inventory.current_page = {}
+unified_inventory.current_searchbox = {}
unified_inventory.current_index = {}
unified_inventory.current_item = {}
unified_inventory.crafts_table = {}
diff --git a/internal.lua b/internal.lua
index b352cdb..0f201ca 100644
--- a/internal.lua
+++ b/internal.lua
@@ -50,7 +50,7 @@ function unified_inventory.get_formspec(player, page)
formspec = formspec .. "image_button["..(start_x + 0.6 * 5)..",9;.8,.8;ui_skip_forward_icon.png;end_list;]"
-- Search box
- formspec = formspec .. "field[9.5,8.325;3,1;searchbox;;]"
+ formspec = formspec .. "field[9.5,8.325;3,1;searchbox;;"..minetest.formspec_escape(unified_inventory.current_searchbox[player_name]).."]"
formspec = formspec .. "image_button[12.2,8.1;.8,.8;ui_search_icon.png;searchbutton;]"
-- Items list