mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 12:31:41 +09:00
Add the toolbar manager
This commit is contained in:
@@ -9,15 +9,36 @@ Discord: https://discord.gg/XSsBV6b
|
||||
The credit below may be used by another script do not remove.
|
||||
]]
|
||||
local credits = {{
|
||||
name='File Header - ExpGaming-Core-GUI',
|
||||
name='A Very Useful Toolbar',
|
||||
owner='Explosive Gaming',
|
||||
dev='Cooldude2606',
|
||||
description='Just A File Header To Organise Code',
|
||||
description='Some simple functions that help to control the toolbar',
|
||||
factorio_version='0.15.23',
|
||||
show=false
|
||||
}}
|
||||
local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end
|
||||
--Please Only Edit Below This Line-----------------------------------------------------------
|
||||
|
||||
local toolbar = ExpGui.toolbar
|
||||
--similar to ExpGui.add_input.button but it also accepts a restriction and button is drawn to the toolbar
|
||||
function toolbar.add_button(name,default_display,default_tooltip,restriction,event)
|
||||
local restriction = restriction or 0
|
||||
if not name then error('Button requires a name') end
|
||||
table.insert(toolbar.buttons,{name,restriction})
|
||||
ExpGui.add_input.button(name,default_display,default_tooltip,event)
|
||||
end
|
||||
--draw the toolbar to the player only showing buttons within their restriction
|
||||
function toolbar.draw(player)
|
||||
if not player then error('Need a player to draw to') end
|
||||
local toolbar_frame = player.gui.top.toolbar or player.gui.top.add{name='toolbar',type='flow'}
|
||||
toolbar_frame.clear()
|
||||
for _,btn in pairs(toolbar.buttons) do
|
||||
local rank = get_rank(player)
|
||||
if btn[2] >= rank.power then
|
||||
ExpGui.add_input.draw_button(toolbar_frame,btn[1])
|
||||
end
|
||||
end
|
||||
end
|
||||
--auto redraw toolbar after new rank is given
|
||||
Event.register(Event.rank_change,function(event) toolbar.draw(event.player) end)
|
||||
--Please Only Edit Above This Line-----------------------------------------------------------
|
||||
return credits
|
||||
Reference in New Issue
Block a user