Added Comments to all gui files

This commit is contained in:
Cooldude2606
2019-05-17 21:47:46 +01:00
parent fbc07dab59
commit dbf6341ad9
11 changed files with 833 additions and 151 deletions

View File

@@ -1,3 +1,10 @@
--- Gui structure for the toolbar (top left)
--[[
>>>> Functions
Toolbar.new_button(name) --- Adds a new button to the toolbar
Toolbar.add_button(button) --- Adds an existing buttton to the toolbar
Toolbar.update(player) --- Updates the player's toolbar with an new buttons or expected change in auth return
]]
local Buttons = require './buttons'
local Gui = require './core'
local Roles = require 'expcore.roles'
@@ -8,6 +15,9 @@ local Toolbar = {
buttons = {}
}
--- Adds a new button to the toolbar
-- @tparam[opt] name string the name of the button to be added
-- @treturn table the button define
function Toolbar.new_button(name)
name = name or #Toolbar.buttons+1
local button = Buttons.new_button('toolbar/'..name)
@@ -16,11 +26,13 @@ function Toolbar.new_button(name)
return button
end
--- Adds an existing buttton to the toolbar
-- @tparam button table the button define for the button to be added
function Toolbar.add_button(button)
table.insert(Toolbar.buttons,button)
Gui.allow_player_to_toggle_top_element_visibility(button.name)
Gui.on_player_show_top(button.name,function(event)
if not button.post_authenticator(event.player,button.clean_name or button.name) then
if not button.post_authenticator(event.player,button.name) then
event.element.visible = false
end
end)
@@ -29,6 +41,8 @@ function Toolbar.add_button(button)
end
end
--- Updates the player's toolbar with an new buttons or expected change in auth return
-- @tparam player LuaPlayer the player to update the toolbar for
function Toolbar.update(player)
local top = Gui.get_top_element_flow(player)
if not top then return end
@@ -37,7 +51,7 @@ function Toolbar.update(player)
local element
if top[button.name] then element = top[button.name]
else element = button:draw_to(top) end
if button.post_authenticator(player,button.clean_name or button.name) then
if button.post_authenticator(player,button.name) then
element.visible = visible
element.enabled = true
else
@@ -47,16 +61,19 @@ function Toolbar.update(player)
end
end
--- When there is a new player they will have the toolbar update
Event.add(defines.events.on_player_created,function(event)
local player = Game.get_player_by_index(event.player_index)
Toolbar.update(player)
end)
--- When a player gets a new role they will have the toolbar updated
Event.add(Roles.player_role_assigned,function(event)
local player = Game.get_player_by_index(event.player_index)
Toolbar.update(player)
end)
--- When a player loses a role they will have the toolbar updated
Event.add(Roles.player_role_unassigned,function(event)
local player = Game.get_player_by_index(event.player_index)
Toolbar.update(player)