Update all code styles

This commit is contained in:
Cooldude2606
2024-09-28 01:56:54 +01:00
parent 5e2a62ab27
commit 292c1a1b68
194 changed files with 9817 additions and 9703 deletions

View File

@@ -132,13 +132,12 @@ local Roles = _C.opt_require("modules.exp_legacy.expcore.roles")
local Event = _C.opt_require("modules/exp_legacy/utils/event")
if Roles and Event then
Event.add(Roles.events.on_role_assigned, function(e)
Gui.update_top_flow(game.get_player(e.player_index))
end)
Event.add(Roles.events.on_role_unassigned, function(e)
Gui.update_top_flow(game.get_player(e.player_index))
end)
Event.add(Roles.events.on_role_assigned, function(e)
Gui.update_top_flow(game.get_player(e.player_index))
end)
Event.add(Roles.events.on_role_unassigned, function(e)
Gui.update_top_flow(game.get_player(e.player_index))
end)
end
return Gui
return Gui

View File

@@ -12,61 +12,61 @@ local Event = require("modules/exp_legacy/utils/event")
--- Button which toggles the top flow elements, version which shows inside the top flow when top flow is visible
-- @element hide_top_flow
local hide_top_flow =
Gui.element{
type = 'sprite-button',
sprite = 'utility/preset',
style = 'tool_button',
tooltip = {'gui_util.button_tooltip'},
name = Gui.unique_static_name
}
:style{
padding = -2,
width = 18,
height = 36
}
:on_click(function(player, _,_)
Gui.toggle_top_flow(player, false)
end)
Gui.element{
type = "sprite-button",
sprite = "utility/preset",
style = "tool_button",
tooltip = { "gui_util.button_tooltip" },
name = Gui.unique_static_name,
}
:style{
padding = -2,
width = 18,
height = 36,
}
:on_click(function(player, _, _)
Gui.toggle_top_flow(player, false)
end)
Gui.core_defines.hide_top_flow = hide_top_flow
--- Button which toggles the top flow elements, version which shows inside the left flow when top flow is hidden
-- @element show_top_flow
local show_top_flow =
Gui.element{
type = 'sprite-button',
sprite = 'utility/preset',
style = 'tool_button',
tooltip = {'gui_util.button_tooltip'},
name = Gui.unique_static_name
}
:style{
padding = -2,
width = 18,
height = 20
}
:on_click(function(player, _,_)
Gui.toggle_top_flow(player, true)
end)
Gui.element{
type = "sprite-button",
sprite = "utility/preset",
style = "tool_button",
tooltip = { "gui_util.button_tooltip" },
name = Gui.unique_static_name,
}
:style{
padding = -2,
width = 18,
height = 20,
}
:on_click(function(player, _, _)
Gui.toggle_top_flow(player, true)
end)
Gui.core_defines.show_top_flow = show_top_flow
--- Button which hides the elements in the left flow, shows inside the left flow when frames are visible
-- @element hide_left_flow
local hide_left_flow =
Gui.element{
type = 'sprite-button',
sprite = 'utility/close_black',
style = 'tool_button',
tooltip = {'expcore-gui.left-button-tooltip'},
name = Gui.unique_static_name
}
:style{
padding = -3,
width = 18,
height = 20
}
:on_click(function(player, _,_)
Gui.hide_left_flow(player)
end)
Gui.element{
type = "sprite-button",
sprite = "utility/close_black",
style = "tool_button",
tooltip = { "expcore-gui.left-button-tooltip" },
name = Gui.unique_static_name,
}
:style{
padding = -3,
width = 18,
height = 20,
}
:on_click(function(player, _, _)
Gui.hide_left_flow(player)
end)
Gui.core_defines.hide_left_flow = hide_left_flow
--- Draw the core elements when a player joins the game
@@ -80,10 +80,10 @@ Event.add(defines.events.on_player_created, function(event)
-- Draw the left flow
local left_flow = Gui.get_left_flow(player)
local button_flow = left_flow.add{ type = 'flow', name = 'gui_core_buttons', direction = 'vertical' }
local button_flow = left_flow.add{ type = "flow", name = "gui_core_buttons", direction = "vertical" }
local show_top = show_top_flow(button_flow)
local hide_left = hide_left_flow(button_flow)
show_top.visible = false
hide_left.visible = false
Gui.draw_left_flow(player)
end)
end)

