Add the toolbar manager

This commit is contained in:
Cooldude2606
2017-07-02 20:30:35 +01:00
parent 45798b7b88
commit 1efdb4ca92
5 changed files with 41 additions and 8 deletions

View File

@@ -12,7 +12,7 @@ local credits = {{
name='Gui Input Handler',
owner='Explosive Gaming',
dev='Cooldude2606',
description='Just A File Header To Organise Code',
description='Handles all gui inputs',
factorio_version='0.15.23',
show=false
}}
@@ -22,17 +22,21 @@ local add_input = ExpGui.add_input
local inputs = ExpGui.inputs
--allows defining of new buttons;;name how to call button;;default_display what is showen on the button;;default_tooltip the tooltip display;;event function(player,element) that runs on click
function add_input.button(name,default_display,default_tooltip,event)
if not name then error('Button requires a name') end
table.insert(inputs.buttons,{name,default_display,default_tooltip,event})
end
--allows defining of text box inputs;;name how to call button;;default_display what is showen on the button;;event function(player,element) that runs on text change
function add_input.text(name,default_display,event)
if not name then error('Text Filed requires a name') end
table.insert(inputs.text,{name,default_display,event})
end
--draws the button into a gui;;frame the frame to draw to;;name name of button to draw;;display(opptinal) overides the default;;tooltip(opptinal) overides the default
function add_input.draw_button(frame,name,display,tooltip)
if not frame or not frame.valid then error('No frame to draw to') end
if not name then error('No button to draw') end
for _,btn in pairs(inputs.buttons) do
if btn[1] == name then
local display = display or btn[2]
local display = display or btn[2] or btn[1]
local tooltip = tooltip or btn[3]
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}
@@ -43,10 +47,12 @@ function add_input.draw_button(frame,name,display,tooltip)
end
end
--draws the text into a gui;;frame the frame to draw to;;name name of button to draw;;display(opptinal) overides the default;;tooltip(opptinal) overides the default
function add_input.draw_button(frame,name,display)
function add_input.draw_text(frame,name,display)
if not frame or not frame.valid then error('No frame to draw to') end
if not name then error('No text filed to draw') end
for _,text in pairs(inputs.text) do
if text[1] == name then
local display = display or text[2]
local display = display or text[2] or text[1]
frame.add{name=name, type='textfield', text=display}
break
end