mirror of
https://github.com/Xevion/project-cybersyn.git
synced 2025-12-07 16:08:10 -06:00
Merge branch 'make-gui-work' into gui-trains-tab
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -13,9 +13,7 @@ function inventory_tab.create()
|
||||
type = "tab",
|
||||
caption = { "cybersyn-gui.inventory" },
|
||||
ref = { "inventory", "tab" },
|
||||
actions = {
|
||||
on_click = { gui = "main", action = "change_tab", tab = "inventory" },
|
||||
},
|
||||
handler = inventory_tab.handle.on_inventory_tab_selected
|
||||
},
|
||||
content = {
|
||||
name = "manager_inventory_content_frame",
|
||||
@@ -243,4 +241,22 @@ function inventory_tab.build(map_data, player_data)
|
||||
|
||||
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
|
||||
|
||||
@@ -18,6 +18,7 @@ local manager = require("scripts.gui.manager")
|
||||
--- @field trains_orderings uint[]
|
||||
--- @field trains_orderings_invert boolean[]
|
||||
--- @field pinning boolean
|
||||
--- @field selected_tab string?
|
||||
|
||||
|
||||
|
||||
@@ -156,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
|
||||
|
||||
@@ -135,7 +135,8 @@ function manager.build(player_data)
|
||||
currently_selected_surface = surface_dropdown.get_item(currently_selected_index)
|
||||
end
|
||||
surface_dropdown.clear_items()
|
||||
i = 0
|
||||
surface_dropdown.add_item("all", 1)
|
||||
i = 1
|
||||
for name, _ in pairs(surfaces) do
|
||||
i = i + 1
|
||||
surface_dropdown.add_item(name, i)
|
||||
@@ -159,11 +160,17 @@ end
|
||||
|
||||
--- @param map_data MapData
|
||||
--- @param player_data PlayerData
|
||||
function manager.update(map_data, player_data)
|
||||
manager.build(player_data)
|
||||
stations_tab.build(map_data, player_data)
|
||||
inventory_tab.build(map_data, player_data)
|
||||
trains_tab.build(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, 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
|
||||
|
||||
|
||||
@@ -307,7 +314,8 @@ function manager.handle.manager_update_surface(player, player_data, refs, e)
|
||||
local i = element.selected_index
|
||||
local refs = player_data.refs
|
||||
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 = game.get_surface(surface_name)
|
||||
surface_id = surface.index
|
||||
|
||||
@@ -13,9 +13,7 @@ function stations_tab.create(widths)
|
||||
type = "tab",
|
||||
caption = { "cybersyn-gui.stations" },
|
||||
ref = { "stations", "tab" },
|
||||
actions = {
|
||||
on_click = { gui = "main", action = "change_tab", tab = "stations" },
|
||||
},
|
||||
handler = stations_tab.handle.on_stations_tab_selected
|
||||
},
|
||||
content = {
|
||||
name = "manager_stations_content_frame",
|
||||
@@ -59,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
|
||||
@@ -74,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
|
||||
@@ -137,6 +137,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
|
||||
|
||||
@@ -311,6 +315,12 @@ function stations_tab.handle.open_station_gui(player, player_data, refs, e)
|
||||
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)
|
||||
|
||||
return stations_tab
|
||||
|
||||
@@ -47,7 +47,7 @@ end
|
||||
--- @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 refs = player_data.refs
|
||||
|
||||
@@ -60,6 +60,8 @@ function trains_tab.build(map_data, player_data)
|
||||
local trains = map_data.trains
|
||||
|
||||
local trains_sorted = {}
|
||||
|
||||
local i = 0
|
||||
for id, train in pairs(trains) do
|
||||
if not train.entity.valid then
|
||||
goto continue
|
||||
@@ -115,6 +117,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
|
||||
|
||||
|
||||
@@ -99,6 +99,9 @@ function util.slot_table_build_from_station(station)
|
||||
if comb1_signals then
|
||||
for _, v in pairs(comb1_signals) do
|
||||
local item = v.signal
|
||||
if item.type == "virtual" then
|
||||
goto continue
|
||||
end
|
||||
local count = v.count
|
||||
local name = item.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
|
||||
::continue::
|
||||
end
|
||||
end
|
||||
return children
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user