mirror of
https://github.com/Xevion/project-cybersyn.git
synced 2025-12-10 08:08:14 -06:00
MVP Stations and Inventory tabs
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
local gui = require("__flib__.gui-lite")
|
local gui = require("__flib__.gui-lite")
|
||||||
|
|
||||||
|
local util = require("scripts.gui.util")
|
||||||
local templates = require("scripts.gui.templates")
|
local templates = require("scripts.gui.templates")
|
||||||
local misc = require("__flib__.misc")
|
local misc = require("__flib__.misc")
|
||||||
|
|
||||||
@@ -46,6 +47,8 @@ function inventory_tab.build(map_data, player_data)
|
|||||||
|
|
||||||
local stations_sorted = {}
|
local stations_sorted = {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for id, station in pairs(map_data.stations) do
|
for id, station in pairs(map_data.stations) do
|
||||||
local entity = station.entity_stop
|
local entity = station.entity_stop
|
||||||
if not entity.valid then
|
if not entity.valid then
|
||||||
@@ -131,6 +134,7 @@ function inventory_tab.build(map_data, player_data)
|
|||||||
if count > 0 then
|
if count > 0 then
|
||||||
if inventory_in_transit[item] == nil then
|
if inventory_in_transit[item] == nil then
|
||||||
inventory_in_transit[item] = 0
|
inventory_in_transit[item] = 0
|
||||||
|
inventory_in_transit[item] = inventory_in_transit[item] + count
|
||||||
else
|
else
|
||||||
inventory_in_transit[item] = inventory_in_transit[item] + count
|
inventory_in_transit[item] = inventory_in_transit[item] + count
|
||||||
end
|
end
|
||||||
@@ -139,17 +143,13 @@ function inventory_tab.build(map_data, player_data)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local inventory_provided_table = refs.inventory_provided_table
|
||||||
local provided_children = {}
|
local provided_children = {}
|
||||||
|
|
||||||
local i = 0
|
local i = 0
|
||||||
for item, count in pairs(inventory_provided) do
|
for item, count in pairs(inventory_provided) do
|
||||||
i = i + 1
|
i = i + 1
|
||||||
local sprite = ""
|
local sprite = util.build_sprite_path(item)
|
||||||
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
|
if game.is_valid_sprite_path(sprite) then
|
||||||
provided_children[#provided_children+1] = {
|
provided_children[#provided_children+1] = {
|
||||||
type = "sprite-button",
|
type = "sprite-button",
|
||||||
@@ -162,22 +162,17 @@ function inventory_tab.build(map_data, player_data)
|
|||||||
.. "] [font=default-semibold]"
|
.. "] [font=default-semibold]"
|
||||||
.. item
|
.. item
|
||||||
.. "[/font]\n"
|
.. "[/font]\n"
|
||||||
.. misc.delineate_number(count)
|
.. misc.delineate_number(count)}
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local inventory_requested_table = refs.inventory_requested_table
|
||||||
local requested_children = {}
|
local requested_children = {}
|
||||||
|
|
||||||
local i = 0
|
local i = 0
|
||||||
for item, count in pairs(inventory_requested) do
|
for item, count in pairs(inventory_requested) do
|
||||||
i = i + 1
|
i = i + 1
|
||||||
local sprite = ""
|
local sprite = util.build_sprite_path(item)
|
||||||
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
|
if game.is_valid_sprite_path(sprite) then
|
||||||
requested_children[#requested_children+1] = {
|
requested_children[#requested_children+1] = {
|
||||||
type = "sprite-button",
|
type = "sprite-button",
|
||||||
@@ -190,22 +185,17 @@ function inventory_tab.build(map_data, player_data)
|
|||||||
.. "] [font=default-semibold]"
|
.. "] [font=default-semibold]"
|
||||||
.. item
|
.. item
|
||||||
.. "[/font]\n"
|
.. "[/font]\n"
|
||||||
.. misc.delineate_number(count)
|
.. misc.delineate_number(count)}
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local inventory_in_transit_table = refs.inventory_in_transit_table
|
||||||
local in_transit_children = {}
|
local in_transit_children = {}
|
||||||
|
|
||||||
local i = 0
|
local i = 0
|
||||||
for item, count in pairs(inventory_in_transit) do
|
for item, count in pairs(inventory_in_transit) do
|
||||||
i = i + 1
|
i = i + 1
|
||||||
local sprite = ""
|
local sprite = util.build_sprite_path(item)
|
||||||
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
|
if game.is_valid_sprite_path(sprite) then
|
||||||
in_transit_children[#in_transit_children+1] = {
|
in_transit_children[#in_transit_children+1] = {
|
||||||
type = "sprite-button",
|
type = "sprite-button",
|
||||||
@@ -218,11 +208,19 @@ function inventory_tab.build(map_data, player_data)
|
|||||||
.. "] [font=default-semibold]"
|
.. "] [font=default-semibold]"
|
||||||
.. item
|
.. item
|
||||||
.. "[/font]\n"
|
.. "[/font]\n"
|
||||||
.. misc.delineate_number(count)
|
.. misc.delineate_number(count)}
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if next(inventory_provided_table.children) ~= nil then
|
||||||
|
refs.inventory_provided_table.clear()
|
||||||
|
end
|
||||||
|
if next(inventory_requested_table.children) ~= nil then
|
||||||
|
refs.inventory_requested_table.clear()
|
||||||
|
end
|
||||||
|
if next(inventory_in_transit_table.children) ~=nil then
|
||||||
|
refs.inventory_in_transit_table.clear()
|
||||||
|
end
|
||||||
gui.add(refs.inventory_provided_table, provided_children)
|
gui.add(refs.inventory_provided_table, provided_children)
|
||||||
gui.add(refs.inventory_requested_table, requested_children)
|
gui.add(refs.inventory_requested_table, requested_children)
|
||||||
gui.add(refs.inventory_in_transit_table, in_transit_children)
|
gui.add(refs.inventory_in_transit_table, in_transit_children)
|
||||||
|
|||||||
@@ -186,7 +186,9 @@ function stations_tab.build(map_data, player_data)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
local scroll_pane = refs.manager_stations_tab_scroll_pane
|
local scroll_pane = refs.manager_stations_tab_scroll_pane
|
||||||
|
if next(scroll_pane.children) ~= nil then
|
||||||
|
refs.manager_stations_tab_scroll_pane.clear()
|
||||||
|
end
|
||||||
|
|
||||||
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]
|
||||||
@@ -203,16 +205,16 @@ function stations_tab.build(map_data, player_data)
|
|||||||
caption = station.entity_stop.backer_name,
|
caption = station.entity_stop.backer_name,
|
||||||
},
|
},
|
||||||
--templates.status_indicator(widths.stations.status, true), --repurposing status column for network name
|
--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 = "sprite-button", style = "ltnm_small_slot_button_default", enabled = false, sprite = "virtual-signal/" .. station.network_name, },
|
||||||
{ type = "label", style_mods = { width = widths.stations.network_id, horizontal_align = "center" }, caption = station.network_flag },
|
{ 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, "provided_requested"),
|
||||||
templates.small_slot_table(widths.stations, color, "shipments"),
|
templates.small_slot_table(widths.stations, color, "shipments"),
|
||||||
templates.small_slot_table(widths.stations, color, "control_signals"),
|
templates.small_slot_table(widths.stations, color, "control_signals"),
|
||||||
}, refs)
|
}, refs)
|
||||||
|
|
||||||
gui.add(refs.provided_requested_table, util.slot_table_build_from_station(station), refs)
|
gui.add(refs.provided_requested_table, util.slot_table_build_from_station(station))
|
||||||
gui.add(refs.shipments_table, util.slot_table_build_from_deliveries(station), refs)
|
gui.add(refs.shipments_table, util.slot_table_build_from_deliveries(station))
|
||||||
gui.add(refs.control_signals_table, util.slot_table_build_from_control_signals(station), refs)
|
gui.add(refs.control_signals_table, util.slot_table_build_from_control_signals(station))
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,20 @@ function util.gui_list(parent, iterator, test, build, update, ...)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Builds a valid sprite path or returns nil
|
||||||
|
--- @param item string
|
||||||
|
--- @return string
|
||||||
|
function util.build_sprite_path(item)
|
||||||
|
local sprite = nil
|
||||||
|
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
|
||||||
|
return sprite
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Updates a slot table based on the passed criteria.
|
--- Updates a slot table based on the passed criteria.
|
||||||
--- @param manifest Manifest
|
--- @param manifest Manifest
|
||||||
--- @param color string
|
--- @param color string
|
||||||
@@ -163,9 +177,11 @@ function util.slot_table_build_from_control_signals(station)
|
|||||||
local name = item.name
|
local name = item.name
|
||||||
local sprite = ""
|
local sprite = ""
|
||||||
local color = "default"
|
local color = "default"
|
||||||
if item.type == "virtual" then
|
if item.type ~= "virtual" then
|
||||||
|
goto continue
|
||||||
|
else
|
||||||
-- don't know how to get the sprite path for signals like cybersyn-priority, so this fizzles
|
-- don't know how to get the sprite path for signals like cybersyn-priority, so this fizzles
|
||||||
sprite = item.type .. "/" .. name
|
sprite = "virtual-signal" .. "/" .. name
|
||||||
end
|
end
|
||||||
if game.is_valid_sprite_path(sprite) then
|
if game.is_valid_sprite_path(sprite) then
|
||||||
children[#children + 1] = {
|
children[#children + 1] = {
|
||||||
@@ -182,6 +198,7 @@ function util.slot_table_build_from_control_signals(station)
|
|||||||
number = count
|
number = count
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
::continue::
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return children
|
return children
|
||||||
|
|||||||
Reference in New Issue
Block a user