From 458ef89f585cbf78f9f3a9fdc8e94ef3b68d04f3 Mon Sep 17 00:00:00 2001 From: Will Berry <73126355+wdberry@users.noreply.github.com> Date: Fri, 10 Mar 2023 12:39:39 -0500 Subject: [PATCH] Add query limit per-player setting to limit results in Stations/Trains GUI tabs --- cybersyn/locale/en/base.cfg | 3 ++- cybersyn/scripts/gui/main.lua | 3 ++- cybersyn/scripts/gui/manager.lua | 4 ++-- cybersyn/scripts/gui/stations.lua | 8 +++++++- cybersyn/scripts/gui/trains.lua | 8 +++++++- cybersyn/settings.lua | 9 +++++++++ 6 files changed, 29 insertions(+), 6 deletions(-) diff --git a/cybersyn/locale/en/base.cfg b/cybersyn/locale/en/base.cfg index ab182b1..42d7217 100644 --- a/cybersyn/locale/en/base.cfg +++ b/cybersyn/locale/en/base.cfg @@ -14,6 +14,7 @@ cybersyn-allow-cargo-in-depot=Allow cargo in depots cybersyn-invert-sign=Invert combinator output (deprecated) cybersyn-manager-enabled=Enable the Cybersyn GUI. cybersyn-manager-update-rate=Manager refresh tick interval +cybersyn-manager-result-limit=Max entities displayed on GUI pages. [mod-setting-description] cybersyn-enable-planner=Enable or disable the central planning algorithm. If disabled no new trains will be dispatched. @@ -29,7 +30,7 @@ cybersyn-warmup-time=How many seconds a cybernetic combinator will wait before c cybersyn-stuck-train-time=After this many seconds from a train's dispatch, an alert will be sent to let you know a train is probably stuck and has not completed its delivery. The player will likely have to debug their network to get the train unstuck. cybersyn-allow-cargo-in-depot=If checked, trains will be allowed to have cargo in depots; no alerts will be generated and the train will not be held. In addition, trains with orders to visit requester stations with "Inactivity condition" checked will wait for inactivity instead of waiting for empty cargo. Useful for creating train systems where depots handle excess cargo. For advanced users only. cybersyn-invert-sign=Flip the sign of the output of cybernetic combinators to be the same as it is in LTN or in earlier versions of Project Cybersyn. - +cybersyn-manager-result-limit=Caps the number of matching enitities (e.g. stations, trains) to limit the amount of update time consumed when the list is refreshed.\n-1 means return all results. [item-name] cybersyn-combinator=Cybernetic combinator diff --git a/cybersyn/scripts/gui/main.lua b/cybersyn/scripts/gui/main.lua index 18893a0..8c8cd4a 100644 --- a/cybersyn/scripts/gui/main.lua +++ b/cybersyn/scripts/gui/main.lua @@ -157,7 +157,8 @@ function manager_gui.tick(global) if manager_data then for i, v in pairs(manager_data.players) do if v.is_manager_open then - manager.update(global, v) + local query_limit = settings.get_player_settings(i)["cybersyn-manager-result-limit"].value + manager.update(global, v, query_limit) end end end diff --git a/cybersyn/scripts/gui/manager.lua b/cybersyn/scripts/gui/manager.lua index d978792..bea70d6 100644 --- a/cybersyn/scripts/gui/manager.lua +++ b/cybersyn/scripts/gui/manager.lua @@ -159,12 +159,12 @@ end --- @param map_data MapData --- @param player_data PlayerData -function manager.update(map_data, player_data) +function manager.update(map_data, player_data, query_limit) if player_data.selected_tab ~= nil then manager.build(player_data) end if player_data.selected_tab == "stations_tab" then - stations_tab.build(map_data, player_data) + stations_tab.build(map_data, player_data, query_limit) elseif player_data.selected_tab == "inventory_tab" then inventory_tab.build(map_data, player_data) end diff --git a/cybersyn/scripts/gui/stations.lua b/cybersyn/scripts/gui/stations.lua index da7065e..f8b1106 100644 --- a/cybersyn/scripts/gui/stations.lua +++ b/cybersyn/scripts/gui/stations.lua @@ -57,7 +57,7 @@ end --- @param map_data MapData --- @param player_data PlayerData --- @return GuiElemDef -function stations_tab.build(map_data, player_data) +function stations_tab.build(map_data, player_data, query_limit) local widths = constants.gui["en"] local refs = player_data.refs @@ -72,6 +72,8 @@ function stations_tab.build(map_data, player_data) local stations_sorted = {} local to_sorted_manifest = {} + + local i = 0 for id, station in pairs(stations) do local entity = station.entity_stop if not entity.valid then @@ -139,6 +141,10 @@ function stations_tab.build(map_data, player_data) end stations_sorted[#stations_sorted + 1] = id + i = i + 1 + if query_limit ~= -1 and i >= query_limit then + break + end ::continue:: end diff --git a/cybersyn/scripts/gui/trains.lua b/cybersyn/scripts/gui/trains.lua index 91498b6..7c3057c 100644 --- a/cybersyn/scripts/gui/trains.lua +++ b/cybersyn/scripts/gui/trains.lua @@ -12,7 +12,7 @@ local trains_tab = {} --- @param map_data MapData --- @param player_data PlayerData --- @return GuiElemDef -function trains_tab.build(map_data, player_data) +function trains_tab.build(map_data, player_data, query_limit) local widths = constants.gui["en"] local search_item = player_data.search_item @@ -22,6 +22,8 @@ function trains_tab.build(map_data, player_data) local trains_sorted = {} + + local i = 0 for id, train in pairs(map_data.trains) do if search_network_name then if search_network_name ~= train.network_name then @@ -70,6 +72,10 @@ function trains_tab.build(map_data, player_data) end trains_sorted[#trains_sorted + 1] = id + i = i + 1 + if query_limit ~= -1 and i >= query_limit then + break + end ::continue:: end diff --git a/cybersyn/settings.lua b/cybersyn/settings.lua index b5494e4..56522c0 100644 --- a/cybersyn/settings.lua +++ b/cybersyn/settings.lua @@ -118,6 +118,15 @@ data:extend({ setting_type = "startup", default_value = true, }, + { + type = "int-setting", + name = "cybersyn-manager-result-limit", + order = "aa", + setting_type = "runtime-per-user", + default_value = -1, + minimum_value = -1, + maximum_value = 2147483647, + } --{ -- type = "bool-setting", -- name = "cybersyn-disable-top-left-button",