View File

@@ -24,19 +24,19 @@ local alignment = Gui.alignment(element, 'example_center_top_alignment', 'center
]]
Gui.alignment =
Gui.element(function(_, parent, name, _,_)
return parent.add{
name = name or 'alignment',
type = 'flow',
}
end)
:style(function(style, _,_, horizontal_align, vertical_align)
style.padding = {1, 2}
style.vertical_align = vertical_align or 'center'
style.horizontal_align = horizontal_align or 'right'
style.vertically_stretchable = style.vertical_align ~= 'center'
style.horizontally_stretchable = style.horizontal_align ~= 'center'
end)
Gui.element(function(_, parent, name, _, _)
return parent.add{
name = name or "alignment",
type = "flow",
}
end)
:style(function(style, _, _, horizontal_align, vertical_align)
style.padding = { 1, 2 }
style.vertical_align = vertical_align or "center"
style.horizontal_align = horizontal_align or "right"
style.vertically_stretchable = style.vertical_align ~= "center"
style.horizontally_stretchable = style.horizontal_align ~= "center"
end)
--[[-- Draw a scroll pane that has a table inside of it
@element Gui.scroll_table
@@ -51,42 +51,42 @@ local scroll_table = Gui.scroll_table(element, 200, 3)
]]
Gui.scroll_table =
Gui.element(function(_, parent, height, column_count, name)
-- Draw the scroll
local scroll_pane =
parent.add{
name = name or 'scroll',
type = 'scroll-pane',
direction = 'vertical',
horizontal_scroll_policy = 'never',
vertical_scroll_policy = 'auto',
style = 'scroll_pane_under_subheader'
Gui.element(function(_, parent, height, column_count, name)
-- Draw the scroll
local scroll_pane =
parent.add{
name = name or "scroll",
type = "scroll-pane",
direction = "vertical",
horizontal_scroll_policy = "never",
vertical_scroll_policy = "auto",
style = "scroll_pane_under_subheader",
}
-- Set the style of the scroll pane
local scroll_style = scroll_pane.style
scroll_style.padding = { 1, 3 }
scroll_style.maximal_height = height
scroll_style.horizontally_stretchable = true
-- Draw the table
local scroll_table =
scroll_pane.add{
type = "table",
name = "table",
column_count = column_count,
}
-- Return the scroll table
return scroll_table
end)
:style{
padding = 0,
cell_padding = 0,
vertical_align = "center",
horizontally_stretchable = true,
}
-- Set the style of the scroll pane
local scroll_style = scroll_pane.style
scroll_style.padding = {1, 3}
scroll_style.maximal_height = height
scroll_style.horizontally_stretchable = true
-- Draw the table
local scroll_table =
scroll_pane.add{
type = 'table',
name = 'table',
column_count = column_count
}
-- Return the scroll table
return scroll_table
end)
:style{
padding = 0,
cell_padding = 0,
vertical_align = 'center',
horizontally_stretchable = true
}
--[[-- Used to add a frame with the header style, has the option for a right alignment flow for buttons
@element Gui.header
@tparam LuaGuiElement parent the parent element to which the header will be added
@@ -105,35 +105,35 @@ local header = Gui.header(
]]
Gui.header =
Gui.element(function(_, parent, caption, tooltip, add_alignment, name, label_name)
-- Draw the header
local header =
parent.add{
name = name or 'header',
type = 'frame',
style = 'subheader_frame'
}
Gui.element(function(_, parent, caption, tooltip, add_alignment, name, label_name)
-- Draw the header
local header =
parent.add{
name = name or "header",
type = "frame",
style = "subheader_frame",
}
-- Change the style of the header
local style = header.style
style.padding = {2, 4}
style.use_header_filler = false
style.horizontally_stretchable = true
-- Change the style of the header
local style = header.style
style.padding = { 2, 4 }
style.use_header_filler = false
style.horizontally_stretchable = true
-- Draw the caption label
if caption then
header.add{
name = label_name or 'header_label',
type = 'label',
style = 'frame_title',
caption = caption,
tooltip = tooltip
}
end
-- Draw the caption label
if caption then
header.add{
name = label_name or "header_label",
type = "label",
style = "frame_title",
caption = caption,
tooltip = tooltip,
}
end
-- Return either the header or the added alignment
return add_alignment and Gui.alignment(header) or header
end)
-- Return either the header or the added alignment
return add_alignment and Gui.alignment(header) or header
end)
--[[-- Used to add a frame with the footer style, has the option for a right alignment flow for buttons
@element Gui.footer
@@ -153,35 +153,35 @@ local footer = Gui.footer(
]]
Gui.footer =
Gui.element(function(_, parent, caption, tooltip, add_alignment, name)
-- Draw the header
local footer =
parent.add{
name = name or 'footer',
type = 'frame',
style = 'subfooter_frame'
}
Gui.element(function(_, parent, caption, tooltip, add_alignment, name)
-- Draw the header
local footer =
parent.add{
name = name or "footer",
type = "frame",
style = "subfooter_frame",
}
-- Change the style of the footer
local style = footer.style
style.padding = {2, 4}
style.use_header_filler = false
style.horizontally_stretchable = true
-- Change the style of the footer
local style = footer.style
style.padding = { 2, 4 }
style.use_header_filler = false
style.horizontally_stretchable = true
-- Draw the caption label
if caption then
footer.add{
name = 'footer_label',
type = 'label',
style = 'frame_title',
caption = caption,
tooltip = tooltip
}
end
-- Draw the caption label
if caption then
footer.add{
name = "footer_label",
type = "label",
style = "frame_title",
caption = caption,
tooltip = tooltip,
}
end
-- Return either the footer or the added alignment
return add_alignment and Gui.alignment(footer) or footer
end)
-- Return either the footer or the added alignment
return add_alignment and Gui.alignment(footer) or footer
end)
--[[-- Used for left frames to give them a nice boarder
@element Gui.container
@@ -194,29 +194,29 @@ local container = Gui.container(parent, 'my_container', 200)
]]
Gui.container =
Gui.element(function(_, parent, name, _)
-- Draw the external container
local frame =
parent.add{
name = name,
type = 'frame'
}
frame.style.horizontally_stretchable = false
Gui.element(function(_, parent, name, _)
-- Draw the external container
local frame =
parent.add{
name = name,
type = "frame",
}
frame.style.horizontally_stretchable = false
-- Return the container
return frame.add{
name = 'container',
type = 'frame',
direction = 'vertical',
style = 'inside_shallow_frame_packed'
}
end)
:style(function(style, element, _,width)
style.vertically_stretchable = false
local frame_style = element.parent.style
frame_style.padding = 2
frame_style.minimal_width = width
end)
-- Return the container
return frame.add{
name = "container",
type = "frame",
direction = "vertical",
style = "inside_shallow_frame_packed",
}
end)
:style(function(style, element, _, width)
style.vertically_stretchable = false
local frame_style = element.parent.style
frame_style.padding = 2
frame_style.minimal_width = width
end)
--[[-- Used to make a solid white bar in a gui
@element Gui.bar
@@ -228,19 +228,22 @@ local bar = Gui.bar(parent, 100)
]]
Gui.bar =
Gui.element(function(_, parent)
return parent.add{
type = 'progressbar',
size = 1,
value = 1
}
end)
:style(function(style, _,width)
style.height = 3
style.color = {r=255, g=255, b=255}
if width then style.width = width
else style.horizontally_stretchable = true end
end)
Gui.element(function(_, parent)
return parent.add{
type = "progressbar",
size = 1,
value = 1,
}
end)
:style(function(style, _, width)
style.height = 3
style.color = { r = 255, g = 255, b = 255 }
if width then
style.width = width
else
style.horizontally_stretchable = true
end
end)
--[[-- Used to make a label which is centered and of a certian size
@element Gui.centered_label
@@ -254,20 +257,20 @@ local label = Gui.centered_label(parent, 100, 'This is centered')
]]
Gui.centered_label =
Gui.element(function(_, parent, width, caption, tooltip)
local label = parent.add{
type = 'label',
caption = caption,
tooltip = tooltip,
}
Gui.element(function(_, parent, width, caption, tooltip)
local label = parent.add{
type = "label",
caption = caption,
tooltip = tooltip,
}
local style = label.style
style.horizontal_align = 'center'
style.single_line = false
style.width = width
local style = label.style
style.horizontal_align = "center"
style.single_line = false
style.width = width
return label
end)
return label
end)
--[[-- Used to make a title which has two bars on either side
@element Gui.title_label
@@ -281,18 +284,18 @@ local label = Gui.centered_label(parent, 100, 'This is centered')
]]
Gui.title_label =
Gui.element(function(_, parent, width, caption, tooltip)
local title_flow = parent.add{ type='flow' }
title_flow.style.vertical_align = 'center'
Gui.element(function(_, parent, width, caption, tooltip)
local title_flow = parent.add{ type = "flow" }
title_flow.style.vertical_align = "center"
Gui.bar(title_flow, width)
local title_label = title_flow.add{
type = 'label',
caption = caption,
tooltip = tooltip,
style = 'frame_title'
}
Gui.bar(title_flow)
Gui.bar(title_flow, width)
local title_label = title_flow.add{
type = "label",
caption = caption,
tooltip = tooltip,
style = "frame_title",
}
Gui.bar(title_flow)
return title_label
end)
return title_label
end)

View File

@@ -88,4 +88,4 @@ function Gui.sprite_style(size, padding, style)
style.height = size
style.width = size
return style
end
end

View File

@@ -4,7 +4,7 @@
]]
local Gui = require("modules.exp_legacy.expcore.gui.prototype")
local mod_gui = require 'mod-gui'
local mod_gui = require "mod-gui"
local hide_left_flow = Gui.core_defines.hide_left_flow.name
@@ -12,7 +12,7 @@ local hide_left_flow = Gui.core_defines.hide_left_flow.name
-- @section leftFlow
-- Triggered when a user changed the visibility of a left flow element by clicking a button
Gui.events.on_visibility_changed_by_click = 'on_visibility_changed_by_click'
Gui.events.on_visibility_changed_by_click = "on_visibility_changed_by_click"
--- Contains the uids of the elements that will shown on the left flow and their join functions
-- @table left_elements
@@ -68,7 +68,7 @@ function Gui.left_toolbar_button(sprite, tooltip, element_define, authenticator)
button:raise_event{
name = Gui.events.on_visibility_changed_by_click,
element = Gui.get_top_element(player, button),
state = Gui.toggle_left_element(player, element_define)
state = Gui.toggle_left_element(player, element_define),
}
end)
@@ -90,8 +90,8 @@ function Gui.inject_left_flow_order(provider)
Gui.get_left_flow_order = provider
local debug_info = debug.getinfo(2, "Sn")
local file_name = debug_info.short_src:sub(10, -5)
local func_name = debug_info.name or ("<anonymous:"..debug_info.linedefined..">")
Gui._left_flow_order_src = file_name..":"..func_name
local func_name = debug_info.name or ("<anonymous:" .. debug_info.linedefined .. ">")
Gui._left_flow_order_src = file_name .. ":" .. func_name
end
--[[-- Draw all the left elements onto the left flow, internal use only with on join
@@ -121,17 +121,17 @@ function Gui.draw_left_flow(player)
end, debug.traceback)
if not draw_success then
log('There as been an error with an element draw function: '..element_define.defined_at..'\n\t'..left_element)
log("There as been an error with an element draw function: " .. element_define.defined_at .. "\n\t" .. left_element)
goto continue
end
-- Check if it should be open by default
local open_on_join = element_define.open_on_join
local visible = type(open_on_join) == 'boolean' and open_on_join or false
if type(open_on_join) == 'function' then
local visible = type(open_on_join) == "boolean" and open_on_join or false
if type(open_on_join) == "function" then
local success, err = xpcall(open_on_join, debug.traceback, player)
if not success then
log('There as been an error with an open on join hander for a gui element:\n\t'..err)
log("There as been an error with an open on join hander for a gui element:\n\t" .. err)
goto continue
end
visible = err
@@ -166,7 +166,7 @@ function Gui.reorder_left_flow(player)
-- Reorder the elements, index 1 is the core ui buttons so +1 is required
for index, element_define in ipairs(flow_order) do
local element = left_flow[element_define.name]
left_flow.swap_children(index+1, element.get_index_in_parent())
left_flow.swap_children(index + 1, element.get_index_in_parent())
end
end
@@ -188,6 +188,7 @@ function Gui.update_left_flow(player)
return true
end
end
hide_button.visible = false
return false
end
@@ -220,7 +221,7 @@ function Gui.hide_left_flow(player)
element_define.toolbar_button:raise_event{
name = Gui.events.on_visibility_changed_by_click,
element = button,
state = false
state = false,
}
end
end
@@ -272,4 +273,4 @@ function Gui.toggle_left_element(player, element_define, state)
Gui.toggle_toolbar_button(player, element_define.toolbar_button, state)
end
return state
end
end

View File

@@ -23,7 +23,7 @@ local Gui = {
--- The prototype used to store the functions of an element define
_prototype_element = {},
--- The prototype metatable applied to new element defines
_mt_element = {}
_mt_element = {},
}
--- Allow access to the element prototype methods
@@ -37,14 +37,14 @@ function Gui._mt_element.__call(self, parent, ...)
-- Asserts to catch common errors
if element then
if self.name and self.name ~= element.name then
error("Static name \""..self.name.."\" expected but got: "..tostring(element.name))
error("Static name \"" .. self.name .. "\" expected but got: " .. tostring(element.name))
end
local event_triggers = element.tags and element.tags.ExpGui_event_triggers
if event_triggers and table.array_contains(event_triggers, self.uid) then
error("Element::triggers_events should not be called on the value you return from the definition")
end
elseif self.name then
error("Static name \""..self.name.."\" expected but no element was returned from the definition")
error("Static name \"" .. self.name .. "\" expected but no element was returned from the definition")
end
-- Register events by default, but allow skipping them
@@ -59,8 +59,8 @@ end
local function get_defined_at(level)
local debug_info = debug.getinfo(level, "Sn")
local file_name = debug_info.short_src:sub(10, -5)
local func_name = debug_info.name or ("<anonymous:"..debug_info.linedefined..">")
return file_name..":"..func_name
local func_name = debug_info.name or ("<anonymous:" .. debug_info.linedefined .. ">")
return file_name .. ":" .. func_name
end
--- Element Define.
@@ -115,19 +115,20 @@ function Gui.element(element_define)
local uid = Gui.uid + 1
Gui.uid = uid
element.uid = uid
Gui.debug_info[uid] = { draw = 'None', style = 'None', events = {} }
Gui.debug_info[uid] = { draw = "None", style = "None", events = {} }
-- Add the definition function
if type(element_define) == 'table' then
if type(element_define) == "table" then
Gui.debug_info[uid].draw = element_define
if element_define.name == Gui.unique_static_name then
element_define.name = "ExpGui_"..tostring(uid)
element_define.name = "ExpGui_" .. tostring(uid)
end
for k, v in pairs(element_define) do
if element[k] == nil then
element[k] = v
end
end
element._draw = function(_, parent)
return parent.add(element_define)
end
@@ -183,7 +184,7 @@ end)
function Gui._prototype_element:style(style_define)
_C.error_if_runtime()
-- Add the definition function
if type(style_define) == 'table' then
if type(style_define) == "table" then
Gui.debug_info[self.uid].style = style_define
self._style = function(style)
for key, value in pairs(style_define) do
@@ -206,7 +207,7 @@ end
function Gui._prototype_element:static_name(name)
_C.error_if_runtime()
if name == Gui.unique_static_name then
self.name = "ExpGui_"..tostring(self.uid)
self.name = "ExpGui_" .. tostring(self.uid)
else
self.name = name
end
@@ -295,7 +296,7 @@ function Gui._prototype_element:raise_event(event)
local success, err = xpcall(handler, debug.traceback, player, element, event)
if not success then
error('There as been an error with an event handler for a gui element:\n\t'..err)
error("There as been an error with an event handler for a gui element:\n\t" .. err)
end
return self
end
@@ -328,84 +329,84 @@ end
-- @tparam function handler the event handler which will be called
-- @usage element_define:on_open(function(event)
-- event.player.print(table.inspect(event))
--end)
-- end)
Gui._prototype_element.on_open = event_handler_factory(defines.events.on_gui_opened)
--- Called when the player closes the GUI they have open.
-- @tparam function handler the event handler which will be called
-- @usage element_define:on_close(function(event)
-- event.player.print(table.inspect(event))
--end)
-- end)
Gui._prototype_element.on_close = event_handler_factory(defines.events.on_gui_closed)
--- Called when LuaGuiElement is clicked.
-- @tparam function handler the event handler which will be called
-- @usage element_define:on_click(function(event)
-- event.player.print(table.inspect(event))
--end)
-- end)
Gui._prototype_element.on_click = event_handler_factory(defines.events.on_gui_click)
--- Called when a LuaGuiElement is confirmed, for example by pressing Enter in a textfield.
-- @tparam function handler the event handler which will be called
-- @usage element_define:on_confirmed(function(event)
-- event.player.print(table.inspect(event))
--end)
-- end)
Gui._prototype_element.on_confirmed = event_handler_factory(defines.events.on_gui_confirmed)
--- Called when LuaGuiElement checked state is changed (related to checkboxes and radio buttons).
-- @tparam function handler the event handler which will be called
-- @usage element_define:on_checked_changed(function(event)
-- event.player.print(table.inspect(event))
--end)
-- end)
Gui._prototype_element.on_checked_changed = event_handler_factory(defines.events.on_gui_checked_state_changed)
--- Called when LuaGuiElement element value is changed (related to choose element buttons).
-- @tparam function handler the event handler which will be called
-- @usage element_define:on_elem_changed(function(event)
-- event.player.print(table.inspect(event))
--end)
-- end)
Gui._prototype_element.on_elem_changed = event_handler_factory(defines.events.on_gui_elem_changed)
--- Called when LuaGuiElement element location is changed (related to frames in player.gui.screen).
-- @tparam function handler the event handler which will be called
-- @usage element_define:on_location_changed(function(event)
-- event.player.print(table.inspect(event))
--end)
-- end)
Gui._prototype_element.on_location_changed = event_handler_factory(defines.events.on_gui_location_changed)
--- Called when LuaGuiElement selected tab is changed (related to tabbed-panes).
-- @tparam function handler the event handler which will be called
-- @usage element_define:on_tab_changed(function(event)
-- event.player.print(table.inspect(event))
--end)
-- end)
Gui._prototype_element.on_tab_changed = event_handler_factory(defines.events.on_gui_selected_tab_changed)
--- Called when LuaGuiElement selection state is changed (related to drop-downs and listboxes).
-- @tparam function handler the event handler which will be called
-- @usage element_define:on_selection_changed(function(event)
-- event.player.print(table.inspect(event))
--end)
-- end)
Gui._prototype_element.on_selection_changed = event_handler_factory(defines.events.on_gui_selection_state_changed)
--- Called when LuaGuiElement switch state is changed (related to switches).
-- @tparam function handler the event handler which will be called
-- @usage element_define:on_switch_changed(function(event)
-- event.player.print(table.inspect(event))
--end)
-- end)
Gui._prototype_element.on_switch_changed = event_handler_factory(defines.events.on_gui_switch_state_changed)
--- Called when LuaGuiElement text is changed by the player.
-- @tparam function handler the event handler which will be called
-- @usage element_define:on_text_changed(function(event)
-- event.player.print(table.inspect(event))
--end)
-- end)
Gui._prototype_element.on_text_changed = event_handler_factory(defines.events.on_gui_text_changed)
--- Called when LuaGuiElement slider value is changed (related to the slider element).
-- @tparam function handler the event handler which will be called
-- @usage element_define:on_value_changed(function(event)
-- event.player.print(table.inspect(event))
--end)
-- end)
Gui._prototype_element.on_value_changed = event_handler_factory(defines.events.on_gui_value_changed)
-- Module return

