mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 12:31:41 +09:00
Added ExpGamingPlayer.playerList
This commit is contained in:
@@ -1,35 +1,39 @@
|
|||||||
--[[
|
--- A full ranking system for factorio.
|
||||||
Explosive Gaming
|
-- @module ExpGamingPlayer.playerList
|
||||||
|
-- @author Cooldude2606
|
||||||
|
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
||||||
|
|
||||||
This file can be used with permission but this and the credit below must remain in the file.
|
local Game = require('FactorioStdLib.Game')
|
||||||
Contact a member of management on our discord to seek permission to use our code.
|
local Gui = require('ExpGamingCore.Gui')
|
||||||
Any changes that you may make to the code are yours but that does not make the script yours.
|
local Admin -- hanndled on load
|
||||||
Discord: https://discord.gg/r6dC2uK
|
|
||||||
]]
|
|
||||||
--Please Only Edit Below This Line-----------------------------------------------------------
|
|
||||||
|
|
||||||
local function _global(reset)
|
local global = global{
|
||||||
global.addons = not reset and global.addons or {}
|
update=0,
|
||||||
global.addons.player_list = not reset and global.addons.player_list or {update=0,delay=10,intervial=54000}
|
delay=10,
|
||||||
return global.addons.player_list
|
intervial=54000
|
||||||
end
|
}
|
||||||
|
|
||||||
local get_player_info = get_player_info or function(player,frame)
|
-- this will be replaced on load if playerInfo module is present
|
||||||
|
local function playerInfo(player,frame)
|
||||||
frame.add{
|
frame.add{
|
||||||
type='label',
|
type='label',
|
||||||
caption={'player-list.no-info-file'}
|
caption={'player-list.no-info-file'}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update()
|
local function getPlayers()
|
||||||
Gui.left.update('player-list')
|
local rtn = {{{r=233,g=63,b=233},'Admin',{}},{{r=255,g=159,b=27},'',{}}}
|
||||||
|
for _,player in pairs(game.connected_players) do
|
||||||
|
if player.admin then table.insert(rtn[2][3],player)
|
||||||
|
else table.insert(rtn[1][3],player) end
|
||||||
|
end
|
||||||
|
return rtn
|
||||||
end
|
end
|
||||||
|
|
||||||
local function queue_update(tick)
|
local function queue_update(tick)
|
||||||
local data = _global()
|
|
||||||
local tick = is_type(tick,'table') and tick.tick or is_type(tick,'number') and tick or game.tick
|
local tick = is_type(tick,'table') and tick.tick or is_type(tick,'number') and tick or game.tick
|
||||||
if tick + data.delay > data.update - data.intervial then
|
if tick + global.delay > global.update - global.intervial then
|
||||||
data.update = tick + data.delay
|
global.update = tick + global.delay
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -57,23 +61,24 @@ Gui.left.add{
|
|||||||
}
|
}
|
||||||
player_list.vertical_scroll_policy = 'auto'
|
player_list.vertical_scroll_policy = 'auto'
|
||||||
player_list.style.maximal_height=195
|
player_list.style.maximal_height=195
|
||||||
for _,rank in pairs(Ranking._ranks()) do
|
local players = getPlayers() -- list of [colour,shortHand,[playerOne,playerTwo]]
|
||||||
for _,player in pairs(rank:get_players(true)) do
|
for _,rank in pairs(players) do
|
||||||
|
for _,player in pairs(rank[3]) do
|
||||||
local flow = player_list.add{type='flow'}
|
local flow = player_list.add{type='flow'}
|
||||||
if rank.short_hand == '' then
|
if rank[2] == '' then
|
||||||
flow.add{
|
flow.add{
|
||||||
type='label',
|
type='label',
|
||||||
name=player.name,
|
name=player.name,
|
||||||
style='caption_label',
|
style='caption_label',
|
||||||
caption={'player-list.format-nil',tick_to_display_format(player.online_time),player.name}
|
caption={'player-list.format-nil',tick_to_display_format(player.online_time),player.name}
|
||||||
}.style.font_color = rank.colour
|
}.style.font_color = rank[1]
|
||||||
else
|
else
|
||||||
flow.add{
|
flow.add{
|
||||||
type='label',
|
type='label',
|
||||||
name=player.name,
|
name=player.name,
|
||||||
style='caption_label',
|
style='caption_label',
|
||||||
caption={'player-list.format',tick_to_display_format(player.online_time),player.name,rank.short_hand}
|
caption={'player-list.format',tick_to_display_format(player.online_time),player.name,rank[2]}
|
||||||
}.style.font_color = rank.colour
|
}.style.font_color = rank[1]
|
||||||
end
|
end
|
||||||
if Admin.report_btn then
|
if Admin.report_btn then
|
||||||
if not rank:allowed('no-report') and player.index ~= frame.player_index then
|
if not rank:allowed('no-report') and player.index ~= frame.player_index then
|
||||||
@@ -88,28 +93,40 @@ Gui.left.add{
|
|||||||
open_on_join=true
|
open_on_join=true
|
||||||
}
|
}
|
||||||
|
|
||||||
Event.register(defines.events.on_tick,function(event)
|
script.on_event(defines.events.on_tick,function(event)
|
||||||
local data = _global()
|
if event.tick > global.update then
|
||||||
if event.tick > data.update then
|
Gui.left.update('player-list')
|
||||||
update()
|
global.update = event.tick + global.intervial
|
||||||
data.update = event.tick + data.intervial
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
Event.register(defines.events.on_gui_click,function(event)
|
script.on_event(defines.events.on_gui_click,function(event)
|
||||||
|
-- lots of checks for it being valid
|
||||||
if event.element and event.element.valid
|
if event.element and event.element.valid
|
||||||
and event.element.parent and event.element.parent.parent and event.element.parent.parent.parent
|
and event.element.parent and event.element.parent.parent and event.element.parent.parent.parent
|
||||||
and event.element.parent.parent.parent.name == 'player-list' then else return end
|
and event.element.parent.parent.parent.name == 'player-list' then else return end
|
||||||
|
-- must be a right click
|
||||||
if event.button == defines.mouse_button_type.right then else return end
|
if event.button == defines.mouse_button_type.right then else return end
|
||||||
local player_list = event.element.parent.parent.parent
|
local player_list = event.element.parent.parent.parent
|
||||||
|
-- hides the player list to show the info
|
||||||
player_list.scroll.style.visible = false
|
player_list.scroll.style.visible = false
|
||||||
local flow = player_list.add{type='flow',direction='vertical'}
|
local flow = player_list.add{type='flow',direction='vertical'}
|
||||||
back_btn:draw(flow)
|
back_btn:draw(flow)
|
||||||
get_player_info(event.element.name,flow,true)
|
playerInfo(event.element.name,flow,true)
|
||||||
if Game.get_player(event.element.name) and event.player_index == Game.get_player(event.element.name).index then return end
|
if Game.get_player(event.element.name) and event.player_index == Game.get_player(event.element.name).index then return end
|
||||||
if Admin and Admin.allowed(event.player_index) then Admin.btn_flow(flow).caption = event.element.name end
|
if Admin and Admin.allowed(event.player_index) then Admin.btn_flow(flow).caption = event.element.name end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
Event.register(defines.events.on_player_joined_game,queue_update)
|
script.on_event(defines.events.on_player_joined_game,queue_update)
|
||||||
Event.register(defines.events.on_player_left_game,queue_update)
|
script.on_event(defines.events.on_player_left_game,queue_update)
|
||||||
Event.register(defines.events.rank_change,queue_update)
|
script.on_event(defines.events.rank_change,queue_update)
|
||||||
|
|
||||||
|
function commands:on_init()
|
||||||
|
if loaded_modules['ExpGamingPlayer.playerInfo'] then playerInfo = require('ExpGamingPlayer.playerInfo') end
|
||||||
|
if loaded_modules['ExpGamingAdmin'] then Admin = require('ExpGamingAdmin') end
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
force_update=function() return Gui.left.update('player-list') end,
|
||||||
|
update=queue_update
|
||||||
|
}
|
||||||
23
modules/ExpGamingPlayer/playerList/softmod.json
Normal file
23
modules/ExpGamingPlayer/playerList/softmod.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"name": "playerList",
|
||||||
|
"version": "4.0.0",
|
||||||
|
"type": "Module",
|
||||||
|
"description": "Used to display player names and online time on the top left.",
|
||||||
|
"location": "<blank>",
|
||||||
|
"keywords": [
|
||||||
|
"Player List",
|
||||||
|
"List",
|
||||||
|
"Gui",
|
||||||
|
"Names"
|
||||||
|
],
|
||||||
|
"author": "<blank>",
|
||||||
|
"contact": "<blank>",
|
||||||
|
"license": "<blank>",
|
||||||
|
"dependencies": {
|
||||||
|
"FactorioStdLib.Game": "^0.8.0",
|
||||||
|
"ExpGamingCore.Gui": "^4.0.0",
|
||||||
|
"ExpGamingCore.Ranking": "?^4.0.0",
|
||||||
|
"ExpGamingAdmin.buttonFlow": "?^4.0.0",
|
||||||
|
"ExpGamingAdmin.reports": "?^4.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
9
modules/ExpGamingPlayer/playerList/src/ranking.lua
Normal file
9
modules/ExpGamingPlayer/playerList/src/ranking.lua
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
local Ranking = require('ExpGamingCore.Ranking')
|
||||||
|
|
||||||
|
return function()
|
||||||
|
local rtn = {}
|
||||||
|
for _,rank in pairs(Ranking.ranks) do
|
||||||
|
table.insert(rtn,{rank.colour,rank.short_hand,rank:get_players(true))
|
||||||
|
end
|
||||||
|
return rtn
|
||||||
|
end
|
||||||
17
modules/ExpGamingPlayer/softmod.json
Normal file
17
modules/ExpGamingPlayer/softmod.json
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"name": "ExpGamingPlayer",
|
||||||
|
"version": "4.0.0",
|
||||||
|
"type": "Collection",
|
||||||
|
"description": "Useful collection of modules for displaying player infomation.",
|
||||||
|
"location": "<blank>",
|
||||||
|
"keywords": [
|
||||||
|
"ExpGaming",
|
||||||
|
"Player",
|
||||||
|
"Information",
|
||||||
|
"AFK"
|
||||||
|
],
|
||||||
|
"author": "Cooldude2606",
|
||||||
|
"contact": "Discord: Cooldude2606#5241",
|
||||||
|
"license": "https://github.com/explosivegaming/scenario/blob/master/LICENSE",
|
||||||
|
"submodules": {}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user