Added Popup guis and test guis in control.lua

This commit is contained in:
Cooldude2606
2017-07-03 21:18:25 +01:00
parent f1ce424e90
commit de5fa86749
6 changed files with 78 additions and 17 deletions

View File

@@ -23,3 +23,10 @@ credit_loop(require("locale/StdLib/event"))
credit_loop(require("locale/file-header")) credit_loop(require("locale/file-header"))
Event.register(-1,function() global.credits = credits end) Event.register(-1,function() global.credits = credits end)
--temp
ExpGui.add_frame.center('Test','Test','A Simple Gui',5)
ExpGui.add_frame.tab('testing','Long Tab','Just Like any other',5,'Test',function(player,tab) for i=0,100 do tab.add{type='label',name=i,caption=player.name} end end)
ExpGui.add_frame.tab('just_a_tab','A Tab','Just Like any other',5,'Test',function(player,tab) tab.add{type='label',name='temp',caption=player.name} end)
ExpGui.add_frame.left('left_test','Player Name','Just Like any other',5,function(player,frame) for i=0,10 do frame.add{type='label',name=i,caption=player.name..'\n'} end end)
ExpGui.add_frame.popup('Message','Message','Just A ToolTip',5,function(player,frame) frame.add{name='TEST',type='label',caption=player.name} end,function(player,frame,args) frame.add{name='Message',type='label',caption=args[1]..' '..args[2]} end)

View File

@@ -22,22 +22,22 @@ local add_frame = ExpGui.add_frame
local frames = ExpGui.frames local frames = ExpGui.frames
local draw_frame = ExpGui.draw_frame local draw_frame = ExpGui.draw_frame
--adds a frame in the center; tabs is a list that can contain already defined tabs; event(player,element) is a option to have a custom gui in the center --adds a frame in the center; tabs is a list that can contain already defined tabs; event(player,element) is a option to have a custom gui in the center
function add_frame.center(name,display,tooltip,restriction,tabs,event) function add_frame.center(name,default_display,default_tooltip,restriction,tabs,event)
if not name then error('Frame requires a name') end if not name then error('Frame requires a name') end
local tabs = tabs or {} local tabs = tabs or {}
table.insert(frames.center,{name,display,tabs,event}) table.insert(frames.center,{name,default_display,tabs,event})
ExpGui.toolbar.add_button(name,display,tooltip,restriction,draw_frame.center) ExpGui.toolbar.add_button(name,default_display,default_tooltip,restriction,draw_frame.center)
end end
--defines a tab; frame is need as every tab must be used once; event(player,tab) is the draw function --defines a tab; frame is need as every tab must be used once; event(player,tab) is the draw function
function add_frame.tab(name,display,tooltip,restriction,frame,event) function add_frame.tab(name,default_display,default_tooltip,restriction,frame,event)
if not name then error('Tab requires a name') end if not name then error('Tab requires a name') end
if not frame then error('Tab requires a frame') end if not frame then error('Tab requires a frame') end
table.insert(frames.tabs,{name,display,frame,event}) table.insert(frames.tabs,{name,default_display,frame,event})
for _,f in pairs(frames.center) do if f[1] == frame then table.insert(f[3],{name,restriction}) end end for _,f in pairs(frames.center) do if f[1] == frame then table.insert(f[3],{name,restriction}) end end
ExpGui.add_input.button(name,display,tooltip,draw_frame.tab) ExpGui.add_input.button(name,default_display,default_tooltip,draw_frame.tab)
end end
--draw the center gui for the player; do not call manuley must use other functions to call --draw the center gui for the player; do not call manuley must use other functions to call
ExpGui.add_input.button('close_center','Close','Close This Gui',function(player,element) player.gui.center.clear() end) 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) function draw_frame.center(player,element)
local frame_data = nil local frame_data = nil
for _,frame in pairs(frames.center) do if element.name == frame[1] then frame_data = frame break end end for _,frame in pairs(frames.center) do if element.name == frame[1] then frame_data = frame break end end

View File

@@ -23,19 +23,19 @@ local frames = ExpGui.frames
local draw_frame = ExpGui.draw_frame local draw_frame = ExpGui.draw_frame
--left guis are always present and only have their visabilty toggled --left guis are always present and only have their visabilty toggled
--adds a frame to the left bar; event(player,frame) must be present for left guis as there is no default --adds a frame to the left bar; event(player,frame) must be present for left guis as there is no default
function add_frame.left(name,display,tooltip,restriction,event) function add_frame.left(name,default_display,default_tooltip,restriction,event)
if not name then error('Frame requires a name') end 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 if not event or type(event) ~= 'function' then error('Frame requires a draw function') end
table.insert(frames.left,{name,display,event}) table.insert(frames.left,{name,default_display,event})
ExpGui.toolbar.add_button(name,display,tooltip,restriction,draw_frame.left) ExpGui.toolbar.add_button(name,default_display,default_tooltip,restriction,draw_frame.left)
end end
--draw the left gui for the player; do not call manuley must use other functions to call --draw the left gui for the player; do not call manuley must use other functions to call
function draw_frame.left(player,element) function draw_frame.left(player,element)
local frame_data = nil local frame_data = nil
for _,frame in pairs(frames.left) do if element.name == frame[1] then frame_data = frame break end end for _,frame in pairs(frames.left) do if element.name == frame[1] then frame_data = frame break end end
local left = player.gui.left local left = mod_gui.get_frame_flow(player)
if left[frame_data[1]] then ExpGui.toggleVisable(left[frame_data[1]]) return end if left[frame_data[1]] then ExpGui.toggleVisable(left[frame_data[1]]) return end
local frame = left.add{name=frame_data[1],type='frame',capption=frame_data[2]} local frame = left.add{name=frame_data[1],type='frame',capption=frame_data[2],direction='vertical'}
frame_data[3](player,frame) frame_data[3](player,frame)
end end
--Please Only Edit Above This Line----------------------------------------------------------- --Please Only Edit Above This Line-----------------------------------------------------------

