mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-01-01 05:01:40 +09:00
Updated ExpGamingCore.Gui
This commit is contained in:
@@ -18,11 +18,11 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ExpGamingLib": "^4.0.0",
|
"ExpGamingLib": "^4.0.0",
|
||||||
"ExpGamingCore.Command": "^4.0.0",
|
"ExpGamingCore.Command": "^4.0.0",
|
||||||
"ExpGamingAdmin.TempBan": "?*",
|
"ExpGamingAdmin.TempBan": "?^4.0.0",
|
||||||
"ExpGamingAdmin.Jail": "?*",
|
"ExpGamingAdmin.Jail": "?^4.0.0",
|
||||||
"ExpGamingAdmin.Warnings": "?*",
|
"ExpGamingAdmin.Warnings": "?^4.0.0",
|
||||||
"ExpGamingAdmin.Reports": "?*",
|
"ExpGamingAdmin.Reports": "?^4.0.0",
|
||||||
"ExpGamingAdmin.ClearInventory": "?*",
|
"ExpGamingAdmin.ClearInventory": "?^4.0.0",
|
||||||
"ExpGamingAdmin.AdminLib": "^4.0.0"
|
"ExpGamingAdmin.AdminLib": "^4.0.0"
|
||||||
},
|
},
|
||||||
"collection": "ExpGamingAdmin@4.0.0",
|
"collection": "ExpGamingAdmin@4.0.0",
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
"Message"
|
"Message"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ExpGamingCore.Server": "*",
|
"ExpGamingCore.Server": "^4.0.0",
|
||||||
"FactorioStdLib.Game": "*",
|
"FactorioStdLib.Game": "^0.8.0",
|
||||||
"ExpGamingCore.Role": "^4.0.0",
|
"ExpGamingCore.Role": "^4.0.0",
|
||||||
"ExpGamingCore.Sync": "^4.0.0"
|
"ExpGamingCore.Sync": "^4.0.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
"FactorioStdLib": "^0.8.0",
|
"FactorioStdLib": "^0.8.0",
|
||||||
"ExpGamingCore.Server": "^4.0.0",
|
"ExpGamingCore.Server": "^4.0.0",
|
||||||
"ExpGamingLib": "^4.0.0",
|
"ExpGamingLib": "^4.0.0",
|
||||||
"FactorioStdLib.Game": "*"
|
"FactorioStdLib.Game": "^0.8.0"
|
||||||
},
|
},
|
||||||
"collection": "ExpGamingCore@4.0.0",
|
"collection": "ExpGamingCore@4.0.0",
|
||||||
"submodules": {}
|
"submodules": {}
|
||||||
|
|||||||
@@ -1,16 +1,13 @@
|
|||||||
--- Adds a uniform preset for guis in the center of the screen which allow for different tabs to be opened
|
--- 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
|
-- @alias center
|
||||||
-- @author Cooldude2606
|
-- @author Cooldude2606
|
||||||
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
-- @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 Game = require('FactorioStdLib.Game')
|
||||||
local Color = require('FactorioStdLib.Color')
|
local Color = require('FactorioStdLib.Color')
|
||||||
local mod_gui = require("mod-gui")
|
local Gui = require('ExpGamingCore.Gui')
|
||||||
local Gui = Gui -- this is to force gui to remain in the ENV
|
local mod_gui = require('mod-gui')
|
||||||
|
|
||||||
local center = {}
|
local center = {}
|
||||||
center._prototype = {}
|
center._prototype = {}
|
||||||
@@ -28,7 +25,7 @@ function center.add(obj)
|
|||||||
obj.tabs = {}
|
obj.tabs = {}
|
||||||
obj._tabs = {}
|
obj._tabs = {}
|
||||||
Gui.data('center',obj.name,obj)
|
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
|
return obj
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -206,10 +203,14 @@ function center._prototype: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
|
||||||
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
|
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
|
-- calling will attempt to add a new gui
|
||||||
return setmetatable(center,{__call=function(self,...) return self.add(...) end})
|
return setmetatable(center,{__call=function(self,...) return self.add(...) end})
|
||||||
24
modules/ExpGamingCore/Gui/center/softmod.json
Normal file
24
modules/ExpGamingCore/Gui/center/softmod.json
Normal 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": {}
|
||||||
|
}
|
||||||
@@ -27,23 +27,6 @@ Gui.data = setmetatable({},{
|
|||||||
end
|
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
|
--- 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
|
||||||
@@ -158,11 +141,7 @@ function Gui.cam_link(data)
|
|||||||
end
|
end
|
||||||
|
|
||||||
script.on_event('on_tick', function(event)
|
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 loaded_modules['ExpGamingCore.Server'] then return end
|
||||||
|
|
||||||
if global.cams and is_type(global.cams,'table') and #global.cams > 0 then
|
if global.cams and is_type(global.cams,'table') and #global.cams > 0 then
|
||||||
local update = 4
|
local update = 4
|
||||||
if global.cam_index >= #global.cams then global.cam_index = 1 end
|
if global.cam_index >= #global.cams then global.cam_index = 1 end
|
||||||
@@ -180,7 +159,6 @@ script.on_event('on_tick', function(event)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
script.on_event('on_player_respawned',function(event)
|
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 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
|
if global.players and is_type(global.players,'table') and #global.players > 0 and global.players[event.player_index] then
|
||||||
local remove = {}
|
local remove = {}
|
||||||
@@ -195,26 +173,15 @@ script.on_event('on_player_respawned',function(event)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
function Gui:on_init()
|
function Gui:on_init()
|
||||||
self.left:on_init(); self.left.on_init = nil
|
if loaded_modules['ExpGamingCore.Server@^4.0.0'] then
|
||||||
self.toolbar:on_init(); self.toolbar.on_init = nil
|
Server = require('ExpGamingCore.Server@^4.0.0')
|
||||||
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
|
verbose('ExpGamingCore.Server is installed; Loading server src')
|
||||||
if loaded_modules['ExpGamingCore.Role@^4.0.0'] then
|
script.on_init(require(module_path..'/src/server',{Gui=self}))
|
||||||
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)
|
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
function Gui:on_post()
|
function Gui:on_post()
|
||||||
Gui.test = require(module_path..'/src/test',{Gui=Gui})
|
Gui.test = require(module_path..'/src/test',{Gui=Gui})
|
||||||
Gui.popup.load() Gui.popup.load = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,14 +9,14 @@
|
|||||||
|
|
||||||
local Game = require('FactorioStdLib.Game')
|
local Game = require('FactorioStdLib.Game')
|
||||||
local Color = require('FactorioStdLib.Color')
|
local Color = require('FactorioStdLib.Color')
|
||||||
local mod_gui = require("mod-gui")
|
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 inputs = {}
|
local inputs = {}
|
||||||
inputs._prototype = {}
|
inputs._prototype = {}
|
||||||
-- these are just so you can have short cuts to this
|
-- these are just so you can have short cuts to this
|
||||||
inputs.events = {
|
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,
|
state=defines.events.on_gui_checked_state_changed,
|
||||||
click=defines.events.on_gui_click,
|
click=defines.events.on_gui_click,
|
||||||
elem=defines.events.on_gui_elem_changed,
|
elem=defines.events.on_gui_elem_changed,
|
||||||
@@ -33,7 +33,7 @@ inputs.events = {
|
|||||||
function inputs._prototype:on_event(event,callback)
|
function inputs._prototype:on_event(event,callback)
|
||||||
if not is_type(callback,'function') then return self end
|
if not is_type(callback,'function') then return self end
|
||||||
if inputs.events[event] then event = inputs.events[event] 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
|
self.events[event] = callback
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@@ -136,15 +136,8 @@ function inputs._event_handler(event)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
inputs._events = {
|
script.on_event(inputs.events,inputs._event_handler)
|
||||||
[inputs.events.state]=inputs._event_handler,
|
inputs.events.error = {}
|
||||||
[inputs.events.click]=inputs._event_handler,
|
|
||||||
[inputs.events.elem]=inputs._event_handler,
|
|
||||||
[inputs.events.state]=inputs._event_handler,
|
|
||||||
[inputs.events.text]=inputs._event_handler,
|
|
||||||
[inputs.events.slider]=inputs._event_handler,
|
|
||||||
[inputs.events.selection]=inputs._event_handler
|
|
||||||
}
|
|
||||||
|
|
||||||
-- the folwing functions are just to make inputs easier but if what you want is not include use inputs.add(obj)
|
-- 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
|
||||||
@@ -381,5 +374,3 @@ end
|
|||||||
|
|
||||||
-- calling will attempt to add a new input
|
-- calling will attempt to add a new input
|
||||||
return setmetatable(inputs,{__call=function(self,...) return self.add(...) end})
|
return setmetatable(inputs,{__call=function(self,...) return self.add(...) end})
|
||||||
|
|
||||||
-- to see examples look at GuiParts/test.lua
|
|
||||||
23
modules/ExpGamingCore/Gui/inputs/softmod.json
Normal file
23
modules/ExpGamingCore/Gui/inputs/softmod.json
Normal 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": {}
|
||||||
|
}
|
||||||
245
modules/ExpGamingCore/Gui/left/control.lua
Normal file
245
modules/ExpGamingCore/Gui/left/control.lua
Normal 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})
|
||||||
26
modules/ExpGamingCore/Gui/left/softmod.json
Normal file
26
modules/ExpGamingCore/Gui/left/softmod.json
Normal 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": {}
|
||||||
|
}
|
||||||
@@ -8,25 +8,13 @@
|
|||||||
-- @function _comment
|
-- @function _comment
|
||||||
|
|
||||||
local Game = require('FactorioStdLib.Game')
|
local Game = require('FactorioStdLib.Game')
|
||||||
local mod_gui = require("mod-gui")
|
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 Server -- loaded on_init
|
||||||
|
|
||||||
local popup = {}
|
local popup = {}
|
||||||
popup._prototype = {}
|
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
|
--- Used to add a popup gui style
|
||||||
-- @usage Gui.left.add{name='foo',caption='Foo',draw=function}
|
-- @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
|
-- @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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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)
|
function popup._prototype:add_left(obj)
|
||||||
obj.name = obj.name or self.name
|
obj.name = obj.name or self.name
|
||||||
self.left = Gui.left(obj)
|
self.left = Gui.left(obj)
|
||||||
end
|
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
|
-- calling will attempt to add a new popup style
|
||||||
return setmetatable(popup,{__call=function(self,...) return self.add(...) end})
|
return setmetatable(popup,{__call=function(self,...) return self.add(...) end})
|
||||||
24
modules/ExpGamingCore/Gui/popup/softmod.json
Normal file
24
modules/ExpGamingCore/Gui/popup/softmod.json
Normal 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": {}
|
||||||
|
}
|
||||||
@@ -15,11 +15,16 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ExpGamingLib": "^4.0.0",
|
"ExpGamingLib": "^4.0.0",
|
||||||
"FactorioStdLib.Table": "^0.8.0",
|
"FactorioStdLib.Table": "^0.8.0",
|
||||||
"FactorioStdLib.Color": "*",
|
"FactorioStdLib.Color": "^0.8.0",
|
||||||
"FactorioStdLib.Game": "*",
|
"FactorioStdLib.Game": "^0.8.0",
|
||||||
"ExpGamingCore.Role": "^4.0.0",
|
"ExpGamingCore.Server": "?^4.0.0"
|
||||||
"ExpGamingCore.Server": "?*"
|
|
||||||
},
|
},
|
||||||
"collection": "ExpGamingCore@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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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})
|
|
||||||
@@ -8,10 +8,10 @@
|
|||||||
-- @function _comment
|
-- @function _comment
|
||||||
|
|
||||||
local Game = require('FactorioStdLib.Game')
|
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 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 = {}
|
local toolbar = {}
|
||||||
|
|
||||||
@@ -85,7 +85,6 @@ function toolbar:on_init()
|
|||||||
if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') end
|
if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') end
|
||||||
end
|
end
|
||||||
|
|
||||||
toolbar.on_role_change = toolbar.draw
|
script.on_event({defines.events.on_role_change,defines.events.on_player_joined_game},toolbar.draw)
|
||||||
toolbar.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
|
-- 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})
|
return setmetatable(toolbar,{__call=function(self,player,extra,...) if extra then return self.add(player,extra,...) else self.draw(player) end end})
|
||||||
13
modules/ExpGamingCore/Gui/toolbar/order_config.lua
Normal file
13
modules/ExpGamingCore/Gui/toolbar/order_config.lua
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
return {
|
||||||
|
'server-info',
|
||||||
|
'readme',
|
||||||
|
'science',
|
||||||
|
'rockets',
|
||||||
|
'player-list',
|
||||||
|
'tasklist',
|
||||||
|
'warp-list',
|
||||||
|
'polls',
|
||||||
|
'announcements',
|
||||||
|
'admin-commands',
|
||||||
|
'game-settings'
|
||||||
|
}
|
||||||
23
modules/ExpGamingCore/Gui/toolbar/softmod.json
Normal file
23
modules/ExpGamingCore/Gui/toolbar/softmod.json
Normal 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": {}
|
||||||
|
}
|
||||||
@@ -17,10 +17,10 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ExpGamingLib": "^4.0.0",
|
"ExpGamingLib": "^4.0.0",
|
||||||
"FactorioStdLib.Table": "^0.8.0",
|
"FactorioStdLib.Table": "^0.8.0",
|
||||||
"FactorioStdLib.Color": "*",
|
"FactorioStdLib.Color": "^0.8.0",
|
||||||
"FactorioStdLib.String": "^0.8.0",
|
"FactorioStdLib.String": "^0.8.0",
|
||||||
"FactorioStdLib.Game": "*",
|
"FactorioStdLib.Game": "^0.8.0",
|
||||||
"ExpGamingCore.Command": "?*"
|
"ExpGamingCore.Command": "?^4.0.0"
|
||||||
},
|
},
|
||||||
"collection": "ExpGamingCore@4.0.0",
|
"collection": "ExpGamingCore@4.0.0",
|
||||||
"submodules": {}
|
"submodules": {}
|
||||||
|
|||||||
@@ -12,8 +12,8 @@
|
|||||||
"contact": "Discord: Cooldude2606#5241",
|
"contact": "Discord: Cooldude2606#5241",
|
||||||
"license": "https://github.com/explosivegaming/scenario/blob/master/LICENSE",
|
"license": "https://github.com/explosivegaming/scenario/blob/master/LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"FactorioStdLib.Game": "*",
|
"FactorioStdLib.Game": "^0.8.0",
|
||||||
"FactorioStdLib.Color": "*",
|
"FactorioStdLib.Color": "^0.8.0",
|
||||||
"FactorioStdLib.Table": "^0.8.0"
|
"FactorioStdLib.Table": "^0.8.0"
|
||||||
},
|
},
|
||||||
"submodules": {}
|
"submodules": {}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
"ExpGamingAdmin.AdminLib": "^4.0.0",
|
"ExpGamingAdmin.AdminLib": "^4.0.0",
|
||||||
"ExpGamingAdmin.buttonFlow": "?^4.0.0",
|
"ExpGamingAdmin.buttonFlow": "?^4.0.0",
|
||||||
"ExpGamingAdmin.reports": "?^4.0.0",
|
"ExpGamingAdmin.reports": "?^4.0.0",
|
||||||
"ExpGamingPlayer.playerInfo": "?*",
|
"ExpGamingPlayer.playerInfo": "?^4.0.0",
|
||||||
"ExpGamingAdmin.Gui": "^4.0.0"
|
"ExpGamingAdmin.Gui": "^4.0.0"
|
||||||
},
|
},
|
||||||
"collection": "ExpGamingPlayer@4.0.0",
|
"collection": "ExpGamingPlayer@4.0.0",
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
testy test
|
|
||||||
Reference in New Issue
Block a user