Updated ExpGamingCore.Gui

This commit is contained in:
Cooldude2606
2018-12-09 15:47:18 +00:00
parent 874d97cc28
commit 1db000dcf0
22 changed files with 452 additions and 346 deletions

View File

@@ -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",

View File

@@ -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"
},

View File

@@ -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": {}

View File

@@ -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})

View File

@@ -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": {}
}

View File

@@ -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

View File

@@ -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

View File

@@ -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": {}
}

View File

@@ -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})

View File

@@ -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": {}
}

View File

@@ -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})

View File

@@ -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": {}
}

View File

@@ -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"
}
}

View File

@@ -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})

View File

@@ -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})

View File

@@ -0,0 +1,13 @@
return {
'server-info',
'readme',
'science',
'rockets',
'player-list',
'tasklist',
'warp-list',
'polls',
'announcements',
'admin-commands',
'game-settings'
}

View File

@@ -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": {}
}

View File

@@ -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": {}

View File

@@ -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": {}

View File

@@ -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",

View File

@@ -1 +0,0 @@
testy test