From 726b8162be09c43e207e8573bb6168f2e66f1143 Mon Sep 17 00:00:00 2001 From: Will Berry <73126355+wdberry@users.noreply.github.com> Date: Fri, 10 Mar 2023 13:57:28 -0500 Subject: [PATCH] Potential item search implementation --- cybersyn/scripts/gui/inventory.lua | 21 +++++++++++++++------ cybersyn/scripts/gui/manager.lua | 16 ++++++++-------- cybersyn/scripts/gui/stations.lua | 29 +++++++++++++++++------------ 3 files changed, 40 insertions(+), 26 deletions(-) diff --git a/cybersyn/scripts/gui/inventory.lua b/cybersyn/scripts/gui/inventory.lua index a335eeb..b1262be 100644 --- a/cybersyn/scripts/gui/inventory.lua +++ b/cybersyn/scripts/gui/inventory.lua @@ -96,12 +96,21 @@ function inventory_tab.build(map_data, player_data) end if search_item then - if not station.deliveries then - goto continue - end - for item_name, _ in pairs(station.deliveries) do - if item_name == search_item then - goto has_match + if station.deliveries then + for item_name, _ in pairs(station.deliveries) do + if item_name == search_item then + goto has_match + end + end + else + local comb1_signals, _ = get_signals(station) + for _, signal_ID in pairs(comb1_signals) do + local item = signal_ID.signal.name + if item then + if string.match(item, search_item) then + goto has_match + end + end end end goto continue diff --git a/cybersyn/scripts/gui/manager.lua b/cybersyn/scripts/gui/manager.lua index bea70d6..d4b371d 100644 --- a/cybersyn/scripts/gui/manager.lua +++ b/cybersyn/scripts/gui/manager.lua @@ -69,14 +69,14 @@ function manager.create(player) clear_and_focus_on_right_click = true, handler = manager.handle.manager_update_text_search, --on_gui_text_changed }, - -- item search box commented out. It *works*, but, the filtering logic only checks delivieres, so I'm not sure what Mami intended it for, so I'm leaving it off for now... - --{ type = "label", style = "subheader_caption_label", caption = { "cybersyn-gui.search-item-label" } }, - --{ - -- name = "manager_item_search_field", - -- type = "textfield", - -- clear_and_focus_on_right_click = true, - -- handler = manager.handle.manager_update_item_search, --on_gui_text_changed - --}, + --item search box commented out. It *works*, but, the filtering logic only checks delivieres, so I'm not sure what Mami intended it for, so I'm leaving it off for now... + { type = "label", style = "subheader_caption_label", caption = { "cybersyn-gui.search-item-label" } }, + { + name = "manager_item_search_field", + type = "textfield", + clear_and_focus_on_right_click = true, + handler = manager.handle.manager_update_item_search, --on_gui_text_changed + }, { type = "empty-widget", style = "flib_horizontal_pusher" }, { type = "label", style = "caption_label", caption = { "cybersyn-gui.network-name-label" } }, { type= "choose-elem-button", name="network", style="slot_button_in_shallow_frame", elem_type="signal", tooltip={"cybersyn-gui.network-tooltip"}, handler=manager.handle.manager_update_network_name, }, diff --git a/cybersyn/scripts/gui/stations.lua b/cybersyn/scripts/gui/stations.lua index 2c34a7c..33a7c5f 100644 --- a/cybersyn/scripts/gui/stations.lua +++ b/cybersyn/scripts/gui/stations.lua @@ -99,14 +99,9 @@ function stations_tab.build(map_data, player_data, query_limit) end if search_network_name then - --nil matches all? - if search_network_name == nil then - goto has_match - end if search_network_name ~= station.network_name then goto continue end - ::has_match:: local train_flag = get_network_flag(station, station.network_name) if not bit32.btest(search_network_mask, train_flag) then goto continue @@ -128,12 +123,22 @@ function stations_tab.build(map_data, player_data, query_limit) if search_item then - if not station.deliveries then - goto continue - end - for item_name, _ in pairs(station.deliveries) do - if item_name == search_item then - goto has_match + + if station.deliveries then + for item_name, _ in pairs(station.deliveries) do + if item_name == search_item then + goto has_match + end + end + else + local comb1_signals, _ = get_signals(station) + for _, signal_ID in pairs(comb1_signals) do + local item = signal_ID.signal.name + if item then + if string.match(item, search_item) then + goto has_match + end + end end end goto continue @@ -289,7 +294,7 @@ function stations_tab.handle.open_station_gui(player, player_data, refs, e) if e.shift then if station_entity.surface ~= player.surface then - util.error_flying_text(gui.player, { "cybersyn-message.error-cross-surface-camera-invalid" }) + util.error_flying_text(player, { "cybersyn-message.error-cross-surface-camera-invalid" }) else player.zoom_to_world(station_entity.position, 1, station_entity)