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

@@ -6,7 +6,7 @@ Manager.setVerbose{
moduleLoad=false, -- when a module is required by the manager moduleLoad=false, -- when a module is required by the manager
moduleInit=false, -- when and within the initation of a module moduleInit=false, -- when and within the initation of a module
modulePost=false, -- when and within the post of a module modulePost=false, -- when and within the post of a module
moduleEnv=true, -- during module runtime, this is a global option set within each module for fine control moduleEnv=false, -- during module runtime, this is a global option set within each module for fine control
eventRegistered=false, -- when a module registers its event handlers eventRegistered=false, -- when a module registers its event handlers
errorCaught=true, -- when an error is caught during runtime errorCaught=true, -- when an error is caught during runtime
output=Manager._verbose -- can be: can be: print || log || other function output=Manager._verbose -- can be: can be: print || log || other function

View File

@@ -252,6 +252,7 @@ return commands
commands.add_command('foo',{'foo.description'},{ commands.add_command('foo',{'foo.description'},{
['player']={true,'player'}, -- a required arg that must be a valid player ['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 ['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) ['reason']={false,'string-inf'} -- an optinal arg that is and infite lengh (useful for reasons)
},function(event,args) },function(event,args)
args.player.print(args.number) args.player.print(args.number)

View File

@@ -27,12 +27,22 @@ Gui.data = setmetatable({},{
end end
}) })
local events = {}
Gui.center = require(module_path..'/src/center',{Gui=Gui}) 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}) 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.left = require(module_path..'/src/left',{Gui=Gui})
Gui.popup = require(module_path..'/src/popup',{Gui=Gui}) Gui.popup = require(module_path..'/src/popup',{Gui=Gui})
Gui.toolbar = require(module_path..'/src/toolbar',{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 --- Add a white bar to any gui frame
-- @usage Gui.bar(frame,100) -- @usage Gui.bar(frame,100)
-- @param frame the frame to draw the line to -- @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 end
-- used so that when gui close key is pressed this will close the gui -- 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 if event.element and event.element.valid then event.element.destroy() end
end) end}
center.on_rank_change = center.clear center.on_rank_change = center.clear
return center return center

View File

