mirror of
https://github.com/Xevion/project-cybersyn.git
synced 2025-12-10 18:08:13 -06:00
changed minor issues
This commit is contained in:
@@ -2,10 +2,12 @@
|
|||||||
Version: 1.2.10
|
Version: 1.2.10
|
||||||
Date: 2022-1-9
|
Date: 2022-1-9
|
||||||
Changes:
|
Changes:
|
||||||
|
- Made the automatic allow list slightly more forgiving to stations where the last wagon would be on a curved rail
|
||||||
- Improved performance when fuel threshold is set to 1
|
- Improved performance when fuel threshold is set to 1
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
- Fixed a bug where it was possible for a single station to be updated twice per dispatch cycle, which could cause a crash
|
- Fixed a bug where it was possible for a single station to be updated twice per dispatch cycle, which could cause a crash
|
||||||
- Fixed a crash where trains would sometimes think a destroyed depot still exists
|
- Fixed a crash where trains would sometimes think a destroyed depot still exists
|
||||||
|
- Fixed a case where the central planner generated a confusing alert
|
||||||
- Removed unfinished mod setting with the broken translation key
|
- Removed unfinished mod setting with the broken translation key
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
Version: 1.2.9
|
Version: 1.2.9
|
||||||
|
|||||||
@@ -20,5 +20,18 @@ data:extend({
|
|||||||
locked_slots_signal,
|
locked_slots_signal,
|
||||||
missing_train_icon,
|
missing_train_icon,
|
||||||
lost_train_icon,
|
lost_train_icon,
|
||||||
nonempty_train_icon
|
nonempty_train_icon,
|
||||||
|
|
||||||
|
--{
|
||||||
|
-- type = "shortcut",
|
||||||
|
-- name = "ltnm-toggle-gui",
|
||||||
|
-- icon = data_util.build_sprite(nil, { 0, 0 }, util.paths.shortcut_icons, 32, 2),
|
||||||
|
-- disabled_icon = data_util.build_sprite(nil, { 48, 0 }, util.paths.shortcut_icons, 32, 2),
|
||||||
|
-- small_icon = data_util.build_sprite(nil, { 0, 32 }, util.paths.shortcut_icons, 24, 2),
|
||||||
|
-- disabled_small_icon = data_util.build_sprite(nil, { 36, 32 }, util.paths.shortcut_icons, 24, 2),
|
||||||
|
-- toggleable = true,
|
||||||
|
-- action = "lua",
|
||||||
|
-- associated_control_input = "ltnm-toggle-gui",
|
||||||
|
-- technology_to_unlock = "logistic-train-network",
|
||||||
|
--},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -363,6 +363,35 @@ local function tick_dispatch(map_data, mod_settings)
|
|||||||
if netand == 0 then
|
if netand == 0 then
|
||||||
goto p_continue
|
goto p_continue
|
||||||
end
|
end
|
||||||
|
|
||||||
|
effective_count = p_station.item_p_counts[item_name]
|
||||||
|
override_threshold = p_station.item_thresholds and p_station.item_thresholds[item_name]
|
||||||
|
if override_threshold and p_station.is_stack and not is_fluid then
|
||||||
|
override_threshold = override_threshold*get_stack_size(map_data, item_name)
|
||||||
|
end
|
||||||
|
if effective_count < (override_threshold or r_threshold) then
|
||||||
|
--this p station should have serviced the current r station, lock it so it can't serve any others
|
||||||
|
--this will lock stations even when the r station manages to find a p station, this not a problem because all stations will be unlocked before it could be an issue
|
||||||
|
table_remove(p_stations, j)
|
||||||
|
if band(p_station.display_state, 4) == 0 then
|
||||||
|
p_station.display_state = p_station.display_state + 4
|
||||||
|
update_display(map_data, p_station)
|
||||||
|
end
|
||||||
|
goto p_continue_remove
|
||||||
|
end
|
||||||
|
|
||||||
|
p_prior = p_station.priority
|
||||||
|
if override_threshold and p_station.item_priority then
|
||||||
|
p_prior = p_station.item_priority--[[@as int]]
|
||||||
|
end
|
||||||
|
if p_prior < best_p_prior then
|
||||||
|
goto p_continue
|
||||||
|
end
|
||||||
|
|
||||||
|
best_p_dist = p_station.entity_stop.valid and r_station.entity_stop.valid and (best_t_to_p_dist + get_dist(p_station.entity_stop, r_station.entity_stop)) or INF
|
||||||
|
if p_prior == best_p_prior and best_p_dist > best_dist then
|
||||||
|
goto p_continue
|
||||||
|
end
|
||||||
if correctness < 1 then
|
if correctness < 1 then
|
||||||
correctness = 1
|
correctness = 1
|
||||||
closest_to_correct_p_station = p_station
|
closest_to_correct_p_station = p_station
|
||||||
@@ -442,35 +471,6 @@ local function tick_dispatch(map_data, mod_settings)
|
|||||||
goto p_continue
|
goto p_continue
|
||||||
end
|
end
|
||||||
|
|
||||||
effective_count = p_station.item_p_counts[item_name]
|
|
||||||
override_threshold = p_station.item_thresholds and p_station.item_thresholds[item_name]
|
|
||||||
if override_threshold and p_station.is_stack and not is_fluid then
|
|
||||||
override_threshold = override_threshold*get_stack_size(map_data, item_name)
|
|
||||||
end
|
|
||||||
if effective_count < (override_threshold or r_threshold) then
|
|
||||||
--this p station should have serviced the current r station, lock it so it can't serve any others
|
|
||||||
--this will lock stations even when the r station manages to find a p station, this not a problem because all stations will be unlocked before it could be an issue
|
|
||||||
table_remove(p_stations, j)
|
|
||||||
if band(p_station.display_state, 4) == 0 then
|
|
||||||
p_station.display_state = p_station.display_state + 4
|
|
||||||
update_display(map_data, p_station)
|
|
||||||
end
|
|
||||||
goto p_continue_remove
|
|
||||||
end
|
|
||||||
|
|
||||||
p_prior = p_station.priority
|
|
||||||
if override_threshold and p_station.item_priority then
|
|
||||||
p_prior = p_station.item_priority--[[@as int]]
|
|
||||||
end
|
|
||||||
if p_prior < best_p_prior then
|
|
||||||
goto p_continue
|
|
||||||
end
|
|
||||||
|
|
||||||
best_p_dist = p_station.entity_stop.valid and r_station.entity_stop.valid and (best_t_to_p_dist + get_dist(p_station.entity_stop, r_station.entity_stop)) or INF
|
|
||||||
if p_prior == best_p_prior and best_p_dist > best_dist then
|
|
||||||
goto p_continue
|
|
||||||
end
|
|
||||||
|
|
||||||
p_station_i = j
|
p_station_i = j
|
||||||
best_train_id = best_p_train_id
|
best_train_id = best_p_train_id
|
||||||
best_p_prior = p_prior
|
best_p_prior = p_prior
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
---@param train LuaTrain
|
---@param train LuaTrain
|
||||||
|
---@return LuaEntity?
|
||||||
function get_any_train_entity(train)
|
function get_any_train_entity(train)
|
||||||
return train.valid and (train.front_stock or train.back_stock or train.carriages[1]) or nil
|
return train.valid and (train.front_stock or train.back_stock or train.carriages[1]) or nil
|
||||||
end
|
end
|
||||||
@@ -47,8 +48,9 @@ end
|
|||||||
|
|
||||||
---@param e Station|Refueler|Train
|
---@param e Station|Refueler|Train
|
||||||
---@param network_name string
|
---@param network_name string
|
||||||
|
---@return int
|
||||||
function get_network_flag(e, network_name)
|
function get_network_flag(e, network_name)
|
||||||
return e.network_name == NETWORK_EACH and (e.network_flag[network_name] or 0) or e.network_flag
|
return e.network_name == NETWORK_EACH and (e.network_flag[network_name] or 0) or e.network_flag--[[@as int]]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
93
cybersyn/scripts/gui/main.lua
Normal file
93
cybersyn/scripts/gui/main.lua
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
local gui = require("__flib__.gui-lite")
|
||||||
|
local mod_gui = require("__core__.lualib.mod-gui")
|
||||||
|
|
||||||
|
local manager = require("scripts.gui.manager")
|
||||||
|
|
||||||
|
|
||||||
|
--- @class PlayerData
|
||||||
|
--- @field refs {[string]: LuaGuiElement}?
|
||||||
|
--- @field search_query string?
|
||||||
|
--- @field search_network_name string?
|
||||||
|
--- @field search_network_mask int
|
||||||
|
--- @field search_surface_idx uint?
|
||||||
|
--- @field search_item string?
|
||||||
|
--- @field trains_orderings uint[]
|
||||||
|
--- @field trains_orderings_invert boolean[]
|
||||||
|
--- @field pinning boolean
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function top_left_button_update(player, player_data)
|
||||||
|
local button_flow = mod_gui.get_button_flow(player)
|
||||||
|
local button = button_flow["top_left_button"]
|
||||||
|
if player_data.disable_top_left_button then
|
||||||
|
if button then
|
||||||
|
button.destroy()
|
||||||
|
end
|
||||||
|
elseif not button then
|
||||||
|
gui.add(button_flow, {
|
||||||
|
type = "sprite-button",
|
||||||
|
name = "top_left_button",
|
||||||
|
style = "mis_mod_gui_button_green",
|
||||||
|
sprite = "mis_configure_white",
|
||||||
|
tooltip = { "", "\n", { "mis-config-gui.configure-tooltip" } },
|
||||||
|
handler = manager.handle.toggle,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local manager_gui = {}
|
||||||
|
|
||||||
|
function manager_gui.on_lua_shortcut(e)
|
||||||
|
if e.prototype_name == "ltnm-toggle-gui" then
|
||||||
|
manager.wrapper(e, manager.handle.toggle)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function manager_gui.on_player_created(e)
|
||||||
|
local player = game.get_player(e.player_index)
|
||||||
|
if not player then return end
|
||||||
|
local player_data = {
|
||||||
|
search_network_mask = -1,
|
||||||
|
trains_orderings = {},
|
||||||
|
trains_orderings_invert = {},
|
||||||
|
pinning = false,
|
||||||
|
refs = manager.create(player),
|
||||||
|
}
|
||||||
|
global.manager_data.players[e.player_index] = player_data
|
||||||
|
|
||||||
|
manager.update(global, player, player_data)
|
||||||
|
top_left_button_update(player, player_data)
|
||||||
|
end
|
||||||
|
|
||||||
|
function manager_gui.on_player_removed(e)
|
||||||
|
global.manager_data.players[e.player_index] = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
--script.on_event(defines.events.on_player_joined_game, function(e)
|
||||||
|
--end)
|
||||||
|
|
||||||
|
--script.on_event(defines.events.on_player_left_game, function(e)
|
||||||
|
--end)
|
||||||
|
|
||||||
|
function manager_gui.on_runtime_mod_setting_changed(e)
|
||||||
|
if e.setting == "cybersyn-disable-top-left-button" then
|
||||||
|
if not e.player_index then return end
|
||||||
|
local player = game.get_player(e.player_index)
|
||||||
|
if not player then return end
|
||||||
|
|
||||||
|
local player_data = global.manager_data.players[e.player_index]
|
||||||
|
player_data.disable_top_left_button = player.mod_settings["cybersyn-disable-top-left-button"].value
|
||||||
|
top_left_button_update(player, player_data)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--gui.handle_events()
|
||||||
|
|
||||||
|
return manager_gui
|
||||||
@@ -13,61 +13,16 @@ local trains_tab = require("scripts.gui.trains")
|
|||||||
--local alerts_tab = require("scripts.gui.alerts")
|
--local alerts_tab = require("scripts.gui.alerts")
|
||||||
|
|
||||||
|
|
||||||
--- @class PlayerData
|
|
||||||
--- @field refs {[string]: LuaGuiElement}?
|
|
||||||
--- @field search_query string?
|
|
||||||
--- @field network_name string
|
|
||||||
--- @field network_flag int
|
|
||||||
--- @field pinning boolean
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function Index:dispatch(msg, e)
|
|
||||||
-- "Transform" the action based on criteria
|
|
||||||
if msg.transform == "handle_refresh_click" then
|
|
||||||
if e.shift then
|
|
||||||
msg.action = "toggle_auto_refresh"
|
|
||||||
else
|
|
||||||
self.state.ltn_data = global.data
|
|
||||||
self.do_update = true
|
|
||||||
end
|
|
||||||
elseif msg.transform == "handle_titlebar_click" then
|
|
||||||
if e.button == defines.mouse_button_type.middle then
|
|
||||||
msg.action = "recenter"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Dispatch the associated action
|
|
||||||
if msg.action then
|
|
||||||
local func = self.actions[msg.action]
|
|
||||||
if func then
|
|
||||||
func(self, msg, e)
|
|
||||||
else
|
|
||||||
log("Attempted to call action `" .. msg.action .. "` for which there is no handler yet.")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Update if necessary
|
|
||||||
if self.do_update then
|
|
||||||
self:update()
|
|
||||||
self.do_update = false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function Index:schedule_update()
|
|
||||||
self.do_update = true
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local manager = {}
|
local manager = {}
|
||||||
|
|
||||||
|
|
||||||
function manager.build(player, player_data)
|
--- @param player LuaPlayer
|
||||||
|
function manager.create(player)
|
||||||
local widths = constants.gui["en"]
|
local widths = constants.gui["en"]
|
||||||
---@type table<string, LuaGuiElement>
|
---@type table<string, LuaGuiElement>
|
||||||
local refs = {}
|
local refs = {}
|
||||||
|
|
||||||
local _, window = gui.add(player.gui.screen, {
|
gui.add(player.gui.screen, {
|
||||||
{
|
{
|
||||||
name = "manager_window",
|
name = "manager_window",
|
||||||
type = "frame",
|
type = "frame",
|
||||||
@@ -111,25 +66,25 @@ function manager.build(player, player_data)
|
|||||||
name = "manager_text_search_field",
|
name = "manager_text_search_field",
|
||||||
type = "textfield",
|
type = "textfield",
|
||||||
clear_and_focus_on_right_click = true,
|
clear_and_focus_on_right_click = true,
|
||||||
handler = manager.handle.update_text_search_query, --on_gui_text_changed
|
handler = manager.handle.update_text_search, --on_gui_text_changed
|
||||||
},
|
},
|
||||||
{ type = "empty-widget", style = "flib_horizontal_pusher" },
|
{ type = "empty-widget", style = "flib_horizontal_pusher" },
|
||||||
{ type = "label", style = "caption_label", caption = { "gui.ltnm-network-id-label" } },
|
{ type = "label", style = "caption_label", caption = { "gui.ltnm-network-id-label" } },
|
||||||
{
|
{
|
||||||
name = "manager_network_id_field",
|
name = "manager_network_mask_field",
|
||||||
type = "textfield",
|
type = "textfield",
|
||||||
style_mods = { width = 120 },
|
style_mods = { width = 120 },
|
||||||
numeric = true,
|
numeric = true,
|
||||||
allow_negative = true,
|
allow_negative = true,
|
||||||
clear_and_focus_on_right_click = true,
|
clear_and_focus_on_right_click = true,
|
||||||
text = "-1",
|
text = "-1",
|
||||||
handler = manager.handle.update_network_id_query, --on_gui_text_changed
|
handler = manager.handle.update_network_mask, --on_gui_text_changed
|
||||||
},
|
},
|
||||||
{ type = "label", style = "caption_label", caption = { "gui.ltnm-surface-label" } },
|
{ type = "label", style = "caption_label", caption = { "gui.ltnm-surface-label" } },
|
||||||
{
|
{
|
||||||
name = "manager_surface_dropdown",
|
name = "manager_surface_dropdown",
|
||||||
type = "drop-down",
|
type = "drop-down",
|
||||||
handler = manager.handle.change_surface, --on_gui_selection_state_changed
|
handler = manager.handle.update_surface, --on_gui_selection_state_changed
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -137,9 +92,6 @@ function manager.build(player, player_data)
|
|||||||
name = "manager_tabbed_pane",
|
name = "manager_tabbed_pane",
|
||||||
type = "tabbed-pane",
|
type = "tabbed-pane",
|
||||||
style = "ltnm_tabbed_pane",
|
style = "ltnm_tabbed_pane",
|
||||||
children = {
|
|
||||||
trains_tab.build(widths, refs),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -149,23 +101,49 @@ function manager.build(player, player_data)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
refs.manager_titlebar.drag_target = window
|
refs.manager_titlebar.drag_target = refs.manager_window
|
||||||
window.force_auto_center()
|
refs.manager_window.force_auto_center()
|
||||||
|
|
||||||
|
return refs
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- @param map_data MapData
|
||||||
--- @param player LuaPlayer
|
--- @param player LuaPlayer
|
||||||
--- @param refs table<string, LuaGuiElement>
|
--- @param player_data PlayerData
|
||||||
function manager.destroy(player, refs)
|
function manager.update(map_data, player, player_data)
|
||||||
refs.manager_window.destroy()
|
local tab = trains_tab.build(map_data, player_data)
|
||||||
|
gui.add(_, tab, player_data.refs)
|
||||||
player.set_shortcut_toggled("ltnm-toggle-gui", false)
|
|
||||||
player.set_shortcut_available("ltnm-toggle-gui", false)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
manager.handle = {}
|
||||||
|
|
||||||
|
--- @param e {player_index: uint}
|
||||||
|
function manager.wrapper(e, handler)
|
||||||
|
local player = game.get_player(e.player_index)
|
||||||
|
if not player then return end
|
||||||
|
local player_data = global.manager_data.players[e.player_index]
|
||||||
|
handler(player, player_data, player_data.refs, e)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function toggle_fab(elem, sprite, state)
|
||||||
|
if state then
|
||||||
|
elem.style = "flib_selected_frame_action_button"
|
||||||
|
elem.sprite = sprite .. "_black"
|
||||||
|
else
|
||||||
|
elem.style = "frame_action_button"
|
||||||
|
elem.sprite = sprite .. "_white"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- @param player LuaPlayer
|
--- @param player LuaPlayer
|
||||||
--- @param player_data PlayerData
|
--- @param player_data PlayerData
|
||||||
--- @param refs table<string, LuaGuiElement>
|
--- @param refs table<string, LuaGuiElement>
|
||||||
function manager.open(player, player_data, refs)
|
function manager.handle.open(player, player_data, refs)
|
||||||
refs.manager_window.bring_to_front()
|
refs.manager_window.bring_to_front()
|
||||||
refs.manager_window.visible = true
|
refs.manager_window.visible = true
|
||||||
player_data.visible = true
|
player_data.visible = true
|
||||||
@@ -177,10 +155,11 @@ function manager.open(player, player_data, refs)
|
|||||||
player.set_shortcut_toggled("ltnm-toggle-gui", true)
|
player.set_shortcut_toggled("ltnm-toggle-gui", true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- @param player LuaPlayer
|
--- @param player LuaPlayer
|
||||||
--- @param player_data PlayerData
|
--- @param player_data PlayerData
|
||||||
--- @param refs table<string, LuaGuiElement>
|
--- @param refs table<string, LuaGuiElement>
|
||||||
function manager.close(player, player_data, refs)
|
function manager.handle.close(player, player_data, refs)
|
||||||
if player_data.pinning then
|
if player_data.pinning then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -195,86 +174,76 @@ function manager.close(player, player_data, refs)
|
|||||||
player.set_shortcut_toggled("ltnm-toggle-gui", false)
|
player.set_shortcut_toggled("ltnm-toggle-gui", false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- @param player LuaPlayer
|
||||||
|
--- @param player_data PlayerData
|
||||||
|
--- @param refs table<string, LuaGuiElement>
|
||||||
|
function manager.handle.toggle(player, player_data, refs)
|
||||||
|
|
||||||
manager.handle = {}
|
|
||||||
|
|
||||||
--- @param e GuiEventData
|
|
||||||
function manager.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)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function toggle_fab(elem, sprite, state)
|
|
||||||
if state then
|
|
||||||
elem.style = "flib_selected_frame_action_button"
|
|
||||||
elem.sprite = sprite .. "_black"
|
|
||||||
else
|
|
||||||
elem.style = "frame_action_button"
|
|
||||||
elem.sprite = sprite .. "_white"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
manager.handle.close = manager.close
|
|
||||||
|
|
||||||
--- @param player LuaPlayer
|
--- @param player LuaPlayer
|
||||||
--- @param player_data PlayerData
|
--- @param player_data PlayerData
|
||||||
--- @param refs table<string, LuaGuiElement>
|
--- @param refs table<string, LuaGuiElement>
|
||||||
function manager.handle.recenter(player, player_data, refs)
|
function manager.handle.recenter(player, player_data, refs)
|
||||||
refs.window.force_auto_center()
|
refs.window.force_auto_center()
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @param player LuaPlayer
|
--- @param player LuaPlayer
|
||||||
--- @param player_data PlayerData
|
--- @param player_data PlayerData
|
||||||
--- @param refs table<string, LuaGuiElement>
|
--- @param refs table<string, LuaGuiElement>
|
||||||
function manager.handle.toggle_auto_refresh(player, player_data, refs)
|
function manager.handle.toggle_auto_refresh(player, player_data, refs)
|
||||||
player_data.auto_refresh = not player_data.auto_refresh
|
player_data.auto_refresh = not player_data.auto_refresh
|
||||||
toggle_fab(refs.manager_refresh_button, "ltnm_refresh", player_data.auto_refresh)
|
toggle_fab(refs.manager_refresh_button, "ltnm_refresh", player_data.auto_refresh)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @param player LuaPlayer
|
--- @param player LuaPlayer
|
||||||
--- @param player_data PlayerData
|
--- @param player_data PlayerData
|
||||||
--- @param refs table<string, LuaGuiElement>
|
--- @param refs table<string, LuaGuiElement>
|
||||||
function manager.handle.toggle_pinned(player, player_data, refs)
|
function manager.handle.toggle_pinned(player, player_data, refs)
|
||||||
player_data.pinned = not player_data.pinned
|
player_data.pinned = not player_data.pinned
|
||||||
toggle_fab(refs.manager_pin_button, "ltnm_pin", player_data.pinned)
|
toggle_fab(refs.manager_pin_button, "ltnm_pin", player_data.pinned)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @param player LuaPlayer
|
--- @param player LuaPlayer
|
||||||
--- @param player_data PlayerData
|
--- @param player_data PlayerData
|
||||||
--- @param refs table<string, LuaGuiElement>
|
--- @param refs table<string, LuaGuiElement>
|
||||||
--- @param e GuiEventData
|
--- @param e GuiEventData
|
||||||
function manager.handle.update_text_search_query(player, player_data, refs, e)
|
function manager.handle.update_text_search(player, player_data, refs, e)
|
||||||
local query = e.text
|
local query = e.text
|
||||||
-- Input sanitization
|
-- Input sanitization
|
||||||
for pattern, replacement in pairs(constants.input_sanitizers) do
|
for pattern, replacement in pairs(constants.input_sanitizers) do
|
||||||
query = string.gsub(query, pattern, replacement)
|
query = string.gsub(query, pattern, replacement)
|
||||||
end
|
end
|
||||||
player_data.search_query = query
|
player_data.search_query = query
|
||||||
|
|
||||||
if Gui.state.search_job then
|
|
||||||
on_tick_n.remove(Gui.state.search_job)
|
|
||||||
end
|
|
||||||
|
|
||||||
if #query == 0 then
|
|
||||||
Gui:schedule_update()
|
|
||||||
else
|
|
||||||
Gui.state.search_job = on_tick_n.add(
|
|
||||||
game.tick + 30,
|
|
||||||
{ gui = "main", action = "update", player_index = Gui.player.index }
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- @param player LuaPlayer
|
--- @param player LuaPlayer
|
||||||
--- @param player_data PlayerData
|
--- @param player_data PlayerData
|
||||||
--- @param refs table<string, LuaGuiElement>
|
--- @param refs table<string, LuaGuiElement>
|
||||||
function manager.handle.update_network_id_query(player, player_data, refs)
|
function manager.handle.update_network_name(player, player_data, refs)
|
||||||
Gui.state.network_id = tonumber(Gui.refs.toolbar.network_id_field.text) or -1
|
local signal = refs.manager_network_name.elem_value
|
||||||
Gui:schedule_update()
|
if signal then
|
||||||
|
player_data.search_network_name = signal.name
|
||||||
|
else
|
||||||
|
player_data.search_network_name = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
--- @param player LuaPlayer
|
||||||
|
--- @param player_data PlayerData
|
||||||
|
--- @param refs table<string, LuaGuiElement>
|
||||||
|
function manager.handle.update_network_mask(player, player_data, refs)
|
||||||
|
player_data.search_network_mask = tonumber(refs.manager_network_mask_field.text) or -1
|
||||||
|
end
|
||||||
|
--- @param player LuaPlayer
|
||||||
|
--- @param player_data PlayerData
|
||||||
|
--- @param refs table<string, LuaGuiElement>
|
||||||
|
function manager.handle.update_surface(player, player_data, refs)
|
||||||
|
local i = refs.manager_surface_dropdown.selected_index
|
||||||
|
player_data.search_surface_idx = i--TODO: fix this
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
gui.add_handlers(manager.handle, manager.wrapper)
|
||||||
|
|
||||||
return manager
|
return manager
|
||||||
|
|||||||
@@ -1,146 +1,226 @@
|
|||||||
|
local format = require("__flib__.format")
|
||||||
local gui = require("__flib__.gui-lite")
|
local gui = require("__flib__.gui-lite")
|
||||||
|
|
||||||
local constants = require("constants")
|
local constants = require("constants")
|
||||||
local util = require("scripts.gui.util")
|
local util = require("scripts.gui.util")
|
||||||
|
|
||||||
local templates = require("templates")
|
local templates = require("scripts.gui.templates")
|
||||||
|
|
||||||
local trains_tab = {}
|
local trains_tab = {}
|
||||||
|
|
||||||
|
|
||||||
function trains_tab.build(map_data, player_id, player_data)
|
--- @param map_data MapData
|
||||||
|
--- @param player_data PlayerData
|
||||||
|
--- @return GuiElemDef
|
||||||
|
function trains_tab.build(map_data, player_data)
|
||||||
local widths = constants.gui["en"]
|
local widths = constants.gui["en"]
|
||||||
|
|
||||||
local search_query = player_data.search_query
|
local search_item = player_data.search_item
|
||||||
local search_network_flag = player_data.network_flag
|
local search_network_name = player_data.search_network_name
|
||||||
local search_network = player_data.network
|
local search_network_mask = player_data.search_network_mask
|
||||||
|
local search_surface_idx = player_data.search_surface_idx
|
||||||
|
|
||||||
|
|
||||||
|
local trains_sorted = {}
|
||||||
|
for id, train in pairs(map_data.trains) do
|
||||||
|
if search_network_name then
|
||||||
|
if search_network_name ~= train.network_name then
|
||||||
|
goto continue
|
||||||
|
end
|
||||||
|
local train_flag = get_network_flag(train, search_network_name)
|
||||||
|
if not bit32.btest(search_network_mask, train_flag) then
|
||||||
|
goto continue
|
||||||
|
end
|
||||||
|
elseif search_network_mask ~= -1 then
|
||||||
|
if train.network_name == NETWORK_EACH then
|
||||||
|
local masks = train.network_flag--[[@as {}]]
|
||||||
|
for _, network_flag in pairs(masks) do
|
||||||
|
if bit32.btest(search_network_mask, network_flag) then
|
||||||
|
goto has_match
|
||||||
|
end
|
||||||
|
end
|
||||||
|
goto continue
|
||||||
|
::has_match::
|
||||||
|
elseif not bit32.btest(search_network_mask, train.network_flag) then
|
||||||
|
goto continue
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if search_surface_idx then
|
||||||
|
local entity = get_any_train_entity(train.entity)
|
||||||
|
if not entity then
|
||||||
|
goto continue
|
||||||
|
end
|
||||||
|
if entity.surface.index ~= search_surface_idx then
|
||||||
|
goto continue
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if search_item then
|
||||||
|
if not train.manifest then
|
||||||
|
goto continue
|
||||||
|
end
|
||||||
|
for i, v in ipairs(train.manifest) do
|
||||||
|
if v.name == search_item then
|
||||||
|
goto has_match
|
||||||
|
end
|
||||||
|
end
|
||||||
|
goto continue
|
||||||
|
::has_match::
|
||||||
|
end
|
||||||
|
|
||||||
|
trains_sorted[#trains_sorted + 1] = id
|
||||||
|
::continue::
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
table.sort(trains_sorted, function(a, b)
|
||||||
|
local train1 = map_data.trains[a]
|
||||||
|
local train2 = map_data.trains[b]
|
||||||
|
for i, v in ipairs(player_data.trains_orderings) do
|
||||||
|
local invert = player_data.trains_orderings_invert[i]
|
||||||
|
if v == ORDER_LAYOUT then
|
||||||
|
if train1.layout_id ~= train2.layout_id then
|
||||||
|
local layout1 = map_data.layouts[train1.layout_id]
|
||||||
|
local layout2 = map_data.layouts[train2.layout_id]
|
||||||
|
for j, c1 in ipairs(layout1) do
|
||||||
|
local c2 = layout2[j]
|
||||||
|
if c1 ~= c2 then
|
||||||
|
return invert ~= (c2 and c1 < c2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if layout2[#layout1 + 1] then
|
||||||
|
return invert ~= true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif v == ORDER_DEPOT then
|
||||||
|
local depot1 = map_data.depots[train1.depot_id]
|
||||||
|
local depot2 = map_data.depots[train2.depot_id]
|
||||||
|
local name1 = depot1.entity_stop.valid and depot1.entity_stop.backer_name
|
||||||
|
local name2 = depot2.entity_stop.valid and depot2.entity_stop.backer_name
|
||||||
|
if name1 ~= name2 then
|
||||||
|
return invert ~= (name1 and (name2 and name1 < name2 or true) or false)
|
||||||
|
end
|
||||||
|
elseif v == ORDER_STATUS then
|
||||||
|
if train1.status ~= train2.status then
|
||||||
|
return invert ~= (train1.status < train2.status)
|
||||||
|
end
|
||||||
|
elseif v == ORDER_MANIFEST then
|
||||||
|
if not train1.manifest then
|
||||||
|
if train2.manifest then
|
||||||
|
return invert ~= true
|
||||||
|
end
|
||||||
|
elseif not train2.manifest then
|
||||||
|
return invert ~= false
|
||||||
|
else
|
||||||
|
local primary_item1 = train1.manifest[1]
|
||||||
|
local primary_item2 = train2.manifest[1]
|
||||||
|
if primary_item1.name ~= primary_item2.name then
|
||||||
|
return invert ~= (primary_item1.type == primary_item2.type and primary_item1.name < primary_item2.name or primary_item1.type == "item")
|
||||||
|
elseif primary_item1.count ~= primary_item2.count then
|
||||||
|
return invert ~= (primary_item1.count < primary_item2.count)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return a < b
|
||||||
|
end)
|
||||||
|
|
||||||
local trains_sorted = player_data.trains_sorted
|
|
||||||
|
|
||||||
---@type GuiElemDef
|
---@type GuiElemDef
|
||||||
local train_list = {}
|
local train_list = {}
|
||||||
--if not sorted_trains then
|
|
||||||
-- sorted_trains = {}
|
|
||||||
-- ids = {}
|
|
||||||
-- for id, train in pairs(map_data) do
|
|
||||||
-- local i = #ids + 1
|
|
||||||
-- ids[i] = id
|
|
||||||
-- sorted_trains[i] = train
|
|
||||||
-- end
|
|
||||||
-- dual_sort(ids, sorted_trains)
|
|
||||||
--end
|
|
||||||
if #trains_sorted == 0 then
|
if #trains_sorted == 0 then
|
||||||
train_list[1] = {
|
train_list[1] = {
|
||||||
type = "label",
|
type = "label",
|
||||||
style = "ltnm_semibold_label",
|
style = "ltnm_semibold_label",
|
||||||
caption = { "gui.ltnm-no-trains" },
|
caption = { "gui.ltnm-no-trains" },
|
||||||
ref = { "trains", "warning_label" },
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
local start, finish, step
|
for idx, train_id in ipairs(trains_sorted) do
|
||||||
if player_data.trains_ascending then
|
|
||||||
start = #trains_sorted
|
|
||||||
finish = 1
|
|
||||||
step = -1
|
|
||||||
else
|
|
||||||
start = 1
|
|
||||||
finish = #trains_sorted
|
|
||||||
step = 1
|
|
||||||
end
|
|
||||||
|
|
||||||
local gui_idx = 1
|
|
||||||
for idx = start, finish, step do
|
|
||||||
local train_id = trains_sorted[idx]
|
|
||||||
local train = map_data.trains[train_id]
|
local train = map_data.trains[train_id]
|
||||||
|
local depot = map_data.depots[train.depot_id]
|
||||||
|
local depot_name = depot.entity_stop.valid and depot.entity_stop.backer_name or ""
|
||||||
|
|
||||||
if
|
local color = idx % 2 == 0 and "dark" or "light"
|
||||||
true
|
train_list[idx] = {
|
||||||
then
|
type = "frame",
|
||||||
local color = gui_idx % 2 == 0 and "dark" or "light"
|
style = "ltnm_table_row_frame_" .. color,
|
||||||
train_list[gui_idx] = {
|
children = {
|
||||||
type = "frame",
|
{
|
||||||
style = "ltnm_table_row_frame_" .. color,
|
type = "frame",
|
||||||
children = {
|
style = "ltnm_table_inset_frame_" .. color,
|
||||||
{
|
children = {
|
||||||
type = "frame",
|
type = "minimap",
|
||||||
style = "ltnm_table_inset_frame_" .. color,
|
style = "ltnm_train_minimap",
|
||||||
children = {
|
{ type = "label", style = "ltnm_minimap_label" },
|
||||||
type = "minimap",
|
{
|
||||||
style = "ltnm_train_minimap",
|
type = "button",
|
||||||
{ type = "label", style = "ltnm_minimap_label" },
|
style = "ltnm_train_minimap_button",
|
||||||
{
|
tooltip = { "gui.ltnm-open-train-gui" },
|
||||||
type = "button",
|
elem_mods = { entity = get_any_train_entity(train.entity) },
|
||||||
style = "ltnm_train_minimap_button",
|
handler = trains_tab.handle.open_train_gui, --on_click
|
||||||
tooltip = { "gui.ltnm-open-train-gui" },
|
tags = { train_id = train_id },
|
||||||
elem_mods = { entity = get_any_train_entity(train.entity) },
|
|
||||||
actions = {
|
|
||||||
on_click = { gui = "main", action = "open_train_gui", train_id = train_id },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type = "label",
|
|
||||||
style_mods = { width = widths.trains.composition },
|
|
||||||
elem_mods = { caption = train.composition },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type = "label", style_mods = { width = widths.trains.depot },
|
|
||||||
elem_mods = { caption = train.depot },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type = "frame",
|
|
||||||
name = "shipment_frame",
|
|
||||||
style = "ltnm_small_slot_table_frame_" .. color,
|
|
||||||
style_mods = { width = widths.trains.shipment },
|
|
||||||
children = {
|
|
||||||
{
|
|
||||||
type = "table",
|
|
||||||
name = "shipment_table",
|
|
||||||
style = "slot_table",
|
|
||||||
column_count = widths.trains.shipment_columns,
|
|
||||||
children = util.slot_table_build(train.manifest, "default"),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
{
|
||||||
gui_idx = gui_idx + 1
|
type = "label",
|
||||||
end
|
style_mods = { width = widths.trains.composition },
|
||||||
|
elem_mods = { caption = train.layout_id },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = "label",
|
||||||
|
style_mods = { width = widths.trains.depot },
|
||||||
|
elem_mods = { caption = depot_name },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = "frame",
|
||||||
|
name = "shipment_frame",
|
||||||
|
style = "ltnm_small_slot_table_frame_" .. color,
|
||||||
|
style_mods = { width = widths.trains.shipment },
|
||||||
|
children = {
|
||||||
|
{
|
||||||
|
type = "table",
|
||||||
|
name = "shipment_table",
|
||||||
|
style = "slot_table",
|
||||||
|
column_count = widths.trains.shipment_columns,
|
||||||
|
children = util.slot_table_build(train.manifest, "default"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
tab = {
|
tab = {
|
||||||
|
name = "trains_tab",
|
||||||
type = "tab",
|
type = "tab",
|
||||||
caption = #trains_sorted == 0 and { "gui.ltnm-trains" } or { "gui.ltnm-trains", #train_list },
|
caption = #trains_sorted == 0 and { "gui.ltnm-trains" } or { "gui.ltnm-trains", #train_list },
|
||||||
badge_text = misc.delineate_number(#ltn_data.sorted_trains.composition),
|
--badge_text = format.number(#ltn_data.sorted_trains.composition),
|
||||||
ref = { "trains", "tab" },
|
handler = trains_tab.handle.change_tab, --on_click
|
||||||
actions = {
|
tags = { tab = "trains_tab" },
|
||||||
on_click = { gui = "main", action = "change_tab", tab = "trains" },
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
content = {
|
content = {
|
||||||
|
name = "trains_content_frame",
|
||||||
type = "frame",
|
type = "frame",
|
||||||
style = "ltnm_main_content_frame",
|
style = "ltnm_main_content_frame",
|
||||||
direction = "vertical",
|
direction = "vertical",
|
||||||
ref = { "trains", "content_frame" },
|
|
||||||
children = {
|
children = {
|
||||||
{
|
{
|
||||||
type = "frame",
|
type = "frame",
|
||||||
style = "ltnm_table_toolbar_frame",
|
style = "ltnm_table_toolbar_frame",
|
||||||
templates.sort_checkbox(widths, "trains", "train_id", true),
|
|
||||||
templates.sort_checkbox(widths, "trains", "status", false),
|
templates.sort_checkbox(widths, "trains", "status", false),
|
||||||
templates.sort_checkbox(widths, "trains", "composition", false, { "gui.ltnm-composition-description" }),
|
templates.sort_checkbox(widths, "trains", "layout", false, { "gui.ltnm-composition-description" }),
|
||||||
templates.sort_checkbox(widths, "trains", "depot", false),
|
templates.sort_checkbox(widths, "trains", "depot", false),
|
||||||
templates.sort_checkbox(widths, "trains", "shipment", false),
|
templates.sort_checkbox(widths, "trains", "shipment", false),
|
||||||
},
|
},
|
||||||
{ type = "scroll-pane", style = "ltnm_table_scroll_pane", ref = { "trains", "scroll_pane" } },
|
{ name = "trains_scroll_pane", type = "scroll-pane", style = "ltnm_table_scroll_pane" },
|
||||||
{
|
{
|
||||||
|
name = "trains_warning_flow",
|
||||||
type = "flow",
|
type = "flow",
|
||||||
style = "ltnm_warning_flow",
|
style = "ltnm_warning_flow",
|
||||||
visible = false,
|
|
||||||
ref = { "trains", "warning_flow" },
|
|
||||||
children = train_list,
|
children = train_list,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ end
|
|||||||
--- @param color string
|
--- @param color string
|
||||||
--- @return GuiElemDef[]
|
--- @return GuiElemDef[]
|
||||||
function util.slot_table_build(manifest, color)
|
function util.slot_table_build(manifest, color)
|
||||||
|
---@type GuiElemDef[]
|
||||||
local children = {}
|
local children = {}
|
||||||
local i = 1
|
|
||||||
for _, item in pairs(manifest) do
|
for _, item in pairs(manifest) do
|
||||||
local name = item.name
|
local name = item.name
|
||||||
local sprite
|
local sprite
|
||||||
@@ -49,7 +49,7 @@ function util.slot_table_build(manifest, color)
|
|||||||
sprite = string.gsub(name, ",", "/")
|
sprite = string.gsub(name, ",", "/")
|
||||||
end
|
end
|
||||||
if game.is_valid_sprite_path(sprite) then
|
if game.is_valid_sprite_path(sprite) then
|
||||||
children[i] = {
|
children[#children + 1] = {
|
||||||
type = "sprite-button",
|
type = "sprite-button",
|
||||||
enabled = false,
|
enabled = false,
|
||||||
style = "ltnm_small_slot_button_" .. color,
|
style = "ltnm_small_slot_button_" .. color,
|
||||||
@@ -61,7 +61,6 @@ function util.slot_table_build(manifest, color)
|
|||||||
"\n"..format.number(count),
|
"\n"..format.number(count),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
i = i + 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return children
|
return children
|
||||||
|
|||||||
@@ -471,7 +471,7 @@ function reset_stop_layout(map_data, stop, is_station_or_refueler, forbidden_ent
|
|||||||
local wagon_number = 0
|
local wagon_number = 0
|
||||||
for i = 1, 112 do
|
for i = 1, 112 do
|
||||||
local rail, rail_direction, rail_connection_direction = pre_rail.get_connected_rail({rail_direction = rail_direction_from_stop, rail_connection_direction = defines.rail_connection_direction.straight})
|
local rail, rail_direction, rail_connection_direction = pre_rail.get_connected_rail({rail_direction = rail_direction_from_stop, rail_connection_direction = defines.rail_connection_direction.straight})
|
||||||
if not rail or rail_connection_direction ~= defines.rail_connection_direction.straight or not rail.valid then
|
if not rail or not rail.valid then
|
||||||
is_break = true
|
is_break = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@@ -555,6 +555,10 @@ function reset_stop_layout(map_data, stop, is_station_or_refueler, forbidden_ent
|
|||||||
end
|
end
|
||||||
search_area = area.move(search_area, area_delta)
|
search_area = area.move(search_area, area_delta)
|
||||||
end
|
end
|
||||||
|
if not rail_connection_direction ~= defines.rail_connection_direction.straight then
|
||||||
|
is_break = true
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
stop.layout_pattern = layout_pattern
|
stop.layout_pattern = layout_pattern
|
||||||
if is_station_or_refueler then
|
if is_station_or_refueler then
|
||||||
|
|||||||
@@ -103,12 +103,19 @@ data:extend({
|
|||||||
default_value = false,
|
default_value = false,
|
||||||
},
|
},
|
||||||
--{
|
--{
|
||||||
|
-- type = "bool-setting",
|
||||||
|
-- name = "cybersyn-disable-top-left-button",
|
||||||
|
-- setting_type = "runtime-player",
|
||||||
|
-- default_value = false,
|
||||||
|
-- order = "ea",
|
||||||
|
--},
|
||||||
|
--{
|
||||||
-- type = "int-setting",
|
-- type = "int-setting",
|
||||||
-- name = "cybersyn-history-length",
|
-- name = "cybersyn-history-length",
|
||||||
-- setting_type = "runtime-global",
|
-- setting_type = "runtime-global",
|
||||||
-- minimum_value = 10,
|
-- minimum_value = 10,
|
||||||
-- maximum_value = 1000,
|
-- maximum_value = 1000,
|
||||||
-- default_value = 50,
|
-- default_value = 50,
|
||||||
-- order = "ea",
|
-- order = "eb",
|
||||||
--},
|
--},
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user