Merge branch 'make-gui-work' into gui-trains-tab

This commit is contained in:
Will Berry
2023-03-10 12:42:44 -05:00
8 changed files with 73 additions and 17 deletions

View File

@@ -14,6 +14,7 @@ cybersyn-allow-cargo-in-depot=Allow cargo in depots
cybersyn-invert-sign=Invert combinator output (deprecated) cybersyn-invert-sign=Invert combinator output (deprecated)
cybersyn-manager-enabled=Enable the Cybersyn GUI. cybersyn-manager-enabled=Enable the Cybersyn GUI.
cybersyn-manager-update-rate=Manager refresh tick interval cybersyn-manager-update-rate=Manager refresh tick interval
cybersyn-manager-result-limit=Max entities displayed on GUI pages.
[mod-setting-description] [mod-setting-description]
cybersyn-enable-planner=Enable or disable the central planning algorithm. If disabled no new trains will be dispatched. 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-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-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-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] [item-name]
cybersyn-combinator=Cybernetic combinator cybersyn-combinator=Cybernetic combinator

View File

@@ -13,9 +13,7 @@ function inventory_tab.create()
type = "tab", type = "tab",
caption = { "cybersyn-gui.inventory" }, caption = { "cybersyn-gui.inventory" },
ref = { "inventory", "tab" }, ref = { "inventory", "tab" },
actions = { handler = inventory_tab.handle.on_inventory_tab_selected
on_click = { gui = "main", action = "change_tab", tab = "inventory" },
},
}, },
content = { content = {
name = "manager_inventory_content_frame", name = "manager_inventory_content_frame",
@@ -243,4 +241,22 @@ function inventory_tab.build(map_data, player_data)
end end
inventory_tab.handle = {}
--- @param e {player_index: uint}
function inventory_tab.wrapper(e, handler)
local player = game.get_player(e.player_index)
if not player then return end
local player_data = global.manager.players[e.player_index]
handler(player, player_data, player_data.refs, e)
end
---@param player LuaPlayer
---@param player_data PlayerData
function inventory_tab.handle.on_inventory_tab_selected(player, player_data)
player_data.selected_tab = "inventory_tab"
end
gui.add_handlers(inventory_tab.handle, inventory_tab.wrapper)
return inventory_tab return inventory_tab

View File

@@ -18,6 +18,7 @@ local manager = require("scripts.gui.manager")
--- @field trains_orderings uint[] --- @field trains_orderings uint[]
--- @field trains_orderings_invert boolean[] --- @field trains_orderings_invert boolean[]
--- @field pinning boolean --- @field pinning boolean
--- @field selected_tab string?
@@ -156,7 +157,8 @@ function manager_gui.tick(global)
if manager_data then if manager_data then
for i, v in pairs(manager_data.players) do for i, v in pairs(manager_data.players) do
if v.is_manager_open then 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 end
end end

View File

@@ -135,7 +135,8 @@ function manager.build(player_data)
currently_selected_surface = surface_dropdown.get_item(currently_selected_index) currently_selected_surface = surface_dropdown.get_item(currently_selected_index)
end end
surface_dropdown.clear_items() surface_dropdown.clear_items()
i = 0 surface_dropdown.add_item("all", 1)
i = 1
for name, _ in pairs(surfaces) do for name, _ in pairs(surfaces) do
i = i + 1 i = i + 1
surface_dropdown.add_item(name, i) surface_dropdown.add_item(name, i)
@@ -159,11 +160,17 @@ end
--- @param map_data MapData --- @param map_data MapData
--- @param player_data PlayerData --- @param player_data PlayerData
function manager.update(map_data, player_data) function manager.update(map_data, player_data, query_limit)
manager.build(player_data) if player_data.selected_tab ~= nil then
stations_tab.build(map_data, player_data) manager.build(player_data)
inventory_tab.build(map_data, player_data) end
trains_tab.build(map_data,player_data) if player_data.selected_tab == "stations_tab" then
stations_tab.build(map_data, player_data, query_limit)
elseif player_data.selected_tab == "inventory_tab" then
inventory_tab.build(map_data, player_data)
elseif player_data.selected_tab == "trains_tab" then
trains_tab.build(map_data, player_data, query_limit)
end
end end
@@ -307,7 +314,8 @@ function manager.handle.manager_update_surface(player, player_data, refs, e)
local i = element.selected_index local i = element.selected_index
local refs = player_data.refs local refs = player_data.refs
local surface_id = -1 local surface_id = -1
if i > 0 then --all surfaces should always be the first entry with an index of 1
if i > 1 then
local surface_name = refs.manager_surface_dropdown.get_item(i) local surface_name = refs.manager_surface_dropdown.get_item(i)
local surface = game.get_surface(surface_name) local surface = game.get_surface(surface_name)
surface_id = surface.index surface_id = surface.index

View File

@@ -13,9 +13,7 @@ function stations_tab.create(widths)
type = "tab", type = "tab",
caption = { "cybersyn-gui.stations" }, caption = { "cybersyn-gui.stations" },
ref = { "stations", "tab" }, ref = { "stations", "tab" },
actions = { handler = stations_tab.handle.on_stations_tab_selected
on_click = { gui = "main", action = "change_tab", tab = "stations" },
},
}, },
content = { content = {
name = "manager_stations_content_frame", name = "manager_stations_content_frame",
@@ -59,7 +57,7 @@ end
--- @param map_data MapData --- @param map_data MapData
--- @param player_data PlayerData --- @param player_data PlayerData
--- @return GuiElemDef --- @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 widths = constants.gui["en"]
local refs = player_data.refs local refs = player_data.refs
@@ -74,6 +72,8 @@ function stations_tab.build(map_data, player_data)
local stations_sorted = {} local stations_sorted = {}
local to_sorted_manifest = {} local to_sorted_manifest = {}
local i = 0
for id, station in pairs(stations) do for id, station in pairs(stations) do
local entity = station.entity_stop local entity = station.entity_stop
if not entity.valid then if not entity.valid then
@@ -137,6 +137,10 @@ function stations_tab.build(map_data, player_data)
end end
stations_sorted[#stations_sorted + 1] = id stations_sorted[#stations_sorted + 1] = id
i = i + 1
if query_limit ~= -1 and i >= query_limit then
break
end
::continue:: ::continue::
end end
@@ -311,6 +315,12 @@ function stations_tab.handle.open_station_gui(player, player_data, refs, e)
end end
end end
---@param player LuaPlayer
---@param player_data PlayerData
function stations_tab.handle.on_stations_tab_selected(player, player_data)
player_data.selected_tab = "stations_tab"
end
gui.add_handlers(stations_tab.handle, stations_tab.wrapper) gui.add_handlers(stations_tab.handle, stations_tab.wrapper)
return stations_tab return stations_tab

View File

@@ -47,7 +47,7 @@ end
--- @param map_data MapData --- @param map_data MapData
--- @param player_data PlayerData --- @param player_data PlayerData
--- @return GuiElemDef --- @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 widths = constants.gui["en"]
local refs = player_data.refs local refs = player_data.refs
@@ -60,6 +60,8 @@ function trains_tab.build(map_data, player_data)
local trains = map_data.trains local trains = map_data.trains
local trains_sorted = {} local trains_sorted = {}
local i = 0
for id, train in pairs(trains) do for id, train in pairs(trains) do
if not train.entity.valid then if not train.entity.valid then
goto continue goto continue
@@ -115,6 +117,10 @@ function trains_tab.build(map_data, player_data)
end end
trains_sorted[#trains_sorted + 1] = id trains_sorted[#trains_sorted + 1] = id
i = i + 1
if query_limit ~= -1 and i >= query_limit then
break
end
::continue:: ::continue::
end end

View File

@@ -99,6 +99,9 @@ function util.slot_table_build_from_station(station)
if comb1_signals then if comb1_signals then
for _, v in pairs(comb1_signals) do for _, v in pairs(comb1_signals) do
local item = v.signal local item = v.signal
if item.type == "virtual" then
goto continue
end
local count = v.count local count = v.count
local name = item.name local name = item.name
local sprite, img_path, item_string = util.generate_item_references(name) local sprite, img_path, item_string = util.generate_item_references(name)
@@ -125,6 +128,7 @@ function util.slot_table_build_from_station(station)
} }
end end
end end
::continue::
end end
end end
return children return children

View File

@@ -118,6 +118,15 @@ data:extend({
setting_type = "startup", setting_type = "startup",
default_value = true, 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", -- type = "bool-setting",
-- name = "cybersyn-disable-top-left-button", -- name = "cybersyn-disable-top-left-button",