diff --git a/src/common.lua b/src/common.lua index bb76144..edd64f5 100644 --- a/src/common.lua +++ b/src/common.lua @@ -610,6 +610,7 @@ local function reset_data(data) data.scrbar_rcp = 1 data.scrbar_usg = 1 data.query_item = nil + data.enable_search = nil data.recipes = nil data.usages = nil data.export_rcp = nil diff --git a/src/fields.lua b/src/fields.lua index 2fe2857..42540b8 100644 --- a/src/fields.lua +++ b/src/fields.lua @@ -309,13 +309,21 @@ end local function rcp_fields(player, data, fields) local sb_rcp, sb_usg = fields.scrbar_rcp, fields.scrbar_usg + if fields.filter and fields.filter == "" then + data.enable_search = nil + end + if fields.cancel then reset_data(data) elseif fields.exit then data.query_item = nil - elseif fields.key_enter_field == "filter" or fields.search then + elseif fields.enable_search then + data.enable_search = true + return set_fs(player) + + elseif fields.filter and (fields.key_enter_field == "filter" or fields.search) then if fields.filter == "" then reset_data(data) return set_fs(player) diff --git a/src/gui.lua b/src/gui.lua index ecdbb85..6c004e0 100644 --- a/src/gui.lua +++ b/src/gui.lua @@ -1325,10 +1325,16 @@ local function get_items_fs(fs, data, player, full_height) bg9(data.inv_width + 0.1, 0, 7.9, full_height, PNG.bg_full, 10) - fs("set_focus[filter]", - "style[filter;font_size=18;textcolor=#ccc]", - fmt("field[%f,0.2;3.35,0.6;filter;;%s]", data.inv_width + 0.85, ESC(data.filter)), - "field_close_on_enter[filter;false]") + if data.enable_search then + fs("set_focus[filter]", + "style[filter;font_size=18;textcolor=#ccc]", + fmt("field[%f,0.2;3.35,0.6;filter;;%s]", data.inv_width + 0.85, ESC(data.filter)), + "field_close_on_enter[filter;false]") + else + fs"style_type[label;font=italic;font_size=18]" + label(data.inv_width + 0.9, 0.49, clr("#aaa", ES"Search...")) + button(data.inv_width + 0.8, 0.2, 4, 1, "enable_search", "") + end image_button(data.inv_width + 0.35, 0.32, 0.35, 0.35, "", "search", "") image_button(data.inv_width + 5.27, 0.3, 0.35, 0.35, "", "prev_page", "")