mirror of
https://github.com/Xevion/project-cybersyn.git
synced 2025-12-10 22:08:11 -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
|
*.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")
|
local manager = require("scripts.gui.manager")
|
||||||
|
|
||||||
--- @class Manager
|
--- @class Manager
|
||||||
--- @field players table<int, PlayerData>
|
--- @field players table<uint, PlayerData>
|
||||||
--- @field item_order table<string, int>
|
--- @field item_order table<string, int>
|
||||||
|
|
||||||
--- @class PlayerData
|
--- @class PlayerData
|
||||||
@@ -65,7 +65,7 @@ function manager_gui.on_player_created(e)
|
|||||||
}
|
}
|
||||||
global.manager.players[e.player_index] = player_data
|
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)
|
--top_left_button_update(player, player_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -92,6 +92,8 @@ function manager_gui.on_runtime_mod_setting_changed(e)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- @param manager Manager
|
--- @param manager Manager
|
||||||
local function init_items(manager)
|
local function init_items(manager)
|
||||||
local item_order = {}
|
local item_order = {}
|
||||||
@@ -135,4 +137,16 @@ function manager_gui.on_init()
|
|||||||
end
|
end
|
||||||
--gui.handle_events()
|
--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
|
return manager_gui
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ local stations_tab = {}
|
|||||||
function stations_tab.create(widths)
|
function stations_tab.create(widths)
|
||||||
return {
|
return {
|
||||||
tab = {
|
tab = {
|
||||||
|
name = "manager_stations_tab",
|
||||||
type = "tab",
|
type = "tab",
|
||||||
caption = { "gui.ltnm-stations" },
|
caption = { "gui.ltnm-stations" },
|
||||||
ref = { "stations", "tab" },
|
ref = { "stations", "tab" },
|
||||||
@@ -17,6 +18,7 @@ function stations_tab.create(widths)
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
content = {
|
content = {
|
||||||
|
name = "manager_stations_content_frame",
|
||||||
type = "frame",
|
type = "frame",
|
||||||
style = "ltnm_main_content_frame",
|
style = "ltnm_main_content_frame",
|
||||||
direction = "vertical",
|
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", "shipments", false, { "gui.ltnm-shipments-description" }),
|
||||||
templates.sort_checkbox(widths, "stations", "control_signals", false),
|
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",
|
type = "flow",
|
||||||
style = "ltnm_warning_flow",
|
style = "ltnm_warning_flow",
|
||||||
@@ -60,6 +62,7 @@ end
|
|||||||
function stations_tab.build(map_data, player_data)
|
function stations_tab.build(map_data, player_data)
|
||||||
|
|
||||||
local widths = constants.gui["en"]
|
local widths = constants.gui["en"]
|
||||||
|
local refs = player_data.refs
|
||||||
|
|
||||||
local search_item = player_data.search_item
|
local search_item = player_data.search_item
|
||||||
local search_network_name = player_data.search_network_name
|
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)
|
return (not player_data.trains_orderings_invert[#player_data.trains_orderings_invert]) == (a < b)
|
||||||
end)
|
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
|
for i, station_id in pairs(stations_sorted) do
|
||||||
local station = map_data.stations[station_id]
|
local station = map_data.stations[station_id]
|
||||||
|
|
||||||
local color = i % 2 == 0 and "dark" or "light"
|
local color = i % 2 == 0 and "dark" or "light"
|
||||||
local row = gui.add(scroll_pane, {
|
gui.add(scroll_pane, {
|
||||||
type = "frame",
|
type = "frame",
|
||||||
style = "ltnm_table_row_frame_" .. color,
|
style = "ltnm_table_row_frame_" .. color,
|
||||||
{
|
{
|
||||||
type = "label",
|
type = "label",
|
||||||
style = "ltnm_clickable_semibold_label",
|
style = "ltnm_clickable_semibold_label",
|
||||||
style_mods = { width = widths.name },
|
style_mods = { width = widths.stations.name },
|
||||||
tooltip = constants.open_station_gui_tooltip,
|
tooltip = constants.open_station_gui_tooltip,
|
||||||
|
caption = station.entity_stop.backer_name,
|
||||||
},
|
},
|
||||||
templates.status_indicator(widths.status, true),
|
--templates.status_indicator(widths.stations.status, true), --repurposing status column for network name
|
||||||
{ type = "label", style_mods = { width = widths.network_id, horizontal_align = "center" } },
|
{ type = "label", style_mods = { width = widths.stations.network_id, }, caption = station.network_name },
|
||||||
templates.small_slot_table(widths, color, "provided_requested"),
|
{ type = "label", style_mods = { width = widths.stations.network_id, horizontal_align = "center" }, caption = station.network_flag },
|
||||||
templates.small_slot_table(widths, color, "shipments"),
|
templates.small_slot_table(widths.stations, color, "provided_requested"),
|
||||||
templates.small_slot_table(widths, color, "control_signals"),
|
templates.small_slot_table(widths.stations, color, "shipments"),
|
||||||
})
|
templates.small_slot_table(widths.stations, color, "control_signals"),
|
||||||
|
}, refs)
|
||||||
|
|
||||||
gui.add(row, {
|
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)
|
||||||
elem_mods = { caption = station.entity_stop.name },
|
gui.add(refs.control_signals_table, util.slot_table_build_from_control_signals(station), refs)
|
||||||
handler = stations_tab.hande.open_station_gui,
|
|
||||||
tags = station_id,
|
|
||||||
},
|
|
||||||
{ elem_mods = { caption = station.network_name } },
|
|
||||||
{ elem_mods = { caption = station.network_flag } },
|
|
||||||
})
|
|
||||||
|
|
||||||
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
|
end
|
||||||
|
|
||||||
if #stations_sorted == 0 then
|
if #stations_sorted == 0 then
|
||||||
refs.warning_flow.visible = true
|
--refs.warning_flow.visible = true
|
||||||
scroll_pane.visible = false
|
scroll_pane.visible = false
|
||||||
refs.content_frame.style = "ltnm_main_warning_frame"
|
--refs.content_frame.style = "ltnm_main_warning_frame"
|
||||||
else
|
else
|
||||||
refs.warning_flow.visible = false
|
--refs.warning_flow.visible = false
|
||||||
scroll_pane.visible = true
|
scroll_pane.visible = true
|
||||||
refs.content_frame.style = "ltnm_main_content_frame"
|
--refs.content_frame.style = "ltnm_main_content_frame"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ end
|
|||||||
--- @param manifest Manifest
|
--- @param manifest Manifest
|
||||||
--- @param color string
|
--- @param color string
|
||||||
--- @return GuiElemDef[]
|
--- @return GuiElemDef[]
|
||||||
function util.slot_table_build(manifest, color)
|
function util.slot_table_build_from_manifest(manifest, color)
|
||||||
---@type GuiElemDef[]
|
---@type GuiElemDef[]
|
||||||
local children = {}
|
local children = {}
|
||||||
for _, item in pairs(manifest) do
|
for _, item in pairs(manifest) do
|
||||||
@@ -66,6 +66,127 @@ function util.slot_table_build(manifest, color)
|
|||||||
return children
|
return children
|
||||||
end
|
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)
|
function util.sorted_iterator(arr, src_tbl, sort_state)
|
||||||
local step = sort_state and 1 or -1
|
local step = sort_state and 1 or -1
|
||||||
local i = sort_state and 1 or #arr
|
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_removed, manager.on_player_removed)
|
||||||
script.on_event(defines.events.on_player_created, manager.on_player_created)
|
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_event(defines.events.on_lua_shortcut, manager.on_lua_shortcut)
|
||||||
|
script.on_nth_tick(60, function()
|
||||||
|
manager.tick(global)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user