mirror of
https://github.com/Xevion/project-cybersyn.git
synced 2025-12-10 10:08:18 -06:00
changed minor issues
This commit is contained in:
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")
|
||||
|
||||
|
||||
--- @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 = {}
|
||||
|
||||
|
||||
function manager.build(player, player_data)
|
||||
--- @param player LuaPlayer
|
||||
function manager.create(player)
|
||||
local widths = constants.gui["en"]
|
||||
---@type table<string, LuaGuiElement>
|
||||
local refs = {}
|
||||
|
||||
local _, window = gui.add(player.gui.screen, {
|
||||
gui.add(player.gui.screen, {
|
||||
{
|
||||
name = "manager_window",
|
||||
type = "frame",
|
||||
@@ -111,25 +66,25 @@ function manager.build(player, player_data)
|
||||
name = "manager_text_search_field",
|
||||
type = "textfield",
|
||||
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 = "label", style = "caption_label", caption = { "gui.ltnm-network-id-label" } },
|
||||
{
|
||||
name = "manager_network_id_field",
|
||||
name = "manager_network_mask_field",
|
||||
type = "textfield",
|
||||
style_mods = { width = 120 },
|
||||
numeric = true,
|
||||
allow_negative = true,
|
||||
clear_and_focus_on_right_click = true,
|
||||
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" } },
|
||||
{
|
||||
name = "manager_surface_dropdown",
|
||||
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",
|
||||
type = "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
|
||||
window.force_auto_center()
|
||||
refs.manager_titlebar.drag_target = refs.manager_window
|
||||
refs.manager_window.force_auto_center()
|
||||
|
||||
return refs
|
||||
end
|
||||
|
||||
--- @param map_data MapData
|
||||
--- @param player LuaPlayer
|
||||
--- @param refs table<string, LuaGuiElement>
|
||||
function manager.destroy(player, refs)
|
||||
refs.manager_window.destroy()
|
||||
|
||||
player.set_shortcut_toggled("ltnm-toggle-gui", false)
|
||||
player.set_shortcut_available("ltnm-toggle-gui", false)
|
||||
--- @param player_data PlayerData
|
||||
function manager.update(map_data, player, player_data)
|
||||
local tab = trains_tab.build(map_data, player_data)
|
||||
gui.add(_, tab, player_data.refs)
|
||||
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_data PlayerData
|
||||
--- @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.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)
|
||||
end
|
||||
|
||||
|
||||
--- @param player LuaPlayer
|
||||
--- @param player_data PlayerData
|
||||
--- @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
|
||||
return
|
||||
end
|
||||
@@ -195,86 +174,76 @@ function manager.close(player, player_data, refs)
|
||||
player.set_shortcut_toggled("ltnm-toggle-gui", false)
|
||||
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
|
||||
|
||||
|
||||
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_data PlayerData
|
||||
--- @param refs table<string, LuaGuiElement>
|
||||
function manager.handle.recenter(player, player_data, refs)
|
||||
refs.window.force_auto_center()
|
||||
refs.window.force_auto_center()
|
||||
end
|
||||
|
||||
--- @param player LuaPlayer
|
||||
--- @param player_data PlayerData
|
||||
--- @param refs table<string, LuaGuiElement>
|
||||
function manager.handle.toggle_auto_refresh(player, player_data, refs)
|
||||
player_data.auto_refresh = not player_data.auto_refresh
|
||||
toggle_fab(refs.manager_refresh_button, "ltnm_refresh", 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)
|
||||
end
|
||||
|
||||
--- @param player LuaPlayer
|
||||
--- @param player_data PlayerData
|
||||
--- @param refs table<string, LuaGuiElement>
|
||||
function manager.handle.toggle_pinned(player, player_data, refs)
|
||||
player_data.pinned = not player_data.pinned
|
||||
toggle_fab(refs.manager_pin_button, "ltnm_pin", player_data.pinned)
|
||||
player_data.pinned = not player_data.pinned
|
||||
toggle_fab(refs.manager_pin_button, "ltnm_pin", player_data.pinned)
|
||||
end
|
||||
|
||||
--- @param player LuaPlayer
|
||||
--- @param player_data PlayerData
|
||||
--- @param refs table<string, LuaGuiElement>
|
||||
--- @param e GuiEventData
|
||||
function manager.handle.update_text_search_query(player, player_data, refs, e)
|
||||
local query = e.text
|
||||
-- Input sanitization
|
||||
for pattern, replacement in pairs(constants.input_sanitizers) do
|
||||
query = string.gsub(query, pattern, replacement)
|
||||
end
|
||||
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
|
||||
function manager.handle.update_text_search(player, player_data, refs, e)
|
||||
local query = e.text
|
||||
-- Input sanitization
|
||||
for pattern, replacement in pairs(constants.input_sanitizers) do
|
||||
query = string.gsub(query, pattern, replacement)
|
||||
end
|
||||
player_data.search_query = query
|
||||
end
|
||||
|
||||
|
||||
--- @param player LuaPlayer
|
||||
--- @param player_data PlayerData
|
||||
--- @param refs table<string, LuaGuiElement>
|
||||
function manager.handle.update_network_id_query(player, player_data, refs)
|
||||
Gui.state.network_id = tonumber(Gui.refs.toolbar.network_id_field.text) or -1
|
||||
Gui:schedule_update()
|
||||
function manager.handle.update_network_name(player, player_data, refs)
|
||||
local signal = refs.manager_network_name.elem_value
|
||||
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
|
||||
|
||||
|
||||
gui.add_handlers(manager.handle, manager.wrapper)
|
||||
|
||||
return manager
|
||||
|
||||
@@ -1,146 +1,226 @@
|
||||
local format = require("__flib__.format")
|
||||
local gui = require("__flib__.gui-lite")
|
||||
|
||||
local constants = require("constants")
|
||||
local util = require("scripts.gui.util")
|
||||
|
||||
local templates = require("templates")
|
||||
local templates = require("scripts.gui.templates")
|
||||
|
||||
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 search_query = player_data.search_query
|
||||
local search_network_flag = player_data.network_flag
|
||||
local search_network = player_data.network
|
||||
local search_item = player_data.search_item
|
||||
local search_network_name = player_data.search_network_name
|
||||
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
|
||||
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
|
||||
train_list[1] = {
|
||||
type = "label",
|
||||
style = "ltnm_semibold_label",
|
||||
caption = { "gui.ltnm-no-trains" },
|
||||
ref = { "trains", "warning_label" },
|
||||
}
|
||||
else
|
||||
local start, finish, step
|
||||
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]
|
||||
for idx, train_id in ipairs(trains_sorted) do
|
||||
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
|
||||
true
|
||||
then
|
||||
local color = gui_idx % 2 == 0 and "dark" or "light"
|
||||
train_list[gui_idx] = {
|
||||
type = "frame",
|
||||
style = "ltnm_table_row_frame_" .. color,
|
||||
children = {
|
||||
{
|
||||
type = "frame",
|
||||
style = "ltnm_table_inset_frame_" .. color,
|
||||
children = {
|
||||
type = "minimap",
|
||||
style = "ltnm_train_minimap",
|
||||
{ type = "label", style = "ltnm_minimap_label" },
|
||||
{
|
||||
type = "button",
|
||||
style = "ltnm_train_minimap_button",
|
||||
tooltip = { "gui.ltnm-open-train-gui" },
|
||||
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"),
|
||||
},
|
||||
local color = idx % 2 == 0 and "dark" or "light"
|
||||
train_list[idx] = {
|
||||
type = "frame",
|
||||
style = "ltnm_table_row_frame_" .. color,
|
||||
children = {
|
||||
{
|
||||
type = "frame",
|
||||
style = "ltnm_table_inset_frame_" .. color,
|
||||
children = {
|
||||
type = "minimap",
|
||||
style = "ltnm_train_minimap",
|
||||
{ type = "label", style = "ltnm_minimap_label" },
|
||||
{
|
||||
type = "button",
|
||||
style = "ltnm_train_minimap_button",
|
||||
tooltip = { "gui.ltnm-open-train-gui" },
|
||||
elem_mods = { entity = get_any_train_entity(train.entity) },
|
||||
handler = trains_tab.handle.open_train_gui, --on_click
|
||||
tags = { train_id = train_id },
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
gui_idx = gui_idx + 1
|
||||
end
|
||||
{
|
||||
type = "label",
|
||||
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
|
||||
|
||||
return {
|
||||
tab = {
|
||||
name = "trains_tab",
|
||||
type = "tab",
|
||||
caption = #trains_sorted == 0 and { "gui.ltnm-trains" } or { "gui.ltnm-trains", #train_list },
|
||||
badge_text = misc.delineate_number(#ltn_data.sorted_trains.composition),
|
||||
ref = { "trains", "tab" },
|
||||
actions = {
|
||||
on_click = { gui = "main", action = "change_tab", tab = "trains" },
|
||||
},
|
||||
--badge_text = format.number(#ltn_data.sorted_trains.composition),
|
||||
handler = trains_tab.handle.change_tab, --on_click
|
||||
tags = { tab = "trains_tab" },
|
||||
},
|
||||
content = {
|
||||
name = "trains_content_frame",
|
||||
type = "frame",
|
||||
style = "ltnm_main_content_frame",
|
||||
direction = "vertical",
|
||||
ref = { "trains", "content_frame" },
|
||||
children = {
|
||||
{
|
||||
type = "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", "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", "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",
|
||||
style = "ltnm_warning_flow",
|
||||
visible = false,
|
||||
ref = { "trains", "warning_flow" },
|
||||
children = train_list,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -38,8 +38,8 @@ end
|
||||
--- @param color string
|
||||
--- @return GuiElemDef[]
|
||||
function util.slot_table_build(manifest, color)
|
||||
---@type GuiElemDef[]
|
||||
local children = {}
|
||||
local i = 1
|
||||
for _, item in pairs(manifest) do
|
||||
local name = item.name
|
||||
local sprite
|
||||
@@ -49,7 +49,7 @@ function util.slot_table_build(manifest, color)
|
||||
sprite = string.gsub(name, ",", "/")
|
||||
end
|
||||
if game.is_valid_sprite_path(sprite) then
|
||||
children[i] = {
|
||||
children[#children + 1] = {
|
||||
type = "sprite-button",
|
||||
enabled = false,
|
||||
style = "ltnm_small_slot_button_" .. color,
|
||||
@@ -61,7 +61,6 @@ function util.slot_table_build(manifest, color)
|
||||
"\n"..format.number(count),
|
||||
},
|
||||
}
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
return children
|
||||
|
||||
Reference in New Issue
Block a user