Center Gui clean

This commit is contained in:
Cooldude2606
2017-10-15 21:49:55 +01:00
parent 95b3acf271
commit 9b6ec9d1a7
4 changed files with 31 additions and 43 deletions

View File

@@ -5,18 +5,7 @@ This file can be used with permission but this and the credit below must remain
Contact a member of management on our discord to seek permission to use our code.
Any changes that you may make to the code are yours but that does not make the script yours.
Discord: https://discord.gg/XSsBV6b
The credit below may be used by another script do not remove.
]]
local credits = {{
name='ExpGaming - Center Gui',
owner='Explosive Gaming',
dev='Cooldude2606',
description='The main GUI in the center',
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 add_frame = ExpGui.add_frame
local frames = ExpGui.frames
@@ -27,33 +16,44 @@ local draw_frame = ExpGui.draw_frame
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})
frames.center[name] = {name=name,display=default_display,tabs=tabs,event=event}
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,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}) end end
frames.tabs[name] = {name=name,display=default_display,frame=frame,event=event}
table.insert(frames.center[frame].tabs,name)
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
ExpGui.add_input.button('close_center','Close','Close this GUI',function(player,element) element.parent.parent.parent.destroy() end)
function draw_frame.center(player,element)
local frame_data = nil
for _,frame in pairs(frames.center) do if element.name == frame.name then frame_data = frame break end end
frame_data = frames.center[element.name]
debug_write({'GUI','CENTER'},player.name..' '..frame_data.name)
--setup so nothing will break (name is set as caption if display a sprite)
if player.gui.is_valid_sprite_path(frame_data.display) then frame_data.display = frame_data.name end
if player.gui.center[frame_data.name] then player.gui.center.clear() return else player.gui.center.clear() end
-- start drawing
local frame = player.gui.center.add{name=frame_data.name,type='frame',caption=frame_data.display,direction='vertical',style=mod_gui.frame_style}
if frame_data.event and type(frame_data.event) == 'function' then frame_data.event(player,frame) return end
-- if a custom draw is not set then it will do the default
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 if ranking.rank_allowed(ranking.get_player_rank(player),t.name..'_tab') then debug_write({'GUI','CENTER','ADD'},t.name) ExpGui.add_input.draw_button(tab_bar,t.name) end end
draw_frame.tab(player,tab_bar[frame_data.tabs[1].name])
-- draw tabs buttons for allowed tabs
local first_tab = nil
for n,tab_name in pairs(frame_data.tabs) do
if ranking.rank_allowed(ranking.get_player_rank(player),tab_name..'_tab') then
first_tab = first_tab or tab_name
debug_write({'GUI','CENTER','ADD'},tab_name)
ExpGui.add_input.draw_button(tab_bar,tab_name)
end
end
draw_frame.tab(player,tab_bar[first_tab])
ExpGui.add_input.draw_button(tab_bar,'close_center')
--sets the size of the gui
tab.style.minimal_height = 300
tab.style.maximal_height = 300
tab.style.minimal_width = 500
@@ -73,9 +73,7 @@ function draw_frame.tab(player,element)
btn.style.font_color = {r = 100, g = 100, b = 100,a=255}
end end
element.parent.parent.parent.tab.clear()
for _,tab in pairs(frames.tabs) do if element.name == tab.name then tab.event(player,element.parent.parent.parent.tab) break end end
frames.tabs[element.name].event(player,element.parent.parent.parent.tab)
end
Event.register(Event.rank_change,function(event) event.player.gui.center.clear() end)
--Please Only Edit Above This Line-----------------------------------------------------------
return credits
Event.register(Event.rank_change,function(event) event.player.gui.center.clear() end)

View File

@@ -26,8 +26,8 @@ function add_input.draw_button(frame,name,display,tooltip)
debug_write({'GUI','INPUT'},name)
if inputs.buttons[name] then
local button = inputs.buttons[name]
local display = display or button.display or button.name
local tooltip = tooltip or button.tooltip
local display = display or button.display or {'expgui.button-no-display'}
local tooltip = tooltip or button.tooltip or {'expgui.button-no-tooltip'}
if frame.gui.is_valid_sprite_path(display) then
frame.add{name=name, type = "sprite-button", sprite=display, tooltip=tooltip, style = mod_gui.button_style}
else
@@ -43,7 +43,7 @@ function add_input.draw_text(frame,name,display)
debug_write({'GUI','INPUT'},name)
if inputs.text[name] then
local text = inputs.text[name]
local display = display or text.display or text.name
local display = display or text.display or {'expgui.text-no-display'}
frame.add{name=name, type='textfield'}
frame[name].caption=display
return
@@ -68,6 +68,4 @@ Event.register(defines.events.on_gui_text_changed, function(event)
local text = inputs.text[event.element.name]
if text.event then text.event(player,event.element) end
end
end)
--Please Only Edit Above This Line-----------------------------------------------------------
return credits
end)

View File

@@ -5,18 +5,7 @@ This file can be used with permission but this and the credit below must remain
Contact a member of management on our discord to seek permission to use our code.
Any changes that you may make to the code are yours but that does not make the script yours.
Discord: https://discord.gg/XSsBV6b
The credit below may be used by another script do not remove.
]]
local credits = {{
name='A Very Useful Toolbar',
owner='Explosive Gaming',
dev='Cooldude2606',
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
@@ -40,6 +29,4 @@ function toolbar.draw(player)
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
Event.register(Event.rank_change,function(event) toolbar.draw(event.player) end)

View File

@@ -15,4 +15,9 @@ command-ran=Command Complete
server-command-help=For use of the highest staff only
debug-command-help=For use of the highest staff only, this will lag A LOT
socket-command-help=For use out side of factorio to run predefinded functions
sudo-info=At game tick: __1__ Queue Lenth: __2__ Number of temp vars: __3__
sudo-info=At game tick: __1__ Queue Lenth: __2__ Number of temp vars: __3__
[expgui]
button-no-display=No name
button-no-tooltip=Ask some one what this does
text-no-display=BLANK