Skip to content

Commit

Permalink
Merge branch 'release/5.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Cooldude2606 committed May 24, 2019
2 parents 51e6079 + 881a3d0 commit fba761a
Show file tree
Hide file tree
Showing 58 changed files with 5,239 additions and 75 deletions.
3 changes: 3 additions & 0 deletions config/file_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ return {
'modules.addons.scorched-earth',
'modules.addons.pollution-grading',
'modules.addons.random-player-colours',
-- GUI
'modules.commands.debug',
-- Config Files
'config.command_auth_admin', -- commands tagged with admin_only are blocked for non admins
'config.command_auth_roles', -- commands must be allowed via the role config
'config.command_auth_runtime_disable', -- allows commands to be enabled and disabled during runtime
'config.permission_groups', -- loads some predefined permission groups
'config.roles', -- loads some predefined roles
'expcore.gui.test'
}
3 changes: 2 additions & 1 deletion config/roles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Roles.new_role('Senior Administrator','SAdmin')
:set_parent('Administrator')
:allow{
'command/interface',
'command/debug',
'command/toggle-cheat-mode'
}

Expand Down Expand Up @@ -237,7 +238,7 @@ Roles.override_player_roles{
FlipHalfling90={'Moderator','Member'},
Gizan={'Pay to Win','Moderator','Member'},
Hobbitkicker={'Moderator','Member'},
jess_gaming={'Trainee','Member'},
jessi_gaming={'Trainee','Member'},
Koroto={'Moderator','Member'},
mafisch3={'Moderator','Member'},
maplesyrup01={'Moderator','Member'},
Expand Down
9 changes: 7 additions & 2 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
-- all files which are loaded (including the config files) are present in ./config/file_loader.lua
-- this file is the landing point for all scenarios please DO NOT edit directly, further comments are to aid development

log('[START] -----| Explosive Gaming Scenario Loader |-----')

-- Info on the data lifecycle and how we use it: https://github.com/Refactorio/RedMew/wiki/The-data-lifecycle
log('[INFO] Setting up lua environment')
require 'resources.data_stages'
_LIFECYCLE = _STAGE.control -- Control stage

Expand All @@ -22,6 +25,7 @@ require 'resources.version'
ext_require = require('expcore.common').ext_require

-- Please go to config/file_loader.lua to edit the files that are loaded
log('[INFO] Getting file loader config')
local files = require 'config.file_loader'

-- Loads all files from the config and logs that they are loaded
Expand All @@ -30,7 +34,7 @@ local errors = {}
for index,path in pairs(files) do

-- Loads the next file in the list
log(string.format('[INFO] Loading files %3d/%s',index,total_file_count))
log(string.format('[INFO] Loading file %3d/%s (%s)',index,total_file_count,path))
local success,file = pcall(require,path)

-- Error Checking
Expand All @@ -49,4 +53,5 @@ end

-- Logs all errors again to make it make it easy to find
log('[INFO] All files loaded with '..#errors..' errors:')
for _,error in pairs(errors) do log(error) end
for _,error in pairs(errors) do log(error) end
log('[END] -----| Explosive Gaming Scenario Loader |-----')
121 changes: 121 additions & 0 deletions expcore/Gui/buttons.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
--- Gui class define for buttons and sprite buttons
--[[
>>>> Functions
Button.new_button(name) --- Creates a new button element define
Button._prototype:on_click(player,element) --- Registers a handler for when the button is clicked
Button._prototype:on_left_click(player,element) --- Registers a handler for when the button is clicked with the left mouse button
Button._prototype:on_right_click(player,element) --- Registers a handler for when the button is clicked with the right mouse button
Button._prototype:set_sprites(sprite,hovered_sprite,clicked_sprite) --- Adds sprites to a button making it a spirte button
Button._prototype:set_click_filter(filter,...) --- Adds a click / mouse button filter to the button
Button._prototype:set_key_filter(filter,...) --- Adds a control key filter to the button
Other functions present from expcore.gui.core
]]
local mod_gui = require 'mod-gui'
local Gui = require 'expcore.gui.core'

local Button = {
_prototype=Gui._prototype_factory{
on_click = Gui._event_factory('on_click'),
on_left_click = Gui._event_factory('on_left_click'),
on_right_click = Gui._event_factory('on_right_click'),
}
}

--- Creates a new button element define
-- @tparam[opt] name string the optional debug name that can be added
-- @treturn table the new button element define
function Button.new_button(name)

local self = Gui._define_factory(Button._prototype)
self.draw_data.type = 'button'
self.draw_data.style = mod_gui.button_style

if name then
self:debug_name(name)
end

Gui.on_click(self.name,function(event)
local mouse_button = event.button
local keys = {alt=event.alt,control=event.control,shift=event.shift}
event.keys = keys

if self.post_authenticator then
if not self.post_authenticator(event.player,self.name) then return end
end

if mouse_button == defines.mouse_button_type.left and self.events.on_left_click then
self.events.on_left_click(event.player,event.element)
elseif mouse_button == defines.mouse_button_type.right and self.events.on_right_click then
self.events.on_right_click(event.player,event.element)
end

if self.mouse_button_filter and not self.mouse_button_filter[mouse_button] then return end
if self.key_button_filter then
for key,state in pairs(self.key_button_filter) do
if state and not keys[key] then return end
end
end

if self.events.on_click then
self.events.on_click(event.player,event.element,event)
end
end)

return self
end

--- Adds sprites to a button making it a spirte button
-- @tparam sprite SpritePath the sprite path for the default sprite for the button
-- @tparam[opt] hovered_sprite SpritePath the sprite path for the sprite when the player hovers over the button
-- @tparam[opt] clicked_sprite SpritePath the sprite path for the sprite when the player clicks the button
-- @treturn self returns the button define to allow chaining
function Button._prototype:set_sprites(sprite,hovered_sprite,clicked_sprite)
self.draw_data.type = 'sprite-button'
self.draw_data.sprite = sprite
self.draw_data.hovered_sprite = hovered_sprite
self.draw_data.clicked_sprite = clicked_sprite
return self
end

--- Adds a click / mouse button filter to the button
-- @tparam filter ?string|table either a table of mouse buttons or the first mouse button to filter, with a table true means allowed
-- @tparam[opt] ... when filter is not a table you can add the mouse buttons one after each other
-- @treturn self returns the button define to allow chaining
function Button._prototype:set_click_filter(filter,...)
if type(filter) == 'string' then
filter = {[filter]=true}
for _,v in pairs({...}) do
filter[v] = true
end
end

for k,v in pairs(filter) do
if type(v) == 'string' then
filter[k] = defines.mouse_button_type[v]
end
end

self.mouse_button_filter = filter
return self
end

--- Adds a control key filter to the button
-- @tparam filter ?string|table either a table of control keys or the first control keys to filter, with a table true means allowed
-- @tparam[opt] ... when filter is not a table you can add the control keyss one after each other
-- @treturn self returns the button define to allow chaining
function Button._prototype:set_key_filter(filter,...)
if type(filter) == 'string' then
filter = {[filter]=true}
for _,v in pairs({...}) do
filter[v] = true
end
end

self.key_button_filter = filter
return self
end

return Button
191 changes: 191 additions & 0 deletions expcore/Gui/center.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
--- Gui structure define for center gui frames
--[[
>>>> Functions
CenterFrames.get_flow(player) --- Gets the center flow for a player
CenterFrames.clear_flow(player) --- Clears the center flow for a player
CenterFrames.draw_frame(player,name) --- Draws the center frame for a player, if already open then will do nothing
CenterFrames.redraw_frame(player,name) --- Draws the center frame for a player, if already open then will destroy it and redraw
CenterFrames.toggle_frame(player,name,state) --- Toggles if the frame is currently open or not, will open if closed and close if open
CenterFrames.new_frame(permision_name) --- Sets the frame to be the current active gui when opened and closes all other frames
CenterFrames._prototype:on_draw(player,frame) --- Use to draw your elements onto the new frame
CenterFrames._prototype:set_auto_focus(state) --- Sets the frame to be the current active gui when opened and closes all other frames
CenterFrames._prototype:draw_frame(player) --- Draws this frame to the player, if already open does nothing (will call on_draw to draw to the frame)
CenterFrames._prototype:redraw_frame(player) --- Draws this frame to the player, if already open it will remove it and redraw it (will call on_draw to draw to the frame)
CenterFrames._prototype:toggle_frame(player) --- Toggles if the frame is open, if open it will close it and if closed it will open it
CenterFrames._prototype:event_handler(action) --- Creates an event handler that will trigger one of its functions, use with Event.add
]]
local Gui = require 'expcore.gui.core'
local Toolbar = require 'expcore.gui.toolbar'
local Game = require 'utils.game'

local CenterFrames = {
_prototype = Gui._prototype_factory{
on_draw = Gui._event_factory('on_draw')
}
}

--- Gets the center flow for a player
-- @tparam player LuapPlayer the player to get the flow for
-- @treturn LuaGuiElement the center flow
function CenterFrames.get_flow(player)
player = Game.get_player_from_any(player)
return player.gui.center
end

--- Clears the center flow for a player
-- @tparam player LuapPlayer the player to clear the flow for
function CenterFrames.clear_flow(player)
local flow = CenterFrames.get_flow(player)
flow.clear()
end

--- Draws the center frame for a player, if already open then will do nothing
-- @tparam player LuapPlayer the player that will have the frame drawn
-- @tparam name string the name of the hui that will drawn
-- @treturn LuaGuiElement the new frame that was made
function CenterFrames.draw_frame(player,name)
local define = Gui.get_define(name,true)
if define then
return define:draw_frame(player)
end
end

--- Draws the center frame for a player, if already open then will destroy it and redraw
-- @tparam player LuapPlayer the player that will have the frame drawn
-- @tparam name string the name of the hui that will drawn
-- @treturn LuaGuiElement the new frame that was made
function CenterFrames.redraw_frame(player,name)
local define = Gui.get_define(name,true)
if define then
return define:draw_frame(player)
end
end

--- Toggles if the frame is currently open or not, will open if closed and close if open
-- @tparam player LuapPlayer the player that will have the frame toggled
-- @tparam name string the name of the hui that will be toggled
-- @tparam[opt] state boolean when set will force a state for the frame
-- @treturn boolean if the frame if no open or closed
function CenterFrames.toggle_frame(player,name,state)
local define = Gui.get_define(name,true)
if define then
if state == true then
define:draw_frame(player)
return true
elseif state == false then
local flow = CenterFrames.get_flow(player)
if flow[define.name] then
flow[define.name].destroy()
end
return false
else
return define:toggle_frame(player)
end
end
end

--- Creates a new center frame define
-- @tparam permision_name string the name that can be used with the permision system
-- @treturn table the new center frame define
function CenterFrames.new_frame(permision_name)
local self = Toolbar.new_button(permision_name)

self:on_click(function(player,element)
self:toggle_frame(player)
end)

local mt = getmetatable(self)
mt.__index = CenterFrames._prototype
mt.__call = self.event_handler

Gui.on_custom_close(self.name,function(event)
local element = event.element
if element and element.valid then element.destroy() end
end)

return self
end

--- Sets the frame to be the current active gui when opened and closes all other frames
-- @tparam[opt=true] state boolean when true will auto close other frames and set this frame as player.opened
function CenterFrames._prototype:set_auto_focus(state)
if state == false then
self.auto_focus = false
else
self.auto_focus = true
end
end

--- Draws this frame to the player, if already open does nothing (will call on_draw to draw to the frame)
-- @tparam player LuaPlayer the player to draw the frame for
-- @treturn LuaGuiElement the new frame that was drawn
function CenterFrames._prototype:draw_frame(player)
player = Game.get_player_from_any(player)
local flow = CenterFrames.get_flow(player)

if flow[self.name] then
return flow[self.name]
end

if self.auto_focus then
flow.clear()
end

local frame = flow.add{
type='frame',
name=self.name
}

if self.auto_focus then
player.opened = frame
end

if self.events.on_draw then
self.events.on_draw(player,frame)
end

return frame
end

--- Draws this frame to the player, if already open it will remove it and redraw it (will call on_draw to draw to the frame)
-- @tparam player LuaPlayer the player to draw the frame for
-- @treturn LuaGuiElement the new frame that was drawn
function CenterFrames._prototype:redraw_frame(player)
player = Game.get_player_from_any(player)
local flow = CenterFrames.get_flow(player)

if flow[self.name] then
flow[self.name].destroy()
end

return self:draw_frame(player)
end

--- Toggles if the frame is open, if open it will close it and if closed it will open it
-- @tparam player LuaPlayer the player to draw the frame for
-- @treturn boolean with the gui frame is now open
function CenterFrames._prototype:toggle_frame(player)
player = Game.get_player_from_any(player)
local flow = CenterFrames.get_flow(player)

if flow[self.name] then
flow[self.name].destroy()
return false
else
self:draw_frame(player)
return true
end
end

--- Creates an event handler that will trigger one of its functions, use with Event.add
-- @tparam[opt=update] action string the action to take on this event
function CenterFrames._prototype:event_handler(action)
action = action or 'update'
return function(event)
local player = Game.get_player_by_index(event.player_index)
self[action](self,player)
end
end

return CenterFrames
Loading

0 comments on commit fba761a

Please sign in to comment.