From e8fd6105ec90edcd295a59d458427bab9cb48e26 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Thu, 14 Sep 2017 21:15:18 +0100 Subject: [PATCH] Prep for more allow on the guis --- .../GUI/ExpGaming - Center Gui.lua | 17 ++++++----------- .../ExpGaming-Core/GUI/ExpGaming - Left Gui.lua | 4 ++-- locale/ExpGaming-Core/GUI/ExpGaming - Popup.lua | 6 ++---- .../ExpGaming-Core/GUI/ExpGaming - Toolbar.lua | 10 +++------- 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua index 0c12514d..a989fbae 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua @@ -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 diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua index 5ef20b7d..ec2cb727 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua @@ -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) diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Popup.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Popup.lua index 254d98f5..e991782e 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Popup.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Popup.lua @@ -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 diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua index 8346bebd..fb05d501 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua @@ -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