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:
@@ -43,6 +43,7 @@ return {
|
||||
'modules.addons.chat-reply',
|
||||
'modules.addons.tree-decon',
|
||||
-- GUI
|
||||
'modules.gui.readme',
|
||||
'modules.gui.rocket-info',
|
||||
'modules.gui.science-info',
|
||||
'modules.gui.warp-list',
|
||||
|
||||
@@ -220,7 +220,8 @@ local default = Roles.new_role('Guest','')
|
||||
'gui/rocket-info',
|
||||
'gui/science-info',
|
||||
'gui/task-list',
|
||||
'gui/warp-list'
|
||||
'gui/warp-list',
|
||||
'gui/readme'
|
||||
}
|
||||
|
||||
--- Jail role
|
||||
|
||||
@@ -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
|
||||
49
modules/gui/readme.lua
Normal file
49
modules/gui/readme.lua
Normal file
@@ -0,0 +1,49 @@
|
||||
--[[-- Gui Module - Readme
|
||||
- Adds a main gui that contains lots of important information about our server
|
||||
@gui Readme
|
||||
@alias readme
|
||||
]]
|
||||
|
||||
local Gui = require 'expcore.gui' --- @dep expcore.gui
|
||||
local Roles = require 'expcore.roles' --- @dep expcore.roles
|
||||
local Event = require 'utils.event' --- @dep utils.event
|
||||
local Game = require 'utils.game' --- @dep utils.game
|
||||
|
||||
--- Main readme container for the center flow
|
||||
-- @element readme
|
||||
local readme_toggle
|
||||
local readme =
|
||||
Gui.element(function(event_trigger,parent)
|
||||
local container = Gui.container(parent,event_trigger,200)
|
||||
return container.parent
|
||||
end)
|
||||
:on_open(function(player)
|
||||
local toggle_button = Gui.get_top_element(player, readme_toggle)
|
||||
Gui.toolbar_button_style(toggle_button, true)
|
||||
end)
|
||||
:on_close(function(player,element)
|
||||
local toggle_button = Gui.get_top_element(player, readme_toggle)
|
||||
Gui.toolbar_button_style(toggle_button, false)
|
||||
Gui.destroy_if_valid(element)
|
||||
end)
|
||||
|
||||
--- Toggle button for the readme gui
|
||||
-- @element readme_toggle
|
||||
readme_toggle =
|
||||
Gui.toolbar_button('virtual-signal/signal-info','Readme',function(player)
|
||||
return Roles.player_allowed(player,'gui/readme')
|
||||
end)
|
||||
:on_click(function(player,element)
|
||||
local center = player.gui.center
|
||||
if center[readme.name] then
|
||||
player.opened = nil
|
||||
else
|
||||
player.opened = readme(center)
|
||||
end
|
||||
end)
|
||||
|
||||
--- When a player joins the game for the first time show this gui
|
||||
Event.add(defines.events.on_player_created,function(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
player.opened = readme(player.gui.center)
|
||||
end)
|
||||
Reference in New Issue
Block a user