Fixed EapGamingCore.Gui

This commit is contained in:
Cooldude2606
2018-09-17 22:32:11 +01:00
parent fcba578e83
commit be49b06151
14 changed files with 70 additions and 51 deletions

View File

@@ -252,6 +252,7 @@ return commands
commands.add_command('foo',{'foo.description'},{
['player']={true,'player'}, -- a required arg that must be a valid player
['number']={true,'number-range',0,10}, -- a required arg that must be a number 0<X<=10
['pwd']={true,function(value,event) if value == 'password123' then return true else return commands.error('Invalid Password') end} -- a requireed arg pwd that has custom validation
['reason']={false,'string-inf'} -- an optinal arg that is and infite lengh (useful for reasons)
},function(event,args)
args.player.print(args.number)

View File

@@ -27,12 +27,22 @@ Gui.data = setmetatable({},{
end
})
local events = {}
Gui.center = require(module_path..'/src/center',{Gui=Gui})
table.merge(events,Gui.center._events)
Gui.center._events = nil
Gui.inputs = require(module_path..'/src/inputs',{Gui=Gui})
table.merge(events,Gui.inputs._events)
Gui.inputs._events = nil
Gui.left = require(module_path..'/src/left',{Gui=Gui})
Gui.popup = require(module_path..'/src/popup',{Gui=Gui})
Gui.toolbar = require(module_path..'/src/toolbar',{Gui=Gui})
for event,callback in pairs(events) do script.on_event(event,callback) end
--- Add a white bar to any gui frame
-- @usage Gui.bar(frame,100)
-- @param frame the frame to draw the line to

View File

@@ -205,9 +205,9 @@ function center._center:add_tab(name,caption,tooltip,callback)
end
-- used so that when gui close key is pressed this will close the gui
script.on_event('on_gui_closed',function(event)
center._events = {[defines.events.on_gui_closed]=function(event)
if event.element and event.element.valid then event.element.destroy() end
end)
end}
center.on_rank_change = center.clear
return center

View File

@@ -125,6 +125,7 @@ function inputs._event_handler(event)
element = elements[event.element.name]
end
if element then
verbose('There was a gui event ('..Event.names[event.name]..') with element: '..event.element.name)
if not is_type(element.events[event.name],'function') then return end
local success, err = pcall(element.events[event.name],event)
if not success then
@@ -134,13 +135,15 @@ function inputs._event_handler(event)
end
end
script.on_event(inputs.events.state,inputs._event_handler)
script.on_event(inputs.events.click,inputs._event_handler)
script.on_event(inputs.events.elem,inputs._event_handler)
script.on_event(inputs.events.state,inputs._event_handler)
script.on_event(inputs.events.text,inputs._event_handler)
script.on_event(inputs.events.slider,inputs._event_handler)
script.on_event(inputs.events.selection,inputs._event_handler)
inputs._events = {
[inputs.events.state]=inputs._event_handler,
[inputs.events.click]=inputs._event_handler,
[inputs.events.elem]=inputs._event_handler,
[inputs.events.state]=inputs._event_handler,
[inputs.events.text]=inputs._event_handler,
[inputs.events.slider]=inputs._event_handler,
[inputs.events.selection]=inputs._event_handler
}
-- the folwing functions are just to make inputs easier but if what you want is not include use inputs.add(obj)
--- Used to define a button, can have many function

View File

@@ -6,6 +6,7 @@
--- This is a submodule of ExpGamingCore.Gui but for ldoc reasons it is under its own module
-- @function _comment
local Game = require('FactorioStdLib.Game@^0.8.0')
local Gui = Gui -- this is to force gui to remain in the ENV
local mod_gui = require("mod-gui")