mirror of
https://github.com/Xevion/project-cybersyn.git
synced 2025-12-06 05:16:06 -06:00
Add mod setting, add click handlers for station tab
This commit is contained in:
@@ -45,8 +45,7 @@ no-history=[img=warning-white] No history
|
||||
no-stations=[img=warning-white] No stations
|
||||
not-available=Not available
|
||||
no-trains=[img=warning-white] No trains
|
||||
open-ltn-combinator-gui=[font=default-semibold][color=128,206,240]Control:[/color][/font] Open LTN Combinator GUI
|
||||
open-station-gui=Open station GUI\n[font=default-semibold][color=128,206,240]Shift:[/color][/font] Open station on map
|
||||
open-station-gui=Open station GUI\n[font=default-semibold][color=128,206,240]Shift:[/color][/font] Open station on map\n[font=default-semibold][color=128,206,240]Control:[/color][/font] Open Station Cybernetic Combinator\n[font=default-semibold][color=128,206,240]Alt:[/color][/font] Open Station Control Cybernetic Combinator
|
||||
open-train-gui=Open train GUI
|
||||
parked-at-depot=Parked at depot
|
||||
parked-at-depot-with-residue=Parked at depot with residue
|
||||
@@ -59,6 +58,7 @@ returning-to-depot=Returning to depot
|
||||
route=Route
|
||||
runtime=Runtime
|
||||
search-label=Search:
|
||||
search-item-label=Search by item:
|
||||
shipments-description=Green = Inbound\nBlue = Outbound
|
||||
shipment=Shipment
|
||||
shipments=Shipments
|
||||
@@ -73,7 +73,8 @@ type=Type
|
||||
unloading-at=Unloading at
|
||||
|
||||
[cybersyn-message]
|
||||
error-ltn-combinator-not-found=Could not find an LTN Combinator for this station.
|
||||
error-cybernetic-combinator-not-found=Could not find a cybernetic combinator for this station.
|
||||
error-station-control-combinator-not-found=Could not find a station control cybernetic combinator for this station.
|
||||
error-station-is-invalid=Station is invalid, please refresh the GUI.
|
||||
error-train-is-invalid=Train is invalid, please refresh the GUI.
|
||||
|
||||
@@ -83,6 +84,7 @@ iterations-per-tick=Decrease this number if you're having performance issues.
|
||||
[cybersyn-mod-setting-name]
|
||||
history-length=History length
|
||||
iterations-per-tick=Iterations per tick [img=info]
|
||||
cybersyn-manager-update-rate=Manager refresh tick interval
|
||||
|
||||
[shortcut-name]
|
||||
cybersyn-toggle-gui=Toggle Cybersyn Manager
|
||||
|
||||
@@ -125,7 +125,7 @@
|
||||
---@field public react_to_train_at_incorrect_station boolean --interface setting
|
||||
---@field public react_to_train_early_to_depot boolean --interface setting
|
||||
---@field public enable_manager boolean
|
||||
---@field public manager_tps double --manager tick rate
|
||||
---@field public manager_update_rate int
|
||||
|
||||
--if this is uncommented it means there are migrations to write
|
||||
|
||||
|
||||
@@ -145,7 +145,6 @@ if script then
|
||||
constants.open_station_gui_tooltip = {
|
||||
"",
|
||||
{ "cybersyn-gui.open-station-gui" },
|
||||
remote.interfaces["ltn-combinator"] and { "", "\n", { "cybersyn-gui.open-ltn-combinator-gui" } } or nil,
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ local stations_tab = require("scripts.gui.stations")
|
||||
local inventory_tab = require("scripts.gui.inventory")
|
||||
--local history_tab = require("scripts.gui.history")
|
||||
--local alerts_tab = require("scripts.gui.alerts")
|
||||
local util = require("scripts.gui.util")
|
||||
|
||||
|
||||
local manager = {}
|
||||
@@ -68,6 +69,14 @@ function manager.create(player)
|
||||
clear_and_focus_on_right_click = true,
|
||||
handler = manager.handle.manager_update_text_search, --on_gui_text_changed
|
||||
},
|
||||
-- item search box commented out. It *works*, but, the filtering logic only checks delivieres, so I'm not sure what Mami intended it for, so I'm leaving it off for now...
|
||||
--{ type = "label", style = "subheader_caption_label", caption = { "cybersyn-gui.search-item-label" } },
|
||||
--{
|
||||
-- name = "manager_item_search_field",
|
||||
-- type = "textfield",
|
||||
-- clear_and_focus_on_right_click = true,
|
||||
-- handler = manager.handle.manager_update_item_search, --on_gui_text_changed
|
||||
--},
|
||||
{ type = "empty-widget", style = "flib_horizontal_pusher" },
|
||||
{ type = "label", style = "caption_label", caption = { "cybersyn-gui.network-name-label" } },
|
||||
{ type= "choose-elem-button", name="network", style="slot_button_in_shallow_frame", elem_type="signal", tooltip={"cybersyn-gui.network-tooltip"}, signal=NETWORK_SIGNAL_GUI_DEFAULT, handler=manager.handle.manager_update_network_name, },
|
||||
@@ -201,21 +210,7 @@ end
|
||||
--- @param player_data PlayerData
|
||||
--- @param refs table<string, LuaGuiElement>
|
||||
function manager.handle.manager_close(player, player_data, refs)
|
||||
if player_data.pinning then
|
||||
return
|
||||
end
|
||||
|
||||
refs.manager_window.visible = false
|
||||
player_data.visible = false
|
||||
|
||||
if player.opened == refs.manager_window then
|
||||
player.opened = nil
|
||||
end
|
||||
|
||||
player_data.is_manager_open = false
|
||||
player.set_shortcut_toggled("cybersyn-toggle-gui", false)
|
||||
|
||||
|
||||
util.close_manager_window(player, player_data, refs)
|
||||
player_data.refs.manager_window.destroy()
|
||||
player_data.refs = manager.create(player)
|
||||
end
|
||||
@@ -269,6 +264,21 @@ function manager.handle.manager_update_text_search(player, player_data, refs, e)
|
||||
player_data.search_query = query
|
||||
end
|
||||
|
||||
--- @param player LuaPlayer
|
||||
--- @param player_data PlayerData
|
||||
--- @param refs table<string, LuaGuiElement>
|
||||
--- @param e GuiEventData
|
||||
function manager.handle.manager_update_item_search(player, player_data, refs, e)
|
||||
local query = e.text
|
||||
if query then
|
||||
-- Input sanitization
|
||||
for pattern, replacement in pairs(constants.input_sanitizers) do
|
||||
query = string.gsub(query, pattern, replacement)
|
||||
end
|
||||
end
|
||||
player_data.search_item = query
|
||||
end
|
||||
|
||||
|
||||
--- @param player LuaPlayer
|
||||
--- @param player_data PlayerData
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -221,4 +221,21 @@ function util.signed_int32(val)
|
||||
return (val >= MAX_INT and val - (2 * MAX_INT)) or val
|
||||
end
|
||||
|
||||
function util.close_manager_window(player, player_data, refs)
|
||||
if player_data.pinning then
|
||||
return
|
||||
end
|
||||
|
||||
refs.manager_window.visible = false
|
||||
player_data.visible = false
|
||||
|
||||
if player.opened == refs.manager_window then
|
||||
player.opened = nil
|
||||
end
|
||||
|
||||
player_data.is_manager_open = false
|
||||
player.set_shortcut_toggled("cybersyn-toggle-gui", false)
|
||||
|
||||
end
|
||||
|
||||
return util
|
||||
|
||||
@@ -825,6 +825,7 @@ local function grab_all_settings()
|
||||
mod_settings.stuck_train_time = settings.global["cybersyn-stuck-train-time"].value--[[@as double]]
|
||||
mod_settings.allow_cargo_in_depot = settings.global["cybersyn-allow-cargo-in-depot"].value--[[@as boolean]]
|
||||
mod_settings.invert_sign = settings.global["cybersyn-invert-sign"].value--[[@as boolean]]
|
||||
mod_settings.manager_update_rate = settings.startup["cybersyn-manager-update-rate"].value--[[@as int]]
|
||||
end
|
||||
local function on_settings_changed(event)
|
||||
grab_all_settings()
|
||||
@@ -933,7 +934,8 @@ 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() --TODO: tick value needs to be converted to mod setting
|
||||
-- TODO: rework this to work as a per-player runtime setting
|
||||
script.on_nth_tick(mod_settings.manager_update_rate, function()
|
||||
manager.tick(global)
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -102,6 +102,15 @@ data:extend({
|
||||
setting_type = "runtime-global",
|
||||
default_value = false,
|
||||
},
|
||||
{
|
||||
type = "int-setting",
|
||||
name = "cybersyn-manager-update-rate",
|
||||
order = "ad",
|
||||
setting_type = "startup",
|
||||
default_value = 60,
|
||||
minimum_value = 1,
|
||||
maximum_value = 2147483647,
|
||||
},
|
||||
--{
|
||||
-- type = "bool-setting",
|
||||
-- name = "cybersyn-disable-top-left-button",
|
||||
|
||||
Reference in New Issue
Block a user