Prep for more allow on the guis

This commit is contained in:
Cooldude2606
2017-09-14 21:15:18 +01:00
parent 2bbc5d1051
commit e8fd6105ec
4 changed files with 13 additions and 24 deletions

View File

@@ -22,20 +22,20 @@ local add_frame = ExpGui.add_frame
local frames = ExpGui.frames
local draw_frame = ExpGui.draw_frame
--Add a frame in the center
--tabs {{name,restriction},{...}} is a list that can contain already defined tabs
--tabs {{name},{...}} is a list that can contain already defined tabs
--event(player,element) is an option to have a custom GUI in the center
function add_frame.center(name,default_display,default_tooltip,restriction,tabs,event)
function add_frame.center(name,default_display,default_tooltip,tabs,event)
if not name then error('Frame requires a name') end
local tabs = tabs or {}
table.insert(frames.center,{name=name,display=default_display,tabs=tabs,event=event})
ExpGui.toolbar.add_button(name,default_display,default_tooltip,restriction,draw_frame.center)
ExpGui.toolbar.add_button(name,default_display,default_tooltip,draw_frame.center)
end
--Define a tab; frame is needed as every tab must be used once; event(player,tab) is the draw function
function add_frame.tab(name,default_display,default_tooltip,restriction,frame,event)
function add_frame.tab(name,default_display,default_tooltip,frame,event)
if not name then error('Tab requires a name') end
if not frame then error('Tab requires a frame') end
table.insert(frames.tabs,{name=name,display=default_display,frame=frame,event=event})
for _,f in pairs(frames.center) do if f.name == frame then table.insert(f.tabs,{name=name,restriction=restriction}) end end
for _,f in pairs(frames.center) do if f.name == frame then table.insert(f.tabs,{name=name}) end end
ExpGui.add_input.button(name,default_display,default_tooltip,draw_frame.tab)
end
--Draw the center GUI for the player; do not call manually, must use other functions to call
@@ -50,12 +50,7 @@ function draw_frame.center(player,element)
local tab_bar_scroll = frame.add{type = "scroll-pane", name= "tab_bar_scroll", vertical_scroll_policy="never", horizontal_scroll_policy="always"}
local tab_bar = tab_bar_scroll.add{type='flow',direction='horizontal',name='tab_bar'}
local tab = frame.add{type = "scroll-pane", name= "tab", vertical_scroll_policy="auto", horizontal_scroll_policy="never"}
for n,t in pairs(frame_data.tabs) do
local temp_restriction = nil
if type(t.restriction) == 'number' then temp_restriction = t.restriction end
local restriction = temp_restriction or string_to_rank(t.restriction).power
if restriction >= get_rank(player).power then ExpGui.add_input.draw_button(tab_bar,t.name) end
end
for n,t in pairs(frame_data.tabs) do if rank_allowed(get_rank(player),t.name..'_tab') then ExpGui.add_input.draw_button(tab_bar,t.name) end end
draw_frame.tab(player,tab_bar[frame_data.tabs[1].name])
ExpGui.add_input.draw_button(tab_bar,'close_center')
tab.style.minimal_height = 300

View File

@@ -24,12 +24,12 @@ local draw_frame = ExpGui.draw_frame
--left GUIs are always present and only have their visibility toggled
--Add a frame to the left bar; event(player,frame) must be present for left GUIs as there is no default
--vis should be true or false based on the player join game state of the GUI
function add_frame.left(name,default_display,default_tooltip,restriction,vis,event)
function add_frame.left(name,default_display,default_tooltip,vis,event)
if not name then error('Frame requires a name') end
if not event or type(event) ~= 'function' then error('Frame requires a draw function') end
local vis = vis or false
table.insert(frames.left,{name=name,display=default_display,event=event,vis=vis})
ExpGui.toolbar.add_button(name,default_display,default_tooltip,restriction,draw_frame.left)
ExpGui.toolbar.add_button(name,default_display,default_tooltip,draw_frame.left)
end
--draw the left GUI for the player; called via script, only call manually when update is true and element is the name of the GUI
function draw_frame.left(player,element,update)

View File

@@ -37,17 +37,15 @@ local function get_next_popup(popups,name)
return frame
end
--adds a frame to the popup flow
--restriction is the power needed to use the on_click function
--on_click(player,element) is what is called when button is clicked if nil no button is made
--event(player,frame,args)
--frame is where it will be drawn to; args is any info you want to pass in
function add_frame.popup(style,default_display,default_tooltip,restriction,on_click,event)
function add_frame.popup(style,default_display,default_tooltip,on_click,event)
if not style then error('Popup style requires a name') end
if not event or type(event) ~= 'function' then error('Popup style requires a draw function') end
local restriction = restriction or 0
table.insert(frames.popup,{style=style,display=default_display,on_click=on_click,event=event})
if on_click and type(on_click) == 'function' then
ExpGui.toolbar.add_button(style,default_display,default_tooltip,restriction,draw_frame.popup_button)
ExpGui.toolbar.add_button(style,default_display,default_tooltip,draw_frame.popup_button)
end
end
--draw the popup on_click GUI for the player; do not call manually must use other functions to call

View File

@@ -20,10 +20,9 @@ local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits
--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
function toolbar.add_button(name,default_display,default_tooltip,event)
if not name then error('Button requires a name') end
table.insert(toolbar.buttons,{name=name,restriction=restriction})
table.insert(toolbar.buttons,{name=name})
ExpGui.add_input.button(name,default_display,default_tooltip,event)
end
--draw the toolbar to the player only showing buttons within their restriction
@@ -33,10 +32,7 @@ function toolbar.draw(player)
toolbar_frame.clear()
for _,button in pairs(toolbar.buttons) do
local rank = get_rank(player)
local temp_restriction = nil
if type(button.restriction) == 'number' then temp_restriction = button.restriction end
local restriction = temp_restriction or string_to_rank(button.restriction).power or 0
if restriction >= rank.power then
if rank_allowed(get_rank(player),button.name) then
ExpGui.add_input.draw_button(toolbar_frame,button.name)
end
end