From 9d17497c9b0548aeb7d0576631a8254751a740ab Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 15 Oct 2017 20:50:56 +0100 Subject: [PATCH] Inputs cleen --- .../ExpGaming-Core/GUI/ExpGaming - Inputs.lua | 56 +++++++++---------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Inputs.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Inputs.lua index 041d6693..684ce654 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Inputs.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Inputs.lua @@ -12,28 +12,27 @@ local inputs = ExpGui.inputs --allows defining of new buttons;;name how to call button;;default_display what is shown 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=name,display=default_display,tooltip=default_tooltip,event=event}) + inputs.buttons[name] = {name=name,display=default_display,tooltip=default_tooltip,event=event}) end --allows defining of text box inputs;;name how to call button;;default_display what is shown 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=name,display=default_display,event=event}) + inputs.text[name] = {name=name,display=default_display,event=event}) end --draws the button into a gui;;frame the frame to draw to;;name name of button to draw;;display(opptinal) overrides the default;;tooltip(opptinal) overrides 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 debug_write({'GUI','INPUT'},name) - for _,button in pairs(inputs.buttons) do - if button.name == name then - local display = display or button.display or button.name - local tooltip = tooltip or button.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 - frame.add{name=name, type = "button", caption=display, tooltip=tooltip, style = mod_gui.button_style} - end return - end + 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 + 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 + frame.add{name=name, type = "button", caption=display, tooltip=tooltip, style = mod_gui.button_style} + end return end error('No Button by the name of '..name) end @@ -42,33 +41,32 @@ 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 debug_write({'GUI','INPUT'},name) - for _,text in pairs(inputs.text) do - if text.name == name then - local display = display or text.display or text.name - frame.add{name=name, type='textfield'} - frame[name].caption=display - break - end + if inputs.text[name] then + local text = inputs.text[name] + local display = display or text.display or text.name + frame.add{name=name, type='textfield'} + frame[name].caption=display + return end + error('No Text by the name of '..name) end --the magic behind the buttons Event.register(defines.events.on_gui_click, function(event) - local player = game.players[event.player_index] + local player = game.players[event.player_index] if event.element.type == 'button' or event.element.type == 'sprite-button' then - for _,button in pairs(inputs.buttons) do - if button.name == event.element.name then - if button.event then button.event(player,event.element) else ranking.rank_print('Button without Function '..button.name,'Mod') end break - end + if inputs.buttons[event.element.name] then + local button = inputs.buttons[event.element.name] + if button.event then button.event(player,event.element) + else ranking.rank_print('Button without Function '..button.name,'Mod') end end end end) --the magic behind the text inputs Event.register(defines.events.on_gui_text_changed, function(event) - local player = game.players[event.player_index] - for _,text in pairs(inputs.text) do - if text.name == event.element.name then - if text.event then text.event(player,event.element) end break - end + local player = game.players[event.player_index] + if inputs.text[event.element.name] then + 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-----------------------------------------------------------