mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 20:41:41 +09:00
Fixed Existing Lua Check Errors
This commit is contained in:
@@ -18,7 +18,7 @@ Gui.element{
|
||||
@usage-- Making a factory function for a button which is contained within a flow
|
||||
-- This method is for when you still want to register event handlers but cant use the table method
|
||||
local example_flow_with_button =
|
||||
Gui.element(function(event_trigger,parent,...)
|
||||
Gui.element(function(event_trigger, parent, ...)
|
||||
-- ... shows that all other arguments from the factory call are passed to this function
|
||||
-- Here we are adding a flow which we will then later add a button to
|
||||
local flow =
|
||||
@@ -60,7 +60,7 @@ Gui.element{
|
||||
caption = 'Example Button',
|
||||
style = 'forward_button' -- factorio styles can be applied here
|
||||
}
|
||||
:style(function(style,element,...)
|
||||
:style(function(style, element, ...)
|
||||
-- style is the current style object for the elemenent
|
||||
-- element is the element that is being changed
|
||||
-- ... shows that all other arguments from the factory call are passed to this function
|
||||
@@ -76,7 +76,7 @@ Gui.element{
|
||||
type = 'button',
|
||||
caption = 'Example Button'
|
||||
}
|
||||
:on_click(function(player,element,event)
|
||||
:on_click(function(player, element, event)
|
||||
-- player is the player who interacted with the element to cause the event
|
||||
-- element is a refrence to the element which caused the event
|
||||
-- event is a raw refrence to the event data if player and element are not enough
|
||||
@@ -98,21 +98,21 @@ Gui.element{
|
||||
width = 18,
|
||||
height = 20
|
||||
}
|
||||
:on_click(function(player,_,_)
|
||||
:on_click(function(player, _,_)
|
||||
Gui.hide_left_flow(player)
|
||||
end)
|
||||
|
||||
@usage-- Eample from defines, Gui.alignment, called like: Gui.alignment(parent, name, horizontal_align, vertical_align)
|
||||
-- Notice how _ are used to blank arguments that are not needed in that context and how they line up with above
|
||||
Gui.alignment =
|
||||
Gui.element(function(_,parent,name,_,_)
|
||||
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(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'
|
||||
|
||||
@@ -23,7 +23,7 @@ Gui.element{
|
||||
width = 18,
|
||||
height = 36
|
||||
}
|
||||
:on_click(function(player,_,_)
|
||||
:on_click(function(player, _,_)
|
||||
Gui.toggle_top_flow(player)
|
||||
end)
|
||||
Gui.core_defines.hide_top_flow = hide_top_flow
|
||||
@@ -42,7 +42,7 @@ Gui.element{
|
||||
width = 18,
|
||||
height = 20
|
||||
}
|
||||
:on_click(function(player,_,_)
|
||||
:on_click(function(player, _,_)
|
||||
Gui.toggle_top_flow(player)
|
||||
end)
|
||||
Gui.core_defines.show_top_flow = show_top_flow
|
||||
@@ -61,13 +61,13 @@ Gui.element{
|
||||
width = 18,
|
||||
height = 20
|
||||
}
|
||||
:on_click(function(player,_,_)
|
||||
: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
|
||||
Event.add(defines.events.on_player_created,function(event)
|
||||
Event.add(defines.events.on_player_created, function(event)
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
-- Draw the top flow
|
||||
|
||||
@@ -17,21 +17,21 @@ local Gui = require 'expcore.gui.prototype'
|
||||
@treturn LuaGuiElement the alignment flow that was created
|
||||
|
||||
@usage-- Adding a right align flow
|
||||
local alignment = Gui.alignment(element,'example_right_alignment')
|
||||
local alignment = Gui.alignment(element, 'example_right_alignment')
|
||||
|
||||
@usage-- Adding a horizontal center and top align flow
|
||||
local alignment = Gui.alignment(element,'example_center_top_alignment','center','top')
|
||||
local alignment = Gui.alignment(element, 'example_center_top_alignment', 'center', 'top')
|
||||
|
||||
]]
|
||||
Gui.alignment =
|
||||
Gui.element(function(_,parent,name,_,_)
|
||||
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(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'
|
||||
@@ -47,11 +47,11 @@ end)
|
||||
@treturn LuaGuiElement the table that was created
|
||||
|
||||
@usage-- Adding a scroll table with max height of 200 and column count of 3
|
||||
local scroll_table = Gui.scroll_table(element,200,3)
|
||||
local scroll_table = Gui.scroll_table(element, 200, 3)
|
||||
|
||||
]]
|
||||
Gui.scroll_table =
|
||||
Gui.element(function(_,parent,height,column_count,name)
|
||||
Gui.element(function(_, parent, height, column_count, name)
|
||||
-- Draw the scroll
|
||||
local scroll_pane =
|
||||
parent.add{
|
||||
@@ -65,7 +65,7 @@ Gui.element(function(_,parent,height,column_count,name)
|
||||
|
||||
-- Set the style of the scroll pane
|
||||
local scroll_style = scroll_pane.style
|
||||
scroll_style.padding = {1,3}
|
||||
scroll_style.padding = {1, 3}
|
||||
scroll_style.maximal_height = height
|
||||
scroll_style.horizontally_stretchable = true
|
||||
|
||||
@@ -105,7 +105,7 @@ local header = Gui.header(
|
||||
|
||||
]]
|
||||
Gui.header =
|
||||
Gui.element(function(_,parent,caption,tooltip,add_alignment,name)
|
||||
Gui.element(function(_, parent, caption, tooltip, add_alignment, name)
|
||||
-- Draw the header
|
||||
local header =
|
||||
parent.add{
|
||||
@@ -116,7 +116,7 @@ Gui.element(function(_,parent,caption,tooltip,add_alignment,name)
|
||||
|
||||
-- Change the style of the header
|
||||
local style = header.style
|
||||
style.padding = {2,4}
|
||||
style.padding = {2, 4}
|
||||
style.use_header_filler = false
|
||||
style.horizontally_stretchable = true
|
||||
|
||||
@@ -153,7 +153,7 @@ local footer = Gui.footer(
|
||||
|
||||
]]
|
||||
Gui.footer =
|
||||
Gui.element(function(_,parent,caption,tooltip,add_alignment,name)
|
||||
Gui.element(function(_, parent, caption, tooltip, add_alignment, name)
|
||||
-- Draw the header
|
||||
local footer =
|
||||
parent.add{
|
||||
@@ -164,7 +164,7 @@ Gui.element(function(_,parent,caption,tooltip,add_alignment,name)
|
||||
|
||||
-- Change the style of the footer
|
||||
local style = footer.style
|
||||
style.padding = {2,4}
|
||||
style.padding = {2, 4}
|
||||
style.use_header_filler = false
|
||||
style.horizontally_stretchable = true
|
||||
|
||||
@@ -190,11 +190,11 @@ end)
|
||||
@tparam number width the minimal width that the frame will have
|
||||
|
||||
@usage-- Adding a container as a base
|
||||
local container = Gui.container(parent,'my_container',200)
|
||||
local container = Gui.container(parent, 'my_container', 200)
|
||||
|
||||
]]
|
||||
Gui.container =
|
||||
Gui.element(function(_,parent,name,_)
|
||||
Gui.element(function(_, parent, name, _)
|
||||
-- Draw the external container
|
||||
local frame =
|
||||
parent.add{
|
||||
@@ -210,7 +210,7 @@ Gui.element(function(_,parent,name,_)
|
||||
style = 'window_content_frame_packed'
|
||||
}
|
||||
end)
|
||||
:style(function(style,element,_,width)
|
||||
:style(function(style, element, _,width)
|
||||
style.vertically_stretchable = false
|
||||
local frame_style = element.parent.style
|
||||
frame_style.padding = 2
|
||||
@@ -227,16 +227,16 @@ local bar = Gui.bar(parent, 100)
|
||||
|
||||
]]
|
||||
Gui.bar =
|
||||
Gui.element(function(_,parent)
|
||||
Gui.element(function(_, parent)
|
||||
return parent.add{
|
||||
type = 'progressbar',
|
||||
size = 1,
|
||||
value = 1
|
||||
}
|
||||
end)
|
||||
:style(function(style,_,width)
|
||||
:style(function(style, _,width)
|
||||
style.height = 3
|
||||
style.color = {r=255,g=255,b=255}
|
||||
style.color = {r=255, g=255, b=255}
|
||||
if width then style.width = width
|
||||
else style.horizontally_stretchable = true end
|
||||
end)
|
||||
@@ -253,7 +253,7 @@ local label = Gui.centered_label(parent, 100, 'This is centered')
|
||||
|
||||
]]
|
||||
Gui.centered_label =
|
||||
Gui.element(function(_,parent,width,caption,tooltip)
|
||||
Gui.element(function(_, parent, width, caption, tooltip)
|
||||
local label = parent.add{
|
||||
type = 'label',
|
||||
caption = caption,
|
||||
@@ -281,11 +281,11 @@ local label = Gui.centered_label(parent, 100, 'This is centered')
|
||||
|
||||
]]
|
||||
Gui.title_label =
|
||||
Gui.element(function(_,parent,width,caption,tooltip)
|
||||
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)
|
||||
Gui.bar(title_flow, width)
|
||||
local title_label = title_flow.add{
|
||||
type = 'label',
|
||||
caption = caption,
|
||||
|
||||
@@ -30,7 +30,7 @@ end
|
||||
local new_enabled_state = Gui.toggle_enabled_state(element)
|
||||
|
||||
]]
|
||||
function Gui.toggle_enabled_state(element,state)
|
||||
function Gui.toggle_enabled_state(element, state)
|
||||
if not element or not element.valid then return end
|
||||
if state == nil then state = not element.enabled end
|
||||
element.enabled = state
|
||||
@@ -46,7 +46,7 @@ end
|
||||
local new_visible_state = Gui.toggle_visible_state(element)
|
||||
|
||||
]]
|
||||
function Gui.toggle_visible_state(element,state)
|
||||
function Gui.toggle_visible_state(element, state)
|
||||
if not element or not element.valid then return end
|
||||
if state == nil then state = not element.visible end
|
||||
element.visible = state
|
||||
@@ -82,7 +82,7 @@ Gui.element{
|
||||
:style(Gui.sprite_style(20))
|
||||
|
||||
]]
|
||||
function Gui.sprite_style(size,padding,style)
|
||||
function Gui.sprite_style(size, padding, style)
|
||||
style = style or {}
|
||||
style.padding = padding or -2
|
||||
style.height = size
|
||||
|
||||
@@ -55,11 +55,11 @@ Gui.left_toolbar_button('entity/inserter', 'Nothing to see here', example_flow_w
|
||||
end)
|
||||
|
||||
]]
|
||||
function Gui.left_toolbar_button(sprite,tooltip,element_define,authenticator)
|
||||
local button = Gui.toolbar_button(sprite,tooltip,authenticator)
|
||||
function Gui.left_toolbar_button(sprite, tooltip, element_define, authenticator)
|
||||
local button = Gui.toolbar_button(sprite, tooltip, authenticator)
|
||||
|
||||
-- Add on_click handler to handle click events comming from the player
|
||||
button:on_click(function(player,_,_)
|
||||
button:on_click(function(player, _,_)
|
||||
local top_flow = Gui.get_top_flow(player)
|
||||
local element = top_flow[button.name]
|
||||
local visibility_state = Gui.toggle_left_element(player, element_define)
|
||||
@@ -169,7 +169,7 @@ function Gui.hide_left_flow(player)
|
||||
|
||||
-- Set the visible state of all elements in the flow
|
||||
hide_button.visible = false
|
||||
for name,_ in pairs(Gui.left_elements) do
|
||||
for name, _ in pairs(Gui.left_elements) do
|
||||
left_flow[name].visible = false
|
||||
|
||||
-- Check if the the element has a toobar button attached
|
||||
@@ -202,7 +202,7 @@ end
|
||||
local frame = Gui.get_left_element(game.player, example_flow_with_button)
|
||||
|
||||
]]
|
||||
function Gui.get_left_element(player,element_define)
|
||||
function Gui.get_left_element(player, element_define)
|
||||
local left_flow = Gui.get_left_flow(player)
|
||||
return left_flow[element_define.name]
|
||||
end
|
||||
@@ -220,7 +220,7 @@ Gui.toggle_top_flow(game.player, example_flow_with_button)
|
||||
Gui.toggle_top_flow(game.player, example_flow_with_button, true)
|
||||
|
||||
]]
|
||||
function Gui.toggle_left_element(player,element_define,state)
|
||||
function Gui.toggle_left_element(player, element_define, state)
|
||||
local left_flow = Gui.get_left_flow(player)
|
||||
local top_flow = Gui.get_top_flow(player)
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@ local Gui = {
|
||||
_prototype_element = {},
|
||||
--- The prototype metatable applied to new element defines
|
||||
_mt_element = {
|
||||
__call = function(self,parent,...)
|
||||
local element = self._draw(self.name,parent,...)
|
||||
if self._style then self._style(element.style,element,...) end
|
||||
__call = function(self, parent, ...)
|
||||
local element = self._draw(self.name, parent, ...)
|
||||
if self._style then self._style(element.style, element, ...) end
|
||||
return element
|
||||
end
|
||||
}
|
||||
@@ -50,7 +50,7 @@ Gui.element{
|
||||
@usage-- Using element defines with a custom factory function
|
||||
-- This method can be used if you still want to be able register event handlers but it is too complex to be compatible with LuaGuiElement.add
|
||||
local example_flow_with_button =
|
||||
Gui.element(function(event_trigger,parent,...)
|
||||
Gui.element(function(event_trigger, parent, ...)
|
||||
-- ... shows that all other arguments from the factory call are passed to this function
|
||||
-- parent is the element which was passed to the factory function where you should add your new element
|
||||
-- here we are adding a flow which we will then later add a button to
|
||||
@@ -90,7 +90,7 @@ function Gui.element(element_define)
|
||||
if type(element_define) == 'table' then
|
||||
Gui.debug_info[name].draw = element_define
|
||||
element_define.name = name
|
||||
element._draw = function(_,parent)
|
||||
element._draw = function(_, parent)
|
||||
return parent.add(element_define)
|
||||
end
|
||||
else
|
||||
@@ -131,7 +131,7 @@ Gui.element{
|
||||
caption = 'Example Button',
|
||||
style = 'forward_button' -- factorio styles can be applied here
|
||||
}
|
||||
:style(function(style,element,...)
|
||||
:style(function(style, element, ...)
|
||||
-- style is the current style object for the elemenent
|
||||
-- element is the element that is being changed
|
||||
-- ... shows that all other arguments from the factory call are passed to this function
|
||||
@@ -147,7 +147,7 @@ function Gui._prototype_element:style(style_define)
|
||||
if type(style_define) == 'table' then
|
||||
Gui.debug_info[self.name].style = style_define
|
||||
self._style = function(style)
|
||||
for key,value in pairs(style_define) do
|
||||
for key, value in pairs(style_define) do
|
||||
style[key] = value
|
||||
end
|
||||
end
|
||||
@@ -171,8 +171,8 @@ element_deinfe:on_custom_event('my_custom_event', function(event)
|
||||
end)
|
||||
|
||||
]]
|
||||
function Gui._prototype_element:on_custom_event(event_name,handler)
|
||||
table.insert(Gui.debug_info[self.name].events,event_name)
|
||||
function Gui._prototype_element:on_custom_event(event_name, handler)
|
||||
table.insert(Gui.debug_info[self.name].events, event_name)
|
||||
Gui.events[event_name] = event_name
|
||||
self[event_name] = handler
|
||||
return self
|
||||
@@ -210,7 +210,7 @@ function Gui._prototype_element:raise_custom_event(event)
|
||||
end
|
||||
event.player = player
|
||||
|
||||
local success, err = pcall(handler,player,element,event)
|
||||
local success, err = pcall(handler, player, element, event)
|
||||
if not success then
|
||||
error('There as been an error with an event handler for a gui element:\n\t'..err)
|
||||
end
|
||||
@@ -227,8 +227,8 @@ local function event_handler_factory(event_name)
|
||||
element_define:raise_custom_event(event)
|
||||
end)
|
||||
|
||||
return function(self,handler)
|
||||
table.insert(Gui.debug_info[self.name].events,debug.getinfo(1, "n").name)
|
||||
return function(self, handler)
|
||||
table.insert(Gui.debug_info[self.name].events, debug.getinfo(1, "n").name)
|
||||
self[event_name] = handler
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -87,10 +87,10 @@ end
|
||||
Gui.toggle_top_flow(game.player)
|
||||
|
||||
@usage-- Open your top flow
|
||||
Gui.toggle_top_flow(game.player,true)
|
||||
Gui.toggle_top_flow(game.player, true)
|
||||
|
||||
]]
|
||||
function Gui.toggle_top_flow(player,state)
|
||||
function Gui.toggle_top_flow(player, state)
|
||||
-- Get the top flow and hide button
|
||||
local top_flow = Gui.get_top_flow(player)
|
||||
if state == nil then state = not top_flow.visible end
|
||||
@@ -130,7 +130,7 @@ Gui.left_toolbar_button('entity/inserter', 'Nothing to see here', function(playe
|
||||
end)
|
||||
|
||||
]]
|
||||
function Gui.toolbar_button(sprite,tooltip,authenticator)
|
||||
function Gui.toolbar_button(sprite, tooltip, authenticator)
|
||||
return Gui.element{
|
||||
type = 'sprite-button',
|
||||
sprite = sprite,
|
||||
|
||||
Reference in New Issue
Block a user