mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-29 20:16:38 +09:00
File Cleanup
This commit is contained in:
@@ -1,221 +0,0 @@
|
||||
--- 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
|
||||
|
||||
local Game = require('FactorioStdLib.Game')
|
||||
local Color = require('FactorioStdLib.Color')
|
||||
local Gui = require('ExpGamingCore.Gui')
|
||||
local mod_gui = require('mod-gui')
|
||||
|
||||
local center = {}
|
||||
center._prototype = {}
|
||||
|
||||
--- Adds a new obj to the center gui
|
||||
-- @usage Gui.center.add{name='foo',caption='Foo',tooltip='Testing',draw=function}
|
||||
-- @usage return_value(player) -- opens the center gui for that player
|
||||
-- @param obj contains the new object, needs name, frame is opt and is function(root_frame)
|
||||
-- @return the object made, used to add tabs, calling the returned value will open the center for the given player
|
||||
function center.add(obj)
|
||||
if not is_type(obj,'table') then return end
|
||||
if not is_type(obj.name,'string') then return end
|
||||
verbose('Created Center Gui: '..obj.name)
|
||||
setmetatable(obj,{__index=center._prototype,__call=function(self,player,...) return center.open(player,self.name,...) end})
|
||||
obj.tabs = {}
|
||||
obj._tabs = {}
|
||||
Gui.data('center',obj.name,obj)
|
||||
if Gui.toolbar then Gui.toolbar(obj.name,obj.caption,obj.tooltip,function(event) return obj:open(event.player_index) end) end
|
||||
return obj
|
||||
end
|
||||
|
||||
--- Used to get the center frame of the player, used mainly in script
|
||||
-- @usage Gui.center.get_flow(player) -- returns gui element
|
||||
-- @param player a player identifier to get the flow for
|
||||
-- @treturn table the gui element flow
|
||||
function center.get_flow(player)
|
||||
player = Game.get_player(player)
|
||||
if not player then error('Invalid player',2) end
|
||||
return player.gui.center.exp_center or player.gui.center.add{name='exp_center',type='flow'}
|
||||
end
|
||||
|
||||
--- Used to open a center frame for a player, extra params are sent to open event
|
||||
-- @usage Gui.center.open(player,'server-info') -- return true
|
||||
-- @param player a player identifier to get the flow for
|
||||
-- @tparam string center_name the name of the center frame to open
|
||||
-- @treturn boolean based on if it succeeded or not
|
||||
function center.open(player,center_name,...)
|
||||
player = Game.get_player(player)
|
||||
if not player then error('Invalid player',2) return false end
|
||||
Gui.center.clear(player)
|
||||
if not Gui.data.center[center_name] then return false end
|
||||
local self = Gui.data.center[center_name]
|
||||
-- this function is the draw function passed to the open event
|
||||
self:open(player,function(...) Gui.center._draw(self,...) end,...)
|
||||
return true
|
||||
end
|
||||
|
||||
-- used as a piece of middle ware for the open event
|
||||
function center._draw(self,frame,...)
|
||||
game.players[frame.player_index].opened=frame
|
||||
if is_type(self.draw,'function') then
|
||||
local success, err = pcall(self.draw,self,frame,...)
|
||||
if not success then error(err) end
|
||||
else error('No Callback on center frame '..self.name) end
|
||||
end
|
||||
|
||||
--- Used to open a center frame for a player
|
||||
-- @usage Gui.center.open_tab(player,'readme','rules') -- return true
|
||||
-- @param player a player identifier to get the flow for
|
||||
-- @tparam string center the name of the center frame to open
|
||||
-- @tparam string tab the name of the tab to open
|
||||
-- @treturn boolean based on if it succeeded or not
|
||||
function center.open_tab(player,center_name,tab)
|
||||
player = Game.get_player(player)
|
||||
if not player then error('Invalid player',2) end
|
||||
if not Gui.center.open(player,center_name) then return false end
|
||||
local name = center_name..'_'..tab
|
||||
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_name].tab_bar.tab_bar_scroll.tab_bar_scroll_flow[name],
|
||||
}
|
||||
return true
|
||||
end
|
||||
|
||||
--- Used to clear the center frame of the player, used mainly in script
|
||||
-- @usage Gui.center.clear(player)
|
||||
-- @param player a player identifier to get the flow for
|
||||
function center.clear(player)
|
||||
player = Game.get_player(player)
|
||||
center.get_flow(player).clear()
|
||||
end
|
||||
|
||||
-- opens this gui for this player, draw is the draw function when event is called from center.open
|
||||
-- this is the default function it can be overridden when the gui is defined, simply call draw on the frame you create
|
||||
-- extra values passed to draw will also be passed to the draw event
|
||||
-- extra values from center.draw and passed to the open event
|
||||
function center._prototype:open(player,draw,...)
|
||||
player = Game.get_player(player)
|
||||
draw = draw or function(...) center._draw(self,...) end
|
||||
local center_flow = center.get_flow(player)
|
||||
if center_flow[self.name] then Gui.center.clear(player) return end
|
||||
local center_frame = center_flow.add{
|
||||
name=self.name,
|
||||
type='frame',
|
||||
caption=self.caption,
|
||||
direction='vertical',
|
||||
style=mod_gui.frame_style
|
||||
}
|
||||
if is_type(center_frame.caption,'string') and player.gui.is_valid_sprite_path(center_frame.caption) then center_frame.caption = '' end
|
||||
draw(center_frame,...)
|
||||
end
|
||||
|
||||
-- this is the default draw function if one is not provided, can be overridden
|
||||
-- not recommended for direct use see Gui.center.open
|
||||
function center._prototype:draw(frame)
|
||||
Gui.bar(frame,510)
|
||||
local tab_bar = frame.add{
|
||||
type='frame',
|
||||
name='tab_bar',
|
||||
style='image_frame',
|
||||
direction='vertical'
|
||||
}
|
||||
tab_bar.style.width = 510
|
||||
tab_bar.style.height = 65
|
||||
local tab_bar_scroll = tab_bar.add{
|
||||
type='scroll-pane',
|
||||
name='tab_bar_scroll',
|
||||
horizontal_scroll_policy='auto-and-reserve-space',
|
||||
vertical_scroll_policy='never'
|
||||
}
|
||||
tab_bar_scroll.style.vertically_squashable = false
|
||||
tab_bar_scroll.style.vertically_stretchable = true
|
||||
tab_bar_scroll.style.width = 500
|
||||
local tab_bar_scroll_flow = tab_bar_scroll.add{
|
||||
type='flow',
|
||||
name='tab_bar_scroll_flow',
|
||||
direction='horizontal'
|
||||
}
|
||||
Gui.bar(frame,510)
|
||||
local tab = frame.add{
|
||||
type ='frame',
|
||||
name='tab',
|
||||
direction='vertical',
|
||||
style='image_frame'
|
||||
}
|
||||
tab.style.width = 510
|
||||
tab.style.height = 305
|
||||
local tab_scroll = tab.add{
|
||||
type ='scroll-pane',
|
||||
name='tab_scroll',
|
||||
horizontal_scroll_policy='never',
|
||||
vertical_scroll_policy='auto'
|
||||
}
|
||||
tab_scroll.style.vertically_squashable = false
|
||||
tab_scroll.style.vertically_stretchable = true
|
||||
tab_scroll.style.width = 500
|
||||
local tab_scroll_flow = tab_scroll.add{
|
||||
type='flow',
|
||||
name='tab_scroll_flow',
|
||||
direction='vertical'
|
||||
}
|
||||
tab_scroll_flow.style.width = 480
|
||||
Gui.bar(frame,510)
|
||||
local first_tab = nil
|
||||
for name,button in pairs(self.tabs) do
|
||||
first_tab = first_tab or name
|
||||
button(tab_bar_scroll_flow).style.font_color = defines.color.white
|
||||
end
|
||||
self._tabs[self.name..'_'..first_tab](tab_scroll_flow)
|
||||
tab_bar_scroll_flow.children[1].style.font_color = defines.color.orange
|
||||
frame.parent.add{type='frame',name='temp'}.destroy()--recenter the GUI
|
||||
end
|
||||
|
||||
--- If default draw is used then you can add tabs to the gui with this function
|
||||
-- @usage _center:add_tab('foo','Foo','Just a tab',function)
|
||||
-- @tparam string name this is the name of the tab
|
||||
-- @tparam string caption this is the words that appear on the tab button
|
||||
-- @tparam[opt] string tooltip the tooltip that is on the button
|
||||
-- @tparam function callback this is called when button is pressed with function(root_frame)
|
||||
-- @return self to allow chaining of _center:add_tab
|
||||
function center._prototype:add_tab(name,caption,tooltip,callback)
|
||||
verbose('Created Tab: '..self.name..'/'..name)
|
||||
self._tabs[self.name..'_'..name] = callback
|
||||
self.tabs[name] = Gui.inputs.add{
|
||||
type='button',
|
||||
name=self.name..'_'..name,
|
||||
caption=caption,
|
||||
tooltip=tooltip
|
||||
}:on_event('click',function(event)
|
||||
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.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
|
||||
if button.name == event.element.name then
|
||||
button.style.font_color = defines.color.orange
|
||||
else
|
||||
button.style.font_color = defines.color.white
|
||||
end
|
||||
end
|
||||
local success, err = pcall(_tab,tab)
|
||||
if not success then error(err) end
|
||||
end
|
||||
end)
|
||||
return self
|
||||
end
|
||||
|
||||
-- used so that when gui close key is pressed this will close the gui
|
||||
Event.add(defines.events.on_gui_closed,function(event)
|
||||
if event.element and event.element.valid then event.element.destroy() end
|
||||
end)
|
||||
|
||||
Event.add(defines.events.on_player_respawned,center.clear)
|
||||
|
||||
function center.on_init()
|
||||
if loaded_modules['ExpGamingCore.Role'] then Event.add(defines.events.on_role_change,center.clear) end
|
||||
end
|
||||
-- calling will attempt to add a new gui
|
||||
return setmetatable(center,{__call=function(self,...) return self.add(...) end})
|
||||
@@ -1,24 +0,0 @@
|
||||
{
|
||||
"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": {}
|
||||
}
|
||||
@@ -1,190 +0,0 @@
|
||||
--- Adds a objective version to custom guis.
|
||||
-- @module ExpGamingCore.Gui
|
||||
-- @alias Gui
|
||||
-- @author Cooldude2606
|
||||
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
||||
|
||||
local Game = require('FactorioStdLib.Game')
|
||||
local Color = require('FactorioStdLib.Color')
|
||||
local Server -- ExpGamingCore.Server@?^4.0.0
|
||||
|
||||
local Gui = {}
|
||||
local global = {}
|
||||
Global.register(global,function(tbl) global = tbl 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 located 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
|
||||
})
|
||||
|
||||
--- Add a white bar to any gui frame
|
||||
-- @usage Gui.bar(frame,100)
|
||||
-- @param frame the frame to draw the line to
|
||||
-- @param[opt=10] width the width of the bar
|
||||
-- @return the line that was made type is progress bar
|
||||
function Gui.bar(frame,width)
|
||||
local line = frame.add{
|
||||
type='progressbar',
|
||||
size=1,
|
||||
value=1
|
||||
}
|
||||
line.style.height = 3
|
||||
line.style.width = width or 10
|
||||
line.style.color = defines.color.white
|
||||
return line
|
||||
end
|
||||
|
||||
--- Adds a label that is centered
|
||||
-- @usage Gui.centered_label(frame, 'Hello, world!')
|
||||
-- @tparam LuaGuiElement frame the parent frame to add the label to
|
||||
-- @tparam string string the string that the label will have
|
||||
function Gui.centered_label(frame, string)
|
||||
local flow = frame.add {frame = 'flow'}
|
||||
local flow_style = flow.style
|
||||
flow_style.align = 'center'
|
||||
flow_style.horizontally_stretchable = true
|
||||
|
||||
local label = flow.add {type = 'label', caption = string}
|
||||
local label_style = label.style
|
||||
label_style.align = 'center'
|
||||
label_style.single_line = false
|
||||
|
||||
return label
|
||||
end
|
||||
|
||||
--- Used to set the index of a drop down to a certain item
|
||||
-- @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
|
||||
function Gui.set_dropdown_index(dropdown,_item)
|
||||
if not dropdown or not dropdown.valid or not dropdown.items or not _item then return end
|
||||
local _index = 1
|
||||
for index, item in pairs(dropdown.items) do
|
||||
if item == _item then _index = index break end
|
||||
end
|
||||
dropdown.selected_index = _index
|
||||
return dropdown
|
||||
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
|
||||
-- @field zoom the zoom to give the new camera
|
||||
-- @field width the width to give the new camera
|
||||
-- @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 depending 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
|
||||
if is_type(data.cam,'table') and data.cam.__self and data.cam.valid then
|
||||
data.cam = data.cam
|
||||
elseif data.frame then
|
||||
data.cam={}
|
||||
data.cam.type='camera'
|
||||
data.cam.name='camera'
|
||||
data.cam.position= data.entity.position
|
||||
data.cam.surface_index= data.surface and data.surface.index or data.entity.surface.index
|
||||
data.cam.zoom = data.zoom
|
||||
data.cam = data.frame.add(data.cam)
|
||||
data.cam.style.width = data.width or 100
|
||||
data.cam.style.height = data.height or 100
|
||||
else return end
|
||||
if not Server or not Server.get_thread('camera-follow') then
|
||||
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(global.cams,{cam=data.cam,entity=data.entity,surface=surface})
|
||||
end
|
||||
if not global.players then
|
||||
global.players = {}
|
||||
end
|
||||
if data.respawn_open then
|
||||
if data.entity.player then
|
||||
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
|
||||
local thread = Server.get_thread('camera-follow')
|
||||
local surface = data.surface and data.surface.index or nil
|
||||
table.insert(thread.data.cams,{cam=data.cam,entity=data.entity,surface=surface})
|
||||
if data.respawn_open then
|
||||
if data.entity.player then
|
||||
if not thread.data.players[data.entity.player.index] then thread.data.players[data.entity.player.index] = {} end
|
||||
table.insert(thread.data.players[data.entity.player.index],data.cam)
|
||||
end
|
||||
end
|
||||
end
|
||||
return data.cam
|
||||
end
|
||||
|
||||
Event.add('on_tick', function(event)
|
||||
if loaded_modules['ExpGamingCore.Server'] then return end
|
||||
if global.cams and is_type(global.cams,'table') and #global.cams > 0 then
|
||||
local update = 4
|
||||
if global.cam_index >= #global.cams then global.cam_index = 1 end
|
||||
if update > #global.cams then update = #global.cams end
|
||||
for cam_offset = 0,update do
|
||||
local _cam = global.cams[global.cam_index+cam_offset]
|
||||
if not _cam then break end
|
||||
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
|
||||
global.cam_index = global.cam_index+update
|
||||
end
|
||||
end)
|
||||
|
||||
Event.add('on_player_respawned',function(event)
|
||||
if loaded_modules['ExpGamingCore.Server'] then return end
|
||||
if global.players and is_type(global.players,'table') and #global.players > 0 and global.players[event.player_index] then
|
||||
local remove = {}
|
||||
local player = Game.get_player(event)
|
||||
for index,cam in pairs(global.players[event.player_index]) do
|
||||
if cam.valid then table.insert(global.cams,{cam=cam,entity=player.character,surface=player.surface})
|
||||
else table.insert(remove,index) end
|
||||
end
|
||||
for n,index in pairs(remove) do
|
||||
table.remove(global.players[event.player_index],index-n+1)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
function Gui:on_init()
|
||||
if loaded_modules['ExpGamingCore.Server'] then
|
||||
Server = require('ExpGamingCore.Server')
|
||||
verbose('ExpGamingCore.Server is installed; Loading server src')
|
||||
script.on_init(require(module_path..'/src/server',{Gui=self}))
|
||||
end
|
||||
end
|
||||
|
||||
function Gui.on_post()
|
||||
Gui.test = require(module_path..'/src/test',{Gui=Gui})
|
||||
end
|
||||
|
||||
|
||||
return Gui
|
||||
@@ -1,375 +0,0 @@
|
||||
--- 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 is a submodule of ExpGamingCore.Gui but for ldoc reasons it is under its own module
|
||||
-- @function _comment
|
||||
|
||||
local Game = require('FactorioStdLib.Game')
|
||||
local Color = require('FactorioStdLib.Color')
|
||||
local mod_gui = require('mod-gui')
|
||||
local Gui = require('ExpGamingCore.Gui')
|
||||
|
||||
local inputs = {}
|
||||
inputs._prototype = {}
|
||||
-- these are just so you can have short cuts to this
|
||||
inputs.events = {
|
||||
--error={}, -- this is added after event calls are added as it is not a script event
|
||||
state=defines.events.on_gui_checked_state_changed,
|
||||
click=defines.events.on_gui_click,
|
||||
elem=defines.events.on_gui_elem_changed,
|
||||
selection=defines.events.on_gui_selection_state_changed,
|
||||
text=defines.events.on_gui_text_changed,
|
||||
slider=defines.events.on_gui_value_changed
|
||||
}
|
||||
|
||||
--- Sets the input to trigger on an certain event
|
||||
-- @usage button:on_event(defines.events.on_gui_click,player_return)
|
||||
-- @param event the event to raise callback on | can be number of the event | can be a key of inputs.events
|
||||
-- @tparam function callback the function you want to run on the event
|
||||
-- @treturn table returns self so you can chain together
|
||||
function inputs._prototype:on_event(event,callback)
|
||||
if not is_type(callback,'function') then return self end
|
||||
if inputs.events[event] then event = inputs.events[event] end
|
||||
if event == inputs.events.error then self._error = callback return self end
|
||||
self.events[event] = callback
|
||||
return self
|
||||
end
|
||||
|
||||
--- Draw the input into the root element
|
||||
-- @usage button:draw(frame)
|
||||
-- @param root the element you want to add the input to
|
||||
-- @return returns the element that was added
|
||||
function inputs._prototype:draw(root)
|
||||
local player = Game.get_player(root.player_index)
|
||||
if is_type(self.draw_data.caption,'string') and player.gui.is_valid_sprite_path(self.draw_data.caption) then
|
||||
local data = table.deepcopy(self.draw_data)
|
||||
data.type = 'sprite-button'
|
||||
data.sprite = data.caption
|
||||
data.caption = nil
|
||||
return root.add(data)
|
||||
elseif is_type(self.draw_data.sprite,'string') and player.gui.is_valid_sprite_path(self.draw_data.sprite) then
|
||||
local data = table.deepcopy(self.draw_data)
|
||||
data.type = 'sprite-button'
|
||||
return root.add(data)
|
||||
elseif is_type(self.data._state,'function') then
|
||||
local data = table.deepcopy(self.draw_data)
|
||||
local success, err = pcall(self.data._state,player,root)
|
||||
if success then data.state = err else error(err) end
|
||||
return root.add(data)
|
||||
elseif is_type(self.data._start,'function') then
|
||||
local data = table.deepcopy(self.draw_data)
|
||||
local success, err = pcall(self.data._start,player,root)
|
||||
if success then data.value = err else error(err) end
|
||||
return root.add(data)
|
||||
elseif is_type(self.data._index,'function') then
|
||||
local data = table.deepcopy(self.draw_data)
|
||||
local success, err = pcall(self.data._index,player,root)
|
||||
if success then data.selected_index = err else error(err) end
|
||||
if is_type(self.data._items,'function') then
|
||||
local success, err = pcall(self.data._items,player,root)
|
||||
if success then data.items = err else error(err) end
|
||||
end
|
||||
return root.add(data)
|
||||
elseif is_type(self.data._items,'function') then
|
||||
local data = table.deepcopy(self.draw_data)
|
||||
local success, err = pcall(self.data._items,player,root)
|
||||
if success then data.items = err else error(err) end
|
||||
if is_type(self.data._index,'function') then
|
||||
local _success, _err = pcall(self.data._index,player,root)
|
||||
if _success then data.selected_index = _err else error(_err) end
|
||||
end
|
||||
return root.add(data)
|
||||
else
|
||||
return root.add(self.draw_data)
|
||||
end
|
||||
end
|
||||
|
||||
--- Add a new input, this is the same as doing frame.add{} but returns a different object
|
||||
-- @usage Gui.inputs.add{type='button',name='test',caption='Test'}
|
||||
-- @usage return_value(frame) -- draws the button onto that frame
|
||||
-- @tparam table obj the new element to add if caption is a sprite path then sprite is used
|
||||
-- @treturn table the custom input object, calling the returned value will draw the button
|
||||
function inputs.add(obj)
|
||||
if not is_type(obj,'table') then return end
|
||||
if not is_type(obj.type,'string') then return end
|
||||
local type = obj.type
|
||||
if type ~= 'button'
|
||||
and type ~= 'sprite-button'
|
||||
and type ~= 'choose-elem-button'
|
||||
and type ~= 'checkbox'
|
||||
and type ~= 'radiobutton'
|
||||
and type ~= 'textfield'
|
||||
and type ~= 'text-box'
|
||||
and type ~= 'slider'
|
||||
and type ~= 'drop-down'
|
||||
then return end
|
||||
verbose('Created Input: '..obj.name..' ('..obj.type..')')
|
||||
if obj.type == 'button' or obj.type == 'sprite-button' then obj.style = mod_gui.button_style end
|
||||
obj.draw_data = table.deepcopy(obj)
|
||||
obj.data = {}
|
||||
obj.events = {}
|
||||
setmetatable(obj,{__index=inputs._prototype,__call=function(self,...) return self:draw(...) end})
|
||||
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.data['inputs_'..event.element.type] or {}
|
||||
local element = elements[event.element.name]
|
||||
if not element and event.element.type == 'sprite-button' then
|
||||
elements = Gui.data.inputs_button or {}
|
||||
element = elements[event.element.name]
|
||||
end
|
||||
if element then
|
||||
verbose('There was a gui event ('..Event.names[event.name]..') with element: '..event.element.name)
|
||||
if not is_type(element.events[event.name],'function') then return end
|
||||
local success, err = Manager.sandbox(element.events[event.name],{},event)
|
||||
if not success then
|
||||
if is_type(element._error,'function') then pcall(element._error)
|
||||
else error(err) end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Event.add(inputs.events,inputs._event_handler)
|
||||
inputs.events.error = {}
|
||||
|
||||
-- the following 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
|
||||
-- @usage Gui.inputs.add_button('test','Test','Just for testing',{{condition,callback},...})
|
||||
-- @tparam string name the name of this button
|
||||
-- @tparam string the display for this button, either text or sprite path
|
||||
-- @tparam string tooltip the tooltip to show on the button
|
||||
-- @param callbacks can either be a single function or a list of function pairs see examples at bottom
|
||||
-- @treturn table the button object that was made, to allow a custom error event if wanted
|
||||
function inputs.add_button(name,display,tooltip,callbacks)
|
||||
local rtn_button = inputs.add{
|
||||
type='button',
|
||||
name=name,
|
||||
caption=display,
|
||||
tooltip=tooltip
|
||||
}
|
||||
rtn_button.data._callbacks = callbacks
|
||||
rtn_button:on_event('click',function(event)
|
||||
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.data.inputs_button or {}
|
||||
button = elements[event.element.name]
|
||||
end
|
||||
local player = Game.get_player(event)
|
||||
local mouse = event.button
|
||||
local keys = {alt=event.alt,ctrl=event.control,shift=event.shift}
|
||||
local element = event.element
|
||||
local btn_callbacks = button.data._callbacks
|
||||
if is_type(btn_callbacks,'function') then btn_callbacks = {{function() return true end,btn_callbacks}} end
|
||||
for _,data in pairs(btn_callbacks) do
|
||||
if is_type(data[1],'function') and is_type(data[2],'function') then
|
||||
local success, err = pcall(data[1],player,mouse,keys,event)
|
||||
if success and err == true then
|
||||
local _success, _err = pcall(data[2],player,element,event)
|
||||
if not _success then error(_err) end
|
||||
elseif not success then error(err) end
|
||||
else error('Invalid Callback Condition Format') end
|
||||
end
|
||||
end)
|
||||
return rtn_button
|
||||
end
|
||||
|
||||
--- Used to define a choose-elem-button callback only on elem_changed
|
||||
-- @usage Gui.inputs.add_elem_button('test','Test','Just for testing',function)
|
||||
-- @tparam string name the name of this button
|
||||
-- @tparam string elem_type the display for this button, either text or sprite path
|
||||
-- @tparam string tooltip the tooltip to show on the button
|
||||
-- @tparam function callback the callback to call on change function(player,element,elem)
|
||||
-- @treturn table the button object that was made, to allow a custom error event if wanted
|
||||
function inputs.add_elem_button(name,elem_type,tooltip,callback)
|
||||
local button = inputs.add{
|
||||
type='choose-elem-button',
|
||||
name=name,
|
||||
elem_type=elem_type,
|
||||
tooltip=tooltip
|
||||
}
|
||||
button.data._callback = callback
|
||||
button:on_event('elem',function(event)
|
||||
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}
|
||||
if is_type(button.data._callback,'function') then
|
||||
local success, err = pcall(button.data._callback,player,element,elem)
|
||||
if not success then error(err) end
|
||||
else error('Invalid Callback') end
|
||||
end)
|
||||
return button
|
||||
end
|
||||
|
||||
--- Used to define a checkbox callback only on state_changed
|
||||
-- @usage Gui.inputs.add_checkbox('test',false,'Just for testing',function,function,funvtion)
|
||||
-- @tparam string name the name of this button
|
||||
-- @tparam boolean radio if this is a radio button
|
||||
-- @tparam string display the display for this button, either text or sprite path
|
||||
-- @tparam function default the callback which choses the default check state
|
||||
-- @tparam function callback_true the callback to call when changed to true
|
||||
-- @tparam function callback_false the callback to call when changed to false
|
||||
-- @treturn table the button object that was made, to allow a custom error event if wanted
|
||||
function inputs.add_checkbox(name,radio,display,default,callback_true,callback_false)
|
||||
local type = 'checkbox'; if radio then type='radiobutton' end
|
||||
local state = false; if is_type(default,'boolean') then state = default end
|
||||
local rtn_checkbox = inputs.add{
|
||||
type=type,
|
||||
name=name,
|
||||
caption=display,
|
||||
state=state
|
||||
}
|
||||
if is_type(default,'function') then rtn_checkbox.data._state = default end
|
||||
rtn_checkbox.data._true = callback_true
|
||||
rtn_checkbox.data._false = callback_false
|
||||
rtn_checkbox:on_event('state',function(event)
|
||||
local checkbox = Gui.data['inputs_'..event.element.type][event.element.name]
|
||||
local player = Game.get_player(event)
|
||||
if event.element.state then
|
||||
if is_type(checkbox.data._true,'function') then
|
||||
local success, err = pcall(checkbox.data._true,player,event.element)
|
||||
if not success then error(err) end
|
||||
else error('Invalid Callback') end
|
||||
else
|
||||
if is_type(checkbox.data._false,'function') then
|
||||
local success, err = pcall(checkbox.data._false,player,event.element)
|
||||
if not success then error(err) end
|
||||
else error('Invalid Callback') end
|
||||
end
|
||||
end)
|
||||
return rtn_checkbox
|
||||
end
|
||||
|
||||
--- Used to reset the state of radio buttons, recommended to be called on_state_change to reset any radio buttons it is meant to work with.
|
||||
-- @usage Gui.inputs.reset_radio{radio1,radio2,...}
|
||||
-- @param elements can be a list of elements or a single element
|
||||
function inputs.reset_radio(elements)
|
||||
if #elements > 0 then
|
||||
for _,element in pairs(elements) do
|
||||
if element.valid then
|
||||
local _elements = Gui.data['inputs_'..element.type] or {}
|
||||
local _element = _elements[element.name]
|
||||
local player = Game.get_player(element.player_index)
|
||||
local state = false
|
||||
local success, err = pcall(_element.data._state,player,element.parent)
|
||||
if success then state = err else error(err) end
|
||||
element.state = state
|
||||
end
|
||||
end
|
||||
else
|
||||
if elements.valid then
|
||||
local _elements = Gui.data['inputs_'..elements.type] or {}
|
||||
local _element = _elements[elements.name]
|
||||
local player = Game.get_player(elements.player_index)
|
||||
local state = false
|
||||
local success, err = pcall(_element.data._state,player,elements.parent)
|
||||
if success then state = err else error(err) end
|
||||
elements.state = state
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Used to define a text callback only on text_changed
|
||||
-- @usage Gui.inputs.add_text('test',false,'Just for testing',function)
|
||||
-- @tparam string name the name of this button
|
||||
-- @tparam boolean box is it a text box rather than a text field
|
||||
-- @tparam string text the starting text
|
||||
-- @tparam function callback the callback to call on change function(player,text,element)
|
||||
-- @treturn table the text object that was made, to allow a custom error event if wanted
|
||||
function inputs.add_text(name,box,text,callback)
|
||||
local type = 'textfield'; if box then type='text-box' end
|
||||
local rtn_textbox = inputs.add{
|
||||
type=type,
|
||||
name=name,
|
||||
text=text
|
||||
}
|
||||
rtn_textbox.data._callback = callback
|
||||
rtn_textbox:on_event('text',function(event)
|
||||
local textbox = Gui.data['inputs_'..event.element.type][event.element.name]
|
||||
local player = Game.get_player(event)
|
||||
local element = event.element
|
||||
local event_callback = textbox.data._callback
|
||||
if is_type(event_callback,'function') then
|
||||
local success, err = pcall(event_callback,player,element.text,element)
|
||||
if not success then error(err) end
|
||||
else error('Invalid Callback Condition Format') end
|
||||
end)
|
||||
return rtn_textbox
|
||||
end
|
||||
|
||||
--- Used to define a slider callback only on value_changed
|
||||
-- @usage Gui.inputs.add_slider('test','horizontal',1,10,5,function)
|
||||
-- @tparam string name the name of this button
|
||||
-- @tparam string orientation direction of the slider
|
||||
-- @tparam number min the lowest number
|
||||
-- @tparam number max the highest number
|
||||
-- @tparam function start_callback either a number or a function to return a number
|
||||
-- @tparam function callback the function to be called on value_changed function(player,value,percent,element)
|
||||
-- @treturn table the slider object that was made, to allow a custom error event if wanted
|
||||
function inputs.add_slider(name,orientation,min,max,start_callback,callback)
|
||||
local slider = inputs.add{
|
||||
type='slider',
|
||||
name=name,
|
||||
orientation=orientation,
|
||||
minimum_value=min,
|
||||
maximum_value=max,
|
||||
value=start_callback
|
||||
}
|
||||
slider.data._start = start_callback
|
||||
slider.data._callback = callback
|
||||
slider:on_event('slider',function(event)
|
||||
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
|
||||
local percent = value/event.element.get_slider_maximum()
|
||||
if is_type(data._callback,'function') then
|
||||
local success, err = pcall(data._callback,player,value,percent,event.element)
|
||||
if not success then error(err) end
|
||||
else error('Invalid Callback Condition Format') end
|
||||
end)
|
||||
return slider
|
||||
end
|
||||
|
||||
--- Used to define a drop down callback only on value_changed
|
||||
-- @usage Gui.inputs.add_drop_down('test',{1,2,3},1,function)
|
||||
-- @tparam string name name of the drop down
|
||||
-- @param items either a list or a function which returns a list
|
||||
-- @param index either a number or a function which returns a number
|
||||
-- @tparam function callback the callback which is called when a new index is selected function(player,selected,items,element)
|
||||
-- @treturn table the drop-down object that was made, to allow a custom error event if wanted
|
||||
function inputs.add_drop_down(name,items,index,callback)
|
||||
local rtn_dropdown = inputs.add{
|
||||
type='drop-down',
|
||||
name=name,
|
||||
items=items,
|
||||
selected_index=index
|
||||
}
|
||||
rtn_dropdown.data._items = items
|
||||
rtn_dropdown.data._index = index
|
||||
rtn_dropdown.data._callback = callback
|
||||
rtn_dropdown:on_event('selection',function(event)
|
||||
local dropdown = Gui.data['inputs_'..event.element.type][event.element.name]
|
||||
local player = Game.get_player(event)
|
||||
local element = event.element
|
||||
local drop_items = element.items
|
||||
local selected = drop_items[element.selected_index]
|
||||
local drop_callback = dropdown.data._callback
|
||||
if is_type(drop_callback,'function') then
|
||||
local success, err = pcall(drop_callback,player,selected,drop_items,element)
|
||||
if not success then error(err) end
|
||||
else error('Invalid Callback Condition Format') end
|
||||
end)
|
||||
return rtn_dropdown
|
||||
end
|
||||
|
||||
-- calling will attempt to add a new input
|
||||
return setmetatable(inputs,{__call=function(self,...) return self.add(...) end})
|
||||
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"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": {}
|
||||
}
|
||||
@@ -1,246 +0,0 @@
|
||||
--- Adds a organiser for left gui elements which will automatically 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 handled 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.register(global,function(tbl) global = tbl end)
|
||||
|
||||
-- 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 visibility 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 default 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 visibility 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
|
||||
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 _,left_frame in pairs(frames) do
|
||||
if left_frame then left_frame:first_open(player) end
|
||||
end
|
||||
end
|
||||
else
|
||||
local frames = Gui.data.left or {}
|
||||
if frame then frames = {[frame]=frames[frame]} or {} end
|
||||
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 _,left_frame in pairs(thread.data.frames) do
|
||||
if left_frame then left_frame: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 _,next_player in pairs(players) do _left:open(next_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 next_player = table.remove(thread.data.players,1)
|
||||
_left:open(next_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 _,next_player in pairs(players) do _left:close(next_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 next_player = table.remove(thread.data.players,1)
|
||||
_left:close(next_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)
|
||||
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)
|
||||
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)
|
||||
player = Game.get_player(player)
|
||||
local left_flow = mod_gui.get_frame_flow(player)
|
||||
local frame
|
||||
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 visibility 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)
|
||||
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_frame = 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_frame.style.visible ~= true then
|
||||
left_frame.style.visible = true
|
||||
left_flow['gui-left-hide'].style.visible = true
|
||||
else
|
||||
left_frame.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_frame.style.visible
|
||||
end
|
||||
|
||||
Event.add(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_frame = Gui.data.left[name]
|
||||
if left_frame then
|
||||
done[name] = true
|
||||
left_frame:first_open(player)
|
||||
end
|
||||
end
|
||||
for name,left_frame in pairs(frames) do
|
||||
if not done[name] then left_frame:first_open(player) end
|
||||
end
|
||||
end)
|
||||
|
||||
Event.add(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})
|
||||
@@ -1,13 +0,0 @@
|
||||
return {
|
||||
'server-info',
|
||||
'readme',
|
||||
'science',
|
||||
'rockets',
|
||||
'player-list',
|
||||
'tasklist',
|
||||
'warp-list',
|
||||
'polls',
|
||||
'announcements',
|
||||
'admin-commands',
|
||||
'game-settings'
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
{
|
||||
"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": {}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
[ExpGamingCore_Gui]
|
||||
unauthorized=401 - Unbefugt: Du hast keinen Zugriff auf diese Befehle!
|
||||
cant-open=Du kannst dieses Menü nicht öffnen, Grund: __1__
|
||||
cant-open-no-reason=Du kannst dieses Menü gerade nicht öffnen.
|
||||
@@ -1,4 +0,0 @@
|
||||
[ExpGamingCore_Gui]
|
||||
unauthorized=401 - Unauthorized: Access is denied due to invalid credentials
|
||||
cant-open=You can't open this panel right now, reason: __1__
|
||||
cant-open-no-reason=You can't open this panel right now
|
||||
@@ -1,4 +0,0 @@
|
||||
[ExpGamingCore_Gui]
|
||||
unauthorized=401 - Unauthorized: Access is denied due to invalid credentials
|
||||
cant-open=You can not open this panel right now, reason: __1__
|
||||
cant-open-no-reason=You can not open this panel right now
|
||||
@@ -1,4 +0,0 @@
|
||||
[ExpGamingCore_Gui]
|
||||
unauthorized=401 - Onbevoegd: toegang wordt geweigerd vanwege ongeldige inloggegevens
|
||||
cant-open=Je kan dit momenteel niet openen. Reden: __1__
|
||||
cant-open-no-reason=Je kan dit momenteel niet openen.
|
||||
@@ -1,4 +0,0 @@
|
||||
[ExpGamingCore_Gui]
|
||||
unauthorized=401 -Otillåten: Tillgång nekas på grund av otillräcklig säkerhetsprövning.
|
||||
cant-open=Du kan inte öppna den här panelen just nu, orsak: __1__
|
||||
cant-open-no-reason=Du kan inte öppna den här panelen just nu
|
||||
@@ -1,130 +0,0 @@
|
||||
--- 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 is a submodule of ExpGamingCore.Gui but for ldoc reasons it is under its own module
|
||||
-- @function _comment
|
||||
|
||||
local Game = require('FactorioStdLib.Game')
|
||||
local mod_gui = require('mod-gui')
|
||||
local Gui = require('ExpGamingCore.Gui')
|
||||
local Server -- loaded on_init
|
||||
|
||||
local popup = {}
|
||||
popup._prototype = {}
|
||||
|
||||
--- Used to add a popup gui style
|
||||
-- @usage Gui.left.add{name='foo',caption='Foo',draw=function}
|
||||
-- @usage return_value(data,player) -- opens popup for one player use popup.open to open for more than one player
|
||||
-- @param obj this is what will be made, needs a name and a draw function(root_frame,data)
|
||||
-- @return the object that is made, calling the returned value will open the popup for that player
|
||||
function popup.add(obj)
|
||||
if not is_type(obj,'table') then return end
|
||||
if not is_type(obj.name,'string') then return end
|
||||
verbose('Created Popup Gui: '..obj.name)
|
||||
setmetatable(obj,{__index=popup._prototype,__call=function(self,data,player) local players = player and {player} or nil return popup.open(self.name,data,players) end})
|
||||
local name = obj.name; obj.name = nil
|
||||
Gui.data('popup',name,obj)
|
||||
obj.name = name
|
||||
return obj
|
||||
end
|
||||
|
||||
-- this is used by the script to find the popup flow
|
||||
function popup.flow(player)
|
||||
player = Game.get_player(player)
|
||||
if not player then error('Invalid Player',2) end
|
||||
local flow = mod_gui.get_frame_flow(player).popups
|
||||
if not flow then flow = mod_gui.get_frame_flow(player).add{name='popups',type='flow',direction='vertical'} flow.style.visible=false end
|
||||
return flow
|
||||
end
|
||||
|
||||
--- Use to open a popup for these players
|
||||
-- @usage Gui.popup.open('ban',nil,{player=1,reason='foo'})
|
||||
-- @tparam string style this is the name you gave to the popup when added
|
||||
-- @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.data.popup[style]
|
||||
players = players or game.connected_players
|
||||
data = data or {}
|
||||
if not _popup then return end
|
||||
if not Server or not Server._thread then
|
||||
for _,player in pairs(players) do
|
||||
if _popup.left then _popup.left:close(player) end
|
||||
local flow = popup.flow(player)
|
||||
flow.style.visible=true
|
||||
local _frame = flow.add{
|
||||
type='frame',
|
||||
direction='horizontal',
|
||||
style=mod_gui.frame_style
|
||||
}
|
||||
local frame = _frame.add{
|
||||
type='frame',
|
||||
name='inner_frame',
|
||||
direction='vertical',
|
||||
style='image_frame'
|
||||
}
|
||||
_popup.close(_frame)
|
||||
if is_type(_popup.draw,'function') then
|
||||
local success, err = pcall(_popup.draw,_popup,frame,data)
|
||||
if not success then error(err) end
|
||||
else error('No Draw On Popup '.._popup.name) end
|
||||
end
|
||||
else
|
||||
Server.new_thread{
|
||||
data={players=players,popup=_popup,data=data}
|
||||
}:on_event('tick',function(self)
|
||||
if #self.data.players == 0 then self:close() return end
|
||||
local player = table.remove(self.data.players,1)
|
||||
if self.data.popup.left then self.data.popup.left:close(player) end
|
||||
local flow = popup.flow(player)
|
||||
flow.style.visible=true
|
||||
local _frame = flow.add{
|
||||
type='frame',
|
||||
direction='horizontal',
|
||||
style=mod_gui.frame_style
|
||||
}
|
||||
local frame = _frame.add{
|
||||
type='frame',
|
||||
name='inner_frame',
|
||||
direction='vertical',
|
||||
style='image_frame'
|
||||
}
|
||||
self.data.popup.close(_frame)
|
||||
if is_type(self.data.popup.draw,'function') then
|
||||
local success, err = pcall(self.data.popup.draw,self.data.popup,frame,self.data.data)
|
||||
if not success then error(err) end
|
||||
else error('No Draw On Popup '..self.data.popup.name) end
|
||||
end):open()
|
||||
end
|
||||
end
|
||||
|
||||
function popup._prototype:add_left(obj)
|
||||
if not Gui.left then return end
|
||||
obj.name = obj.name or self.name
|
||||
self.left = Gui.left(obj)
|
||||
end
|
||||
|
||||
function popup.on_init()
|
||||
if loaded_modules['ExpGamingCore.Server'] then Server = require('ExpGamingCore.Server') end
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
Event.add(defines.events.on_player_joined_game,popup.flow)
|
||||
|
||||
-- calling will attempt to add a new popup style
|
||||
return setmetatable(popup,{__call=function(self,...) return self.add(...) end})
|
||||
@@ -1,24 +0,0 @@
|
||||
{
|
||||
"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": {}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
{
|
||||
"name": "ExpGamingCore.Gui",
|
||||
"version": "4.0.0",
|
||||
"description": "Adds a objective version to custom guis.",
|
||||
"location": "FSM_ARCHIVE",
|
||||
"keywords": [
|
||||
"Library",
|
||||
"Lib",
|
||||
"ExpGaming",
|
||||
"Core",
|
||||
"Gui",
|
||||
"ExpGui"
|
||||
],
|
||||
"dependencies": {
|
||||
"ExpGamingLib": "^4.0.0",
|
||||
"FactorioStdLib.Table": "^0.8.0",
|
||||
"FactorioStdLib.Color": "^0.8.0",
|
||||
"FactorioStdLib.Game": "^0.8.0",
|
||||
"ExpGamingCore.Server": "?^4.0.0"
|
||||
},
|
||||
"collection": "ExpGamingCore@4.0.0",
|
||||
"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,40 +0,0 @@
|
||||
--- This file will be loaded when ExpGamingCore.Server is present
|
||||
-- @function _comment
|
||||
|
||||
local Game = require('FactorioStdLib.Game')
|
||||
local Server = require('ExpGamingCore.Server')
|
||||
|
||||
Server.add_module_to_interface('ExpGui','ExpGamingCore.Gui')
|
||||
|
||||
--- Adds a server thread that allows the camera follows to be toggled off and on
|
||||
return function()
|
||||
Server.new_thread{
|
||||
name='camera-follow',
|
||||
data={cams={},cam_index=1,players={}}
|
||||
}:on_event('tick',function(self)
|
||||
local update = 4
|
||||
if self.data.cam_index >= #self.data.cams then self.data.cam_index = 1 end
|
||||
if update > #self.data.cams then update = #self.data.cams end
|
||||
for cam_offset = 0,update do
|
||||
local _cam = self.data.cams[self.data.cam_index+cam_offset]
|
||||
if not _cam then break 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
|
||||
end
|
||||
end
|
||||
self.data.cam_index = self.data.cam_index+update
|
||||
end):on_event(defines.events.on_player_respawned,function(self,event)
|
||||
if self.data.players[event.player_index] then
|
||||
local remove = {}
|
||||
local player = Game.get_player(event)
|
||||
for index,cam in pairs(self.data.players[event.player_index]) do
|
||||
if cam.valid then table.insert(self.data.cams,{cam=cam,entity=player.character,surface=player.surface})
|
||||
else table.insert(remove,index) end
|
||||
end
|
||||
for n,index in pairs(remove) do
|
||||
table.remove(self.data.players[event.player_index],index-n+1)
|
||||
end
|
||||
end
|
||||
end):open()
|
||||
end
|
||||
@@ -1,187 +0,0 @@
|
||||
--- 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 Game = require('FactorioStdLib.Game')
|
||||
local Gui = Gui -- this is to force gui to remain in the ENV
|
||||
local mod_gui = require("mod-gui")
|
||||
|
||||
local gui_test_close = Gui.inputs{
|
||||
name='gui-test-close',
|
||||
type='button',
|
||||
caption='Close Test Gui'
|
||||
}:on_event('click',function(event) event.element.parent.destroy() end)
|
||||
|
||||
local caption_test = Gui.inputs{
|
||||
name='text-button',
|
||||
type='button',
|
||||
caption='Test'
|
||||
}:on_event('click',function(event) game.print('test') end)
|
||||
|
||||
local sprite_test = Gui.inputs{
|
||||
name='sprite-button',
|
||||
type='button',
|
||||
sprite='item/lab'
|
||||
}:on_event('click',function(event) game.print('test') end)
|
||||
|
||||
local input_test = Gui.inputs.add_button('test-inputs','Try RMB','alt,ctrl,shift and mouse buttons',{
|
||||
{
|
||||
function(player,mouse,keys) return mouse == defines.mouse_button_type.left and keys.alt end,
|
||||
function(player,element) player_return('Left: Alt',nil,player) end
|
||||
},
|
||||
{
|
||||
function(player,mouse,keys) return mouse == defines.mouse_button_type.left and keys.ctrl end,
|
||||
function(player,element) player_return('Left: Ctrl',nil,player) end
|
||||
},
|
||||
{
|
||||
function(player,mouse,keys) return mouse == defines.mouse_button_type.left and keys.shift end,
|
||||
function(player,element) player_return('Left: Shift',nil,player) end
|
||||
},
|
||||
{
|
||||
function(player,mouse,keys) return mouse == defines.mouse_button_type.right and keys.alt end,
|
||||
function(player,element) player_return('Right: Alt',nil,player) end
|
||||
},
|
||||
{
|
||||
function(player,mouse,keys) return mouse == defines.mouse_button_type.right and keys.ctrl end,
|
||||
function(player,element) player_return('Right: Ctrl',nil,player) end
|
||||
},
|
||||
{
|
||||
function(player,mouse,keys) return mouse == defines.mouse_button_type.right and keys.shift end,
|
||||
function(player,element) player_return('Right: Shift',nil,player) end
|
||||
}
|
||||
}):on_event('error',function(err) game.print('this is error handling') end)
|
||||
|
||||
local elem_test = Gui.inputs.add_elem_button('test-elem','item','Testing Elems',function(player,element,elem)
|
||||
player_return(elem.type..' '..elem.value,nil,player)
|
||||
end)
|
||||
|
||||
local check_test = Gui.inputs.add_checkbox('test-check',false,'Cheat Mode',function(player,parent)
|
||||
return game.players[parent.player_index].cheat_mode
|
||||
end,function(player,element)
|
||||
player.cheat_mode = true
|
||||
end,function(player,element)
|
||||
player.cheat_mode = false
|
||||
end)
|
||||
|
||||
local radio_test = Gui.inputs.add_checkbox('test-radio',true,'Kill Self',function(player,parent)
|
||||
return false
|
||||
end,function(player,element)
|
||||
if player.character then player.character.die() end
|
||||
Gui.inputs.reset_radio(element.parent['test-radio-reset'])
|
||||
end)
|
||||
|
||||
local radio_test_reset = Gui.inputs.add_checkbox('test-radio-reset',true,'Reset Kill Self',function(player,parent)
|
||||
return not parent['test-radio'].state
|
||||
end,function(player,element)
|
||||
Gui.inputs.reset_radio(element.parent['test-radio'])
|
||||
end)
|
||||
|
||||
local text_test = Gui.inputs.add_text('test-text',false,'default text',function(player,text,element)
|
||||
player_return(text,nil,player)
|
||||
end)
|
||||
|
||||
local box_test = Gui.inputs.add_text('test-box',true,'default text but a box',function(player,text,element)
|
||||
player_return(text,nil,player)
|
||||
end)
|
||||
|
||||
local slider_test = Gui.inputs.add_slider('test-slider','vertical',0,5,function(player,parent)
|
||||
return player.character_running_speed_modifier
|
||||
end,function(player,value,percent,element)
|
||||
player.character_running_speed_modifier = value
|
||||
player_return('Value In Percent of Max '..math.floor(percent*100)-(math.floor(percent*100)%5),nil,player)
|
||||
end)
|
||||
|
||||
local drop_test = Gui.inputs.add_drop_down('test-drop',table.keys(defines.color),1,function(player,selected,items,element)
|
||||
player.color = defines.color[selected]
|
||||
player.chat_color = defines.color[selected]
|
||||
end)
|
||||
|
||||
--- 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_test_close(frame)
|
||||
caption_test(frame)
|
||||
sprite_test(frame)
|
||||
input_test(frame)
|
||||
elem_test(frame)
|
||||
check_test(frame)
|
||||
radio_test(frame)
|
||||
radio_test_reset(frame)
|
||||
text_test(frame)
|
||||
box_test(frame)
|
||||
slider_test(frame)
|
||||
drop_test(frame)
|
||||
end
|
||||
|
||||
Gui.toolbar.add('open-gui-test','Open Test Gui','Opens the test gui with every input',test_gui)
|
||||
|
||||
-- testing the center gui
|
||||
Gui.center{
|
||||
name='test-center',
|
||||
caption='Gui Center',
|
||||
tooltip='Just a gui test'
|
||||
}:add_tab('tab-1','Tab 1','Just a tab',function(frame)
|
||||
frame.add{type='label',caption='Test'}
|
||||
end):add_tab('tab-2','Tab 2','Just a tab',function(frame)
|
||||
for i = 1,100 do
|
||||
frame.add{type='label',caption='Test 2'}
|
||||
end
|
||||
end)
|
||||
|
||||
-- testing the left gui
|
||||
Gui.left{
|
||||
name='test-left',
|
||||
caption='Gui Left',
|
||||
tooltip='just testing',
|
||||
draw=function(self,frame)
|
||||
for _,player in pairs(game.connected_players) do
|
||||
frame.add{type='label',caption=player.name}
|
||||
end
|
||||
end,
|
||||
can_open=function(player) return player.index == 1 end
|
||||
}
|
||||
|
||||
local text_popup = Gui.inputs.add_text('test-popup-text',true,'Message To Send',function(player,text,element)
|
||||
element.text = text
|
||||
end)
|
||||
local send_popup = Gui.inputs{
|
||||
type='button',
|
||||
name='test-popup-send',
|
||||
caption='Send Message'
|
||||
}:on_event('click',function(event)
|
||||
local player = Game.get_player(event)
|
||||
local message = event.element.parent['test-popup-text'].text
|
||||
Gui.popup.open('test-popup',{message=message,player=player.name})
|
||||
end)
|
||||
Gui.popup{
|
||||
name='test-popup',
|
||||
caption='Gui Popup',
|
||||
draw=function(self,frame,data)
|
||||
frame.add{type='label',caption='Opened by: '..data.player}
|
||||
frame.add{type='label',caption='Message: '..data.message}
|
||||
end
|
||||
}:add_left{
|
||||
caption='Gui Left w/ Popup',
|
||||
tooltip='Send a message',
|
||||
draw=function(self,frame)
|
||||
text_popup:draw(frame)
|
||||
send_popup:draw(frame)
|
||||
end
|
||||
}
|
||||
|
||||
return test_gui
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
--- 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 is a submodule of ExpGamingCore.Gui but for ldoc reasons it is under its own module
|
||||
-- @function _comment
|
||||
|
||||
local Game = require('FactorioStdLib.Game')
|
||||
local mod_gui = require('mod-gui')
|
||||
local Gui = require('ExpGamingCore.Gui')
|
||||
local order_config = require(module_path..'/order_config')
|
||||
local Role -- this is optional and is handled by it being present, it is loaded on init
|
||||
|
||||
local toolbar = {}
|
||||
|
||||
toolbar.hide = Gui.inputs{
|
||||
name='gui-toolbar-hide',
|
||||
type='button',
|
||||
caption='<'
|
||||
}:on_event('click',function(event)
|
||||
if event.element.caption == '<' then
|
||||
event.element.caption = '>'
|
||||
for _,child in pairs(event.element.parent.children) do
|
||||
if child.name ~= event.element.name then child.style.visible = false end
|
||||
end
|
||||
else
|
||||
event.element.caption = '<'
|
||||
for _,child in pairs(event.element.parent.children) do
|
||||
if child.name ~= event.element.name then child.style.visible = true end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
--- Add a button to the toolbar, ranks need to be allowed to use these buttons if ranks is preset
|
||||
-- @usage toolbar.add('foo','Foo','Test',function() game.print('test') end)
|
||||
-- @tparam string name the name of the button
|
||||
-- @tparam string caption can be a sprite path or text to show
|
||||
-- @tparam string tooltip the help to show for the button
|
||||
-- @tparam function callback the function which is called on_click
|
||||
-- @treturn table the button object that was made, calling the returned value will draw the toolbar button added
|
||||
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.data('toolbar',name,button)
|
||||
return button
|
||||
end
|
||||
|
||||
--- Draws the toolbar for a certain player
|
||||
-- @usage toolbar.draw(1)
|
||||
-- @param player the player to draw the tool bar of
|
||||
function toolbar.draw(player)
|
||||
player = Game.get_player(player)
|
||||
if not player then return end
|
||||
local toolbar_frame = mod_gui.get_button_flow(player)
|
||||
toolbar_frame.clear()
|
||||
if not Gui.data.toolbar then return end
|
||||
toolbar.hide(toolbar_frame).style.maximal_width = 15
|
||||
local done = {}
|
||||
for _,name in pairs(order_config) do
|
||||
local button = Gui.data.toolbar[name]
|
||||
if button then
|
||||
done[name] = true
|
||||
if is_type(Role,'table') then
|
||||
if Role.allowed(player,name) then
|
||||
button(toolbar_frame)
|
||||
end
|
||||
else button(toolbar_frame) end
|
||||
end
|
||||
end
|
||||
for name,button in pairs(Gui.data.toolbar) do
|
||||
if not done[name] then
|
||||
if is_type(Role,'table') then
|
||||
if Role.allowed(player,name) then
|
||||
button(toolbar_frame)
|
||||
end
|
||||
else button(toolbar_frame) end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function toolbar.on_init()
|
||||
if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') end
|
||||
end
|
||||
|
||||
Event.add({defines.events.on_role_change,defines.events.on_player_joined_game},toolbar.draw)
|
||||
-- calling with only a player will draw the toolbar for that player, more params will attempt to add a button
|
||||
return setmetatable(toolbar,{__call=function(self,player,extra,...) if extra then return self.add(player,extra,...) else self.draw(player) end end})
|
||||
@@ -1,13 +0,0 @@
|
||||
return {
|
||||
'server-info',
|
||||
'readme',
|
||||
'science',
|
||||
'rockets',
|
||||
'player-list',
|
||||
'tasklist',
|
||||
'warp-list',
|
||||
'polls',
|
||||
'announcements',
|
||||
'admin-commands',
|
||||
'game-settings'
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"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": {}
|
||||
}
|
||||
Reference in New Issue
Block a user