@@ -125,6 +125,7 @@ function inputs._event_handler(event)
element = elements[event.element.name] element = elements[event.element.name]
end end
if element then 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 if not is_type(element.events[event.name],'function') then return end
local success, err = pcall(element.events[event.name],event) local success, err = pcall(element.events[event.name],event)
if not success then if not success then
@@ -134,13 +135,15 @@ function inputs._event_handler(event)
end end
end end
script.on_event(inputs.events.state,inputs._event_handler) inputs._events = {
script.on_event(inputs.events.click,inputs._event_handler) [inputs.events.state]=inputs._event_handler,
script.on_event(inputs.events.elem,inputs._event_handler) [inputs.events.click]=inputs._event_handler,
script.on_event(inputs.events.state,inputs._event_handler) [inputs.events.elem]=inputs._event_handler,
script.on_event(inputs.events.text,inputs._event_handler) [inputs.events.state]=inputs._event_handler,
script.on_event(inputs.events.slider,inputs._event_handler) [inputs.events.text]=inputs._event_handler,
script.on_event(inputs.events.selection,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) -- 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 --- 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 --- This is a submodule of ExpGamingCore.Gui but for ldoc reasons it is under its own module
-- @function _comment -- @function _comment
local Game = require('FactorioStdLib.Game@^0.8.0')
local Gui = Gui -- this is to force gui to remain in the ENV local Gui = Gui -- this is to force gui to remain in the ENV
local mod_gui = require("mod-gui") local mod_gui = require("mod-gui")

View File

@@ -3,25 +3,19 @@
-- @author Cooldude2606 -- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
local Game = require('FactorioStdLib.Game') local Game = require('FactorioStdLib.Game@^0.8.0')
local Gui = require('ExpGamingCore.Gui') local Gui = require('ExpGamingCore.Gui@^4.0.0')
local Admin -- hanndled on load local Admin -- ExpGamingAdmin.AdminLib@^4.0.0
local global = global{ -- Local Varibles
update=0, local playerInfo = function(player,frame)
delay=10,
intervial=54000
}
-- this will be replaced on load if playerInfo module is present
local function playerInfo(player,frame)
frame.add{ frame.add{
type='label', type='label',
caption={'player-list.no-info-file'} caption={'ExpGamingPlayer-playerList.no-info-file'}
} }
end end
local function getPlayers() local getPlayers = function()
local rtn = {{{r=233,g=63,b=233},'Admin',{}},{{r=255,g=159,b=27},'',{}}} local rtn = {{{r=233,g=63,b=233},'Admin',{}},{{r=255,g=159,b=27},'',{}}}
for _,player in pairs(game.connected_players) do for _,player in pairs(game.connected_players) do
if player.admin then table.insert(rtn[2][3],player) if player.admin then table.insert(rtn[2][3],player)
@@ -30,7 +24,24 @@ local function getPlayers()
return rtn return rtn
end end
local function queue_update(tick) -- Module Define
local module_verbose = false
local ThisModule = {
on_init=function(self)
if loaded_modules['ExpGamingPlayer.playerInfo'] then playerInfo = require('ExpGamingPlayer.playerInfo') end
if loaded_modules['ExpGamingCore.Ranking@^4.0.0'] then getPlayers = require(module_path..'/src/ranking') end
if loaded_modules['ExpGamingAdmin.AdminLib@^4.0.0'] then Admin = require('ExpGamingAdmin.AdminLib@^4.0.0') end
end
}
-- Global Define
local global = global{
update=0,
delay=10,
intervial=54000
}
function ThisModule.update(tick)
local tick = is_type(tick,'table') and tick.tick or is_type(tick,'number') and tick or game.tick local tick = is_type(tick,'table') and tick.tick or is_type(tick,'number') and tick or game.tick
if tick + global.delay > global.update - global.intervial then if tick + global.delay > global.update - global.intervial then
global.update = tick + global.delay global.update = tick + global.delay
@@ -49,7 +60,7 @@ end)
Gui.left.add{ Gui.left.add{
name='player-list', name='player-list',
caption='entity/player', caption='entity/player',
tooltip={'player-list.tooltip'}, tooltip={'ExpGamingPlayer-playerList.tooltip'},
draw=function(frame) draw=function(frame)
frame.caption = '' frame.caption = ''
local player_list = frame.add{ local player_list = frame.add{
@@ -70,18 +81,18 @@ Gui.left.add{
type='label', type='label',
name=player.name, name=player.name,
style='caption_label', style='caption_label',
caption={'player-list.format-nil',tick_to_display_format(player.online_time),player.name} caption={'ExpGamingPlayer-playerList.format-nil',tick_to_display_format(player.online_time),player.name}
}.style.font_color = rank[1] }.style.font_color = rank[1]
else else
flow.add{ flow.add{
type='label', type='label',
name=player.name, name=player.name,
style='caption_label', style='caption_label',
caption={'player-list.format',tick_to_display_format(player.online_time),player.name,rank[2]} caption={'ExpGamingPlayer-playerList.format',tick_to_display_format(player.online_time),player.name,rank[2]}
}.style.font_color = rank[1] }.style.font_color = rank[1]
end end
if Admin.report_btn then if Admin and Admin.report_btn then
if not rank:allowed('no-report') and player.index ~= frame.player_index then if not rank[4] and player.index ~= frame.player_index then
local btn = Admin.report_btn:draw(flow) local btn = Admin.report_btn:draw(flow)
btn.style.height = 20 btn.style.height = 20
btn.style.width = 20 btn.style.width = 20
@@ -114,18 +125,12 @@ script.on_event(defines.events.on_gui_click,function(event)
back_btn:draw(flow) back_btn:draw(flow)
playerInfo(event.element.name,flow,true) playerInfo(event.element.name,flow,true)
if Game.get_player(event.element.name) and event.player_index == Game.get_player(event.element.name).index then return end if Game.get_player(event.element.name) and event.player_index == Game.get_player(event.element.name).index then return end
if Admin and Admin.allowed and Admin.allowed(event.player_index) then Admin.btn_flow(flow).caption = event.element.name end if Admin and Admin.allowed(event.player_index) then Admin.btn_flow(flow).caption = event.element.name end
end) end)
script.on_event(defines.events.on_player_joined_game,queue_update) script.on_event(defines.events.on_player_joined_game,ThisModule.update)
script.on_event(defines.events.on_player_left_game,queue_update) script.on_event(defines.events.on_player_left_game,ThisModule.update)
script.on_event(defines.events.rank_change,queue_update) script.on_event(defines.events.rank_change,ThisModule.update)
return { ThisModule.force_update = function() return Gui.left.update('player-list') end
force_update=function() return Gui.left.update('player-list') end, return ThisModule
update=queue_update,
on_init=function(self)
if loaded_modules['ExpGamingPlayer.playerInfo'] then playerInfo = require('ExpGamingPlayer.playerInfo') end
if loaded_modules['ExpGamingAdmin.AdminLib'] then Admin = require('ExpGamingAdmin.AdminLib') end
end
}

View File

@@ -1,4 +1,4 @@
[player-list] [ExpGamingPlayer-playerList]
tooltip=Verkleinere die Spielerliste. Rechtsklicke einen Spieler für Informationen über ihn. tooltip=Verkleinere die Spielerliste. Rechtsklicke einen Spieler für Informationen über ihn.
format-nil=__1__ - __2__ format-nil=__1__ - __2__
format=__1__ - __2__ - __3__ format=__1__ - __2__ - __3__

View File

@@ -1,4 +1,4 @@
[player-list] [ExpGamingPlayer-playerList]
tooltip=Toggle player list, right click player for more info tooltip=Toggle player list, right click player for more info
format-nil=__1__ - __2__ format-nil=__1__ - __2__
format=__1__ - __2__ - __3__ format=__1__ - __2__ - __3__

View File

@@ -1,4 +1,4 @@
[player-list] [ExpGamingPlayer-playerList]
tooltip=Toogle player list, right click player for info tooltip=Toogle player list, right click player for info
format-nil=__1__ - __2__ format-nil=__1__ - __2__
format=__1__ - __2__ - __3__ format=__1__ - __2__ - __3__

View File

@@ -1,4 +1,4 @@
[player-list] [ExpGamingPlayer-playerList]
tooltip=Toggle speler lijst. Rechtermuisklik op een speler voor meer info tooltip=Toggle speler lijst. Rechtermuisklik op een speler voor meer info
format-nil=__1__ - __2__ format-nil=__1__ - __2__
format=__1__ - __2__ - __3__ format=__1__ - __2__ - __3__

View File

@@ -1,4 +1,4 @@
[player-list] [ExpGamingPlayer-playerList]
tooltip=Växla spelarlista, högerklicka på spelare för mer information. tooltip=Växla spelarlista, högerklicka på spelare för mer information.
format-nil=__1__ - __2__ format-nil=__1__ - __2__
format=__1__ - __2__ - __3__ format=__1__ - __2__ - __3__

View File

@@ -1,9 +1,9 @@
local Ranking = require('ExpGamingCore.Ranking') local Ranking = require('ExpGamingCore.Ranking@^4.0.0')
return function() return function()
local rtn = {} local rtn = {}
for _,rank in pairs(Ranking.ranks) do for _,rank in pairs(Ranking.ranks) do
table.insert(rtn,{rank.colour,rank.short_hand,rank:get_players(true)) table.insert(rtn,{rank.colour,rank.short_hand,rank:get_players(true),rank:allowed('no-report')})
end end
return rtn return rtn
end end

View File

@@ -19,7 +19,6 @@ return {
['ExpGamingCore.Server@^4.0.0']='./modules/ExpGamingCore/Server', ['ExpGamingCore.Server@^4.0.0']='./modules/ExpGamingCore/Server',
['ExpGamingCommands.tags@4.0.0']='./modules/ExpGamingCommands/tags', ['ExpGamingCommands.tags@4.0.0']='./modules/ExpGamingCommands/tags',
['ExpGamingCore.Commands@^4.0.0']='./modules/ExpGamingCore/Commands', ['ExpGamingCore.Commands@^4.0.0']='./modules/ExpGamingCore/Commands',
['ExpGamingAdmin.Commands@4.0.0']='./modules/ExpGamingCommands/kill',
['ExpGamingCommands.home@4.0.0']='./modules/ExpGamingCommands/home', ['ExpGamingCommands.home@4.0.0']='./modules/ExpGamingCommands/home',
['ExpGamingCommands.cheatMode@4.0.0']='./modules/ExpGamingCommands/cheatMode', ['ExpGamingCommands.cheatMode@4.0.0']='./modules/ExpGamingCommands/cheatMode',
['ExpGamingCommands.bonus@4.0.0']='./modules/ExpGamingCommands/bonus', ['ExpGamingCommands.bonus@4.0.0']='./modules/ExpGamingCommands/bonus',
@@ -27,12 +26,12 @@ return {
['ExpGamingCore.Gui@4.0.0']='./modules/ExpGamingCore/Gui', ['ExpGamingCore.Gui@4.0.0']='./modules/ExpGamingCore/Gui',
['ExpGamingCore.Sync@^4.0.0']='./modules/ExpGamingCore/Sync', ['ExpGamingCore.Sync@^4.0.0']='./modules/ExpGamingCore/Sync',
['ExpGamingPlayer.playerList@4.0.0']='./modules/ExpGamingPlayer/playerList', ['ExpGamingPlayer.playerList@4.0.0']='./modules/ExpGamingPlayer/playerList',
['ExpGamingAdmin.AdminLib@^4.0.0']='./modules/ExpGamingAdmin/AdminLib',
['ExpGamingPlayer.playerInfo@4.0.0']='./modules/ExpGamingPlayer/playerInfo', ['ExpGamingPlayer.playerInfo@4.0.0']='./modules/ExpGamingPlayer/playerInfo',
['ExpGamingCore.Sync@4.0.0']='./modules/ExpGamingCore/Sync', ['ExpGamingCore.Sync@4.0.0']='./modules/ExpGamingCore/Sync',
['ExpGamingBot.discordAlerts@4.0.0']='./modules/ExpGamingBot/discordAlerts', ['ExpGamingBot.discordAlerts@4.0.0']='./modules/ExpGamingBot/discordAlerts',
['ExpGamingBot.autoMessage@4.0.0']='./modules/ExpGamingBot/autoMessage', ['ExpGamingBot.autoMessage@4.0.0']='./modules/ExpGamingBot/autoMessage',
['ExpGamingPlayer.afkKick@4.0.0']='./modules/ExpGamingPlayer/afkKick', ['ExpGamingPlayer.afkKick@4.0.0']='./modules/ExpGamingPlayer/afkKick',
['ExpGamingAdmin.AdminLib@^4.0.0']='./modules/ExpGamingAdmin/AdminLib',
['ExpGamingAdmin.AdminLib@4.0.0']='./modules/ExpGamingAdmin/AdminLib', ['ExpGamingAdmin.AdminLib@4.0.0']='./modules/ExpGamingAdmin/AdminLib',
['ExpGamingAdmin.Warnings@4.0.0']='./modules/ExpGamingAdmin/Warnings', ['ExpGamingAdmin.Warnings@4.0.0']='./modules/ExpGamingAdmin/Warnings',
['ExpGamingAdmin.Reports@4.0.0']='./modules/ExpGamingAdmin/Reports', ['ExpGamingAdmin.Reports@4.0.0']='./modules/ExpGamingAdmin/Reports',
@@ -46,6 +45,6 @@ return {
['ExpGamingCommands.teleport@4.0.0']='./modules/ExpGamingCommands/teleport', ['ExpGamingCommands.teleport@4.0.0']='./modules/ExpGamingCommands/teleport',
['ExpGamingAdmin.Kick@4.0.0']='./modules/ExpGamingAdmin/Kick', ['ExpGamingAdmin.Kick@4.0.0']='./modules/ExpGamingAdmin/Kick',
['ExpGamingAdmin.Jail@4.0.0']='./modules/ExpGamingAdmin/Jail', ['ExpGamingAdmin.Jail@4.0.0']='./modules/ExpGamingAdmin/Jail',
['ExpGamingCommands.admin@4.0.0']='./modules/ExpGamingCommands/admin', ['ExpGamingAdmin.Commands@4.0.0']='./modules/ExpGamingAdmin/Commands',
['ExpGamingAdmin.Ban@4.0.0']='./modules/ExpGamingAdmin/Ban', ['ExpGamingAdmin.Ban@4.0.0']='./modules/ExpGamingAdmin/Ban',
} }