From 45798b7b88699f812e809c4169ed0a79f1fd0a18 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 2 Jul 2017 11:17:22 +0100 Subject: [PATCH] Add Gui Inputs (Unable to test) --- .../ExpGaming - Server Interface.lua | 2 +- .../GUI/ExpGaming - Center Gui.lua | 23 ++++++ .../ExpGaming-Core/GUI/ExpGaming - Inputs.lua | 76 +++++++++++++++++++ .../GUI/ExpGaming - Left Gui.lua | 23 ++++++ .../GUI/ExpGaming - Modlue Setup.lua | 49 ++++++++++++ .../GUI/ExpGaming - Player Table.lua | 23 ++++++ .../ExpGaming-Core/GUI/ExpGaming - Popup.lua | 23 ++++++ .../GUI/ExpGaming - Toolbar.lua | 23 ++++++ locale/ExpGaming-Core/GUI/file-header.lua | 8 +- 9 files changed, 248 insertions(+), 2 deletions(-) create mode 100644 locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua create mode 100644 locale/ExpGaming-Core/GUI/ExpGaming - Inputs.lua create mode 100644 locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua create mode 100644 locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua create mode 100644 locale/ExpGaming-Core/GUI/ExpGaming - Player Table.lua create mode 100644 locale/ExpGaming-Core/GUI/ExpGaming - Popup.lua create mode 100644 locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua diff --git a/locale/ExpGaming-Core/ExpGaming - Server Interface.lua b/locale/ExpGaming-Core/ExpGaming - Server Interface.lua index 0a581e14..4f380587 100644 --- a/locale/ExpGaming-Core/ExpGaming - Server Interface.lua +++ b/locale/ExpGaming-Core/ExpGaming - Server Interface.lua @@ -45,7 +45,7 @@ Event.register(defines.events.on_tick, function(event) command=table.remove(global.sudo) if command and command.fun and type(command.fun) == 'function' then local args = command.var or {} - command.fun(args[1],args[2],args[3],args[4],args[5],args[6]) + command.fun(unpack(args)) end end end) diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua new file mode 100644 index 00000000..c0e1633b --- /dev/null +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Center Gui.lua @@ -0,0 +1,23 @@ +--[[ +Explosive Gaming + +This file can be used with permission but this and the credit below must remain in the file. +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='File Header - ExpGaming-Core-GUI', + owner='Explosive Gaming', + dev='Cooldude2606', + description='Just A File Header To Organise Code', + 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----------------------------------------------------------- + +--Please Only Edit Above This Line----------------------------------------------------------- +return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Inputs.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Inputs.lua new file mode 100644 index 00000000..8855d6e0 --- /dev/null +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Inputs.lua @@ -0,0 +1,76 @@ +--[[ +Explosive Gaming + +This file can be used with permission but this and the credit below must remain in the file. +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='Gui Input Handler', + owner='Explosive Gaming', + dev='Cooldude2606', + description='Just A File Header To Organise Code', + 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_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) + 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) + 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) + for _,btn in pairs(inputs.buttons) do + if btn[1] == name then + local display = display or btn[2] + 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} + else + frame.add{name=name, type = "button", caption=display, tooltip=tooltip, style = mod_gui.button_style} + end break + end + 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) + for _,text in pairs(inputs.text) do + if text[1] == name then + local display = display or text[2] + frame.add{name=name, type='textfield', text=display} + break + end + end +end +--the magic behind the buttons +Event.register(defines.events.on_gui_click, function(event) + local player = game.players[event.player_index] + if event.element.type == 'button' or event.element.type == 'sprite-button' then + for _,btn in pairs(inputs.buttons) do + if btn[1] == event.element.name then + if btn[4] then btn[4](player,event.element) else rank_print('Button Without Function '..btn[1],'Mod') end break + 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[1] == event.element.name then + if text[3] then text[3](player,event.element) end break + end + end +end) +--Please Only Edit Above This Line----------------------------------------------------------- +return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua new file mode 100644 index 00000000..c0e1633b --- /dev/null +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Left Gui.lua @@ -0,0 +1,23 @@ +--[[ +Explosive Gaming + +This file can be used with permission but this and the credit below must remain in the file. +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='File Header - ExpGaming-Core-GUI', + owner='Explosive Gaming', + dev='Cooldude2606', + description='Just A File Header To Organise Code', + 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----------------------------------------------------------- + +--Please Only Edit Above This Line----------------------------------------------------------- +return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua new file mode 100644 index 00000000..dec5d7ec --- /dev/null +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Modlue Setup.lua @@ -0,0 +1,49 @@ +--[[ +Explosive Gaming + +This file can be used with permission but this and the credit below must remain in the file. +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='Setup for the Gui Object', + owner='Explosive Gaming', + dev='Cooldude2606', + description='The very fondation of the Gui System', + 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----------------------------------------------------------- +ExpGui = { + add_frame={ + --center + --left + --popup + }, + add_input={ + --button + --text + --draw_button + --draw_text + }, + toolbar={ + --draw + --add_button + }, + --add_player_table + inputs={ + buttons={}, + text={} + }, + frames={ + center={}, + left={}, + popup={} + } +} +--Please Only Edit Above This Line----------------------------------------------------------- +return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Player Table.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Player Table.lua new file mode 100644 index 00000000..c0e1633b --- /dev/null +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Player Table.lua @@ -0,0 +1,23 @@ +--[[ +Explosive Gaming + +This file can be used with permission but this and the credit below must remain in the file. +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='File Header - ExpGaming-Core-GUI', + owner='Explosive Gaming', + dev='Cooldude2606', + description='Just A File Header To Organise Code', + 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----------------------------------------------------------- + +--Please Only Edit Above This Line----------------------------------------------------------- +return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Popup.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Popup.lua new file mode 100644 index 00000000..c0e1633b --- /dev/null +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Popup.lua @@ -0,0 +1,23 @@ +--[[ +Explosive Gaming + +This file can be used with permission but this and the credit below must remain in the file. +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='File Header - ExpGaming-Core-GUI', + owner='Explosive Gaming', + dev='Cooldude2606', + description='Just A File Header To Organise Code', + 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----------------------------------------------------------- + +--Please Only Edit Above This Line----------------------------------------------------------- +return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua new file mode 100644 index 00000000..c0e1633b --- /dev/null +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Toolbar.lua @@ -0,0 +1,23 @@ +--[[ +Explosive Gaming + +This file can be used with permission but this and the credit below must remain in the file. +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='File Header - ExpGaming-Core-GUI', + owner='Explosive Gaming', + dev='Cooldude2606', + description='Just A File Header To Organise Code', + 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----------------------------------------------------------- + +--Please Only Edit Above This Line----------------------------------------------------------- +return credits \ No newline at end of file diff --git a/locale/ExpGaming-Core/GUI/file-header.lua b/locale/ExpGaming-Core/GUI/file-header.lua index c0e1633b..32df0761 100644 --- a/locale/ExpGaming-Core/GUI/file-header.lua +++ b/locale/ExpGaming-Core/GUI/file-header.lua @@ -18,6 +18,12 @@ local credits = {{ }} local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end --Please Only Edit Below This Line----------------------------------------------------------- - +credit_loop(require("ExpGaming - Modlue Setup")) +credit_loop(require("ExpGaming - Inputs")) +credit_loop(require("ExpGaming - Toolbar")) +credit_loop(require("ExpGaming - Center Gui")) +credit_loop(require("ExpGaming - Left Gui")) +credit_loop(require("ExpGaming - Player Table")) +credit_loop(require("ExpGaming - Popup")) --Please Only Edit Above This Line----------------------------------------------------------- return credits \ No newline at end of file