From 1db000dcf07b3cb9d447ee8c12794594a31c98aa Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 9 Dec 2018 15:47:18 +0000 Subject: [PATCH] Updated ExpGamingCore.Gui --- modules/ExpGamingAdmin/Commands/softmod.json | 10 +- modules/ExpGamingBot/autoMessage/softmod.json | 4 +- modules/ExpGamingCore/Group/softmod.json | 2 +- .../{src/center.lua => center/control.lua} | 21 +- modules/ExpGamingCore/Gui/center/softmod.json | 24 ++ modules/ExpGamingCore/Gui/control.lua | 41 +-- .../{src/inputs.lua => inputs/control.lua} | 21 +- modules/ExpGamingCore/Gui/inputs/softmod.json | 23 ++ modules/ExpGamingCore/Gui/left/control.lua | 245 ++++++++++++++++++ .../Gui/{ => left}/order_config.lua | 0 modules/ExpGamingCore/Gui/left/softmod.json | 26 ++ .../Gui/{src/popup.lua => popup/control.lua} | 44 ++-- modules/ExpGamingCore/Gui/popup/softmod.json | 24 ++ modules/ExpGamingCore/Gui/softmod.json | 15 +- modules/ExpGamingCore/Gui/src/left.lua | 240 ----------------- .../{src/toolbar.lua => toolbar/control.lua} | 9 +- .../Gui/toolbar/order_config.lua | 13 + .../ExpGamingCore/Gui/toolbar/softmod.json | 23 ++ modules/ExpGamingCore/Server/softmod.json | 6 +- modules/ExpGamingLib/softmod.json | 4 +- .../ExpGamingPlayer/playerList/softmod.json | 2 +- modules/test.txt | 1 - 22 files changed, 452 insertions(+), 346 deletions(-) rename modules/ExpGamingCore/Gui/{src/center.lua => center/control.lua} (94%) create mode 100644 modules/ExpGamingCore/Gui/center/softmod.json rename modules/ExpGamingCore/Gui/{src/inputs.lua => inputs/control.lua} (96%) create mode 100644 modules/ExpGamingCore/Gui/inputs/softmod.json create mode 100644 modules/ExpGamingCore/Gui/left/control.lua rename modules/ExpGamingCore/Gui/{ => left}/order_config.lua (100%) create mode 100644 modules/ExpGamingCore/Gui/left/softmod.json rename modules/ExpGamingCore/Gui/{src/popup.lua => popup/control.lua} (90%) create mode 100644 modules/ExpGamingCore/Gui/popup/softmod.json delete mode 100644 modules/ExpGamingCore/Gui/src/left.lua rename modules/ExpGamingCore/Gui/{src/toolbar.lua => toolbar/control.lua} (93%) create mode 100644 modules/ExpGamingCore/Gui/toolbar/order_config.lua create mode 100644 modules/ExpGamingCore/Gui/toolbar/softmod.json delete mode 100644 modules/test.txt diff --git a/modules/ExpGamingAdmin/Commands/softmod.json b/modules/ExpGamingAdmin/Commands/softmod.json index 048efd51..6318ff19 100644 --- a/modules/ExpGamingAdmin/Commands/softmod.json +++ b/modules/ExpGamingAdmin/Commands/softmod.json @@ -18,11 +18,11 @@ "dependencies": { "ExpGamingLib": "^4.0.0", "ExpGamingCore.Command": "^4.0.0", - "ExpGamingAdmin.TempBan": "?*", - "ExpGamingAdmin.Jail": "?*", - "ExpGamingAdmin.Warnings": "?*", - "ExpGamingAdmin.Reports": "?*", - "ExpGamingAdmin.ClearInventory": "?*", + "ExpGamingAdmin.TempBan": "?^4.0.0", + "ExpGamingAdmin.Jail": "?^4.0.0", + "ExpGamingAdmin.Warnings": "?^4.0.0", + "ExpGamingAdmin.Reports": "?^4.0.0", + "ExpGamingAdmin.ClearInventory": "?^4.0.0", "ExpGamingAdmin.AdminLib": "^4.0.0" }, "collection": "ExpGamingAdmin@4.0.0", diff --git a/modules/ExpGamingBot/autoMessage/softmod.json b/modules/ExpGamingBot/autoMessage/softmod.json index 677e9d2b..2f4d5ea3 100644 --- a/modules/ExpGamingBot/autoMessage/softmod.json +++ b/modules/ExpGamingBot/autoMessage/softmod.json @@ -11,8 +11,8 @@ "Message" ], "dependencies": { - "ExpGamingCore.Server": "*", - "FactorioStdLib.Game": "*", + "ExpGamingCore.Server": "^4.0.0", + "FactorioStdLib.Game": "^0.8.0", "ExpGamingCore.Role": "^4.0.0", "ExpGamingCore.Sync": "^4.0.0" }, diff --git a/modules/ExpGamingCore/Group/softmod.json b/modules/ExpGamingCore/Group/softmod.json index 51157d8b..ae5eee74 100644 --- a/modules/ExpGamingCore/Group/softmod.json +++ b/modules/ExpGamingCore/Group/softmod.json @@ -16,7 +16,7 @@ "FactorioStdLib": "^0.8.0", "ExpGamingCore.Server": "^4.0.0", "ExpGamingLib": "^4.0.0", - "FactorioStdLib.Game": "*" + "FactorioStdLib.Game": "^0.8.0" }, "collection": "ExpGamingCore@4.0.0", "submodules": {} diff --git a/modules/ExpGamingCore/Gui/src/center.lua b/modules/ExpGamingCore/Gui/center/control.lua similarity index 94% rename from modules/ExpGamingCore/Gui/src/center.lua rename to modules/ExpGamingCore/Gui/center/control.lua index e51c35ea..a1f56b83 100644 --- a/modules/ExpGamingCore/Gui/src/center.lua +++ b/modules/ExpGamingCore/Gui/center/control.lua @@ -1,16 +1,13 @@ --- Adds a uniform preset for guis in the center of the screen which allow for different tabs to be opened --- @module ExpGamingCore.Gui.Center +-- @module ExpGamingCore.Gui.center -- @alias center -- @author Cooldude2606 -- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE ---- This is a submodule of ExpGamingCore.Gui but for ldoc reasons it is under its own module --- @function _comment - local Game = require('FactorioStdLib.Game') local Color = require('FactorioStdLib.Color') -local mod_gui = require("mod-gui") -local Gui = Gui -- this is to force gui to remain in the ENV +local Gui = require('ExpGamingCore.Gui') +local mod_gui = require('mod-gui') local center = {} center._prototype = {} @@ -28,7 +25,7 @@ function center.add(obj) obj.tabs = {} obj._tabs = {} Gui.data('center',obj.name,obj) - Gui.toolbar(obj.name,obj.caption,obj.tooltip,obj.open) + if Gui.toolbar then Gui.toolbar(obj.name,obj.caption,obj.tooltip,obj.open) end return obj end @@ -206,10 +203,14 @@ function center._prototype:add_tab(name,caption,tooltip,callback) end -- used so that when gui close key is pressed this will close the gui -center._events = {[defines.events.on_gui_closed]=function(event) +script.on_event(defines.events.on_gui_closed,function(event) if event.element and event.element.valid then event.element.destroy() end -end} +end) -center.on_role_change = center.clear +script.on_event(defines.events.on_player_respawned,center.clear) + +function center:on_init() + if loaded_modules['ExpGamingCore.Role'] then script.on_event(defines.events.on_role_change,center.clear) end +end -- calling will attempt to add a new gui return setmetatable(center,{__call=function(self,...) return self.add(...) end}) \ No newline at end of file diff --git a/modules/ExpGamingCore/Gui/center/softmod.json b/modules/ExpGamingCore/Gui/center/softmod.json new file mode 100644 index 00000000..7d1dda86 --- /dev/null +++ b/modules/ExpGamingCore/Gui/center/softmod.json @@ -0,0 +1,24 @@ +{ + "name": "ExpGamingCore.Gui.center", + "version": "4.0.0", + "description": "Adds a pre-made center gui format.", + "author": "Cooldude2606", + "contact": "Discord: Cooldude2606#5241", + "license": "https://github.com/explosivegaming/scenario/blob/master/LICENSE", + "location": "FSM_ARCHIVE", + "keywords": [ + "Gui", + "Center" + ], + "collection": "ExpGamingCore.Gui@4.0.0", + "dependencies": { + "mod-gui": "*", + "FactorioStdLib.Game": "^0.8.0", + "FactorioStdLib.Color": "^0.8.0", + "ExpGamingCore.Role": "?^4.0.0", + "ExpGamingCore.Gui": "^4.0.0", + "ExpGamingCore.Gui.inputs": "^4.0.0", + "ExpGamingCore.Gui.toolbar": "?^4.0.0" + }, + "submodules": {} +} diff --git a/modules/ExpGamingCore/Gui/control.lua b/modules/ExpGamingCore/Gui/control.lua index 9c20d668..4482a500 100644 --- a/modules/ExpGamingCore/Gui/control.lua +++ b/modules/ExpGamingCore/Gui/control.lua @@ -27,23 +27,6 @@ Gui.data = setmetatable({},{ end }) -local events = {} -local order_config = require(module_path..'/order_config') - -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,order_config=order_config,self_global=global}) -Gui.popup = require(module_path..'/src/popup',{Gui=Gui}) -Gui.toolbar = require(module_path..'/src/toolbar',{Gui=Gui,order_config=order_config}) - -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 @@ -158,11 +141,7 @@ function Gui.cam_link(data) end script.on_event('on_tick', function(event) - if Gui.left and ((event.tick+10)/(3600*game.speed)) % 15 == 0 then - Gui.left.update() - end if loaded_modules['ExpGamingCore.Server'] then return end - if global.cams and is_type(global.cams,'table') and #global.cams > 0 then local update = 4 if global.cam_index >= #global.cams then global.cam_index = 1 end @@ -180,7 +159,6 @@ script.on_event('on_tick', function(event) end) script.on_event('on_player_respawned',function(event) - if Gui.center then Gui.center.clear() end if loaded_modules['ExpGamingCore.Server'] then return end if global.players and is_type(global.players,'table') and #global.players > 0 and global.players[event.player_index] then local remove = {} @@ -195,26 +173,15 @@ script.on_event('on_player_respawned',function(event) end) function Gui:on_init() - self.left:on_init(); self.left.on_init = nil - self.toolbar:on_init(); self.toolbar.on_init = nil - if loaded_modules['ExpGamingCore.Server@^4.0.0'] then Server = require('ExpGamingCore.Server@^4.0.0') verbose('ExpGamingCore.Server is installed; Loading server src') script.on_init(require(module_path..'/src/server',{Gui=self})) end - if loaded_modules['ExpGamingCore.Role@^4.0.0'] then - verbose('ExpGamingCore.Role is installed; Loading ranking src') - script.on_event('on_role_change',function(event) - self.toolbar.on_role_change(event) - self.center.on_role_change(event) - end) + if loaded_modules['ExpGamingCore.Server@^4.0.0'] then + Server = require('ExpGamingCore.Server@^4.0.0') + verbose('ExpGamingCore.Server is installed; Loading server src') + script.on_init(require(module_path..'/src/server',{Gui=self})) end - script.on_event('on_player_joined_game',function(event) - self.toolbar.on_player_joined_game(event) - self.popup.on_player_joined_game(event) - self.left.on_player_joined_game(event) - end) end function Gui:on_post() Gui.test = require(module_path..'/src/test',{Gui=Gui}) - Gui.popup.load() Gui.popup.load = nil end diff --git a/modules/ExpGamingCore/Gui/src/inputs.lua b/modules/ExpGamingCore/Gui/inputs/control.lua similarity index 96% rename from modules/ExpGamingCore/Gui/src/inputs.lua rename to modules/ExpGamingCore/Gui/inputs/control.lua index cbd7d404..3785c277 100644 --- a/modules/ExpGamingCore/Gui/src/inputs.lua +++ b/modules/ExpGamingCore/Gui/inputs/control.lua @@ -9,14 +9,14 @@ local Game = require('FactorioStdLib.Game') local Color = require('FactorioStdLib.Color') -local mod_gui = require("mod-gui") -local Gui = Gui -- this is to force gui to remain in the ENV +local mod_gui = require('mod-gui') +local Gui = require('ExpGamingCore.Gui') local inputs = {} inputs._prototype = {} -- these are just so you can have short cuts to this inputs.events = { - error='error', + --error={}, -- this is added after event calls are added as it is not a script event state=defines.events.on_gui_checked_state_changed, click=defines.events.on_gui_click, elem=defines.events.on_gui_elem_changed, @@ -33,7 +33,7 @@ inputs.events = { function inputs._prototype:on_event(event,callback) if not is_type(callback,'function') then return self end if inputs.events[event] then event = inputs.events[event] end - if event == 'error' then self._error = callback return self end + if event == inputs.events.error then self._error = callback return self end self.events[event] = callback return self end @@ -136,15 +136,8 @@ function inputs._event_handler(event) end end -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 -} +script.on_event(inputs.events,inputs._event_handler) +inputs.events.error = {} -- 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 @@ -381,5 +374,3 @@ end -- calling will attempt to add a new input return setmetatable(inputs,{__call=function(self,...) return self.add(...) end}) - --- to see examples look at GuiParts/test.lua diff --git a/modules/ExpGamingCore/Gui/inputs/softmod.json b/modules/ExpGamingCore/Gui/inputs/softmod.json new file mode 100644 index 00000000..ba17e5a2 --- /dev/null +++ b/modules/ExpGamingCore/Gui/inputs/softmod.json @@ -0,0 +1,23 @@ +{ + "name": "ExpGamingCore.Gui.inputs", + "version": "4.0.0", + "description": "Addds an event manager for gui inputs and easy input creation", + "author": "Cooldude2606", + "contact": "Discord: Cooldude2606#5241", + "license": "https://github.com/explosivegaming/scenario/blob/master/LICENSE", + "location": "FSM_ARCHIVE", + "keywords": [ + "Gui", + "Inputs", + "Buttons", + "Text Fields" + ], + "collection": "ExpGamingCore.Gui@4.0.0", + "dependencies": { + "mod-gui": "*", + "FactorioStdLib.Color": "^0.8.0", + "FactorioStdLib.Game": "^0.8.0", + "ExpGamingCore.Gui": "^4.0.0" + }, + "submodules": {} +} diff --git a/modules/ExpGamingCore/Gui/left/control.lua b/modules/ExpGamingCore/Gui/left/control.lua new file mode 100644 index 00000000..ed89957f --- /dev/null +++ b/modules/ExpGamingCore/Gui/left/control.lua @@ -0,0 +1,245 @@ +--- Adds a organiser for left gui ellements which will automaticaly update there information and have open requirements +-- @module ExpGamingCore.Gui.Left +-- @alias left +-- @author Cooldude2606 +-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE + +--- This is a submodule of ExpGamingCore.Gui but for ldoc reasons it is under its own module +-- @function _comment +local Game = require('FactorioStdLib.Game') +local Server = require('ExpGamingCore.Server') +local Color = require('FactorioStdLib.Color') +local mod_gui = require('mod-gui') +local Gui = require('ExpGamingCore.Gui') +local order_config = require(module_path..'/order_config') +local Role -- this is optional and is hanndled by it being present, it is loaded on init + +local left = {} +left._prototype = {} + +left.hide = Gui.inputs{ + name='gui-left-hide', + type='button', + caption='<' +}:on_event('click',function(event) + for _,child in pairs(event.element.parent.children) do + if child.name ~= 'popups' then child.style.visible = false end + end +end) + +local global = global() + +-- used for debugging +function left.override_open(state) + global.over_ride_left_can_open = state +end +--- Used to add a left gui frame +-- @usage Gui.left.add{name='foo',caption='Foo',tooltip='just testing',open_on_join=true,can_open=function,draw=function} +-- @usage return_value(player) -- toggles visiblity for that player, if no player then updates for all players +-- @param obj this is what will be made, needs a name and a draw function(root_frame), open_on_join can be used to set the deaful state true/false, can_open is a test to block it from opening but is not needed +-- @return the object that is made, calling the returned value with out a param will update the gui, else will toggle visiblity for that player +function left.add(obj) + if not is_type(obj,'table') then return end + if not is_type(obj.name,'string') then return end + verbose('Created Left Gui: '..obj.name) + setmetatable(obj,{__index=left._prototype,__call=function(self,player) if player then return self:toggle(player) else return left.update(self.name) end end}) + Gui.data('left',obj.name,obj) + if Gui.toolbar then Gui.toolbar(obj.name,obj.caption,obj.tooltip,function(event) obj:toggle(event) end) end + return obj +end + +--- This is used to update all the guis of connected players, good idea to use our thread system as it as nested for loops +-- @usage Gui.left.update() +-- @tparam[opt] string frame this is the name of a frame if you only want to update one +-- @param[opt] players the player to update for, if not given all players are updated, can be one player +function left.update(frame,players) + if not Server or not Server._thread then + local players = is_type(players,'table') and #players > 0 and {unpack(players)} or is_type(players,'table') and {players} or Game.get_player(players) and {Game.get_player(players)} or game.connected_players + for _,player in pairs(players) do + local frames = Gui.data.left or {} + if frame then frames = {[frame]=frames[frame]} or {} end + for name,left in pairs(frames) do + if _left then left:first_open(player) end + end + end + else + local frames = Gui.data.left or {} + if frame then frames = {[frame]=frames[frame]} or {} end + local players = is_type(players,'table') and #players > 0 and {unpack(players)} or is_type(players,'table') and {players} or Game.get_player(players) and {Game.get_player(players)} or game.connected_players + Server.new_thread{ + data={players=players,frames=frames} + }:on_event('tick',function(thread) + if #thread.data.players == 0 then thread:close() return end + local player = table.remove(thread.data.players,1) + Server.new_thread{ + data={player=player,frames=thread.data.frames} + }:on_event('resolve',function(thread) + for name,left in pairs(thread.data.frames) do + if left then left:first_open(thread.data.player) end + end + end):queue() + end):open() + end +end + +--- Used to open the left gui of every player +-- @usage Gui.left.open('foo') +-- @tparam string left_name this is the gui that you want to open +-- @tparam[opt] LuaPlayer the player to open the gui for +function left.open(left_name,player) + local players = player and {player} or game.connected_players + local _left = Gui.data.left[left_name] + if not _left then return end + if not Server or not Server._thread then + for _,player in pairs(players) do _left:open(player) end + else + Server.new_thread{ + data={players=players} + }:on_event('tick',function(thread) + if #thread.data.players == 0 then thread:close() return end + local player = table.remove(thread.data.players,1) + _left:open(player) + end):open() + end +end + +--- Used to close the left gui of every player +-- @usage Gui.left.close('foo') +-- @tparam string left_name this is the gui that you want to close +-- @tparam[opt] LuaPlayer the player to close the gui for +function left.close(left_name,player) + local players = player and {player} or game.connected_players + local _left = Gui.data.left[left_name] + if not _left then return end + if not Server or not Server._thread or player then + for _,player in pairs(players) do _left:close(player) end + else + Server.new_thread{ + data={players=players} + }:on_event('tick',function(thread) + if #thread.data.players == 0 then thread:close() return end + local player = table.remove(thread.data.players,1) + _left:close(player) + end):open() + end +end + + +--- Used to force the gui open for the player +-- @usage left:open(player) +-- @tparam luaPlayer player the player to open the gui for +function left._prototype:open(player) + local player = Game.get_player(player) + if not player then error('Invalid Player') end + local left_flow = mod_gui.get_frame_flow(player) + if not left_flow[self.name] then self:first_open(player) end + left_flow[self.name].style.visible = true + if left_flow['gui-left-hide'] then left_flow['gui-left-hide'].style.visible = true end +end + +--- Used to force the gui closed for the player +-- @usage left:open(player) +-- @tparam luaPlayer player the player to close the gui for +function left._prototype:close(player) + local player = Game.get_player(player) + if not player then error('Invalid Player') end + local left_flow = mod_gui.get_frame_flow(player) + if not left_flow[self.name] then self:first_open(player) end + left_flow[self.name].style.visible = false + local count = 0 + for _,child in pairs(left_flow.children) do if child.style.visible then count = count+1 end if count > 1 then break end end + if count == 1 and left_flow['gui-left-hide'] then left_flow['gui-left-hide'].style.visible = false end +end + +--- When the gui is first made or is updated this function is called, used by the script +-- @usage left:first_open(player) -- returns the frame +-- @tparam LuaPlayer player the player to draw the gui for +-- @treturn LuaFrame the frame made/updated +function left._prototype:first_open(player) + local player = Game.get_player(player) + local left_flow = mod_gui.get_frame_flow(player) + local frame = nil + if left_flow[self.name] then + frame = left_flow[self.name] + frame.clear() + else + if not left_flow['gui-left-hide'] then left.hide(left_flow).style.maximal_width=15 end + frame = left_flow.add{type='frame',name=self.name,style=mod_gui.frame_style,caption=self.caption,direction='vertical'} + frame.style.visible = false + if is_type(self.open_on_join,'boolean') then frame.style.visible = self.open_on_join left_flow['gui-left-hide'].style.visible = true end + end + if is_type(self.draw,'function') then self.draw(frame) else frame.style.visible = false error('No Callback On '..self.name) end + return frame +end + +--- Toggles the visiblity of the gui based on some conditions +-- @usage left:toggle(player) -- returns new state +-- @tparam LuaPlayer player the player to toggle the gui for, remember there are condition which need to be met +-- @treturn boolean the new state that the gui is in +function left._prototype:toggle(player) + local player = Game.get_player(player) + local left_flow = mod_gui.get_frame_flow(player) + if not left_flow[self.name] then self:first_open(player) end + local left = left_flow[self.name] + local open = false + if is_type(self.can_open,'function') then + local success, err = pcall(self.can_open,player) + if not success then error(err) + elseif err == true then open = true + elseif global.over_ride_left_can_open then + if is_type(Role,'table') then + if Role.allowed(player,self.name) then open = true + else open = {'ExpGamingCore_Gui.unauthorized'} end + else open = true end + else open = err end + else + if is_type(Role,'table') then + if Role.allowed(player,self.name) then open = true + else open = {'ExpGamingCore_Gui.unauthorized'} end + else open = true end + end + if open == true and left.style.visible ~= true then + left.style.visible = true + left_flow['gui-left-hide'].style.visible = true + else + left.style.visible = false + local count = 0 + for _,child in pairs(left_flow.children) do if child.style.visible then count = count+1 end if count > 1 then break end end + if count == 1 and left_flow['gui-left-hide'] then left_flow['gui-left-hide'].style.visible = false end + end + if open == false then player_return({'ExpGamingCore_Gui.cant-open-no-reason'},defines.textcolor.crit,player) player.play_sound{path='utility/cannot_build'} + elseif open ~= true then player_return({'ExpGamingCore_Gui.cant-open',open},defines.textcolor.crit,player) player.play_sound{path='utility/cannot_build'} end + return left.style.visible +end + +script.on_event(defines.events.on_player_joined_game,function(event) + -- draws the left guis when a player first joins, fake_event is just because i am lazy + local player = Game.get_player(event) + local frames = Gui.data.left or {} + local left_flow = mod_gui.get_frame_flow(player) + if not left_flow['gui-left-hide'] then left.hide(left_flow).style.maximal_width=15 end + local done = {} + for _,name in pairs(order_config) do + local left = Gui.data.left[name] + if left then + done[name] = true + left:first_open(player) + end + end + for name,left in pairs(frames) do + if not done[name] then left:first_open(player) end + end +end) + +script.on_event(defines.events.on_tick,function(event) + if ((event.tick+10)/(3600*game.speed)) % 15 == 0 then + left.update() + end +end) + +function left:on_init() + if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') end +end + +-- calling will attempt to add a new gui +return setmetatable(left,{__call=function(self,...) return self.add(...) end}) \ No newline at end of file diff --git a/modules/ExpGamingCore/Gui/order_config.lua b/modules/ExpGamingCore/Gui/left/order_config.lua similarity index 100% rename from modules/ExpGamingCore/Gui/order_config.lua rename to modules/ExpGamingCore/Gui/left/order_config.lua diff --git a/modules/ExpGamingCore/Gui/left/softmod.json b/modules/ExpGamingCore/Gui/left/softmod.json new file mode 100644 index 00000000..d02b320e --- /dev/null +++ b/modules/ExpGamingCore/Gui/left/softmod.json @@ -0,0 +1,26 @@ +{ + "name": "ExpGamingCore.Gui.left", + "version": "4.0.0", + "description": "Adds an easy way to create auto updating left guis with toggle buttons.", + "author": "Cooldude2606", + "contact": "Discord: Cooldude2606#5241", + "license": "https://github.com/explosivegaming/scenario/blob/master/LICENSE", + "location": "FSM_ARCHIVE", + "keywords": [ + "Gui", + "Left", + "AutoUpdate" + ], + "collection": "ExpGamingCore.Gui@4.0.0", + "dependencies": { + "mod-gui": "*", + "FactorioStdLib.Game": "^0.8.0", + "ExpGamingCore.Server": "^4.0.0", + "FactorioStdLib.Color": "^0.8.0", + "ExpGamingCore.Gui": "^4.0.0", + "ExpGamingCore.Gui.inputs": "^4.0.0", + "ExpGamingCore.Gui.toolbar": "?^4.0.0", + "ExpGamingCore.Role": "?^4.0.0" + }, + "submodules": {} +} diff --git a/modules/ExpGamingCore/Gui/src/popup.lua b/modules/ExpGamingCore/Gui/popup/control.lua similarity index 90% rename from modules/ExpGamingCore/Gui/src/popup.lua rename to modules/ExpGamingCore/Gui/popup/control.lua index 9c1bb03b..626f1172 100644 --- a/modules/ExpGamingCore/Gui/src/popup.lua +++ b/modules/ExpGamingCore/Gui/popup/control.lua @@ -8,25 +8,13 @@ -- @function _comment local Game = require('FactorioStdLib.Game') -local mod_gui = require("mod-gui") -local Gui = Gui -- this is to force gui to remain in the ENV +local mod_gui = require('mod-gui') +local Gui = require('ExpGamingCore.Gui') +local Server -- loaded on_init local popup = {} popup._prototype = {} -function popup.load() - popup._prototype.close = Gui.inputs.add{ - type='button', - name='popup-close', - caption='utility/set_bar_slot', - tooltip='Close This Popup' - }:on_event('click',function(event) - local frame = event.element.parent - local parent = frame.parent - if frame and frame.valid then frame.destroy() if #parent.children == 0 then parent.style.visible = false end end - end) -end - --- Used to add a popup gui style -- @usage Gui.left.add{name='foo',caption='Foo',draw=function} -- @usage return_value(data,player) -- opens popup for one player use popup.open to open for more than one player @@ -113,12 +101,30 @@ function popup.open(style,data,players) end end -function popup._prototype:add_left(obj) - obj.name = obj.name or self.name - self.left = Gui.left(obj) +function popup:on_init() + if loaded_modules['ExpGamingCore.Server'] then Server = require('ExpGamingCore.Server') end + if loaded_modules['ExpGamingCore.Gui.left'] then + function popup._prototype:add_left(obj) + obj.name = obj.name or self.name + self.left = Gui.left(obj) + end + end end -popup.on_player_joined_game = popup.flow +function popup:on_post() + popup._prototype.close = Gui.inputs.add{ + type='button', + name='popup-close', + caption='utility/set_bar_slot', + tooltip='Close This Popup' + }:on_event('click',function(event) + local frame = event.element.parent + local parent = frame.parent + if frame and frame.valid then frame.destroy() if #parent.children == 0 then parent.style.visible = false end end + end) +end + +script.on_event(defines.events.on_player_joined_game,popup.flow) -- calling will attempt to add a new popup style return setmetatable(popup,{__call=function(self,...) return self.add(...) end}) \ No newline at end of file diff --git a/modules/ExpGamingCore/Gui/popup/softmod.json b/modules/ExpGamingCore/Gui/popup/softmod.json new file mode 100644 index 00000000..f4b3f736 --- /dev/null +++ b/modules/ExpGamingCore/Gui/popup/softmod.json @@ -0,0 +1,24 @@ +{ + "name": "ExpGamingCore.Gui.popup", + "version": "4.0.0", + "description": "Adds popup guis to the gui system which builds upon the left gui system.", + "author": "Cooldude2606", + "contact": "Discord: Cooldude2606#5241", + "license": "https://github.com/explosivegaming/scenario/blob/master/LICENSE", + "location": "FSM_ARCHIVE", + "keywords": [ + "Gui", + "Popup", + "Left" + ], + "collection": "ExpGamingCore.Gui@4.0.0", + "dependencies": { + "mod-gui": "*", + "FactorioStdLib.Game": "^0.8.0", + "ExpGamingCore.Gui": "^4.0.0", + "ExpGamingCore.Gui.inputs": "^4.0.0", + "ExpGamingCore.Server": "?^4.0.0", + "ExpGamingCore.Gui.left": "?^4.0.0" + }, + "submodules": {} +} diff --git a/modules/ExpGamingCore/Gui/softmod.json b/modules/ExpGamingCore/Gui/softmod.json index bdf2b6bb..658649aa 100644 --- a/modules/ExpGamingCore/Gui/softmod.json +++ b/modules/ExpGamingCore/Gui/softmod.json @@ -15,11 +15,16 @@ "dependencies": { "ExpGamingLib": "^4.0.0", "FactorioStdLib.Table": "^0.8.0", - "FactorioStdLib.Color": "*", - "FactorioStdLib.Game": "*", - "ExpGamingCore.Role": "^4.0.0", - "ExpGamingCore.Server": "?*" + "FactorioStdLib.Color": "^0.8.0", + "FactorioStdLib.Game": "^0.8.0", + "ExpGamingCore.Server": "?^4.0.0" }, "collection": "ExpGamingCore@4.0.0", - "submodules": {} + "submodules": { + "ExpGamingCore.Gui.center": "4.0.0", + "ExpGamingCore.Gui.inputs": "4.0.0", + "ExpGamingCore.Gui.left": "4.0.0", + "ExpGamingCore.Gui.popup": "4.0.0", + "ExpGamingCore.Gui.toolbar": "4.0.0" + } } diff --git a/modules/ExpGamingCore/Gui/src/left.lua b/modules/ExpGamingCore/Gui/src/left.lua deleted file mode 100644 index 942ddf6b..00000000 --- a/modules/ExpGamingCore/Gui/src/left.lua +++ /dev/null @@ -1,240 +0,0 @@ ---- Adds a organiser for left gui ellements which will automaticaly update there information and have open requirements --- @module ExpGamingCore.Gui.Left --- @alias left --- @author Cooldude2606 --- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE - ---- This is a submodule of ExpGamingCore.Gui but for ldoc reasons it is under its own module --- @function _comment - - local Game = require('FactorioStdLib.Game') - local Server = require('ExpGamingCore.Server') - local Color = require('FactorioStdLib.Color') - local Role -- this is optional and is hanndled by it being present, it is loaded on init - local mod_gui = require("mod-gui") - local Gui = Gui -- this is to force gui to remain in the ENV - local order_config = order_config - - local left = {} - left._prototype = {} - - left.hide = Gui.inputs{ - name='gui-left-hide', - type='button', - caption='<' - }:on_event('click',function(event) - for _,child in pairs(event.element.parent.children) do - if child.name ~= 'popups' then child.style.visible = false end - end - end) - - local global = self_global - - -- used for debugging - function left.override_open(state) - global.over_ride_left_can_open = state - end - --- Used to add a left gui frame - -- @usage Gui.left.add{name='foo',caption='Foo',tooltip='just testing',open_on_join=true,can_open=function,draw=function} - -- @usage return_value(player) -- toggles visiblity for that player, if no player then updates for all players - -- @param obj this is what will be made, needs a name and a draw function(root_frame), open_on_join can be used to set the deaful state true/false, can_open is a test to block it from opening but is not needed - -- @return the object that is made, calling the returned value with out a param will update the gui, else will toggle visiblity for that player - function left.add(obj) - if not is_type(obj,'table') then return end - if not is_type(obj.name,'string') then return end - verbose('Created Left Gui: '..obj.name) - setmetatable(obj,{__index=left._prototype,__call=function(self,player) if player then return self:toggle(player) else return left.update(self.name) end end}) - Gui.data('left',obj.name,obj) - Gui.toolbar(obj.name,obj.caption,obj.tooltip,function(event) obj:toggle(event) end) - return obj - end - - --- This is used to update all the guis of connected players, good idea to use our thread system as it as nested for loops - -- @usage Gui.left.update() - -- @tparam[opt] string frame this is the name of a frame if you only want to update one - -- @param[opt] players the player to update for, if not given all players are updated, can be one player - function left.update(frame,players) - if not Server or not Server._thread then - local players = is_type(players,'table') and #players > 0 and {unpack(players)} or is_type(players,'table') and {players} or Game.get_player(players) and {Game.get_player(players)} or game.connected_players - for _,player in pairs(players) do - local frames = Gui.data.left or {} - if frame then frames = {[frame]=frames[frame]} or {} end - for name,left in pairs(frames) do - if _left then left:first_open(player) end - end - end - else - local frames = Gui.data.left or {} - if frame then frames = {[frame]=frames[frame]} or {} end - local players = is_type(players,'table') and #players > 0 and {unpack(players)} or is_type(players,'table') and {players} or Game.get_player(players) and {Game.get_player(players)} or game.connected_players - Server.new_thread{ - data={players=players,frames=frames} - }:on_event('tick',function(thread) - if #thread.data.players == 0 then thread:close() return end - local player = table.remove(thread.data.players,1) - Server.new_thread{ - data={player=player,frames=thread.data.frames} - }:on_event('resolve',function(thread) - for name,left in pairs(thread.data.frames) do - if left then left:first_open(thread.data.player) end - end - end):queue() - end):open() - end - end - - --- Used to open the left gui of every player - -- @usage Gui.left.open('foo') - -- @tparam string left_name this is the gui that you want to open - -- @tparam[opt] LuaPlayer the player to open the gui for - function left.open(left_name,player) - local players = player and {player} or game.connected_players - local _left = Gui.data.left[left_name] - if not _left then return end - if not Server or not Server._thread then - for _,player in pairs(players) do _left:open(player) end - else - Server.new_thread{ - data={players=players} - }:on_event('tick',function(thread) - if #thread.data.players == 0 then thread:close() return end - local player = table.remove(thread.data.players,1) - _left:open(player) - end):open() - end - end - - --- Used to close the left gui of every player - -- @usage Gui.left.close('foo') - -- @tparam string left_name this is the gui that you want to close - -- @tparam[opt] LuaPlayer the player to close the gui for - function left.close(left_name,player) - local players = player and {player} or game.connected_players - local _left = Gui.data.left[left_name] - if not _left then return end - if not Server or not Server._thread or player then - for _,player in pairs(players) do _left:close(player) end - else - Server.new_thread{ - data={players=players} - }:on_event('tick',function(thread) - if #thread.data.players == 0 then thread:close() return end - local player = table.remove(thread.data.players,1) - _left:close(player) - end):open() - end - end - - - --- Used to force the gui open for the player - -- @usage left:open(player) - -- @tparam luaPlayer player the player to open the gui for - function left._prototype:open(player) - local player = Game.get_player(player) - if not player then error('Invalid Player') end - local left_flow = mod_gui.get_frame_flow(player) - if not left_flow[self.name] then self:first_open(player) end - left_flow[self.name].style.visible = true - if left_flow['gui-left-hide'] then left_flow['gui-left-hide'].style.visible = true end - end - - --- Used to force the gui closed for the player - -- @usage left:open(player) - -- @tparam luaPlayer player the player to close the gui for - function left._prototype:close(player) - local player = Game.get_player(player) - if not player then error('Invalid Player') end - local left_flow = mod_gui.get_frame_flow(player) - if not left_flow[self.name] then self:first_open(player) end - left_flow[self.name].style.visible = false - local count = 0 - for _,child in pairs(left_flow.children) do if child.style.visible then count = count+1 end if count > 1 then break end end - if count == 1 and left_flow['gui-left-hide'] then left_flow['gui-left-hide'].style.visible = false end - end - - --- When the gui is first made or is updated this function is called, used by the script - -- @usage left:first_open(player) -- returns the frame - -- @tparam LuaPlayer player the player to draw the gui for - -- @treturn LuaFrame the frame made/updated - function left._prototype:first_open(player) - local player = Game.get_player(player) - local left_flow = mod_gui.get_frame_flow(player) - local frame = nil - if left_flow[self.name] then - frame = left_flow[self.name] - frame.clear() - else - if not left_flow['gui-left-hide'] then left.hide(left_flow).style.maximal_width=15 end - frame = left_flow.add{type='frame',name=self.name,style=mod_gui.frame_style,caption=self.caption,direction='vertical'} - frame.style.visible = false - if is_type(self.open_on_join,'boolean') then frame.style.visible = self.open_on_join left_flow['gui-left-hide'].style.visible = true end - end - if is_type(self.draw,'function') then self.draw(frame) else frame.style.visible = false error('No Callback On '..self.name) end - return frame - end - - --- Toggles the visiblity of the gui based on some conditions - -- @usage left:toggle(player) -- returns new state - -- @tparam LuaPlayer player the player to toggle the gui for, remember there are condition which need to be met - -- @treturn boolean the new state that the gui is in - function left._prototype:toggle(player) - local player = Game.get_player(player) - local left_flow = mod_gui.get_frame_flow(player) - if not left_flow[self.name] then self:first_open(player) end - local left = left_flow[self.name] - local open = false - if is_type(self.can_open,'function') then - local success, err = pcall(self.can_open,player) - if not success then error(err) - elseif err == true then open = true - elseif global.over_ride_left_can_open then - if is_type(Role,'table') then - if Role.allowed(player,self.name) then open = true - else open = {'ExpGamingCore_Gui.unauthorized'} end - else open = true end - else open = err end - else - if is_type(Role,'table') then - if Role.allowed(player,self.name) then open = true - else open = {'ExpGamingCore_Gui.unauthorized'} end - else open = true end - end - if open == true and left.style.visible ~= true then - left.style.visible = true - left_flow['gui-left-hide'].style.visible = true - else - left.style.visible = false - local count = 0 - for _,child in pairs(left_flow.children) do if child.style.visible then count = count+1 end if count > 1 then break end end - if count == 1 and left_flow['gui-left-hide'] then left_flow['gui-left-hide'].style.visible = false end - end - if open == false then player_return({'ExpGamingCore_Gui.cant-open-no-reason'},defines.textcolor.crit,player) player.play_sound{path='utility/cannot_build'} - elseif open ~= true then player_return({'ExpGamingCore_Gui.cant-open',open},defines.textcolor.crit,player) player.play_sound{path='utility/cannot_build'} end - return left.style.visible - end - - left.on_player_joined_game = function(event) - -- draws the left guis when a player first joins, fake_event is just because i am lazy - local player = Game.get_player(event) - local frames = Gui.data.left or {} - local left_flow = mod_gui.get_frame_flow(player) - if not left_flow['gui-left-hide'] then left.hide(left_flow).style.maximal_width=15 end - local done = {} - for _,name in pairs(order_config) do - local left = Gui.data.left[name] - if left then - done[name] = true - left:first_open(player) - end - end - for name,left in pairs(frames) do - if not done[name] then left:first_open(player) end - end - end - - function left:on_init() - if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') end - end - - -- calling will attempt to add a new gui - return setmetatable(left,{__call=function(self,...) return self.add(...) end}) \ No newline at end of file diff --git a/modules/ExpGamingCore/Gui/src/toolbar.lua b/modules/ExpGamingCore/Gui/toolbar/control.lua similarity index 93% rename from modules/ExpGamingCore/Gui/src/toolbar.lua rename to modules/ExpGamingCore/Gui/toolbar/control.lua index f2efa707..6ce6a159 100644 --- a/modules/ExpGamingCore/Gui/src/toolbar.lua +++ b/modules/ExpGamingCore/Gui/toolbar/control.lua @@ -8,10 +8,10 @@ -- @function _comment local Game = require('FactorioStdLib.Game') +local mod_gui = require('mod-gui') +local Gui = require('ExpGamingCore.Gui') +local order_config = require(module_path..'/order_config') local Role -- this is optional and is hanndled by it being present, it is loaded on init -local mod_gui = require("mod-gui") -local Gui = Gui -- this is to force gui to remain in the ENV -local order_config = order_config local toolbar = {} @@ -85,7 +85,6 @@ function toolbar:on_init() if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') end end -toolbar.on_role_change = toolbar.draw -toolbar.on_player_joined_game = toolbar.draw +script.on_event({defines.events.on_role_change,defines.events.on_player_joined_game},toolbar.draw) -- calling with only a player will draw the toolbar for that player, more params will attempt to add a button return setmetatable(toolbar,{__call=function(self,player,extra,...) if extra then return self.add(player,extra,...) else self.draw(player) end end}) \ No newline at end of file diff --git a/modules/ExpGamingCore/Gui/toolbar/order_config.lua b/modules/ExpGamingCore/Gui/toolbar/order_config.lua new file mode 100644 index 00000000..7f19658f --- /dev/null +++ b/modules/ExpGamingCore/Gui/toolbar/order_config.lua @@ -0,0 +1,13 @@ +return { + 'server-info', + 'readme', + 'science', + 'rockets', + 'player-list', + 'tasklist', + 'warp-list', + 'polls', + 'announcements', + 'admin-commands', + 'game-settings' +} \ No newline at end of file diff --git a/modules/ExpGamingCore/Gui/toolbar/softmod.json b/modules/ExpGamingCore/Gui/toolbar/softmod.json new file mode 100644 index 00000000..54884fbf --- /dev/null +++ b/modules/ExpGamingCore/Gui/toolbar/softmod.json @@ -0,0 +1,23 @@ +{ + "name": "ExpGamingCore.Gui.toolbar", + "version": "4.0.0", + "description": "Adds a toolbar at the top of the screen", + "author": "Cooldude2606", + "contact": "Discord: Cooldude26060#5241", + "license": "https://github.com/explosivegaming/scenario/blob/master/LICENSE", + "location": "FSM_ARCHIVE", + "keywords": [ + "Gui", + "Toolbar", + "Buttons" + ], + "collection": "ExpGamingCore.Gui@4.0.0", + "dependencies": { + "mod-gui": "*", + "FactorioStdLib.Game": "^0.8.0", + "ExpGamingCore.Gui": "^4.0.0", + "ExpGamingCore.Gui.inputs": "^4.0.0", + "ExpGamingCore.Role": "?^4.0.0" + }, + "submodules": {} +} diff --git a/modules/ExpGamingCore/Server/softmod.json b/modules/ExpGamingCore/Server/softmod.json index eb549ed2..adef0284 100644 --- a/modules/ExpGamingCore/Server/softmod.json +++ b/modules/ExpGamingCore/Server/softmod.json @@ -17,10 +17,10 @@ "dependencies": { "ExpGamingLib": "^4.0.0", "FactorioStdLib.Table": "^0.8.0", - "FactorioStdLib.Color": "*", + "FactorioStdLib.Color": "^0.8.0", "FactorioStdLib.String": "^0.8.0", - "FactorioStdLib.Game": "*", - "ExpGamingCore.Command": "?*" + "FactorioStdLib.Game": "^0.8.0", + "ExpGamingCore.Command": "?^4.0.0" }, "collection": "ExpGamingCore@4.0.0", "submodules": {} diff --git a/modules/ExpGamingLib/softmod.json b/modules/ExpGamingLib/softmod.json index 13ff302a..dd7c3616 100644 --- a/modules/ExpGamingLib/softmod.json +++ b/modules/ExpGamingLib/softmod.json @@ -12,8 +12,8 @@ "contact": "Discord: Cooldude2606#5241", "license": "https://github.com/explosivegaming/scenario/blob/master/LICENSE", "dependencies": { - "FactorioStdLib.Game": "*", - "FactorioStdLib.Color": "*", + "FactorioStdLib.Game": "^0.8.0", + "FactorioStdLib.Color": "^0.8.0", "FactorioStdLib.Table": "^0.8.0" }, "submodules": {} diff --git a/modules/ExpGamingPlayer/playerList/softmod.json b/modules/ExpGamingPlayer/playerList/softmod.json index 82789d56..7cfc86cd 100644 --- a/modules/ExpGamingPlayer/playerList/softmod.json +++ b/modules/ExpGamingPlayer/playerList/softmod.json @@ -17,7 +17,7 @@ "ExpGamingAdmin.AdminLib": "^4.0.0", "ExpGamingAdmin.buttonFlow": "?^4.0.0", "ExpGamingAdmin.reports": "?^4.0.0", - "ExpGamingPlayer.playerInfo": "?*", + "ExpGamingPlayer.playerInfo": "?^4.0.0", "ExpGamingAdmin.Gui": "^4.0.0" }, "collection": "ExpGamingPlayer@4.0.0", diff --git a/modules/test.txt b/modules/test.txt deleted file mode 100644 index c188b94b..00000000 --- a/modules/test.txt +++ /dev/null @@ -1 +0,0 @@ -testy test \ No newline at end of file