diff --git a/cybersyn/scripts/gui/inventory.lua b/cybersyn/scripts/gui/inventory.lua index f80ca49..a335eeb 100644 --- a/cybersyn/scripts/gui/inventory.lua +++ b/cybersyn/scripts/gui/inventory.lua @@ -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 diff --git a/cybersyn/scripts/gui/main.lua b/cybersyn/scripts/gui/main.lua index 3f28d97..18893a0 100644 --- a/cybersyn/scripts/gui/main.lua +++ b/cybersyn/scripts/gui/main.lua @@ -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? diff --git a/cybersyn/scripts/gui/manager.lua b/cybersyn/scripts/gui/manager.lua index dafe4e3..d978792 100644 --- a/cybersyn/scripts/gui/manager.lua +++ b/cybersyn/scripts/gui/manager.lua @@ -134,7 +134,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,9 +160,14 @@ 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) + 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) + elseif player_data.selected_tab == "inventory_tab" then + inventory_tab.build(map_data, player_data) + end end @@ -305,7 +311,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 diff --git a/cybersyn/scripts/gui/stations.lua b/cybersyn/scripts/gui/stations.lua index abe61fc..da7065e 100644 --- a/cybersyn/scripts/gui/stations.lua +++ b/cybersyn/scripts/gui/stations.lua @@ -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", @@ -315,6 +313,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 diff --git a/cybersyn/scripts/gui/util.lua b/cybersyn/scripts/gui/util.lua index c7b7a6c..c1981f3 100644 --- a/cybersyn/scripts/gui/util.lua +++ b/cybersyn/scripts/gui/util.lua @@ -100,6 +100,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) @@ -126,6 +129,7 @@ function util.slot_table_build_from_station(station) } end end + ::continue:: end end return children