From 7d9a647ff9049774f1409967be7f3a3b5f2dd02b Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Thu, 28 Dec 2017 13:53:18 +0000 Subject: [PATCH] Testing Player List --- Addons/Guis/player-list.lua | 42 ++++++++++++++++++++++++++++++++----- locale/en/player-list.cfg | 4 ++++ 2 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 locale/en/player-list.cfg diff --git a/Addons/Guis/player-list.lua b/Addons/Guis/player-list.lua index f0bab2bb..c6f95f4a 100644 --- a/Addons/Guis/player-list.lua +++ b/Addons/Guis/player-list.lua @@ -10,13 +10,17 @@ Discord: https://discord.gg/r6dC2uK local function _global(reset) global.addons = not reset and global.addons or {} - global.addons.player_list = not reset and global.addons.player_list or {update=0,delay=10} + global.addons.player_list = not reset and global.addons.player_list or {update=0,delay=10,intervial=54000} return global.addons.player_list end +local function update() + Gui.left.update('player-list') +end + local function queue_update(tick) local data = _global() - local tick = 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 then data.update = tick + data.delay end @@ -25,7 +29,7 @@ end Gui.left.add{ name='player-list', caption='entity/player', - tooltip='Toggles the player list', + tooltip={'player-list.tooltip'}, draw=function(frame) frame.caption = '' local player_list = frame.add{ @@ -35,7 +39,35 @@ Gui.left.add{ vertical_scroll_policy="always", horizontal_scroll_policy="never" } - + for _,rank in pairs(Ranking._ranks()) do + for _,player in pairs(rank:get_players(true)) do + if rank.short_hand == '' then + player_list.add{ + type='label', + style='caption_style', + caption={'player-list.format-nil',tick_to_display_format(player.online_time),player.name} + }.style.font_color = rank.colour + else + player_list.add{ + type='label', + style='caption_style', + caption={'player-list.format',tick_to_display_format(player.online_time),player.name,rank.short_hand} + }.style.font_color = rank.colour + end + end + end end, open_on_join=true -} \ No newline at end of file +} + +Event.register(defines.events.on_tick,function(event) + local data = _global() + if event.tick > data.update then + update() + data.update = event.tick + data.intervial + end +end) + +Event.register(defines.events.on_player_joined_game,queue_update) +Event.register(defines.events.on_player_left_game,queue_update) +Event.register(defines.events.rank_change,queue_update) \ No newline at end of file diff --git a/locale/en/player-list.cfg b/locale/en/player-list.cfg new file mode 100644 index 00000000..66af1947 --- /dev/null +++ b/locale/en/player-list.cfg @@ -0,0 +1,4 @@ +[player-list] +tooltip=Toggles The PLayer List +format-nil=__1__ - __2__ +format=__1__ - __2__ - __3__ \ No newline at end of file