mirror of
https://github.com/Xevion/project-cybersyn.git
synced 2025-12-09 10:08:15 -06:00
Stations tab mostly working (control signals need virtual signal sprite paths figured out)
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1,3 @@
|
||||
*.zip
|
||||
.vscode/launch.json
|
||||
.vscode/settings.json
|
||||
@@ -4,7 +4,7 @@ local mod_gui = require("__core__.lualib.mod-gui")
|
||||
local manager = require("scripts.gui.manager")
|
||||
|
||||
--- @class Manager
|
||||
--- @field players table<int, PlayerData>
|
||||
--- @field players table<uint, PlayerData>
|
||||
--- @field item_order table<string, int>
|
||||
|
||||
--- @class PlayerData
|
||||
@@ -65,7 +65,7 @@ function manager_gui.on_player_created(e)
|
||||
}
|
||||
global.manager.players[e.player_index] = player_data
|
||||
|
||||
manager.update(global, player, player_data)
|
||||
--manager.update(global, player, player_data)
|
||||
--top_left_button_update(player, player_data)
|
||||
end
|
||||
|
||||
@@ -92,6 +92,8 @@ function manager_gui.on_runtime_mod_setting_changed(e)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
--- @param manager Manager
|
||||
local function init_items(manager)
|
||||
local item_order = {}
|
||||
@@ -135,4 +137,16 @@ function manager_gui.on_init()
|
||||
end
|
||||
--gui.handle_events()
|
||||
|
||||
---@param global cybersyn.global
|
||||
function manager_gui.tick(global)
|
||||
local manager_data = global.manager
|
||||
if manager_data then
|
||||
for i, v in pairs(manager_data.players) do
|
||||
if v.is_manager_open then
|
||||
manager.update(global, v)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return manager_gui
|
||||
|
||||
@@ -9,6 +9,7 @@ local stations_tab = {}
|
||||
function stations_tab.create(widths)
|
||||
return {
|
||||
tab = {
|
||||
name = "manager_stations_tab",
|
||||
type = "tab",
|
||||
caption = { "gui.ltnm-stations" },
|
||||
ref = { "stations", "tab" },
|
||||
@@ -17,6 +18,7 @@ function stations_tab.create(widths)
|
||||
},
|
||||
},
|
||||
content = {
|
||||
name = "manager_stations_content_frame",
|
||||
type = "frame",
|
||||
style = "ltnm_main_content_frame",
|
||||
direction = "vertical",
|
||||
@@ -37,7 +39,7 @@ function stations_tab.create(widths)
|
||||
templates.sort_checkbox(widths, "stations", "shipments", false, { "gui.ltnm-shipments-description" }),
|
||||
templates.sort_checkbox(widths, "stations", "control_signals", false),
|
||||
},
|
||||
{ type = "scroll-pane", style = "ltnm_table_scroll_pane", ref = { "stations", "scroll_pane" } },
|
||||
{ name = "manager_stations_tab_scroll_pane", type = "scroll-pane", style = "ltnm_table_scroll_pane", ref = { "stations", "scroll_pane" } },
|
||||
{
|
||||
type = "flow",
|
||||
style = "ltnm_warning_flow",
|
||||
@@ -60,6 +62,7 @@ end
|
||||
function stations_tab.build(map_data, player_data)
|
||||
|
||||
local widths = constants.gui["en"]
|
||||
local refs = player_data.refs
|
||||
|
||||
local search_item = player_data.search_item
|
||||
local search_network_name = player_data.search_network_name
|
||||
@@ -182,65 +185,45 @@ function stations_tab.build(map_data, player_data)
|
||||
return (not player_data.trains_orderings_invert[#player_data.trains_orderings_invert]) == (a < b)
|
||||
end)
|
||||
|
||||
local scroll_pane = refs.scroll_pane
|
||||
local scroll_pane = refs.manager_stations_tab_scroll_pane
|
||||
|
||||
|
||||
for i, station_id in pairs(stations_sorted) do
|
||||
local station = map_data.stations[station_id]
|
||||
|
||||
local color = i % 2 == 0 and "dark" or "light"
|
||||
local row = gui.add(scroll_pane, {
|
||||
gui.add(scroll_pane, {
|
||||
type = "frame",
|
||||
style = "ltnm_table_row_frame_" .. color,
|
||||
{
|
||||
type = "label",
|
||||
style = "ltnm_clickable_semibold_label",
|
||||
style_mods = { width = widths.name },
|
||||
style_mods = { width = widths.stations.name },
|
||||
tooltip = constants.open_station_gui_tooltip,
|
||||
caption = station.entity_stop.backer_name,
|
||||
},
|
||||
templates.status_indicator(widths.status, true),
|
||||
{ type = "label", style_mods = { width = widths.network_id, horizontal_align = "center" } },
|
||||
templates.small_slot_table(widths, color, "provided_requested"),
|
||||
templates.small_slot_table(widths, color, "shipments"),
|
||||
templates.small_slot_table(widths, color, "control_signals"),
|
||||
})
|
||||
--templates.status_indicator(widths.stations.status, true), --repurposing status column for network name
|
||||
{ type = "label", style_mods = { width = widths.stations.network_id, }, caption = station.network_name },
|
||||
{ type = "label", style_mods = { width = widths.stations.network_id, horizontal_align = "center" }, caption = station.network_flag },
|
||||
templates.small_slot_table(widths.stations, color, "provided_requested"),
|
||||
templates.small_slot_table(widths.stations, color, "shipments"),
|
||||
templates.small_slot_table(widths.stations, color, "control_signals"),
|
||||
}, refs)
|
||||
|
||||
gui.add(row, {
|
||||
{
|
||||
elem_mods = { caption = station.entity_stop.name },
|
||||
handler = stations_tab.hande.open_station_gui,
|
||||
tags = station_id,
|
||||
},
|
||||
{ elem_mods = { caption = station.network_name } },
|
||||
{ elem_mods = { caption = station.network_flag } },
|
||||
})
|
||||
gui.add(refs.provided_requested_table, util.slot_table_build_from_station(station), refs)
|
||||
gui.add(refs.shipments_table, util.slot_table_build_from_deliveries(station), refs)
|
||||
gui.add(refs.control_signals_table, util.slot_table_build_from_control_signals(station), refs)
|
||||
|
||||
util.slot_table_update(row.provided_requested_frame.provided_requested_table, {
|
||||
{ color = "green", entries = station.provided, translations = dictionaries.materials },
|
||||
{ color = "red", entries = station.requested, translations = dictionaries.materials },
|
||||
})
|
||||
util.slot_table_update(row.shipments_frame.shipments_table, {
|
||||
{ color = "green", entries = station.inbound, translations = dictionaries.materials },
|
||||
{ color = "blue", entries = station.outbound, translations = dictionaries.materials },
|
||||
})
|
||||
util.slot_table_update(row.control_signals_frame.control_signals_table, {
|
||||
{
|
||||
color = "default",
|
||||
entries = station.control_signals,
|
||||
translations = dictionaries.virtual_signals,
|
||||
type = "virtual-signal",
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
if #stations_sorted == 0 then
|
||||
refs.warning_flow.visible = true
|
||||
--refs.warning_flow.visible = true
|
||||
scroll_pane.visible = false
|
||||
refs.content_frame.style = "ltnm_main_warning_frame"
|
||||
--refs.content_frame.style = "ltnm_main_warning_frame"
|
||||
else
|
||||
refs.warning_flow.visible = false
|
||||
--refs.warning_flow.visible = false
|
||||
scroll_pane.visible = true
|
||||
refs.content_frame.style = "ltnm_main_content_frame"
|
||||
--refs.content_frame.style = "ltnm_main_content_frame"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ end
|
||||
--- @param manifest Manifest
|
||||
--- @param color string
|
||||
--- @return GuiElemDef[]
|
||||
function util.slot_table_build(manifest, color)
|
||||
function util.slot_table_build_from_manifest(manifest, color)
|
||||
---@type GuiElemDef[]
|
||||
local children = {}
|
||||
for _, item in pairs(manifest) do
|
||||
@@ -66,6 +66,127 @@ function util.slot_table_build(manifest, color)
|
||||
return children
|
||||
end
|
||||
|
||||
--- @param station Station
|
||||
--- @param color string
|
||||
--- @return GuiElemDef[]
|
||||
function util.slot_table_build_from_station(station)
|
||||
---@type GuiElemDef[]
|
||||
local children = {}
|
||||
local comb1_signals, comb2_signals = get_signals(station)
|
||||
if comb1_signals then
|
||||
for _, v in pairs(comb1_signals) do
|
||||
local item = v.signal
|
||||
local count = v.count
|
||||
local name = item.name
|
||||
local sprite
|
||||
local color
|
||||
if count > 0 then
|
||||
color = "green"
|
||||
else
|
||||
color = "red"
|
||||
end
|
||||
if item.type then
|
||||
sprite = item.type .. "/" .. name
|
||||
else
|
||||
if name then
|
||||
sprite = string.gsub(name, ",", "/")
|
||||
else
|
||||
--idunno?
|
||||
end
|
||||
end
|
||||
if game.is_valid_sprite_path(sprite) then
|
||||
children[#children + 1] = {
|
||||
type = "sprite-button",
|
||||
enabled = false,
|
||||
style = "ltnm_small_slot_button_" .. color,
|
||||
sprite = sprite,
|
||||
tooltip = {
|
||||
"",
|
||||
"[img=" .. sprite .. "]",
|
||||
{ "item-name." .. name },
|
||||
"\n"..format.number(count),
|
||||
},
|
||||
number = count
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
return children
|
||||
end
|
||||
|
||||
function util.slot_table_build_from_deliveries(station)
|
||||
---@type GuiElemDef[]
|
||||
local children = {}
|
||||
local deliveries = station.deliveries
|
||||
local sprite = ""
|
||||
for item, count in pairs(deliveries) do
|
||||
local color
|
||||
if count > 0 then
|
||||
color = "green"
|
||||
else
|
||||
color = "blue"
|
||||
end
|
||||
if game.is_valid_sprite_path("item/" .. item) then
|
||||
sprite = "item/" .. item
|
||||
elseif game.is_valid_sprite_path("fluid/" .. item) then
|
||||
sprite = "fluid/" .. item
|
||||
end
|
||||
if game.is_valid_sprite_path(sprite) then
|
||||
children[#children + 1] = {
|
||||
type = "sprite-button",
|
||||
enabled = false,
|
||||
style = "ltnm_small_slot_button_" .. color,
|
||||
sprite = sprite,
|
||||
tooltip = {
|
||||
"",
|
||||
"[img=" .. sprite .. "]",
|
||||
{ item },
|
||||
"\n"..format.number(count),
|
||||
},
|
||||
number = count
|
||||
}
|
||||
end
|
||||
end
|
||||
return children
|
||||
end
|
||||
|
||||
--- @param station Station
|
||||
--- @return GuiElemDef[]
|
||||
function util.slot_table_build_from_control_signals(station)
|
||||
---@type GuiElemDef[]
|
||||
local children = {}
|
||||
local comb1_signals, comb2_signals = get_signals(station)
|
||||
if comb1_signals then
|
||||
for _, v in pairs(comb1_signals) do
|
||||
local item = v.signal
|
||||
local count = v.count
|
||||
local name = item.name
|
||||
local sprite = ""
|
||||
local color = "default"
|
||||
if item.type == "virtual" then
|
||||
-- don't know how to get the sprite path for signals like cybersyn-priority, so this fizzles
|
||||
sprite = item.type .. "/" .. name
|
||||
end
|
||||
if game.is_valid_sprite_path(sprite) then
|
||||
children[#children + 1] = {
|
||||
type = "sprite-button",
|
||||
enabled = false,
|
||||
style = "ltnm_small_slot_button_" .. color,
|
||||
sprite = sprite,
|
||||
tooltip = {
|
||||
"",
|
||||
"[img=" .. sprite .. "]",
|
||||
{ "item-name." .. name },
|
||||
"\n"..format.number(count),
|
||||
},
|
||||
number = count
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
return children
|
||||
end
|
||||
|
||||
function util.sorted_iterator(arr, src_tbl, sort_state)
|
||||
local step = sort_state and 1 or -1
|
||||
local i = sort_state and 1 or #arr
|
||||
|
||||
@@ -933,6 +933,9 @@ local function main()
|
||||
script.on_event(defines.events.on_player_removed, manager.on_player_removed)
|
||||
script.on_event(defines.events.on_player_created, manager.on_player_created)
|
||||
script.on_event(defines.events.on_lua_shortcut, manager.on_lua_shortcut)
|
||||
script.on_nth_tick(60, function()
|
||||
manager.tick(global)
|
||||
end)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user