View File

@@ -9,15 +9,69 @@ Discord: https://discord.gg/XSsBV6b
The credit below may be used by another script do not remove. The credit below may be used by another script do not remove.
]] ]]
local credits = {{ local credits = {{
name='File Header - ExpGaming-Core-GUI', name='ExpGaming - Popup Gui',
owner='Explosive Gaming', owner='Explosive Gaming',
dev='Cooldude2606', dev='Cooldude2606',
description='Just A File Header To Organise Code', description='Small popups in the top left',
factorio_version='0.15.23', factorio_version='0.15.23',
show=false show=false
}} }}
local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end
--Please Only Edit Below This Line----------------------------------------------------------- --Please Only Edit Below This Line-----------------------------------------------------------
local add_frame = ExpGui.add_frame
local frames = ExpGui.frames
local draw_frame = ExpGui.draw_frame
--used to draw the next popup frame
ExpGui.add_input.button('close_popup','X','Close This Popup',function(player,element) element.parent.destroy() end)
local function get_next_popup(popups,name)
if name then
local flow = popups.add{type='flow',name=name..'_on_click',direction='horizontal'}
local frame = flow.add{name='popup_frame',type='frame',direction='vertical'}
ExpGui.add_input.draw_button(flow,'close_popup') return frame
end
local current = #popups.children
for _,p in pairs(popups.children) do
if p.name == 'popup'..current then current = current+1 else
local flow = popups.add{type='flow',name='popup'..current,direction='horizontal'}
local frame = flow.add{name='popup_frame',type='frame',direction='vertical'}
ExpGui.add_input.draw_button(flow,'close_popup') return frame end
end
if #popups.children == 0 then
local flow = popups.add{type='flow',name='popup'..current,direction='horizontal'}
local frame = flow.add{name='popup_frame',type='frame',direction='vertical'}
ExpGui.add_input.draw_button(flow,'close_popup') return frame end
end
--adds a frame to the popup flow;restriction is the power need 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 drawen to; args is any infor you want to pass in
function add_frame.popup(style,default_display,default_tooltip,restriction,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,default_display,on_click,event})
if on_click and type(on_click) == 'function' then
ExpGui.toolbar.add_button(style,default_display,default_tooltip,restriction,draw_frame.popup_button)
end
end
--draw the popup on_click gui for the player; do not call manuley must use other functions to call
function draw_frame.popup_button(player,element)
local frame_data = nil
for _,frame in pairs(frames.popup) do if element.name == frame[1] then frame_data = frame break end end
local popups = mod_gui.get_frame_flow(player).popups or mod_gui.get_frame_flow(player).add{name='popups',type='flow',direction='vertical'}
if popups[frame_data[1]..'_on_click'] then popups[frame_data[1]..'_on_click'].destroy() return end
local frame = get_next_popup(popups,frame_data[1])
frame_data[3](player,frame)
end
--used to draw a popup style can be called at any time; can not be called from a button directly
function draw_frame.popup(style,args)
local args = args or {}
local frame_data = nil
for _,frame in pairs(frames.popup) do if style == frame[1] then frame_data = frame break end end
for _,player in pairs(game.connected_players) do
local popups = mod_gui.get_frame_flow(player).popups or mod_gui.get_frame_flow(player).add{name='popups',type='flow',direction='vertical'}
local frame = get_next_popup(popups)
frame_data[4](player,frame,args)
end
end
--Please Only Edit Above This Line----------------------------------------------------------- --Please Only Edit Above This Line-----------------------------------------------------------
return credits return credits

View File

@@ -29,7 +29,7 @@ end
--draw the toolbar to the player only showing buttons within their restriction --draw the toolbar to the player only showing buttons within their restriction
function toolbar.draw(player) function toolbar.draw(player)
if not player then error('Need a player to draw to') end if not player then error('Need a player to draw to') end
local toolbar_frame = player.gui.top local toolbar_frame = mod_gui.get_button_flow(player)
toolbar_frame.clear() toolbar_frame.clear()
for _,btn in pairs(toolbar.buttons) do for _,btn in pairs(toolbar.buttons) do
local rank = get_rank(player) local rank = get_rank(player)

View File

@@ -23,7 +23,7 @@ credit_loop(require("ExpGaming - Inputs"))
credit_loop(require("ExpGaming - Toolbar")) credit_loop(require("ExpGaming - Toolbar"))
credit_loop(require("ExpGaming - Center Gui")) credit_loop(require("ExpGaming - Center Gui"))
credit_loop(require("ExpGaming - Left Gui")) credit_loop(require("ExpGaming - Left Gui"))
credit_loop(require("ExpGaming - Player Table"))
credit_loop(require("ExpGaming - Popup")) credit_loop(require("ExpGaming - Popup"))
credit_loop(require("ExpGaming - Player Table"))
--Please Only Edit Above This Line----------------------------------------------------------- --Please Only Edit Above This Line-----------------------------------------------------------
return credits return credits