Added Module: ExpGamingCore.Gui

This commit is contained in:
Cooldude2606
2018-06-07 14:17:16 +01:00
parent 9be85f04a6
commit 5a40fe6649
38 changed files with 1621 additions and 868 deletions

View File

@@ -1,36 +1,46 @@
--[[
Explosive Gaming
This file can be used with permission but this and the credit below must remain in the file.
Contact a member of management on our discord to seek permission to use our code.
Any changes that you may make to the code are yours but that does not make the script yours.
Discord: https://discord.gg/r6dC2uK
]]
--- Adds a objective version to custom guis.
-- @module ExpGamingCore.Gui
-- @alias Gui
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
local Gui = {}
local Gui_data = {}
-- only really used when parts of expcore are missing, or script debuging (ie to store the location of frames)
function Gui._global(reset)
global.exp_core = not reset and global.exp_core or {}
global.exp_core.gui = not reset and global.exp_core.gui or {}
return global.exp_core.gui
end
--- Stores all the on_player_joined_game event handlers for the guis
-- @table events
Gui.events = {join={},rank={}}
-- this is to enforce the read only propetry of the gui
function Gui._add_data(key,value_key,value)
if game then return end
if not Gui_data[key] then Gui_data[key] = {} end
Gui_data[key][value_key] = value
end
--- Used to set and get data about different guis
-- @usage Gui.data[location] -- returns the gui data for that gui location ex center
-- @usage Gui.data(location,gui_name,gui_data) -- adds gui data for a gui at a location
-- @tparam string location the location to get/set the data, center left etc...
-- @tparam[opt] string key the name of the gui to set the value of
-- @param[opt] value the data that will be set can be any value but table advised
-- @treturn[1] table all the gui data that is locationed in that location
Gui.data = setmetatable({},{
__call=function(tbl,location,key,value)
if not location then return tbl end
if not key then return rawget(tbl,location) or rawset(tbl,location,{}) and rawget(tbl,location) end
if game then error('New guis cannot be added during runtime',2) end
if not rawget(tbl,location) then rawset(tbl,location,{}) end
rawset(rawget(tbl,location),key,value)
end
})
function Gui._get_data(key) return Gui_data[key] end
Gui.center = require(module_path..'/GuiParts/center')
Gui.inputs = require(module_path..'/GuiParts/inputs')
Gui.left = require(module_path..'/GuiParts/left')
Gui.popup = require(module_path..'/GuiParts/popup')
Gui.toolbar = require(module_path..'/GuiParts/toolbar')
-- loaded the different gui parts, each is its own module for ldoc reasons
local join, rank
Gui.center, join, rank = require(module_path..'/src/center')
table.insert(Gui.events.join,event) table.insert(Gui.events.rank,rank)
Gui.inputs, event = require(module_path..'/src/inputs')
table.insert(Gui.events.join,event) table.insert(Gui.events.rank,rank)
Gui.left, event = require(module_path..'/src/left')
table.insert(Gui.events.join,event) table.insert(Gui.events.rank,rank)
Gui.popup, event = require(module_path..'/src/popup')
table.insert(Gui.events.join,event) table.insert(Gui.events.rank,rank)
Gui.toolbar, event = require(module_path..'/src/toolbar')
table.insert(Gui.events.join,event) table.insert(Gui.events.rank,rank)
join, rank = nil, nil
--- Add a white bar to any gui frame
-- @usage Gui.bar(frame,100)
@@ -50,7 +60,7 @@ function Gui.bar(frame,width)
end
--- Used to set the index of a drop down to a certian item
-- @usage Gui.set_dropdown_index(dropdown,player.name)
-- @usage Gui.set_dropdown_index(dropdown,player.name) -- will select the index with the players name as the value
-- @param dropdown the dropdown that is to be effected
-- @param _item this is the item to look for
-- @return returns the dropdown if it was successful
@@ -64,43 +74,22 @@ function Gui.set_dropdown_index(dropdown,_item)
return dropdown
end
Gui.on_init=function(self)
Gui.test = require(module_path..'/GuiParts/test')
if not Server then return end
Event.register(-1,function(event)
Server.new_thread{
name='camera-follow',
data={cams={},cam_index=1,players={}}
}:on_event('tick',function(self)
local _cam = self.data.cams[self.data.cam_index]
if not _cam then self.data.cam_index = 1 _cam = self.data.cams[self.data.cam_index] end
if not _cam then return end
if not _cam.cam.valid then table.remove(self.data.cams,self.data.cam_index)
elseif not _cam.entity.valid then table.remove(self.data.cams,self.data.cam_index)
else _cam.cam.position = _cam.entity.position if not _cam.surface then _cam.cam.surface_index = _cam.entity.surface.index end self.data.cam_index = self.data.cam_index+1
end
end):on_event('error',function(self,err)
-- posible error handling if needed
error(err)
end):on_event(defines.events.on_player_respawned,function(self,event)
if self.data.players[event.player_index] then
local remove = {}
for index,cam in pairs(self.data.players[event.player_index]) do
Gui.cam_link{cam=cam,entity=Game.get_player(event).character}
if not cam.valid then table.insert(remove,index) end
end
for _,index in pairs(remove) do
table.remove(self.data.players[event.player_index],index)
end
end
end):open()
end)
function Gui:on_init()
if loaded_modules.Server then verbose('ExpGamingCore.Server is installed; Loading server src') require(module_path..'/src/server') end
if loaded_modules.Ranking then
verbose('ExpGamingCore.Ranking is installed; Loading ranking src')
script.on_event('on_player_joined_game',function(event)
for _,callback in pairs(Gui.events.rank) do callback(event) end
end)
end
end
--- Adds a camera that updates every tick (or less depeading on how many are opening) it will move to follow an entity
-- @usage Gui.cam_link{entity=game.player.character,frame=frame,width=50,hight=50,zoom=1}
-- @usage Gui.cam_link{entity=game.player.character,cam=frame.camera,surface=game.surfaces['testing']}
-- @tparam table data contains all other params given below
function Gui:on_post()
Gui.test = require(module_path..'/src/test')
end
--- Prams for Gui.cam_link
-- @table ParametersForCamLink
-- @field entity this is the entity that the camera will follow
-- @field cam a camera that you already have in the gui
-- @field frame the frame to add the camera to, no effect if cam param is given
@@ -109,6 +98,11 @@ end
-- @field height the height to give the new camera
-- @field surface this will over ride the surface that the camera follows on, allowing for a 'ghost surface' while keeping same position
-- @field respawn_open if set to true then the camera will auto re link to the player after a respawn
--- Adds a camera that updates every tick (or less depeading on how many are opening) it will move to follow an entity
-- @usage Gui.cam_link{entity=game.player.character,frame=frame,width=50,hight=50,zoom=1}
-- @usage Gui.cam_link{entity=game.player.character,cam=frame.camera,surface=game.surfaces['testing']}
-- @tparam table data contains all other params given below
-- @return the camera that the function used be it made or given as a param
function Gui.cam_link(data)
if not data.entity or not data.entity.valid then return end
@@ -126,21 +120,21 @@ function Gui.cam_link(data)
data.cam.style.height = data.height or 100
else return end
if not Server or not Server._thread or not Server.get_thread('camera-follow') then
if not Gui._global().cams then
Gui._global().cams = {}
Gui._global().cam_index = 1
if not global().cams then
global().cams = {}
global().cam_index = 1
end
if data.cam then
local surface = data.surface and data.surface.index or nil
table.insert(Gui._global().cams,{cam=data.cam,entity=data.entity,surface=surface})
table.insert(global().cams,{cam=data.cam,entity=data.entity,surface=surface})
end
if not Gui._global().players then
Gui._global().players = {}
if not global().players then
global().players = {}
end
if data.respawn_open then
if data.entity.player then
if not Gui._global().players[data.entity.player.index] then Gui._global().players[data.entity.player.index] = {} end
table.insert(Gui._global().players[data.entity.player.index],data.cam)
if not global().players[data.entity.player.index] then global().players[data.entity.player.index] = {} end
table.insert(global().players[data.entity.player.index],data.cam)
end
end
else
@@ -157,30 +151,34 @@ function Gui.cam_link(data)
return data.cam
end
Event.register(defines.events.on_tick, function(event)
script.on_event('on_player_joined_game',function(event)
for _,callback in pairs(Gui.events.join) do callback(event) end
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 Gui._global().cams and is_type(Gui._global().cams,'table') and #Gui._global().cams > 0 then
local _cam = Gui._global().cams[Gui._global().cam_index]
if not _cam then Gui._global().cam_index = 1 _cam = Gui._global().cams[Gui._global().cam_index] end
if global().cams and is_type(global().cams,'table') and #global().cams > 0 then
local _cam = global().cams[global().cam_index]
if not _cam then global().cam_index = 1 _cam = global().cams[global().cam_index] end
if not _cam then return end
if not _cam.cam.valid then table.remove(Gui._global().cams,Gui._global().cam_index)
elseif not _cam.entity.valid then table.remove(Gui._global().cams,Gui._global().cam_index)
else _cam.cam.position = _cam.entity.position if not _cam.surface then _cam.cam.surface_index = _cam.entity.surface.index end Gui._global().cam_index = Gui._global().cam_index+1
if not _cam.cam.valid then table.remove(global().cams,global().cam_index)
elseif not _cam.entity.valid then table.remove(global().cams,global().cam_index)
else _cam.cam.position = _cam.entity.position if not _cam.surface then _cam.cam.surface_index = _cam.entity.surface.index end global().cam_index = global().cam_index+1
end
end
end)
Event.register(defines.events.on_player_respawned,function(event)
if Gui._global().players and is_type(Gui._global().players,'table') and #Gui._global().players > 0 and Gui._global().players[event.player_index] then
script.on_event('on_player_respawned',function(event)
if global().players and is_type(global().players,'table') and #global().players > 0 and global().players[event.player_index] then
local remove = {}
for index,cam in pairs(Gui._global().players[event.player_index]) do
for index,cam in pairs(global().players[event.player_index]) do
Gui.cam_link{cam=cam,entity=Game.get_player(event).character}
if not cam.valid then table.insert(remove,index) end
end
for _,index in pairs(remove) do
table.remove(Gui._global().players[event.player_index],index)
table.remove(global().players[event.player_index],index)
end
end
end)

View File

@@ -1,11 +1,11 @@
--[[
Explosive Gaming
--- Adds a uniform preset for guis in the center of the screen which allow for different tabs to be opened
-- @module ExpGamingCore.Gui.Center
-- @alias center
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
This file can be used with permission but this and the credit below must remain in the file.
Contact a member of management on our discord to seek permission to use our code.
Any changes that you may make to the code are yours but that does not make the script yours.
Discord: https://discord.gg/r6dC2uK
]]
--- This is a submodule of ExpGamingCore.Gui but for ldoc reasons it is under its own module
-- @function _comment
local center = {}
center._center = {}
@@ -21,7 +21,7 @@ function center.add(obj)
setmetatable(obj,{__index=center._center})
obj.tabs = {}
obj._tabs = {}
Gui._add_data('center',obj.name,obj)
Gui.data('center',obj.name,obj)
Gui.toolbar.add(obj.name,obj.caption,obj.tooltip,obj.open)
return obj
end
@@ -43,8 +43,8 @@ end
function center.open(player,center)
local player = Game.get_player(player)
Gui.center.clear(player)
if not Gui._get_data('center')[center] then return false end
Gui._get_data('center')[center].open{
if not Gui.data.center[center] then return false end
Gui.data.center[center].open{
element={name=center},
player_index=player.index
}
@@ -61,8 +61,8 @@ function center.open_tab(player,center,tab)
local player = Game.get_player(player)
if not Gui.center.open(player,center) then return false end
local name = center..'_'..tab
if not Gui._get_data('inputs_button')[name] then return false end
Gui._get_data('inputs_button')[name].events[defines.events.on_gui_click]{
if not Gui.data.inputs_button[name] then return false end
Gui.data.inputs_button[name].events[defines.events.on_gui_click]{
element=Gui.center.get_flow(player)[center].tab_bar.tab_bar_scroll.tab_bar_scroll_flow[name],
}
return true
@@ -80,7 +80,7 @@ end
-- not recomented for direct use see Gui.center.open
function center._center.open(event)
local player = Game.get_player(event)
local _center = Gui._get_data('center')[event.element.name]
local _center = Gui.data.center[event.element.name]
local center_flow = center.get_flow(player)
if center_flow[_center.name] then Gui.center.clear(player) return end
local center_frame = center_flow.add{
@@ -179,7 +179,7 @@ function center._center:add_tab(name,caption,tooltip,callback)
local tab = event.element.parent.parent.parent.parent.tab.tab_scroll.tab_scroll_flow
tab.clear()
local frame_name = tab.parent.parent.parent.name
local _center = Gui._get_data('center')[frame_name]
local _center = Gui.data.center[frame_name]
local _tab = _center._tabs[event.element.name]
if is_type(_tab,'function') then
for _,button in pairs(event.element.parent.children) do
@@ -197,13 +197,10 @@ function center._center:add_tab(name,caption,tooltip,callback)
end
-- used so that when gui close key is pressed this will close the gui
Event.register(defines.events.on_gui_closed,function(event)
script.on_event('on_gui_closed',function(event)
if event.element and event.element.valid then event.element.destroy() end
end)
-- when the player rank is changed it closses the center guis
if defines.events.rank_change then
Event.register(defines.events.rank_change,center.clear)
end
return center
-- second return is join event and third is rank change event
return center, nil, center.clear

View File

@@ -1,11 +1,11 @@
--[[
Explosive Gaming
--- Adds a clean way of making new inputs for a gui allowing for sliders and text inputs to be hanndleded with custom events
-- @module ExpGamingCore.Gui.Inputs
-- @alias inputs
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
This file can be used with permission but this and the credit below must remain in the file.
Contact a member of management on our discord to seek permission to use our code.
Any changes that you may make to the code are yours but that does not make the script yours.
Discord: https://discord.gg/r6dC2uK
]]
--- This is a submodule of ExpGamingCore.Gui but for ldoc reasons it is under its own module
-- @function _comment
local inputs = {}
inputs._input = {}
@@ -106,17 +106,17 @@ function inputs.add(obj)
obj.data = {}
obj.events = {}
setmetatable(obj,{__index=inputs._input})
Gui._add_data('inputs_'..type,obj.name,obj)
Gui.data('inputs_'..type,obj.name,obj)
return obj
end
-- this just runs the events given to inputs
function inputs._event_handler(event)
if not event.element then return end
local elements = Gui._get_data('inputs_'..event.element.type) or {}
local elements = Gui.data['inputs_'..event.element.type] or {}
local element = elements[event.element.name]
if not element and event.element.type == 'sprite-button' then
elements = Gui._get_data('inputs_button') or {}
elements = Gui.data.inputs_button or {}
element = elements[event.element.name]
end
if element then
@@ -129,13 +129,13 @@ function inputs._event_handler(event)
end
end
Event.register(inputs.events.state,inputs._event_handler)
Event.register(inputs.events.click,inputs._event_handler)
Event.register(inputs.events.elem,inputs._event_handler)
Event.register(inputs.events.state,inputs._event_handler)
Event.register(inputs.events.text,inputs._event_handler)
Event.register(inputs.events.slider,inputs._event_handler)
Event.register(inputs.events.selection,inputs._event_handler)
script.on_event(inputs.events.state,inputs._event_handler)
script.on_event(inputs.events.click,inputs._event_handler)
script.on_event(inputs.events.elem,inputs._event_handler)
script.on_event(inputs.events.state,inputs._event_handler)
script.on_event(inputs.events.text,inputs._event_handler)
script.on_event(inputs.events.slider,inputs._event_handler)
script.on_event(inputs.events.selection,inputs._event_handler)
-- 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
@@ -154,10 +154,10 @@ function inputs.add_button(name,display,tooltip,callbacks)
}
button.data._callbacks = callbacks
button:on_event('click',function(event)
local elements = Gui._get_data('inputs_'..event.element.type) or {}
local elements = Gui.data['inputs_'..event.element.type] or {}
local button = elements[event.element.name]
if not button and event.element.type == 'sprite-button' then
elements = Gui._get_data('inputs_button') or {}
elements = Gui.data.inputs_button or {}
button = elements[event.element.name]
end
local player = Game.get_player(event)
@@ -195,7 +195,7 @@ function inputs.add_elem_button(name,elem_type,tooltip,callback)
}
button.data._callback = callback
button:on_event('elem',function(event)
local button = Gui._get_data('inputs_'..event.element.type)[event.element.name]
local button = Gui.data['inputs_'..event.element.type][event.element.name]
local player = Game.get_player(event)
local element = event.element or {elem_type=nil,elem_value=nil}
local elem = {type=element.elem_type,value=element.elem_value}
@@ -229,7 +229,7 @@ function inputs.add_checkbox(name,radio,display,default,callback_true,callback_f
checkbox.data._true = callback_true
checkbox.data._false = callback_false
checkbox:on_event('state',function(event)
local checkbox = Gui._get_data('inputs_'..event.element.type)[event.element.name]
local checkbox = Gui.data['inputs_'..event.element.type][event.element.name]
local player = Game.get_player(event)
local state = event.element.state
if state then
@@ -254,7 +254,7 @@ function inputs.reset_radio(elements)
if #elements > 0 then
for _,element in pairs(elements) do
if element.valid then
local _elements = Gui._get_data('inputs_'..element.type) or {}
local _elements = Gui.data['inputs_'..element.type] or {}
local _element = _elements[element.name]
local player = Game.get_player(element.player_index)
local state = false
@@ -265,7 +265,7 @@ function inputs.reset_radio(elements)
end
else
if elements.valid then
local _elements = Gui._get_data('inputs_'..elements.type) or {}
local _elements = Gui.data['inputs_'..elements.type] or {}
local _element = _elements[elements.name]
local player = Game.get_player(elements.player_index)
local state = false
@@ -292,7 +292,7 @@ function inputs.add_text(name,box,text,callback)
}
textbox.data._callback = callback
textbox:on_event('text',function(event)
local textbox = Gui._get_data('inputs_'..event.element.type)[event.element.name]
local textbox = Gui.data['inputs_'..event.element.type][event.element.name]
local player = Game.get_player(event)
local element = event.element
local callback = textbox.data._callback
@@ -325,7 +325,7 @@ function inputs.add_slider(name,orientation,min,max,start_callback,callback)
slider.data._start = start_callback
slider.data._callback = callback
slider:on_event('slider',function(event)
local slider = Gui._get_data('inputs_'..event.element.type)[event.element.name]
local slider = Gui.data['inputs_'..event.element.type][event.element.name]
local player = Game.get_player(event)
local value = event.element.slider_value
local data = slider.data
@@ -356,7 +356,7 @@ function inputs.add_drop_down(name,items,index,callback)
drop_down.data._index = index
drop_down.data._callback = callback
drop_down:on_event('selection',function(event)
local drop_down = Gui._get_data('inputs_'..event.element.type)[event.element.name]
local drop_down = Gui.data['inputs_'..event.element.type][event.element.name]
local player = Game.get_player(event)
local element = event.element
local items = element.items
@@ -370,6 +370,7 @@ function inputs.add_drop_down(name,items,index,callback)
return drop_down
end
return inputs
-- second return is join event and third is rank change event
return inputs, nil, nil
-- to see examples look at GuiParts/test.lua

View File

@@ -1,18 +1,18 @@
--[[
Explosive Gaming
--- 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 file can be used with permission but this and the credit below must remain in the file.
Contact a member of management on our discord to seek permission to use our code.
Any changes that you may make to the code are yours but that does not make the script yours.
Discord: https://discord.gg/r6dC2uK
]]
--- This is a submodule of ExpGamingCore.Gui but for ldoc reasons it is under its own module
-- @function _comment
local left = {}
left._left = {}
-- used for debugging
function left.override_open(state)
Gui._global().over_ride_left_can_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}
@@ -23,7 +23,7 @@ function left.add(obj)
if not is_type(obj.name,'string') then return end
verbose('Created Left Gui: '..obj.name)
setmetatable(obj,{__index=left._left})
Gui._add_data('left',obj.name,obj)
Gui.data('left',obj.name,obj)
Gui.toolbar.add(obj.name,obj.caption,obj.tooltip,obj.toggle)
return obj
end
@@ -36,7 +36,7 @@ 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._get_data('left') or {}
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
@@ -46,7 +46,7 @@ function left.update(frame,players)
end
end
else
local frames = Gui._get_data('left') or {}
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{
@@ -72,7 +72,7 @@ end
-- @usage Gui.left.open('foo')
-- @tparam string left_name this is the gui that you want to open
function left.open(left_name)
local _left = Gui._get_data('left')[left_name]
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(game.connected_players) do
@@ -95,7 +95,7 @@ end
-- @usage Gui.left.close('foo')
-- @tparam string left_name this is the gui that you want to close
function left.close(left_name)
local _left = Gui._get_data('left')[left_name]
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(game.connected_players) do
@@ -117,7 +117,7 @@ end
-- this is used to draw the gui for the first time (these guis are never destoryed), used by the script
function left._left.open(event)
local player = Game.get_player(event)
local _left = Gui._get_data('left')[event.element.name]
local _left = Gui.data.left[event.element.name]
local left_flow = mod_gui.get_frame_flow(player)
local frame = nil
if left_flow[_left.name] then
@@ -134,7 +134,7 @@ end
-- this is called when the toolbar button is pressed
function left._left.toggle(event)
local player = Game.get_player(event)
local _left = Gui._get_data('left')[event.element.name]
local _left = Gui.data.left[event.element.name]
local left_flow = mod_gui.get_frame_flow(player)
if not left_flow[_left.name] then _left.open(event) end
local left = left_flow[_left.name]
@@ -143,7 +143,7 @@ function left._left.toggle(event)
local success, err = pcall(_left.can_open,player)
if not success then error(err)
elseif err == true then open = true
elseif Gui._global().over_ride_left_can_open then
elseif global().over_ride_left_can_open then
if is_type(Ranking,'table') and Ranking._presets and Ranking._presets().meta.rank_count > 0 then
if Ranking.get_rank(player):allowed(_left.name) then open = true
else open = {gui.unauthorized} end
@@ -164,14 +164,13 @@ function left._left.toggle(event)
elseif open ~= true then player_return({'gui.cant-open',open},defines.textcolor.crit,player) player.play_sound{path='utility/cannot_build'} end
end
-- draws the left guis when a player first joins, fake_event is just because i am lazy
Event.register(defines.events.on_player_joined_game,function(event)
-- second return is join event and third is rank change event
return left, 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._get_data('left') or {}
local frames = Gui.data.left or {}
for name,left in pairs(frames) do
local fake_event = {player_index=player.index,element={name=name}}
left.open(fake_event)
end
end)
return left
end, nil

View File

@@ -1,11 +1,11 @@
--[[
Explosive Gaming
--- Adds a location for popups which can be dismissed by a player and created from other scripts
-- @module ExpGamingCore.Gui.Popup
-- @alias popup
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
This file can be used with permission but this and the credit below must remain in the file.
Contact a member of management on our discord to seek permission to use our code.
Any changes that you may make to the code are yours but that does not make the script yours.
Discord: https://discord.gg/r6dC2uK
]]
--- This is a submodule of ExpGamingCore.Gui but for ldoc reasons it is under its own module
-- @function _comment
local popup = {}
popup._popup = {}
@@ -32,7 +32,7 @@ function popup.add(obj)
verbose('Created Popup Gui: '..obj.name)
setmetatable(obj,{__index=popup._popup})
local name = obj.name; obj.name = nil
Gui._add_data('popup',name,obj)
Gui.data('popup',name,obj)
obj.name = name
return obj
end
@@ -50,7 +50,7 @@ end
-- @param data this is the data that is sent to the draw function
-- @tparam[opt=game.connected_players] table players the players to open the popup for
function popup.open(style,data,players)
local _popup = Gui._get_data('popup')[style]
local _popup = Gui.data.popup[style]
local players = players or game.connected_players
local data = data or {}
if not _popup then return end
@@ -107,6 +107,5 @@ function popup._popup:add_left(obj)
self.left = Gui.left.add(obj)
end
Event.register(defines.events.on_player_joined_game,popup.flow)
return popup
-- second return is join event and third is rank change event
return popup, popup.flow, nil

View File

@@ -0,0 +1,39 @@
--- Adds a objective version to custom guis.
-- @submodule ExpGamingCore.Gui
-- @alias Gui
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
--- This file will be loaded when ExpGamingCore.Commands is present
-- @function _comment
--- Adds a server thread that allows the camera follows to be toggled off and on
-- @function __comment
script.on_event(-1,function(event)
Server.new_thread{
name='camera-follow',
data={cams={},cam_index=1,players={}}
}:on_event('tick',function(self)
local _cam = self.data.cams[self.data.cam_index]
if not _cam then self.data.cam_index = 1 _cam = self.data.cams[self.data.cam_index] end
if not _cam then return end
if not _cam.cam.valid then table.remove(self.data.cams,self.data.cam_index)
elseif not _cam.entity.valid then table.remove(self.data.cams,self.data.cam_index)
else _cam.cam.position = _cam.entity.position if not _cam.surface then _cam.cam.surface_index = _cam.entity.surface.index end self.data.cam_index = self.data.cam_index+1
end
end):on_event('error',function(self,err)
-- posible error handling if needed
error(err)
end):on_event(defines.events.on_player_respawned,function(self,event)
if self.data.players[event.player_index] then
local remove = {}
for index,cam in pairs(self.data.players[event.player_index]) do
Gui.cam_link{cam=cam,entity=Game.get_player(event).character}
if not cam.valid then table.insert(remove,index) end
end
for _,index in pairs(remove) do
table.remove(self.data.players[event.player_index],index)
end
end
end):open()
end)

View File

@@ -1,4 +1,10 @@
-- this is just testing all the diffrent inputs to open test use /c Gui.test()
--- Used to test all gui elements and parts can be used in game via Gui.test()
-- @module ExpGamingCore.Gui.Test
-- @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 gui_tset_close = Gui.inputs.add{
name='gui-test-close',
@@ -90,9 +96,13 @@ local drop_test = Gui.inputs.add_drop_down('test-drop',table.keys(defines.color)
player.chat_color = defines.color[selected]
end)
local function test_gui(event)
if not game.player and not event.player_index then return end
local player = game.player or Game.get_player(event)
--- The funcation that is called when calling Gui.test
-- @function Gui.test
-- @usage Gui.test() -- draws test gui
-- @param[opt=game.player] player a pointer to a player to draw the test gui for
local function test_gui(player)
local player = game.player or Game.get_player(player) or nil
if not player then return end
if mod_gui.get_frame_flow(player)['gui-test'] then mod_gui.get_frame_flow(player)['gui-test'].destroy() end
local frame = mod_gui.get_frame_flow(player).add{type='frame',name='gui-test',direction='vertical'}
gui_tset_close:draw(frame)

View File

@@ -1,11 +1,11 @@
--[[
Explosive Gaming
--- Adds a toolbar to the top left of the screen
-- @module ExpGamingCore.Gui.Toolbar
-- @alias toolbar
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
This file can be used with permission but this and the credit below must remain in the file.
Contact a member of management on our discord to seek permission to use our code.
Any changes that you may make to the code are yours but that does not make the script yours.
Discord: https://discord.gg/r6dC2uK
]]
--- This is a submodule of ExpGamingCore.Gui but for ldoc reasons it is under its own module
-- @function _comment
local toolbar = {}
@@ -20,7 +20,7 @@ function toolbar.add(name,caption,tooltip,callback)
verbose('Created Toolbar Button: '..name)
local button = Gui.inputs.add{type='button',name=name,caption=caption,tooltip=tooltip}
button:on_event(Gui.inputs.events.click,callback)
Gui._add_data('toolbar',name,button)
Gui.data('toolbar',name,button)
return button
end
@@ -32,8 +32,8 @@ function toolbar.draw(player)
if not player then return end
local toolbar_frame = mod_gui.get_button_flow(player)
toolbar_frame.clear()
if not Gui._get_data('toolbar') then return end
for name,button in pairs(Gui._get_data('toolbar')) do
if not Gui.data.toolbar then return end
for name,button in pairs(Gui.data.toolbar) do
if is_type(Ranking,'table') and Ranking._presets and Ranking._presets().meta.rank_count > 0 then
local rank = Ranking.get_rank(player)
if rank:allowed(name) then
@@ -43,9 +43,5 @@ function toolbar.draw(player)
end
end
if defines.events.rank_change then
Event.register(defines.events.rank_change,toolbar.draw)
end
Event.register(defines.events.on_player_joined_game,toolbar.draw)
return toolbar
-- second return is join event and third is rank change event
return toolbar, toolbar.draw, toolbar.draw

View File

@@ -427,10 +427,19 @@ script.on_event('on_tick',function(event)
end
end)
Ranking.on_init=function(self)
if loaded_modules.Server then require(module_path..'/src/server') end
require(module_path..'/src/core')
require(module_path..'/src/config')
_G.Ranking = Ranking
verbose('Loading rank core...')
require(module_path..'/src/core')
verbose('Loading rank configs...')
require(module_path..'/src/config')
_G.Ranking = nil
function Ranking:on_init()
if loaded_modules.Server then verbose('ExpGamingCore.Server is installed; Loading server src') require(module_path..'/src/server') end
end
function Ranking:on_post()
-- other modules can creat ranks during init and this will then set up the meta data
-- sets up the power system, the lower the power the closer to root, root is 0
-- there must be a rank with is_root flag set and one rank with is_default flag set, if multiple found then first found is used
local root = Ranking.get_rank(Ranking.meta.root)

View File

@@ -461,8 +461,8 @@ script.on_event(-2,function(event)
for uuid,thread in pairs(Server.threads) do setmetatable(thread,{__index=Server._thread}) end
end)
Server.on_init=function(self)
if loaded_modules.commands then require(module_path..'/src/commands') end
function Server:on_init()
if loaded_modules.commands then verbose('ExpGamingCore.Commands is installed; Loading commands src') require(module_path..'/src/commands') end
end
return Server

View File

@@ -1,4 +1,4 @@
--- Description - A small description that will be displayed on the doc
--- Adds a thread system and event listening and a admin bypass (recommend to disable /c and use optional /interface)
-- @submodule ExpGamingCore.Server
-- @alias Server
-- @author Cooldude2606

View File

@@ -292,11 +292,12 @@ script.on_event('on_tick',function(event)
end)
function Sync:on_init()
-- updates installed mods
if loaded_modules.Gui then verbose('ExpGamingCore.Gui is installed; Loading gui src') require(module_path..'/src/gui') end
if loaded_modules.Ranking then verbose('ExpGamingCore.Ranking is installed; Loading ranking src') require(module_path..'/src/ranking') end
end
function Sync:on_post()
Sync.info{mods=table.keys(loaded_modules)}
-- optinal dependies
if loaded_modules.Gui then verbose('ExpGamingCore.Gui is installed; Loading gui lib') require(module_path..'/src/gui') end
if loaded_modules.Ranking then verbose('ExpGamingCore.Ranking is installed; Loading ranking lib') require(module_path..'/src/ranking') end
end
return Sync

View File

@@ -41,7 +41,7 @@ script.on_event('rank_change',function(event)
local rank = Ranking.get_rank(event.new_rank)
local player = Game.get_player(event)
local by_player_name = Game.get_player(event.by_player_index) or '<server>'
local global = global('Ranking')
local global = global.Ranking
if rank.group.name == 'Jail' and global.last_change ~= player.name then
Sync.emit_embeded{
title='Player Jail',