View File

@@ -4,7 +4,7 @@
]]
local Gui = require("modules.exp_legacy.expcore.gui.prototype")
local mod_gui = require 'mod-gui' --- @dep mod-gui
local mod_gui = require "mod-gui" --- @dep mod-gui
local toolbar_button_size = 36
local hide_top_flow = Gui.core_defines.hide_top_flow.name
@@ -14,7 +14,7 @@ local show_top_flow = Gui.core_defines.show_top_flow.name
-- @section topFlow
-- Triggered when a user changed the visibility of a left flow element by clicking a button
Gui.events.on_toolbar_button_toggled = 'on_toolbar_button_toggled'
Gui.events.on_toolbar_button_toggled = "on_toolbar_button_toggled"
--- Contains the uids of the elements that will shown on the top flow and their auth functions
-- @table top_elements
@@ -26,7 +26,7 @@ Gui.top_flow_button_style = mod_gui.button_style
--- The style that should be used for buttons on the top flow when their flow is visible
-- @field Gui.top_flow_button_toggled_style
Gui.top_flow_button_toggled_style = 'menu_button_continue'
Gui.top_flow_button_toggled_style = "menu_button_continue"
--[[-- Styles a top flow button depending on the state given
@tparam LuaGuiElement button the button element to style
@@ -40,7 +40,7 @@ Gui.toolbar_button_style(button, false)
]]
function Gui.toolbar_button_style(button, state, size)
---@cast button LuaGuiElement
--- @cast button LuaGuiElement
if state then
button.style = Gui.top_flow_button_toggled_style
else
@@ -108,8 +108,8 @@ function Gui.inject_top_flow_order(provider)
Gui.get_top_flow_order = provider
local debug_info = debug.getinfo(2, "Sn")
local file_name = debug_info.short_src:sub(10, -5)
local func_name = debug_info.name or ("<anonymous:"..debug_info.linedefined..">")
Gui._top_flow_order_src = file_name..":"..func_name
local func_name = debug_info.name or ("<anonymous:" .. debug_info.linedefined .. ">")
Gui._top_flow_order_src = file_name .. ":" .. func_name
end
--[[-- Updates the visible state of all the elements on the players top flow, uses authenticator
@@ -137,12 +137,12 @@ function Gui.update_top_flow(player)
if not element then
element = element_define(top_flow)
else
top_flow.swap_children(index+1, element.get_index_in_parent())
top_flow.swap_children(index + 1, element.get_index_in_parent())
end
-- Set the visible state
local allowed = element_define.authenticator
if type(allowed) == 'function' then allowed = allowed(player) end
if type(allowed) == "function" then allowed = allowed(player) end
element.visible = allowed or false
-- If its not visible and there is a left element, then hide it
@@ -176,7 +176,7 @@ function Gui.reorder_top_flow(player)
-- Reorder the elements, index 1 is the core ui buttons so +1 is required
for index, element_define in ipairs(flow_order) do
local element = top_flow[element_define.name]
top_flow.swap_children(index+1, element.get_index_in_parent())
top_flow.swap_children(index + 1, element.get_index_in_parent())
end
end
@@ -243,7 +243,7 @@ function Gui.toggle_toolbar_button(player, element_define, state)
name = Gui.events.on_toolbar_button_toggled,
element = toolbar_button,
player = player,
state = state
state = state,
}
return state
end
@@ -262,18 +262,18 @@ end)
]]
function Gui.toolbar_button(sprite, tooltip, authenticator)
return Gui.element{
type = 'sprite-button',
sprite = sprite,
tooltip = tooltip,
style = Gui.top_flow_button_style,
name = Gui.unique_static_name
}
:style{
minimal_width = toolbar_button_size,
height = toolbar_button_size,
padding = -2
}
:add_to_top_flow(authenticator)
type = "sprite-button",
sprite = sprite,
tooltip = tooltip,
style = Gui.top_flow_button_style,
name = Gui.unique_static_name,
}
:style{
minimal_width = toolbar_button_size,
height = toolbar_button_size,
padding = -2,
}
:add_to_top_flow(authenticator)
end
--[[-- Creates a toggle button on the top flow with consistent styling
@@ -293,23 +293,23 @@ end)
]]
function Gui.toolbar_toggle_button(sprite, tooltip, authenticator)
local button =
Gui.element{
type = 'sprite-button',
sprite = sprite,
tooltip = tooltip,
style = Gui.top_flow_button_style,
name = Gui.unique_static_name
}
:style{
minimal_width = toolbar_button_size,
height = toolbar_button_size,
padding = -2
}
:add_to_top_flow(authenticator)
Gui.element{
type = "sprite-button",
sprite = sprite,
tooltip = tooltip,
style = Gui.top_flow_button_style,
name = Gui.unique_static_name,
}
:style{
minimal_width = toolbar_button_size,
height = toolbar_button_size,
padding = -2,
}
:add_to_top_flow(authenticator)
button:on_click(function(player, _, _)
Gui.toggle_toolbar_button(player, button)
end)
return button
end
end