mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Working center gui
This commit is contained in:
@@ -42,28 +42,6 @@ function Gui._prototype_element:add_to_left_flow(open_on_join)
|
||||
return self
|
||||
end
|
||||
|
||||
--[[-- Styles a top flow button depending on the state given
|
||||
@tparam LuaGuiElement the button element to style
|
||||
@tparam boolean state The state the button is in
|
||||
|
||||
@usage-- Sets the button to the visible style
|
||||
Gui.left_toolbar_button_style(button, true)
|
||||
|
||||
@usage-- Sets the button to the hidden style
|
||||
Gui.left_toolbar_button_style(button, false)
|
||||
|
||||
]]
|
||||
function Gui.left_toolbar_button_style(button, state)
|
||||
if state then
|
||||
button.style = Gui.top_flow_button_visible_style
|
||||
else
|
||||
button.style = Gui.top_flow_button_style
|
||||
end
|
||||
button.style.minimal_width = 36
|
||||
button.style.height = 36
|
||||
button.style.padding = -2
|
||||
end
|
||||
|
||||
--[[-- Creates a button on the top flow which will toggle the given element define, the define must exist in the left flow
|
||||
@tparam string sprite the sprite that you want to use on the button
|
||||
@tparam ?string|Concepts.LocalizedString tooltip the tooltip that you want the button to have
|
||||
@@ -78,18 +56,7 @@ end)
|
||||
|
||||
]]
|
||||
function Gui.left_toolbar_button(sprite,tooltip,element_define,authenticator)
|
||||
local button = Gui.element{
|
||||
type = 'sprite-button',
|
||||
sprite = sprite,
|
||||
tooltip = tooltip,
|
||||
style = Gui.top_flow_button_style
|
||||
}
|
||||
:style{
|
||||
minimal_width = 36,
|
||||
height = 36,
|
||||
padding = -2
|
||||
}
|
||||
:add_to_top_flow(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,_,_)
|
||||
@@ -152,7 +119,7 @@ function Gui.draw_left_flow(player)
|
||||
local button = top_flow[element_define.toolbar_button]
|
||||
if button then
|
||||
-- Style the button
|
||||
Gui.left_toolbar_button_style(button, visible)
|
||||
Gui.toolbar_button_style(button, visible)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -206,7 +173,7 @@ function Gui.hide_left_flow(player)
|
||||
local button = top_flow[element_define.toolbar_button]
|
||||
if button then
|
||||
-- Style the button
|
||||
Gui.left_toolbar_button_style(button, false)
|
||||
Gui.toolbar_button_style(button, false)
|
||||
-- Get the button define from the reverse lookup on the element
|
||||
local button_define = Gui.defines[element_define.toolbar_button]
|
||||
-- Raise the custom event if all of the top checks have passed
|
||||
@@ -263,7 +230,7 @@ function Gui.toggle_left_element(player,element_define,state)
|
||||
local button = top_flow[element_define.toolbar_button]
|
||||
if button then
|
||||
-- Style the button
|
||||
Gui.left_toolbar_button_style(button, state)
|
||||
Gui.toolbar_button_style(button, state)
|
||||
end
|
||||
end
|
||||
return state
|
||||
|
||||
@@ -365,11 +365,11 @@ end
|
||||
|
||||
--- Called when the player opens a GUI.
|
||||
-- @tparam function handler the event handler which will be called
|
||||
Gui._prototype_element.on_opened = event_handler_factory(defines.events.on_gui_opened)
|
||||
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
|
||||
Gui._prototype_element.on_closed = event_handler_factory(defines.events.on_gui_closed)
|
||||
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
|
||||
|
||||
@@ -101,4 +101,67 @@ function Gui.toggle_top_flow(player,state)
|
||||
top_flow.visible = state
|
||||
|
||||
return state
|
||||
end
|
||||
|
||||
--[[-- Get the element define that is in the top flow, use in events without an element refrence
|
||||
@tparam LuaPlayer player the player that you want to get the element for
|
||||
@tparam table element_define the element that you want to get
|
||||
@treturn LuaGuiElement the gui element linked to this define for this player
|
||||
|
||||
@usage-- Get your top element
|
||||
local button = Gui.get_top_element(game.player, example_button)
|
||||
|
||||
]]
|
||||
function Gui.get_top_element(player, element_define)
|
||||
local top_flow = Gui.get_top_flow(player)
|
||||
return top_flow[element_define.name]
|
||||
end
|
||||
|
||||
--[[-- Creates a button on the top flow with consistent styling
|
||||
@tparam string sprite the sprite that you want to use on the button
|
||||
@tparam ?string|Concepts.LocalizedString tooltip the tooltip that you want the button to have
|
||||
@tparam[opt] function authenticator used to decide if the button should be visible to a player
|
||||
|
||||
@usage-- Add a button to the toolbar
|
||||
local toolbar_button =
|
||||
Gui.left_toolbar_button('entity/inserter', 'Nothing to see here', function(player)
|
||||
return player.admin
|
||||
end)
|
||||
|
||||
]]
|
||||
function Gui.toolbar_button(sprite,tooltip,authenticator)
|
||||
return Gui.element{
|
||||
type = 'sprite-button',
|
||||
sprite = sprite,
|
||||
tooltip = tooltip,
|
||||
style = Gui.top_flow_button_style
|
||||
}
|
||||
:style{
|
||||
minimal_width = 36,
|
||||
height = 36,
|
||||
padding = -2
|
||||
}
|
||||
:add_to_top_flow(authenticator)
|
||||
end
|
||||
|
||||
--[[-- Styles a top flow button depending on the state given
|
||||
@tparam LuaGuiElement the button element to style
|
||||
@tparam boolean state The state the button is in
|
||||
|
||||
@usage-- Sets the button to the visible style
|
||||
Gui.toolbar_button_style(button, true)
|
||||
|
||||
@usage-- Sets the button to the hidden style
|
||||
Gui.toolbar_button_style(button, false)
|
||||
|
||||
]]
|
||||
function Gui.toolbar_button_style(button, state)
|
||||
if state then
|
||||
button.style = Gui.top_flow_button_visible_style
|
||||
else
|
||||
button.style = Gui.top_flow_button_style
|
||||
end
|
||||
button.style.minimal_width = 36
|
||||
button.style.height = 36
|
||||
button.style.padding = -2
|
||||
end
|
||||
Reference in New Issue
Block a user