|
19 | 19 | ---@return GuiElemDef[] |
20 | 20 | function SearchGui.build_surface_results(surface_name, surface_data) |
21 | 21 | local gui_elements = {} |
22 | | - for entity_name, entity_surface_data in pairs(surface_data) do |
23 | | - for _, group in pairs(entity_surface_data) do |
24 | | - local distance_info = {""} |
25 | | - if group.distance then |
26 | | - distance_info = {"", "\n[font=default-semibold][color=255, 230, 192]", {"search-gui.distance-tooltip"}, ":[/color][/font] ", util.format_number(math.ceil(group.distance), true), "m"} |
| 22 | + for _, group in pairs(surface_data) do |
| 23 | + local entity_name = group.entity_name |
| 24 | + local distance_info = {""} |
| 25 | + if group.distance then |
| 26 | + distance_info = {"", "\n[font=default-semibold][color=255, 230, 192]", {"search-gui.distance-tooltip"}, ":[/color][/font] ", util.format_number(math.ceil(group.distance), true), "m"} |
| 27 | + end |
| 28 | + local extra_info = {""} |
| 29 | + if group.recipe_list then |
| 30 | + extra_info = {""} |
| 31 | + local multiple_recipes = false |
| 32 | + local number_of_recipes = 0 |
| 33 | + for _ in pairs(group.recipe_list) do number_of_recipes = number_of_recipes + 1 end |
| 34 | + |
| 35 | + if number_of_recipes > 1 then |
| 36 | + multiple_recipes = true |
27 | 37 | end |
28 | | - local extra_info = {""} |
29 | | - if group.recipe_list then |
30 | | - extra_info = {""} |
31 | | - local multiple_recipes = false |
32 | | - local number_of_recipes = 0 |
33 | | - for _ in pairs(group.recipe_list) do number_of_recipes = number_of_recipes + 1 end |
34 | | - |
35 | | - if number_of_recipes > 1 then |
36 | | - multiple_recipes = true |
37 | | - end |
38 | | - if number_of_recipes <= 10 then |
39 | | - -- Localised strings must not have more than 20 parameters |
40 | | - for name, recipe_info in pairs(group.recipe_list) do |
41 | | - local string = "\n" |
42 | | - if multiple_recipes then |
43 | | - string = string .. "[font=default-bold]" .. recipe_info.count .. " × [/font]" |
44 | | - end |
45 | | - string = string .. "[recipe=" .. name .. "] " |
46 | | - table.insert(extra_info, string) |
47 | | - table.insert(extra_info, recipe_info.localised_name) |
| 38 | + if number_of_recipes <= 10 then |
| 39 | + -- Localised strings must not have more than 20 parameters |
| 40 | + for name, recipe_info in pairs(group.recipe_list) do |
| 41 | + local string = "\n" |
| 42 | + if multiple_recipes then |
| 43 | + string = string .. "[font=default-bold]" .. recipe_info.count .. " × [/font]" |
48 | 44 | end |
| 45 | + string = string .. "[recipe=" .. name .. "] " |
| 46 | + table.insert(extra_info, string) |
| 47 | + table.insert(extra_info, recipe_info.localised_name) |
49 | 48 | end |
50 | 49 | end |
51 | | - if group.item_count then |
52 | | - extra_info = {"", "\n[font=default-semibold][color=255, 230, 192]", {"gui-train.add-item-count-condition"}, ":[/color][/font] ", util.format_number(math.floor(group.item_count), true)} |
53 | | - end |
54 | | - if group.fluid_count then |
55 | | - extra_info = {"", "\n[font=default-semibold][color=255, 230, 192]", {"gui-train.add-fluid-count-condition"}, ":[/color][/font] ", util.format_number(math.floor(group.fluid_count), true)} |
56 | | - end |
57 | | - if group.module_count then |
58 | | - extra_info = {"", "\n[font=default-semibold][color=255, 230, 192]", {"search-gui.module-count-tooltip"}, ":[/color][/font] ", util.format_number(math.floor(group.module_count), true)} |
59 | | - end |
60 | | - if group.request_count then |
61 | | - extra_info = {"", "\n[font=default-semibold][color=255, 230, 192]", {"search-gui.request-count-tooltip"}, ":[/color][/font] ", util.format_number(math.floor(group.request_count), true)} |
62 | | - end |
63 | | - if group.signal_count then |
64 | | - extra_info = {"", "\n[font=default-semibold][color=255, 230, 192]", {"search-gui.signal-count-tooltip"}, ":[/color][/font] ", util.format_number(math.floor(group.signal_count), true)} |
65 | | - end |
66 | | - local sprite = "entity/" .. entity_name |
| 50 | + end |
| 51 | + if group.item_count then |
| 52 | + extra_info = {"", "\n[font=default-semibold][color=255, 230, 192]", {"gui-train.add-item-count-condition"}, ":[/color][/font] ", util.format_number(math.floor(group.item_count), true)} |
| 53 | + end |
| 54 | + if group.fluid_count then |
| 55 | + extra_info = {"", "\n[font=default-semibold][color=255, 230, 192]", {"gui-train.add-fluid-count-condition"}, ":[/color][/font] ", util.format_number(math.floor(group.fluid_count), true)} |
| 56 | + end |
| 57 | + if group.module_count then |
| 58 | + extra_info = {"", "\n[font=default-semibold][color=255, 230, 192]", {"search-gui.module-count-tooltip"}, ":[/color][/font] ", util.format_number(math.floor(group.module_count), true)} |
| 59 | + end |
| 60 | + if group.request_count then |
| 61 | + extra_info = {"", "\n[font=default-semibold][color=255, 230, 192]", {"search-gui.request-count-tooltip"}, ":[/color][/font] ", util.format_number(math.floor(group.request_count), true)} |
| 62 | + end |
| 63 | + if group.signal_count then |
| 64 | + extra_info = {"", "\n[font=default-semibold][color=255, 230, 192]", {"search-gui.signal-count-tooltip"}, ":[/color][/font] ", util.format_number(math.floor(group.signal_count), true)} |
| 65 | + end |
| 66 | + local sprite = "entity/" .. entity_name |
| 67 | + if not helpers.is_valid_sprite_path(sprite) then |
| 68 | + sprite = "item/" .. entity_name |
67 | 69 | if not helpers.is_valid_sprite_path(sprite) then |
68 | | - sprite = "item/" .. entity_name |
| 70 | + sprite = "fluid/" .. entity_name |
69 | 71 | if not helpers.is_valid_sprite_path(sprite) then |
70 | | - sprite = "fluid/" .. entity_name |
| 72 | + sprite = "recipe/" .. entity_name |
71 | 73 | if not helpers.is_valid_sprite_path(sprite) then |
72 | | - sprite = "recipe/" .. entity_name |
| 74 | + sprite = "virtual-signal/" .. entity_name |
73 | 75 | if not helpers.is_valid_sprite_path(sprite) then |
74 | | - sprite = "virtual-signal/" .. entity_name |
75 | | - if not helpers.is_valid_sprite_path(sprite) then |
76 | | - sprite = "utility/questionmark" |
77 | | - end |
| 76 | + sprite = "utility/questionmark" |
78 | 77 | end |
79 | 78 | end |
80 | 79 | end |
81 | 80 | end |
82 | | - table.insert(gui_elements, |
83 | | - { |
84 | | - type = "sprite-button", |
85 | | - sprite = sprite, |
86 | | - tooltip = {"", "[font=default-bold]", group.localised_name, "[/font]", distance_info, extra_info, "\n", {"search-gui.result-tooltip"}}, |
87 | | - style = "slot_button", |
88 | | - number = group.resource_count or group.count, |
89 | | - tags = {position = group.avg_position, surface = surface_name, selection_boxes = group.selection_boxes}, |
90 | | - handler = {[defines.events.on_gui_click] = SearchGui.open_location_on_map} |
91 | | - } |
92 | | - ) |
93 | 81 | end |
| 82 | + table.insert(gui_elements, |
| 83 | + { |
| 84 | + type = "sprite-button", |
| 85 | + sprite = sprite, |
| 86 | + tooltip = {"", "[font=default-bold]", group.localised_name, "[/font]", distance_info, extra_info, "\n", {"search-gui.result-tooltip"}}, |
| 87 | + style = "slot_button", |
| 88 | + number = group.resource_count or group.count, |
| 89 | + tags = {position = group.avg_position, surface = surface_name, selection_boxes = group.selection_boxes}, |
| 90 | + handler = {[defines.events.on_gui_click] = SearchGui.open_location_on_map} |
| 91 | + } |
| 92 | + ) |
94 | 93 | end |
95 | 94 | return gui_elements |
96 | 95 | end |
@@ -223,14 +222,13 @@ function SearchGui.build_results(data, statistics, frame, check_result_found, in |
223 | 222 | local surface_contains_results = false |
224 | 223 | for _, category_data in pairs(surface_data) do |
225 | 224 | -- TODO surface_statistics check here? |
226 | | - surface_contains_results = surface_contains_results or not not next(category_data) |
| 225 | + surface_contains_results = surface_contains_results or table_size(category_data) > 0 |
227 | 226 | end |
228 | 227 | result_found = result_found or surface_contains_results |
229 | 228 | if not surface_contains_results then |
230 | 229 | goto continue |
231 | 230 | end |
232 | 231 |
|
233 | | - -- TODO sort somewhere before showing storage, modules, requesters, ... |
234 | 232 | gui.add(frame, { |
235 | 233 | SearchGui.build_surface_name(include_surface_name, surface_name), |
236 | 234 | SearchGui.build_surface_count(statistics[surface_name], include_surface_name), |
|
0 commit comments