mirror of
https://github.com/Xevion/project-cybersyn.git
synced 2025-12-08 16:08:07 -06:00
Add mod setting, add click handlers for station tab
This commit is contained in:
@@ -70,10 +70,11 @@ function stations_tab.build(map_data, player_data)
|
||||
local search_network_mask = player_data.search_network_mask
|
||||
local search_surface_idx = player_data.search_surface_idx
|
||||
|
||||
local stations = map_data.stations
|
||||
|
||||
local stations_sorted = {}
|
||||
local to_sorted_manifest = {}
|
||||
for id, station in pairs(map_data.stations) do
|
||||
for id, station in pairs(stations) do
|
||||
local entity = station.entity_stop
|
||||
if not entity.valid then
|
||||
goto continue
|
||||
@@ -210,10 +211,11 @@ function stations_tab.build(map_data, player_data)
|
||||
end
|
||||
|
||||
for i, station_id in pairs(stations_sorted) do
|
||||
local station = map_data.stations[station_id]
|
||||
--- @type Station
|
||||
local station = stations[station_id]
|
||||
local network_name = "signal-everything"
|
||||
local network_flag = -1
|
||||
if station.search_network_name ~= nil then
|
||||
if station.network_name ~= nil then
|
||||
network_name = station.network_name
|
||||
end
|
||||
if station.network_flag ~= nil then
|
||||
@@ -223,13 +225,14 @@ function stations_tab.build(map_data, player_data)
|
||||
local color = i % 2 == 0 and "dark" or "light"
|
||||
gui.add(scroll_pane, {
|
||||
type = "frame",
|
||||
style = "ltnm_table_row_frame_" .. color,
|
||||
{
|
||||
type = "label",
|
||||
style = "ltnm_clickable_semibold_label",
|
||||
style_mods = { width = widths.stations.name },
|
||||
tooltip = constants.open_station_gui_tooltip,
|
||||
caption = station.entity_stop.backer_name,
|
||||
handler = stations_tab.handle.open_station_gui,
|
||||
tags = { station_id = station_id }
|
||||
},
|
||||
--templates.status_indicator(widths.stations.status, true), --repurposing status column for network name
|
||||
{ type = "sprite-button", style = "ltnm_small_slot_button_default", enabled = false, sprite = "virtual-signal/" .. network_name, },
|
||||
@@ -257,9 +260,64 @@ function stations_tab.build(map_data, player_data)
|
||||
end
|
||||
|
||||
|
||||
stations_tab.hande = {}
|
||||
stations_tab.handle = {}
|
||||
|
||||
function stations_tab.hande.open_station_gui()
|
||||
--- @param e {player_index: uint}
|
||||
function stations_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 e GuiEventData
|
||||
--- @param player_data PlayerData
|
||||
function stations_tab.handle.open_station_gui(player, player_data, refs, e)
|
||||
local station_id = e.element.tags.station_id
|
||||
--- @type Station
|
||||
local station = global.stations[station_id]
|
||||
local station_entity = station.entity_stop
|
||||
local station_comb1 = station.entity_comb1
|
||||
local station_comb2 = station.entity_comb2
|
||||
|
||||
if not station_entity or not station_entity.valid then
|
||||
util.error_flying_text(gui.player, { "message.ltnm-error-station-is-invalid" })
|
||||
return
|
||||
end
|
||||
|
||||
if e.shift then
|
||||
player.zoom_to_world(station_entity.position, 1, station_entity)
|
||||
|
||||
rendering.draw_circle({
|
||||
color = constants.colors.red.tbl,
|
||||
target = station_entity.position,
|
||||
surface = station_entity.surface,
|
||||
radius = 0.5,
|
||||
filled = false,
|
||||
width = 5,
|
||||
time_to_live = 60 * 3,
|
||||
players = { player },
|
||||
})
|
||||
|
||||
if not player_data.pinning then util.close_manager_window(player, player_data, refs) end
|
||||
elseif e.control then
|
||||
if station_comb1 ~= nil and station_comb1.valid then
|
||||
player.opened = station_comb1
|
||||
else
|
||||
util.error_flying_text(player, { "cybersyn-message.error-cybernetic-combinator-not-found" })
|
||||
end
|
||||
|
||||
elseif e.alt then
|
||||
if station_comb2 ~= nil and station_comb2.valid then
|
||||
player.opened = station_comb2
|
||||
else
|
||||
util.error_flying_text(player, { "cybersyn-message.error-station-control-combinator-not-found" })
|
||||
end
|
||||
else
|
||||
player.opened = station_entity
|
||||
end
|
||||
end
|
||||
|
||||
gui.add_handlers(stations_tab.handle, stations_tab.wrapper)
|
||||
|
||||
return stations_tab
|
||||
|
||||
Reference in New Issue
Block a user