mirror of
https://github.com/minetest-mods/unified_inventory.git
synced 2024-11-19 22:03:43 +01:00
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>.
This commit is contained in:
parent
20cf474886
commit
01297996a6
@ -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",
|
||||
|
1
init.lua
1
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 = {}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user