mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 04:21:41 +09:00
Spell Check and Lua Check
This commit is contained in:
@@ -15,11 +15,11 @@ 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, fraw is opt and is function(root_frame)
|
||||
-- @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
|
||||
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 = {}
|
||||
@@ -30,32 +30,32 @@ function center.add(obj)
|
||||
end
|
||||
|
||||
--- Used to get the center frame of the player, used mainly in script
|
||||
-- @usage Gui.center.get_flow(player) -- returns gui emelemt
|
||||
-- @param player a player indifier to get the flow for
|
||||
-- @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)
|
||||
local player = Game.get_player(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 indifier to get the flow for
|
||||
-- @tparam string center the name of the center frame to open
|
||||
-- @treturn boelon based on if it successed or not
|
||||
function center.open(player,center,...)
|
||||
local player = Game.get_player(player)
|
||||
-- @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] then return false end
|
||||
local self = Gui.data.center[center]
|
||||
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 pice of middle ware for the open event
|
||||
-- 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
|
||||
@@ -66,37 +66,37 @@ end
|
||||
|
||||
--- Used to open a center frame for a player
|
||||
-- @usage Gui.center.open_tab(player,'readme','rules') -- return true
|
||||
-- @param player a player indifier to get the flow for
|
||||
-- @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 boelon based on if it successed or not
|
||||
function center.open_tab(player,center,tab)
|
||||
local player = Game.get_player(player)
|
||||
-- @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) then return false end
|
||||
local name = center..'_'..tab
|
||||
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].tab_bar.tab_bar_scroll.tab_bar_scroll_flow[name],
|
||||
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 indifier to get the flow for
|
||||
-- @param player a player identifier to get the flow for
|
||||
function center.clear(player)
|
||||
local player = Game.get_player(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 overriden when the gui is defined, simply call draw on the frame you create
|
||||
-- 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,...)
|
||||
local player = Game.get_player(player)
|
||||
local draw = draw or function(...) center._draw(self,...) end
|
||||
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{
|
||||
@@ -110,8 +110,8 @@ function center._prototype:open(player,draw,...)
|
||||
draw(center_frame,...)
|
||||
end
|
||||
|
||||
-- this is the default draw function if one is not provided, can be overriden
|
||||
-- not recomented for direct use see Gui.center.open
|
||||
-- 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{
|
||||
@@ -123,8 +123,8 @@ function center._prototype:draw(frame)
|
||||
tab_bar.style.width = 510
|
||||
tab_bar.style.height = 65
|
||||
local tab_bar_scroll = tab_bar.add{
|
||||
type='scroll-pane',
|
||||
name='tab_bar_scroll',
|
||||
type='scroll-pane',
|
||||
name='tab_bar_scroll',
|
||||
horizontal_scroll_policy='auto-and-reserve-space',
|
||||
vertical_scroll_policy='never'
|
||||
}
|
||||
@@ -147,7 +147,7 @@ function center._prototype:draw(frame)
|
||||
tab.style.height = 305
|
||||
local tab_scroll = tab.add{
|
||||
type ='scroll-pane',
|
||||
name='tab_scroll',
|
||||
name='tab_scroll',
|
||||
horizontal_scroll_policy='never',
|
||||
vertical_scroll_policy='auto'
|
||||
}
|
||||
@@ -155,8 +155,8 @@ function center._prototype:draw(frame)
|
||||
tab_scroll.style.vertically_stretchable = true
|
||||
tab_scroll.style.width = 500
|
||||
local tab_scroll_flow = tab_scroll.add{
|
||||
type='flow',
|
||||
name='tab_scroll_flow',
|
||||
type='flow',
|
||||
name='tab_scroll_flow',
|
||||
direction='vertical'
|
||||
}
|
||||
tab_scroll_flow.style.width = 480
|
||||
@@ -171,7 +171,7 @@ function center._prototype:draw(frame)
|
||||
frame.parent.add{type='frame',name='temp'}.destroy()--recenter the GUI
|
||||
end
|
||||
|
||||
--- If deafult draw is used then you can add tabs to the gui with this function
|
||||
--- 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
|
||||
@@ -214,7 +214,7 @@ end)
|
||||
|
||||
script.on_event(defines.events.on_player_respawned,center.clear)
|
||||
|
||||
function center:on_init()
|
||||
function center.on_init()
|
||||
if loaded_modules['ExpGamingCore.Role'] then script.on_event(defines.events.on_role_change,center.clear) end
|
||||
end
|
||||
-- calling will attempt to add a new gui
|
||||
|
||||
@@ -16,7 +16,7 @@ local global = global()
|
||||
-- @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
|
||||
-- @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
|
||||
@@ -31,7 +31,7 @@ Gui.data = setmetatable({},{
|
||||
-- @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 progressbar
|
||||
-- @return the line that was made type is progress bar
|
||||
function Gui.bar(frame,width)
|
||||
local line = frame.add{
|
||||
type='progressbar',
|
||||
@@ -44,11 +44,11 @@ function Gui.bar(frame,width)
|
||||
return line
|
||||
end
|
||||
|
||||
--- Adds a lable that is centered
|
||||
-- @usage Gui.centered_label(frane, 'Hello, world!')
|
||||
--- 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 lable will have
|
||||
function Gui.centered_label(frane, string)
|
||||
-- @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'
|
||||
@@ -62,13 +62,13 @@ function Gui.centered_label(frane, string)
|
||||
return label
|
||||
end
|
||||
|
||||
--- Used to set the index of a drop down to a certian item
|
||||
--- 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 dropdown and dropdown.valid and dropdown.items and _item then else return end
|
||||
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
|
||||
@@ -88,7 +88,7 @@ end
|
||||
-- @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
|
||||
--- 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
|
||||
@@ -103,7 +103,7 @@ function Gui.cam_link(data)
|
||||
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.zomm = data.zoom
|
||||
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
|
||||
@@ -147,7 +147,7 @@ script.on_event('on_tick', function(event)
|
||||
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]
|
||||
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)
|
||||
@@ -162,6 +162,7 @@ script.on_event('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
|
||||
@@ -173,14 +174,14 @@ script.on_event('on_player_respawned',function(event)
|
||||
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}))
|
||||
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()
|
||||
function Gui.on_post()
|
||||
Gui.test = require(module_path..'/src/test',{Gui=Gui})
|
||||
end
|
||||
|
||||
|
||||
@@ -78,8 +78,8 @@ function inputs._prototype:draw(root)
|
||||
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
|
||||
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
|
||||
@@ -87,25 +87,25 @@ function inputs._prototype:draw(root)
|
||||
end
|
||||
end
|
||||
|
||||
--- Add a new input, this is the same as doing frame.add{} but returns a diffrent object
|
||||
--- 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 calue will draw the button
|
||||
-- @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' or
|
||||
type == 'sprite-button' or
|
||||
type == 'choose-elem-button' or
|
||||
type == 'checkbox' or
|
||||
type == 'radiobutton' or
|
||||
type == 'textfield' or
|
||||
type == 'text-box' or
|
||||
type == 'slider' or
|
||||
type == 'drop-down'
|
||||
then else return end
|
||||
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)
|
||||
@@ -139,23 +139,23 @@ end
|
||||
script.on_event(inputs.events,inputs._event_handler)
|
||||
inputs.events.error = {}
|
||||
|
||||
-- the folwing functions are just to make inputs easier but if what you want is not include use inputs.add(obj)
|
||||
-- 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 exaplmes at bottom
|
||||
-- @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 button = inputs.add{
|
||||
local rtn_button = inputs.add{
|
||||
type='button',
|
||||
name=name,
|
||||
caption=display,
|
||||
tooltip=tooltip
|
||||
}
|
||||
button.data._callbacks = callbacks
|
||||
button:on_event('click',function(event)
|
||||
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
|
||||
@@ -166,19 +166,19 @@ function inputs.add_button(name,display,tooltip,callbacks)
|
||||
local mouse = event.button
|
||||
local keys = {alt=event.alt,ctrl=event.control,shift=event.shift}
|
||||
local element = event.element
|
||||
local callbacks = button.data._callbacks
|
||||
if is_type(callbacks,'function') then callbacks = {{function(...) return true end,callbacks}} end
|
||||
for _,data in pairs(callbacks) do
|
||||
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
|
||||
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
|
||||
end)
|
||||
return button
|
||||
return rtn_button
|
||||
end
|
||||
|
||||
--- Used to define a choose-elem-button callback only on elem_changed
|
||||
@@ -221,20 +221,19 @@ end
|
||||
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 checkbox = inputs.add{
|
||||
local rtn_checkbox = inputs.add{
|
||||
type=type,
|
||||
name=name,
|
||||
caption=display,
|
||||
state=state
|
||||
}
|
||||
if is_type(default,'function') then checkbox.data._state = default end
|
||||
checkbox.data._true = callback_true
|
||||
checkbox.data._false = callback_false
|
||||
checkbox:on_event('state',function(event)
|
||||
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)
|
||||
local state = event.element.state
|
||||
if state then
|
||||
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
|
||||
@@ -246,10 +245,10 @@ function inputs.add_checkbox(name,radio,display,default,callback_true,callback_f
|
||||
else error('Invalid Callback') end
|
||||
end
|
||||
end)
|
||||
return checkbox
|
||||
return rtn_checkbox
|
||||
end
|
||||
|
||||
--- Used to reset the state of radio buttons, recomened to be called on_state_change to reset any radio buttons it is ment to work with.
|
||||
--- 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)
|
||||
@@ -287,23 +286,23 @@ end
|
||||
-- @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 textbox = inputs.add{
|
||||
local rtn_textbox = inputs.add{
|
||||
type=type,
|
||||
name=name,
|
||||
text=text
|
||||
}
|
||||
textbox.data._callback = callback
|
||||
textbox:on_event('text',function(event)
|
||||
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 callback = textbox.data._callback
|
||||
if is_type(callback,'function') then
|
||||
local success, err = pcall(callback,player,element.text,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 textbox
|
||||
return rtn_textbox
|
||||
end
|
||||
|
||||
--- Used to define a slider callback only on value_changed
|
||||
@@ -348,28 +347,28 @@ end
|
||||
-- @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 drop_down = inputs.add{
|
||||
local rtn_dropdown = inputs.add{
|
||||
type='drop-down',
|
||||
name=name,
|
||||
items=items,
|
||||
selected_index=index
|
||||
}
|
||||
drop_down.data._items = items
|
||||
drop_down.data._index = index
|
||||
drop_down.data._callback = callback
|
||||
drop_down:on_event('selection',function(event)
|
||||
local drop_down = Gui.data['inputs_'..event.element.type][event.element.name]
|
||||
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 items = element.items
|
||||
local selected = items[element.selected_index]
|
||||
local callback = drop_down.data._callback
|
||||
if is_type(callback,'function') then
|
||||
local success, err = pcall(callback,player,selected,items,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 drop_down
|
||||
return rtn_dropdown
|
||||
end
|
||||
|
||||
-- calling will attempt to add a new input
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
--- Adds a organiser for left gui ellements which will automaticaly update there information and have open requirements
|
||||
--- 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
|
||||
@@ -12,7 +12,7 @@ local Color = require('FactorioStdLib.Color')
|
||||
local mod_gui = require('mod-gui')
|
||||
local Gui = require('ExpGamingCore.Gui')
|
||||
local order_config = require(module_path..'/order_config')
|
||||
local Role -- this is optional and is hanndled by it being present, it is loaded on init
|
||||
local Role -- this is optional and is handled by it being present, it is loaded on init
|
||||
|
||||
local left = {}
|
||||
left._prototype = {}
|
||||
@@ -35,11 +35,11 @@ function left.override_open(state)
|
||||
end
|
||||
--- Used to add a left gui frame
|
||||
-- @usage Gui.left.add{name='foo',caption='Foo',tooltip='just testing',open_on_join=true,can_open=function,draw=function}
|
||||
-- @usage return_value(player) -- toggles visiblity for that player, if no player then updates for all players
|
||||
-- @param obj this is what will be made, needs a name and a draw function(root_frame), open_on_join can be used to set the deaful state true/false, can_open is a test to block it from opening but is not needed
|
||||
-- @return the object that is made, calling the returned value with out a param will update the gui, else will toggle visiblity for that player
|
||||
-- @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,'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})
|
||||
@@ -54,18 +54,18 @@ end
|
||||
-- @param[opt] players the player to update for, if not given all players are updated, can be one player
|
||||
function left.update(frame,players)
|
||||
if not Server or not Server._thread then
|
||||
local players = is_type(players,'table') and #players > 0 and {unpack(players)} or is_type(players,'table') and {players} or Game.get_player(players) and {Game.get_player(players)} or game.connected_players
|
||||
players = is_type(players,'table') and #players > 0 and {unpack(players)} or is_type(players,'table') and {players} or Game.get_player(players) and {Game.get_player(players)} or game.connected_players
|
||||
for _,player in pairs(players) do
|
||||
local frames = Gui.data.left or {}
|
||||
if frame then frames = {[frame]=frames[frame]} or {} end
|
||||
for name,left in pairs(frames) do
|
||||
if _left then left:first_open(player) end
|
||||
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
|
||||
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
|
||||
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)
|
||||
@@ -74,8 +74,8 @@ function left.update(frame,players)
|
||||
Server.new_thread{
|
||||
data={player=player,frames=thread.data.frames}
|
||||
}:on_event('resolve',function(thread)
|
||||
for name,left in pairs(thread.data.frames) do
|
||||
if left then left:first_open(thread.data.player) end
|
||||
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()
|
||||
@@ -91,14 +91,14 @@ function left.open(left_name,player)
|
||||
local _left = Gui.data.left[left_name]
|
||||
if not _left then return end
|
||||
if not Server or not Server._thread then
|
||||
for _,player in pairs(players) do _left:open(player) end
|
||||
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 player = table.remove(thread.data.players,1)
|
||||
_left:open(player)
|
||||
local next_player = table.remove(thread.data.players,1)
|
||||
_left:open(next_player)
|
||||
end):open()
|
||||
end
|
||||
end
|
||||
@@ -112,14 +112,14 @@ function left.close(left_name,player)
|
||||
local _left = Gui.data.left[left_name]
|
||||
if not _left then return end
|
||||
if not Server or not Server._thread or player then
|
||||
for _,player in pairs(players) do _left:close(player) end
|
||||
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 player = table.remove(thread.data.players,1)
|
||||
_left:close(player)
|
||||
local next_player = table.remove(thread.data.players,1)
|
||||
_left:close(next_player)
|
||||
end):open()
|
||||
end
|
||||
end
|
||||
@@ -129,7 +129,7 @@ end
|
||||
-- @usage left:open(player)
|
||||
-- @tparam luaPlayer player the player to open the gui for
|
||||
function left._prototype:open(player)
|
||||
local player = Game.get_player(player)
|
||||
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
|
||||
@@ -141,7 +141,7 @@ end
|
||||
-- @usage left:open(player)
|
||||
-- @tparam luaPlayer player the player to close the gui for
|
||||
function left._prototype:close(player)
|
||||
local player = Game.get_player(player)
|
||||
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
|
||||
@@ -156,11 +156,11 @@ end
|
||||
-- @tparam LuaPlayer player the player to draw the gui for
|
||||
-- @treturn LuaFrame the frame made/updated
|
||||
function left._prototype:first_open(player)
|
||||
local player = Game.get_player(player)
|
||||
player = Game.get_player(player)
|
||||
local left_flow = mod_gui.get_frame_flow(player)
|
||||
local frame = nil
|
||||
if left_flow[self.name] then
|
||||
frame = left_flow[self.name]
|
||||
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
|
||||
@@ -172,15 +172,15 @@ function left._prototype:first_open(player)
|
||||
return frame
|
||||
end
|
||||
|
||||
--- Toggles the visiblity of the gui based on some conditions
|
||||
--- 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)
|
||||
local player = Game.get_player(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 = left_flow[self.name]
|
||||
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)
|
||||
@@ -198,18 +198,18 @@ function left._prototype:toggle(player)
|
||||
else open = {'ExpGamingCore_Gui.unauthorized'} end
|
||||
else open = true end
|
||||
end
|
||||
if open == true and left.style.visible ~= true then
|
||||
left.style.visible = true
|
||||
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.style.visible = false
|
||||
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.style.visible
|
||||
return left_frame.style.visible
|
||||
end
|
||||
|
||||
script.on_event(defines.events.on_player_joined_game,function(event)
|
||||
@@ -220,14 +220,14 @@ script.on_event(defines.events.on_player_joined_game,function(event)
|
||||
if not left_flow['gui-left-hide'] then left.hide(left_flow).style.maximal_width=15 end
|
||||
local done = {}
|
||||
for _,name in pairs(order_config) do
|
||||
local left = Gui.data.left[name]
|
||||
if left then
|
||||
local left_frame = Gui.data.left[name]
|
||||
if left_frame then
|
||||
done[name] = true
|
||||
left:first_open(player)
|
||||
left_frame:first_open(player)
|
||||
end
|
||||
end
|
||||
for name,left in pairs(frames) do
|
||||
if not done[name] then left:first_open(player) end
|
||||
for name,left_frame in pairs(frames) do
|
||||
if not done[name] then left_frame:first_open(player) end
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -237,7 +237,7 @@ script.on_event(defines.events.on_tick,function(event)
|
||||
end
|
||||
end)
|
||||
|
||||
function left:on_init()
|
||||
function left.on_init()
|
||||
if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') end
|
||||
end
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ end
|
||||
|
||||
-- this is used by the script to find the popup flow
|
||||
function popup.flow(player)
|
||||
local player = Game.get_player(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
|
||||
@@ -47,8 +47,8 @@ end
|
||||
-- @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]
|
||||
local players = players or game.connected_players
|
||||
local data = data or {}
|
||||
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
|
||||
@@ -107,11 +107,11 @@ function popup._prototype:add_left(obj)
|
||||
self.left = Gui.left(obj)
|
||||
end
|
||||
|
||||
function popup:on_init()
|
||||
function popup.on_init()
|
||||
if loaded_modules['ExpGamingCore.Server'] then Server = require('ExpGamingCore.Server') end
|
||||
end
|
||||
|
||||
function popup:on_post()
|
||||
function popup.on_post()
|
||||
popup._prototype.close = Gui.inputs.add{
|
||||
type='button',
|
||||
name='popup-close',
|
||||
|
||||
@@ -7,7 +7,7 @@ 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(event)
|
||||
return function()
|
||||
Server.new_thread{
|
||||
name='camera-follow',
|
||||
data={cams={},cam_index=1,players={}}
|
||||
|
||||
@@ -53,30 +53,30 @@ local input_test = Gui.inputs.add_button('test-inputs','Try RMB','alt,ctrl,shift
|
||||
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 handliling') 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
|
||||
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)
|
||||
local radio_test = Gui.inputs.add_checkbox('test-radio',true,'Kill Self',function(player,parent)
|
||||
return false
|
||||
end,function(player,element)
|
||||
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)
|
||||
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)
|
||||
end,function(player,element)
|
||||
Gui.inputs.reset_radio(element.parent['test-radio'])
|
||||
end)
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ local Game = require('FactorioStdLib.Game')
|
||||
local mod_gui = require('mod-gui')
|
||||
local Gui = require('ExpGamingCore.Gui')
|
||||
local order_config = require(module_path..'/order_config')
|
||||
local Role -- this is optional and is hanndled by it being present, it is loaded on init
|
||||
local Role -- this is optional and is handled by it being present, it is loaded on init
|
||||
|
||||
local toolbar = {}
|
||||
|
||||
@@ -52,7 +52,7 @@ end
|
||||
-- @usage toolbar.draw(1)
|
||||
-- @param player the player to draw the tool bar of
|
||||
function toolbar.draw(player)
|
||||
local player = Game.get_player(player)
|
||||
player = Game.get_player(player)
|
||||
if not player then return end
|
||||
local toolbar_frame = mod_gui.get_button_flow(player)
|
||||
toolbar_frame.clear()
|
||||
@@ -81,7 +81,7 @@ function toolbar.draw(player)
|
||||
end
|
||||
end
|
||||
|
||||
function toolbar:on_init()
|
||||
function toolbar.on_init()
|
||||
if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user