From 6432326b1b779680cac28a0133dcfce5e5dd65a5 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 26 May 2019 15:32:52 +0100 Subject: [PATCH 1/5] Minor bug fixes --- config/{file_loader.lua => _file_loader.lua} | 10 +- ..._starting_items.lua => advanced_start.lua} | 0 config/config.cfg | 3 - .../auth_admin.lua} | 0 .../auth_roles.lua} | 0 .../auth_runtime_disable.lua} | 0 .../parse_general.lua} | 0 .../parse_roles.lua} | 2 +- control.lua | 2 +- expcore/gui/left.lua | 2 +- expcore/locale/de.cfg | 9 -- expcore/locale/en.cfg | 32 ------- expcore/locale/nl.cfg | 9 -- expcore/locale/sv-SE.cfg | 9 -- locale/en/commands.cfg | 94 +++++++++++-------- locale/en/expcore.cfg | 4 +- ...-starting-items.lua => advanced-start.lua} | 2 +- modules/addons/random-player-colours.lua | 4 +- modules/commands/admin-chat.lua | 4 +- modules/commands/cheat-mode.lua | 2 +- modules/commands/clear-inventory.lua | 2 +- modules/commands/help.lua | 14 +-- modules/commands/jail.lua | 18 ++-- modules/commands/kill.lua | 6 +- modules/commands/repair.lua | 4 +- modules/commands/reports.lua | 24 ++--- modules/commands/roles.lua | 12 +-- modules/commands/spawn.lua | 6 +- modules/commands/tag.lua | 4 +- modules/commands/teleport.lua | 14 +-- modules/commands/warnings.lua | 12 +-- 31 files changed, 130 insertions(+), 174 deletions(-) rename config/{file_loader.lua => _file_loader.lua} (77%) rename config/{advanced_starting_items.lua => advanced_start.lua} (100%) delete mode 100644 config/config.cfg rename config/{command_auth_admin.lua => expcore-commands/auth_admin.lua} (100%) rename config/{command_auth_roles.lua => expcore-commands/auth_roles.lua} (100%) rename config/{command_auth_runtime_disable.lua => expcore-commands/auth_runtime_disable.lua} (100%) rename config/{command_parse_general.lua => expcore-commands/parse_general.lua} (100%) rename config/{command_parse_roles.lua => expcore-commands/parse_roles.lua} (97%) delete mode 100644 expcore/locale/de.cfg delete mode 100644 expcore/locale/en.cfg delete mode 100644 expcore/locale/nl.cfg delete mode 100644 expcore/locale/sv-SE.cfg rename modules/addons/{advanced-starting-items.lua => advanced-start.lua} (95%) diff --git a/config/file_loader.lua b/config/_file_loader.lua similarity index 77% rename from config/file_loader.lua rename to config/_file_loader.lua index 744c058c..0c1b476c 100644 --- a/config/file_loader.lua +++ b/config/_file_loader.lua @@ -26,7 +26,7 @@ return { 'modules.addons.chat-popups', 'modules.addons.damage-popups', 'modules.addons.death-logger', - 'modules.addons.advanced-starting-items', + 'modules.addons.advanced-start', 'modules.addons.spawn-area', 'modules.addons.compilatron', 'modules.addons.scorched-earth', @@ -35,10 +35,10 @@ return { -- GUI 'modules.commands.debug', -- Config Files - 'config.command_auth_admin', -- commands tagged with admin_only are blocked for non admins - 'config.command_auth_roles', -- commands must be allowed via the role config - 'config.command_auth_runtime_disable', -- allows commands to be enabled and disabled during runtime + 'config.expcore-commands.auth_admin', -- commands tagged with admin_only are blocked for non admins + 'config.expcore-commands.auth_roles', -- commands must be allowed via the role config + 'config.expcore-commands.auth_runtime_disable', -- allows commands to be enabled and disabled during runtime 'config.permission_groups', -- loads some predefined permission groups 'config.roles', -- loads some predefined roles - 'expcore.gui.test' + 'expcore.gui.test' -- loads multiple gui defines to test the gui system } \ No newline at end of file diff --git a/config/advanced_starting_items.lua b/config/advanced_start.lua similarity index 100% rename from config/advanced_starting_items.lua rename to config/advanced_start.lua diff --git a/config/config.cfg b/config/config.cfg deleted file mode 100644 index b12b17cf..00000000 --- a/config/config.cfg +++ /dev/null @@ -1,3 +0,0 @@ -[command-auth] -admin-only=This command is for (game) admins only! -command-disabled=This command has been disabled by management! \ No newline at end of file diff --git a/config/command_auth_admin.lua b/config/expcore-commands/auth_admin.lua similarity index 100% rename from config/command_auth_admin.lua rename to config/expcore-commands/auth_admin.lua diff --git a/config/command_auth_roles.lua b/config/expcore-commands/auth_roles.lua similarity index 100% rename from config/command_auth_roles.lua rename to config/expcore-commands/auth_roles.lua diff --git a/config/command_auth_runtime_disable.lua b/config/expcore-commands/auth_runtime_disable.lua similarity index 100% rename from config/command_auth_runtime_disable.lua rename to config/expcore-commands/auth_runtime_disable.lua diff --git a/config/command_parse_general.lua b/config/expcore-commands/parse_general.lua similarity index 100% rename from config/command_parse_general.lua rename to config/expcore-commands/parse_general.lua diff --git a/config/command_parse_roles.lua b/config/expcore-commands/parse_roles.lua similarity index 97% rename from config/command_parse_roles.lua rename to config/expcore-commands/parse_roles.lua index efdf2a00..3d468aaf 100644 --- a/config/command_parse_roles.lua +++ b/config/expcore-commands/parse_roles.lua @@ -2,7 +2,7 @@ local Commands = require 'expcore.commands' local Roles = require 'expcore.roles' local auto_complete = ext_require('expcore.common','auto_complete') -require 'config.command_parse_general' +require 'config.expcore-commands.parse_general' Commands.add_parse('role',function(input,player,reject) if not input then return end diff --git a/control.lua b/control.lua index 48a4fbbc..e4ed6c3f 100644 --- a/control.lua +++ b/control.lua @@ -26,7 +26,7 @@ ext_require = require('expcore.common').ext_require -- Please go to config/file_loader.lua to edit the files that are loaded log('[INFO] Getting file loader config') -local files = require 'config.file_loader' +local files = require 'config._file_loader' -- Loads all files from the config and logs that they are loaded local total_file_count = string.format('%3d',#files) diff --git a/expcore/gui/left.lua b/expcore/gui/left.lua index da7f37e4..fb62761c 100644 --- a/expcore/gui/left.lua +++ b/expcore/gui/left.lua @@ -239,7 +239,7 @@ end LeftFrames.toggle_button = Buttons.new_button() -:set_tooltip('Close Windows') +:set_tooltip{'expcore-gui.left-button-tooltip'} :set_caption('<') :on_click(function(player,element) for _,define in pairs(LeftFrames.frames) do diff --git a/expcore/locale/de.cfg b/expcore/locale/de.cfg deleted file mode 100644 index e872b325..00000000 --- a/expcore/locale/de.cfg +++ /dev/null @@ -1,9 +0,0 @@ -[expcore-commands] -unauthorized=401 - Unbefugt: Zugang verweigert. Du hast keinen Zugriff auf diese Befehle! -reject-number-range=ungültige Reichweite, Min: __1__, Max: __2__ -reject-string-max-length=ungültige Länge, Max: __1__ -reject-player=ungültiger Spieler Name, __1__ , Versuche "Tab" zu benutzen, damit sich der Name automatisch vervollständigt. -reject-player-online=Der betroffene Spieler ist offline, Befehl konnte nicht ausgeführt werden. -reject-player-alive=Der betroffene Spieler ist Tod, Befehl konnte nicht ausgeführt werden. -invalid-inputs=ungültige Eingabe, /__1__ __2__ -command-ran=Befehl ausgeführt. \ No newline at end of file diff --git a/expcore/locale/en.cfg b/expcore/locale/en.cfg deleted file mode 100644 index 931ce162..00000000 --- a/expcore/locale/en.cfg +++ /dev/null @@ -1,32 +0,0 @@ -time-symbol-days-short=__1__d - -[expcore-commands] -unauthorized=Unauthorized, Access is denied due to invalid credentials -reject-string-options=Invalid Option, Must be one of: __1__ -reject-string-max-length=Invalid Length, Max: __1__ -reject-number=Invalid Number. -reject-number-range=Invalid Range, Min (inclusive): __1__, Max (inclusive): __2__ -reject-player=Invaild Player Name, __1__ ,try using tab key to auto-complete the name -reject-player-online=Player is offline. -reject-player-alive=Player is dead. -reject-force=Invaild Force Name. -reject-surface=Invaild Surface Name. -invalid-inputs=Invalid Input, /__1__ __2__ -invalid-param=Invalid Param "__1__"; __2__ -command-help=__1__ - __2__ -command-ran=Command Complete -command-fail=Command failed to run: __1__ -command-error-log-format=[ERROR] command/__1__ :: __2__ - -[expcore-roles] -error-log-format-flag=[ERROR] roleFlag/__1__ :: __2__ -error-log-format-promote=[ERROR] rolePromote/__1__ :: __2__ -game-message-assign=__1__ has been assigned to __2__ by __3__ -game-message-unassign=__1__ has been unassigned from __2__ by __3__ -reject-role=Invalid Role Name. -reject-player-role=Player has a higher role. - -[gui_util] -button_tooltip=Shows / hides the Toolbar Gui buttons. - -[expcore-gui] diff --git a/expcore/locale/nl.cfg b/expcore/locale/nl.cfg deleted file mode 100644 index 21e1ed58..00000000 --- a/expcore/locale/nl.cfg +++ /dev/null @@ -1,9 +0,0 @@ -[expcore-commands] -unauthorized=401 - Onbevoegd: toegang wordt geweigerd vanwege ongeldige inloggegevens -reject-number-range=Onjuiste radius, Min: __1__, Max: __2__ -reject-string-max-length=Onjuiste lengte, Max: __1__ -reject-player=Onjuiste naam, __1__ , probeer tab te gebruiken om de naam automatisch in te vullen -reject-player-online=Speler is offline. -reject-player-alive=Speler is dood. -invalid-inputs=Onjuiste invoer, /__1__ __2__ -command-ran=Commando uitgevoerd. diff --git a/expcore/locale/sv-SE.cfg b/expcore/locale/sv-SE.cfg deleted file mode 100644 index 078b7f17..00000000 --- a/expcore/locale/sv-SE.cfg +++ /dev/null @@ -1,9 +0,0 @@ -[expcore-commands] -unauthorized=401 - Otillåten: Tillgång nekas på grund av otillräcklig säkerhetsprövning. -reject-number-range=Invalid räckvid, Min: __1__, Max: __2__ -reject-string-max-length=ogiltig längd, Max: __1__ -reject-player=Ogiltigt spelarnamn, __1__ , försök använda tab-tangenten för att auto-slutföra namn. -reject-player-online=Spelare är offline. Kommando misslyckades med att köras. -reject-player-alive=Spelare är död. Kommando misslyckades med att köras. -invalid-inputs=Igiltig inmatning, /__1__ __2__ -command-ran=Kommandot slutfört diff --git a/locale/en/commands.cfg b/locale/en/commands.cfg index f987582c..12812c63 100644 --- a/locale/en/commands.cfg +++ b/locale/en/commands.cfg @@ -1,38 +1,56 @@ -[exp-commands] -kill-already-dead=You are already dead. -admin-chat-format=[Admin Chat] __1__: __2__ -tp-no-position-found=No position to teleport to was found, please try again later. -tp-to-self=Player can not be teleported to themselves. -chelp-title=Help results for "__1__": -chelp-footer=[__1__ results found; page __2__ of __3__] -chelp-format=/__1__ __2__ - __3__ __4__ -chelp-alias=Alias: __1__ -chelp-out-of-range=__1__ is an invalid page number. -roles-higher-role=The role you tried to assign is higher than your highest. -roles-list=All roles are: __1__ -roles-list-player=__1__ has: __2__ -roles-list-element=__1__, __2__ -jail-give=__1__ was jailed by __2__. Reason: __3__ -jail-remove=__1__ was unjailed by __2__. -jail-already-jailed=__1__ is already in jail. -jail-not-jailed=__1__ is not currently in jail. -jail-temp-ban=__1__ was temp banned until next reset by __2__. Reason: __3__ -jail-temp-ban-clear=__1__ was cleared from temp banned by __2__. -jail-not-temp-banned=__1__ is not currently temp banned. -jail-already-banned=__1__ is already banned. -report-player-immune=This player can not be reported. -report-non-admin=__1__ was reported for __2__. -report-admin=__1__ was reported by __2__ for __3__. -report-already-reported=You can only report a player once, you can ask a moderator to clear this report. -report-not-reported=The player had no reports on them. -report-player-count-title=The following players have reports against them: -report-player-report-title=__1__ has the following reports agasinst them: -report-list=__1__: __2__ -report-removed=__1__ has one or more reports removed by __2__. -warnings-received=__1__ recived a warning from __2__ for __3__. -warnings-player=__1__ has __2__ warnings and __3__/__4__ script warnings. -warnings-list-tilte=The following player have this many warnings (and this many script warnings): -warnings-list=__1__: __2__ (__3__/__4__) -warnings-cleared=__1__ had all they warnings cleared by __2__. -spawn-unavailable=They was a problem getting you to spawn, please try again later. -repair-result=__1__ entites were revived and __2__ were healed to max health. \ No newline at end of file +[expcom-kill] +already-dead=You are already dead. + +[expcom-admin-chat] +format=[Admin Chat] __1__: __2__ + +[expcom-tp] +no-position-found=No position to teleport to was found, please try again later. +to-self=Player can not be teleported to themselves. + +[expcom-chelp] +title=Help results for "__1__": +footer=[__1__ results found; page __2__ of __3__] +format=/__1__ __2__ - __3__ __4__ +alias=Alias: __1__ +out-of-range=__1__ is an invalid page number. + +[expcom-roles] +higher-role=The role you tried to assign is higher than your highest. +list=All roles are: __1__ +list-player=__1__ has: __2__ +list-element=__1__, __2__ + +[expcom-jail] +give=__1__ was jailed by __2__. Reason: __3__ +remove=__1__ was unjailed by __2__. +already-jailed=__1__ is already in jail. +not-jailed=__1__ is not currently in jail. +temp-ban=__1__ was temp banned until next reset by __2__. Reason: __3__ +temp-ban-clear=__1__ was cleared from temp banned by __2__. +not-temp-banned=__1__ is not currently temp banned. +already-banned=__1__ is already banned. + +[expcom-report] +player-immune=This player can not be reported. +non-admin=__1__ was reported for __2__. +admin=__1__ was reported by __2__ for __3__. +already-reported=You can only report a player once, you can ask a moderator to clear this report. +not-reported=The player had no reports on them. +player-count-title=The following players have reports against them: +player-report-title=__1__ has the following reports agasinst them: +list=__1__: __2__ +removed=__1__ has one or more reports removed by __2__. + +[expcom-warnings] +received=__1__ recived a warning from __2__ for __3__. +player=__1__ has __2__ warnings and __3__/__4__ script warnings. +list-tilte=The following player have this many warnings (and this many script warnings): +list=__1__: __2__ (__3__/__4__) +cleared=__1__ had all they warnings cleared by __2__. + +[expcom-spawn] +unavailable=They was a problem getting you to spawn, please try again later. + +[expcom-repair] +result=__1__ entites were revived and __2__ were healed to max health. \ No newline at end of file diff --git a/locale/en/expcore.cfg b/locale/en/expcore.cfg index 931ce162..58830616 100644 --- a/locale/en/expcore.cfg +++ b/locale/en/expcore.cfg @@ -1,4 +1,5 @@ time-symbol-days-short=__1__d +color-tag=[color=__1__]__2__[/color] [expcore-commands] unauthorized=Unauthorized, Access is denied due to invalid credentials @@ -27,6 +28,7 @@ reject-role=Invalid Role Name. reject-player-role=Player has a higher role. [gui_util] -button_tooltip=Shows / hides the Toolbar Gui buttons. +button_tooltip=Shows/hides the toolbar. [expcore-gui] +left-button-tooltip=Hide all open windows. \ No newline at end of file diff --git a/modules/addons/advanced-starting-items.lua b/modules/addons/advanced-start.lua similarity index 95% rename from modules/addons/advanced-starting-items.lua rename to modules/addons/advanced-start.lua index f402e5dc..07ed9ddc 100644 --- a/modules/addons/advanced-starting-items.lua +++ b/modules/addons/advanced-start.lua @@ -1,7 +1,7 @@ --- Adds a better method of player starting items based on production levels. local Event = require 'utils.event' local Game = require 'utils.game' -local config = require 'config.advanced_starting_items' +local config = require 'config.advanced_start' local items = config.items Event.add(defines.events.on_player_created, function(event) diff --git a/modules/addons/random-player-colours.lua b/modules/addons/random-player-colours.lua index 0e347997..9c47f8be 100644 --- a/modules/addons/random-player-colours.lua +++ b/modules/addons/random-player-colours.lua @@ -9,15 +9,13 @@ Global.register(config,function(tbl) config = tbl end) -local white = Colours.white -local black = Colours.black Event.add(defines.events.on_player_created,function(event) local player = Game.get_player_by_index(event.player_index) local color = 'white' if config.players[player.name] then color = config.players[player.name] else - while not config.disallow[color] do + while config.disallow[color] do color = table.get_random_dictionary_entry(Colours,true) end color = Colours[color] diff --git a/modules/commands/admin-chat.lua b/modules/commands/admin-chat.lua index e9f32b50..f3038941 100644 --- a/modules/commands/admin-chat.lua +++ b/modules/commands/admin-chat.lua @@ -1,6 +1,6 @@ local Commands = require 'expcore.commands' local format_chat_player_name = ext_require('expcore.common','format_chat_player_name') -require 'config.command_parse_general' +require 'config.expcore-commands.parse_general' Commands.new_command('admin-chat','Sends a message in chat that only admins can see.') :add_param('message',false) -- the message to send in the admin chat @@ -11,7 +11,7 @@ Commands.new_command('admin-chat','Sends a message in chat that only admins can local player_name_colour = format_chat_player_name(player) for _,return_player in pairs(game.connected_players) do if return_player.admin then - return_player.print{'exp-commands.admin-chat-format',player_name_colour,message} + return_player.print{'expcom-admin-chat.format',player_name_colour,message} end end return Commands.success -- prevents command complete message from showing diff --git a/modules/commands/cheat-mode.lua b/modules/commands/cheat-mode.lua index 6aef5fca..ab40cb30 100644 --- a/modules/commands/cheat-mode.lua +++ b/modules/commands/cheat-mode.lua @@ -1,5 +1,5 @@ local Commands = require 'expcore.commands' -require 'config.command_parse_general' +require 'config.expcore-commands.parse_general' Commands.new_command('toggle-cheat-mode','Toggles cheat mode for your player, or another player.') :add_param('player',true,'player') -- player to toggle chest mode of, can be nil for self diff --git a/modules/commands/clear-inventory.lua b/modules/commands/clear-inventory.lua index 0b8a8d26..b33c3029 100644 --- a/modules/commands/clear-inventory.lua +++ b/modules/commands/clear-inventory.lua @@ -1,6 +1,6 @@ local Commands = require 'expcore.commands' local move_items = ext_require('expcore.common','move_items') -require 'config.command_parse_roles' +require 'config.expcore-commands.parse_roles' Commands.new_command('clear-inventory','Clears a players inventory') :add_param('player',false,'player-role-alive') diff --git a/modules/commands/help.lua b/modules/commands/help.lua index 419a23ac..11d2c647 100644 --- a/modules/commands/help.lua +++ b/modules/commands/help.lua @@ -1,6 +1,6 @@ local Commands = require 'expcore.commands' local Global = require 'utils.global' -require 'config.command_parse_general' +require 'config.expcore-commands.parse_general' local results_per_page = 5 @@ -42,9 +42,9 @@ Commands.new_command('chelp','Searches for a keyword in all commands you are all -- adds the new command to the page page_count = page_count + 1 found = found + 1 - local alias_format = #command_data.aliases > 0 and {'exp-commands.chelp-alias',table.concat(command_data.aliases,', ')} or '' + local alias_format = #command_data.aliases > 0 and {'expcom-chelp.alias',table.concat(command_data.aliases,', ')} or '' table.insert(pages[current_page],{ - 'exp-commands.chelp-format', + 'expcom-chelp.format', command_data.name, command_data.description, command_data.help, @@ -60,15 +60,15 @@ Commands.new_command('chelp','Searches for a keyword in all commands you are all end -- print the requested page keyword = keyword == '' and '' or keyword - Commands.print({'exp-commands.chelp-title',keyword},'cyan') + Commands.print({'expcom-chelp.title',keyword},'cyan') if pages[page] then for _,command in pairs(pages[page]) do Commands.print(command) end - Commands.print({'exp-commands.chelp-footer',found,page,#pages},'cyan') + Commands.print({'expcom-chelp.footer',found,page,#pages},'cyan') else - Commands.print({'exp-commands.chelp-footer',found,page,#pages},'cyan') - return Commands.error{'exp-commands.chelp-out-of-range',page} + Commands.print({'expcom-chelp.footer',found,page,#pages},'cyan') + return Commands.error{'expcom-chelp.out-of-range',page} end -- blocks command complete message return Commands.success diff --git a/modules/commands/jail.lua b/modules/commands/jail.lua index 6a30789f..a5d7ae37 100644 --- a/modules/commands/jail.lua +++ b/modules/commands/jail.lua @@ -1,7 +1,7 @@ local Commands = require 'expcore.commands' local JailControl = require 'modules.addons.jail-control' local format_chat_player_name = ext_require('expcore.common','format_chat_player_name') -require 'config.command_parse_roles' +require 'config.expcore-commands.parse_roles' Commands.new_command('jail','Puts a player into jail and removes all other roles.') :add_param('player',false,'player-role') @@ -12,9 +12,9 @@ Commands.new_command('jail','Puts a player into jail and removes all other roles local action_player_name_color = format_chat_player_name(action_player) local by_player_name_color = format_chat_player_name(player) if JailControl.jail_player(action_player,player.name) then - game.print{'exp-commands.jail-give',action_player_name_color,by_player_name_color,reason} + game.print{'expcom-jail.give',action_player_name_color,by_player_name_color,reason} else - return Commands.error{'exp-commands.jail-already-jailed',action_player_name_color} + return Commands.error{'expcom-jail.already-jailed',action_player_name_color} end end) @@ -26,9 +26,9 @@ Commands.new_command('unjail','Puts a player into jail and removes all other rol local action_player_name_color = format_chat_player_name(action_player) local by_player_name_color = format_chat_player_name(player) if JailControl.unjail_player(action_player,player.name) then - game.print{'exp-commands.jail-remove',action_player_name_color,by_player_name_color} + game.print{'expcom-jail.remove',action_player_name_color,by_player_name_color} else - return Commands.error{'exp-commands.jail-not-jailed',action_player_name_color} + return Commands.error{'expcom-jail.not-jailed',action_player_name_color} end end) @@ -40,9 +40,9 @@ Commands.new_command('temp-ban','Temp bans a player until the next reset; this r local action_player_name_color = format_chat_player_name(action_player) local by_player_name_color = format_chat_player_name(player) if JailControl.temp_ban_player(action_player,player.name,reason) then - game.print{'exp-commands.jail-temp-ban',action_player_name_color,by_player_name_color,reason} + game.print{'expcom-jail.temp-ban',action_player_name_color,by_player_name_color,reason} else - return Commands.error{'exp-commands.jail-already-banned',action_player_name_color} + return Commands.error{'expcom-jail.already-banned',action_player_name_color} end end) @@ -54,8 +54,8 @@ Commands.new_command('clear-temp-ban','Removes temp ban from a player; this will local action_player_name_color = format_chat_player_name(action_player) local by_player_name_color = format_chat_player_name(player) if JailControl.clear_temp_ban_player(action_player,player.name) then - game.print{'exp-commands.jail-temp-ban-clear',action_player_name_color,by_player_name_color} + game.print{'expcom-jail.temp-ban-clear',action_player_name_color,by_player_name_color} else - return Commands.error{'exp-commands.jail-not-temp-banned',action_player_name_color} + return Commands.error{'expcom-jail.not-temp-banned',action_player_name_color} end end) \ No newline at end of file diff --git a/modules/commands/kill.lua b/modules/commands/kill.lua index 0c36e327..e0076165 100644 --- a/modules/commands/kill.lua +++ b/modules/commands/kill.lua @@ -1,7 +1,7 @@ local Commands = require 'expcore.commands' local Roles = require 'expcore.roles' -require 'config.command_parse_general' -require 'config.command_parse_roles' +require 'config.expcore-commands.parse_general' +require 'config.expcore-commands.parse_roles' Commands.new_command('kill','Kills yourself or another player.') :add_param('player',true,'player-role-alive') -- the player to kill, must be alive to be valid @@ -14,7 +14,7 @@ end} :register(function(player,action_player,raw) if not action_player then -- can only be nil if no player given and the user is dead - return Commands.error{'exp-commands.kill-already-dead'} + return Commands.error{'expcom-kill.already-dead'} end if player == action_player then action_player.character.die() diff --git a/modules/commands/repair.lua b/modules/commands/repair.lua index 660ec6eb..e1644fb8 100644 --- a/modules/commands/repair.lua +++ b/modules/commands/repair.lua @@ -1,6 +1,6 @@ local Commands = require 'expcore.commands' local config = require 'config.repair' -require 'config.command_parse_general' +require 'config.expcore-commands.parse_general' local max_time_to_live = 4294967295 -- unit32 max Commands.new_command('repair','Repairs entities on your force around you') @@ -40,5 +40,5 @@ Commands.new_command('repair','Repairs entities on your force around you') end end end - return Commands.success{'exp-commands.repair-result',revive_count,heal_count} + return Commands.success{'expcom-repair.result',revive_count,heal_count} end) \ No newline at end of file diff --git a/modules/commands/reports.lua b/modules/commands/reports.lua index 3c57f533..98fec56d 100644 --- a/modules/commands/reports.lua +++ b/modules/commands/reports.lua @@ -2,14 +2,14 @@ local Roles = require 'expcore.roles' local Commands = require 'expcore.commands' local ReportsControl = require 'modules.addons.reports-control' local format_chat_player_name = ext_require('expcore.common','format_chat_player_name') -require 'config.command_parse_general' +require 'config.expcore-commands.parse_general' Commands.new_command('report','Reports a player and notifies moderators') :add_param('player',false,function(input,player,reject) input = Commands.parse('player',input,player,reject) if not input then return end if Roles.player_has_flag(input,'report-immune') then - return reject{'exp-commands.report-player-immune'} + return reject{'expcom-report.player-immune'} else return input end @@ -21,10 +21,10 @@ end) local action_player_name_color = format_chat_player_name(action_player) local by_player_name_color = format_chat_player_name(player) if ReportsControl.report_player(action_player,reason,player.name) then - game.print{'exp-commands.report-non-admin',action_player_name_color,reason} - Roles.print_to_roles_higher('Trainee',{'exp-commands.report-admin',action_player_name_color,by_player_name_color,reason}) + game.print{'expcom-report.non-admin',action_player_name_color,reason} + Roles.print_to_roles_higher('Trainee',{'expcom-report.admin',action_player_name_color,by_player_name_color,reason}) else - return Commands.error{'exp-commands.report-already-reported'} + return Commands.error{'expcom-report.already-reported'} end end) @@ -35,18 +35,18 @@ Commands.new_command('get-reports','Gets a list of all reports that a player has if action_player then local reports = ReportsControl.get_player_reports(action_player) local action_player_name_color = format_chat_player_name(action_player) - Commands.print{'exp-commands.report-player-report-title',action_player_name_color} + Commands.print{'expcom-report.player-report-title',action_player_name_color} for player_name,reason in pairs(reports) do local by_player_name_color = format_chat_player_name(player_name) - Commands.print{'exp-commands.report-list',by_player_name_color,reason} + Commands.print{'expcom-report.list',by_player_name_color,reason} end else local user_reports = ReportsControl.user_reports - Commands.print{'exp-commands.report-player-count-title'} + Commands.print{'expcom-report.player-count-title'} for player_name,reports in pairs(user_reports) do local player_name_color = format_chat_player_name(player_name) local report_count = ReportsControl.count_player_reports(player_name) - Commands.print{'exp-commands.report-list',player_name_color,report_count} + Commands.print{'expcom-report.list',player_name_color,report_count} end end end) @@ -57,14 +57,14 @@ Commands.new_command('clear-reports','Clears all reports from a player or just t :register(function(player,action_player,from_player,raw) if from_player then if not ReportsControl.remove_player_report(action_player,from_player.name) then - return Commands.error{'exp-commands.report-not-reported'} + return Commands.error{'expcom-report.not-reported'} end else if not ReportsControl.clear_player_reports(action_player) then - return Commands.error{'exp-commands.report-not-reported'} + return Commands.error{'expcom-report.not-reported'} end end local action_player_name_color = format_chat_player_name(action_player) local by_player_name_color = format_chat_player_name(player) - game.print{'exp-commands.report-removed',action_player_name_color,by_player_name_color} + game.print{'expcom-report.removed',action_player_name_color,by_player_name_color} end) \ No newline at end of file diff --git a/modules/commands/roles.lua b/modules/commands/roles.lua index c8b54f57..d9d3b6d4 100644 --- a/modules/commands/roles.lua +++ b/modules/commands/roles.lua @@ -16,7 +16,7 @@ Commands.new_command('assign-role','Assigns a role to a player') if player_highest.index < role.index then Roles.assign_player(action_player,role,player.name) else - return Commands.error{'exp-commands.roles-higher-role'} + return Commands.error{'expcom-roles.higher-role'} end end) @@ -30,7 +30,7 @@ Commands.new_command('unassign-role','Unassigns a role from a player') if player_highest.index < role.index then Roles.unassign_player(action_player,role,player.name) else - return Commands.error{'exp-commands.roles-higher-role'} + return Commands.error{'expcom-roles.higher-role'} end end) @@ -39,7 +39,7 @@ Commands.new_command('list-roles','Lists all roles in they correct order') :add_alias('lsroles','roles') :register(function(player,action_player,raw) local roles = Roles.config.order - local message = {'exp-commands.roles-list'} + local message = {'expcom-roles.list'} if action_player then roles = Roles.get_player_roles(action_player) end @@ -48,13 +48,13 @@ Commands.new_command('list-roles','Lists all roles in they correct order') local colour = role.custom_color or Colours.white local role_name = format_chat_colour_localized(role.name,colour) if index == 1 then - message = {'exp-commands.roles-list',role_name} + message = {'expcom-roles.list',role_name} if action_player then local player_name_colour = format_chat_player_name(action_player) - message = {'exp-commands.roles-list-player',player_name_colour,role_name} + message = {'expcom-roles.list-player',player_name_colour,role_name} end else - message = {'exp-commands.roles-list-element',message,role_name} + message = {'expcom-roles.list-element',message,role_name} end end return Commands.success(message) diff --git a/modules/commands/spawn.lua b/modules/commands/spawn.lua index 9e27bfbf..cc1fe512 100644 --- a/modules/commands/spawn.lua +++ b/modules/commands/spawn.lua @@ -23,14 +23,14 @@ Commands.new_command('go-to-spawn','Teleport to spawn') :add_alias('spawn','tp-spawn') :register(function(player,action_player) if not action_player then - return Commands.error{'exp-commands.spawn-unavailable'} + return Commands.error{'expcom-spawn.unavailable'} elseif action_player == player then if not teleport(player) then - return Commands.error{'exp-commands.spawn-unavailable'} + return Commands.error{'expcom-spawn.unavailable'} end elseif Roles.player_allowed(player,'command/go-to-spawn/always') then if not teleport(action_player) then - return Commands.error{'exp-commands.spawn-unavailable'} + return Commands.error{'expcom-spawn.unavailable'} end else return Commands.error{'expcore-commands.unauthorized'} diff --git a/modules/commands/tag.lua b/modules/commands/tag.lua index 18c1f0e5..0c5e5cf4 100644 --- a/modules/commands/tag.lua +++ b/modules/commands/tag.lua @@ -1,7 +1,7 @@ local Commands = require 'expcore.commands' local Roles = require 'expcore.roles' -require 'config.command_parse_general' -require 'config.command_parse_roles' +require 'config.expcore-commands.parse_general' +require 'config.expcore-commands.parse_roles' Commands.new_command('tag','Sets your player tag.') :add_param('tag',false,'string-max-length',20) -- new tag for your player max 20 char diff --git a/modules/commands/teleport.lua b/modules/commands/teleport.lua index e1fdd893..0f456c9e 100644 --- a/modules/commands/teleport.lua +++ b/modules/commands/teleport.lua @@ -1,5 +1,5 @@ local Commands = require 'expcore.commands' -require 'config.command_parse_general' +require 'config.expcore-commands.parse_general' local function teleport(from_player,to_player) local surface = to_player.surface @@ -18,11 +18,11 @@ Commands.new_command('teleport','Teleports a player to another player.') :register(function(player,from_player,to_player,raw) if from_player.index == to_player.index then -- return if attempting to teleport to self - return Commands.error{'exp-commands.tp-to-self'} + return Commands.error{'expcom-tp.to-self'} end if not teleport(from_player,to_player) then -- return if the teleport failed - return Commands.error{'exp-commands.tp-no-position-found'} + return Commands.error{'expcom-tp.no-position-found'} end end) @@ -32,11 +32,11 @@ Commands.new_command('bring','Teleports a player to you.') :register(function(player,from_player,raw) if from_player.index == player.index then -- return if attempting to teleport to self - return Commands.error{'exp-commands.tp-to-self'} + return Commands.error{'expcom-tp.to-self'} end if not teleport(from_player,player) then -- return if the teleport failed - return Commands.error{'exp-commands.tp-no-position-found'} + return Commands.error{'expcom-tp.no-position-found'} end end) @@ -47,10 +47,10 @@ Commands.new_command('goto','Teleports you to a player.') :register(function(player,to_player,raw) if to_player.index == player.index then -- return if attempting to teleport to self - return Commands.error{'exp-commands.tp-to-self'} + return Commands.error{'expcom-tp.to-self'} end if not teleport(player,to_player) then -- return if the teleport failed - return Commands.error{'exp-commands.tp-no-position-found'} + return Commands.error{'expcom-tp.no-position-found'} end end) \ No newline at end of file diff --git a/modules/commands/warnings.lua b/modules/commands/warnings.lua index ae3c9692..1a86e4bd 100644 --- a/modules/commands/warnings.lua +++ b/modules/commands/warnings.lua @@ -2,7 +2,7 @@ local Commands = require 'expcore.commands' local WarningsControl = require 'modules.addons.warnings-control' local format_chat_player_name = ext_require('expcore.common','format_chat_player_name') local config = require 'config.warnings' -require 'config.command_parse_roles' +require 'config.expcore-commands.parse_roles' Commands.new_command('give-warning','Gives a warning to a player; may lead to automatic script action.') :add_param('player',false,'player-role') @@ -13,7 +13,7 @@ Commands.new_command('give-warning','Gives a warning to a player; may lead to au WarningsControl.add_warnings(action_player,player.name) local action_player_name_color = format_chat_player_name(action_player) local by_player_name_color = format_chat_player_name(player) - game.print{'exp-commands.warnings-received',action_player_name_color,by_player_name_color,reason} + game.print{'expcom-warnings.received',action_player_name_color,by_player_name_color,reason} end) Commands.new_command('get-warnings','Gets the number of warnings a player has. If no player then lists all players and the number of warnings they have.') @@ -24,7 +24,7 @@ Commands.new_command('get-warnings','Gets the number of warnings a player has. I local warnings = WarningsControl.get_warnings(action_player) local script_warnings = WarningsControl.get_temp_warnings(action_player) local action_player_name_color = format_chat_player_name(action_player) - Commands.print{'exp-commands.warnings-player',action_player_name_color,warnings,script_warnings,config.temp_warning_limit} + Commands.print{'expcom-warnings.player',action_player_name_color,warnings,script_warnings,config.temp_warning_limit} else local rtn = {} local user_warnings = WarningsControl.user_warnings @@ -38,10 +38,10 @@ Commands.new_command('get-warnings','Gets the number of warnings a player has. I end rtn[player_name][2] = #warnings end - Commands.print{'exp-commands.warnings-list-tilte'} + Commands.print{'expcom-warnings.list-tilte'} for player_name,warnings in pairs(rtn) do local player_name_color = format_chat_player_name(player_name) - Commands.print{'exp-commands.warnings-list',player_name_color,warnings[1],warnings[2],config.temp_warning_limit} + Commands.print{'expcom-warnings.list',player_name_color,warnings[1],warnings[2],config.temp_warning_limit} end end end) @@ -53,5 +53,5 @@ Commands.new_command('clear-warnings','Clears all warnings (and script warnings) WarningsControl.clear_temp_warnings(action_player,player.name) local action_player_name_color = format_chat_player_name(action_player) local by_player_name_color = format_chat_player_name(player) - game.print{'exp-commands.warnings-cleared',action_player_name_color,by_player_name_color} + game.print{'expcom-warnings.cleared',action_player_name_color,by_player_name_color} end) \ No newline at end of file From aefdb80dee8d23bc3e902fb3fbd4d439adc15d77 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 26 May 2019 19:24:27 +0100 Subject: [PATCH 2/5] Added Player List --- config/_file_loader.lua | 1 + config/action_buttons.lua | 42 +++++++ config/roles.lua | 1 + expcore/gui.lua | 4 + expcore/gui/core.lua | 52 ++++++++ expcore/gui/left.lua | 13 +- locale/en/expcore.cfg | 4 + modules/gui/player-list.lua | 242 ++++++++++++++++++++++++++++++++++++ 8 files changed, 357 insertions(+), 2 deletions(-) create mode 100644 config/action_buttons.lua create mode 100644 modules/gui/player-list.lua diff --git a/config/_file_loader.lua b/config/_file_loader.lua index 0c1b476c..24c135c7 100644 --- a/config/_file_loader.lua +++ b/config/_file_loader.lua @@ -33,6 +33,7 @@ return { 'modules.addons.pollution-grading', 'modules.addons.random-player-colours', -- GUI + 'modules.gui.player-list', 'modules.commands.debug', -- Config Files 'config.expcore-commands.auth_admin', -- commands tagged with admin_only are blocked for non admins diff --git a/config/action_buttons.lua b/config/action_buttons.lua new file mode 100644 index 00000000..402d6481 --- /dev/null +++ b/config/action_buttons.lua @@ -0,0 +1,42 @@ +local Gui = require 'expcore.gui' +local Roles = require 'expcore.roles' +local Store = require 'expcore.store' +local Game = require 'utils.game' + +local action_player_store = 'gui.left.player-list.action-player' + +local function tool_button_style(style) + Gui.set_padding_style(style,-1,-1,-1,-1) + style.height = 28 + style.width = 28 +end + +local function auth_lower_role(player,action_player) + local player_highest = Roles.get_player_highest_role(player) + local action_player_highest = Roles.get_player_highest_role(action_player) + if player_highest.index < action_player_highest.index then + return true + end +end + +local function get_action_player(player) + local action_player_name = Store.get_child(action_player_store,player.name) + local action_player = Game.get_player_from_any(action_player_name) + return action_player +end + +local report_player = +Gui.new_button() +:set_sprites('utility/warning') +:set_tooltip('Report player') +:set_style('tool_button',tool_button_style) +:on_click(function(player,element) + local action_player = get_action_player(player) +end) + +return { + ['command/report'] = { + auth=auth_lower_role, + report_player + } +} \ No newline at end of file diff --git a/config/roles.lua b/config/roles.lua index b1863ea7..6ea8ddc9 100644 --- a/config/roles.lua +++ b/config/roles.lua @@ -181,6 +181,7 @@ local default = Roles.new_role('Guest','') 'command/chelp', 'command/list-roles', 'command/report', + 'gui/player-list', } --- Jail role diff --git a/expcore/gui.lua b/expcore/gui.lua index 5831acf8..70f0ffc3 100644 --- a/expcore/gui.lua +++ b/expcore/gui.lua @@ -13,6 +13,8 @@ local Gui = require 'expcore.gui.core' Gui._prototype:debug_name(name) --- Sets a debug alias for the define Gui._prototype:set_caption(caption) --- Sets the caption for the element define Gui._prototype:set_tooltip(tooltip) --- Sets the tooltip for the element define + Gui._prototype:set_style(style,callback) --- Sets the style for the element define + Gui._prototype:set_embeded_flow(state) --- Sets the element to be drawn inside a nameless flow, can be given a name using a function Gui._prototype:on_element_update(callback) --- Add a hander to run on the general value update event, different classes will handle this event differently Gui._prototype:set_pre_authenticator(callback) --- Sets an authenticator that blocks the draw function if check fails @@ -34,6 +36,7 @@ local Gui = require 'expcore.gui.core' Gui.toggle_enable(element) --- Will toggle the enabled state of an element Gui.toggle_visible(element) --- Will toggle the visiblity of an element + Gui.set_padding(element,up,down,left,right) --- Sets the padding for a gui element ]] local Instances = require 'expcore.gui.instances' @@ -195,6 +198,7 @@ Gui.classes.left_frames = LeftFrames LeftFrames.new_frame(permision_name) --- Creates a new left frame define LeftFrames._prototype:set_open_by_default(state) --- Sets if the frame is visible when a player joins, can also be a function to return a boolean + LeftFrames._prototype:set_direction(direction) --- Sets the direction of the frame, either vertical or horizontal LeftFrames._prototype:get_frame(player) --- Gets the frame for this define from the left frame flow LeftFrames._prototype:is_open(player) --- Returns if the player currently has this define visible LeftFrames._prototype:toggle(player) --- Toggles the visiblty of the left frame diff --git a/expcore/gui/core.lua b/expcore/gui/core.lua index 07d7e8f7..8eb407cf 100644 --- a/expcore/gui/core.lua +++ b/expcore/gui/core.lua @@ -128,6 +128,8 @@ Gui._prototype:debug_name(name) --- Sets a debug alias for the define Gui._prototype:set_caption(caption) --- Sets the caption for the element define Gui._prototype:set_tooltip(tooltip) --- Sets the tooltip for the element define + Gui._prototype:set_style(style,callback) --- Sets the style for the element define + Gui._prototype:set_embeded_flow(state) --- Sets the element to be drawn inside a nameless flow, can be given a name using a function Gui._prototype:on_element_update(callback) --- Add a hander to run on the general value update event, different classes will handle this event differently Gui._prototype:set_pre_authenticator(callback) --- Sets an authenticator that blocks the draw function if check fails @@ -149,6 +151,8 @@ Gui.toggle_enable(element) --- Will toggle the enabled state of an element Gui.toggle_visible(element) --- Will toggle the visiblity of an element + Gui.set_padding(element,up,down,left,right) --- Sets the padding for a gui element + Gui.set_padding_style(style,up,down,left,right) --- Sets the padding for a gui style ]] local Gui = require 'utils.gui' local Game = require 'utils.game' @@ -316,6 +320,28 @@ function Gui._prototype:set_tooltip(tooltip) return self end +--- Sets the style for the element define +-- @tparam style string the style that will be used for this element when drawn +-- @tapram[opt] callback function function is called when element is drawn to alter its style +-- @treturn self the element define to allow chaining +function Gui._prototype:set_style(style,callback) + self.draw_data.style = style + self.events.on_style = callback + return self +end + +--- Sets the element to be drawn inside a nameless flow, can be given a name using a function +-- @tparam state ?boolean|function when true a padless flow is created to contain the element +-- @treturn self the element define to allow chaining +function Gui._prototype:set_embeded_flow(state) + if state == false or type(state) == 'function' then + self.embeded_flow = state + else + self.embeded_flow = true + end + return self +end + --- Sets an authenticator that blocks the draw function if check fails -- @tparam callback function the function that will be ran to test if the element should be drawn or not -- callback param - player LuaPlayer - the player that the element is being drawn to @@ -358,8 +384,21 @@ function Gui._prototype:draw_to(element,...) if not self.pre_authenticator(player,self.name) then return end end + if self.embeded_flow then + local embeded_name + if type(self.embeded_flow) == 'function' then + embeded_name = self.embeded_flow(element,...) + end + element = element.add{type='flow',name=embeded_name} + Gui.set_padding(element) + end + local new_element = element.add(self.draw_data) + if self.events.on_style then + self.events.on_style(new_element.style) + end + if self.post_authenticator then new_element.enabled = self.post_authenticator(player,self.name) end @@ -510,4 +549,17 @@ function Gui.set_padding(element,up,down,left,right) style.right_padding = right or 0 end +--- Sets the padding for a gui style +-- @tparam element LuaStyle the element to set the padding for +-- @tparam[opt=0] up number the amount of padding on the top +-- @tparam[opt=0] down number the amount of padding on the bottom +-- @tparam[opt=0] left number the amount of padding on the left +-- @tparam[opt=0] right number the amount of padding on the right +function Gui.set_padding_style(style,up,down,left,right) + style.top_padding = up or 0 + style.bottom_padding = down or 0 + style.left_padding = left or 0 + style.right_padding = right or 0 +end + return Gui \ No newline at end of file diff --git a/expcore/gui/left.lua b/expcore/gui/left.lua index fb62761c..63efb267 100644 --- a/expcore/gui/left.lua +++ b/expcore/gui/left.lua @@ -33,6 +33,7 @@ LeftFrames.new_frame(permision_name) --- Creates a new left frame define LeftFrames._prototype:set_open_by_default(state) --- Sets if the frame is visible when a player joins, can also be a function to return a boolean + LeftFrames._prototype:set_direction(direction) --- Sets the direction of the frame, either vertical or horizontal LeftFrames._prototype:get_frame(player) --- Gets the frame for this define from the left frame flow LeftFrames._prototype:is_open(player) --- Returns if the player currently has this define visible LeftFrames._prototype:toggle(player) --- Toggles the visiblty of the left frame @@ -159,6 +160,13 @@ function LeftFrames._prototype:set_open_by_default(state) return self end +--- Sets the direction of the frame, either vertical or horizontal +-- @tparam direction string the direction to have the elements be added to thef frame +function LeftFrames._prototype:set_direction(direction) + self.direction = direction + return self +end + --- Gets the frame for this define from the left frame flow -- @tparam player LuaPlayer the player to get the frame of -- @treturn LuaGuiElement the frame in the left frame flow for this define @@ -212,7 +220,7 @@ end -- @tparam player LuaPlayer the player to update the frame of function LeftFrames._prototype:redraw(player) local frame = self:get_frame(player) - frame.claer() + frame.clear() if self.events.on_draw then self.events.on_draw(player,frame) end @@ -263,7 +271,8 @@ Event.add(defines.events.on_player_created,function(event) for _,define in pairs(LeftFrames.frames) do local frame = flow.add{ type='frame', - name=define.name + name=define.name, + direction=define.direction } if define.events.on_draw then diff --git a/locale/en/expcore.cfg b/locale/en/expcore.cfg index 58830616..ddde52d4 100644 --- a/locale/en/expcore.cfg +++ b/locale/en/expcore.cfg @@ -1,6 +1,10 @@ time-symbol-days-short=__1__d color-tag=[color=__1__]__2__[/color] +[time-format] +simple-format-tagged=__1__ __2__ +simple-format-div=__1__:__2__ + [expcore-commands] unauthorized=Unauthorized, Access is denied due to invalid credentials reject-string-options=Invalid Option, Must be one of: __1__ diff --git a/modules/gui/player-list.lua b/modules/gui/player-list.lua new file mode 100644 index 00000000..a434f1eb --- /dev/null +++ b/modules/gui/player-list.lua @@ -0,0 +1,242 @@ +--- Gui left frame define for a player list +local Gui = require 'expcore.gui' +local Roles = require 'expcore.roles' +local Store = require 'expcore.store' +local Game = require 'utils.game' +local Event = require 'utils.event' +local format_time = ext_require('expcore.common','format_time') +local config = require 'config.action_buttons' +local Colors = require 'resources.color_presets' + +local action_player_store = 'gui.left.player-list.action-player' + +--- Button used to open the action bar +local open_action_bar = +Gui.new_button() +:set_sprites('utility/expand_dots_white') +:set_tooltip('Options') +:set_embeded_flow(function(element,action_player_name) + return action_player_name +end) +:set_style('frame_button',function(style) + Gui.set_padding_style(style,-2,-2,-2,-2) + style.width = 8 + style.height = 14 +end) +:on_click(function(player,element) + Store.set_child(action_player_store,player.name,element.parent.name) +end) + +--- Button used to close the action bar +local close_action_bar = +Gui.new_button() +:set_sprites('utility/close_black') +:set_tooltip('Close options') +:set_style('tool_button',function(style) + Gui.set_padding_style(style,-1,-1,-1,-1) + style.height = 28 + style.width = 28 +end) +:on_click(function(player,element) + Store.set_child(action_player_store,player.name,nil) +end) + +--[[ Creates the main gui areas for the player list + element + > container + >> scroll + >>> table + >> action_bar +]] +local function generate_container(element) + Gui.set_padding(element,2,2,2,2) + element.style.minimal_width = 200 + + -- main container which contains the other elements + local container = + element.add{ + name='container', + type='frame', + direction='vertical', + style='window_content_frame_packed' + } + Gui.set_padding(container) + + -- a scroll bar which allows 8 players to be seen at once + local list_scroll = + container.add{ + name='scroll', + type='scroll-pane', + direction='vertical', + horizontal_scroll_policy='never', + vertical_scroll_policy='auto-and-reserve-space' + } + Gui.set_padding(list_scroll,1,1,2,2) + list_scroll.style.horizontally_stretchable = true + list_scroll.style.maximal_height = 200 + + -- 3 wide table to contain: action button, player name, and play time + local list_table = + list_scroll.add{ + name='table', + type='table', + column_count=3 + } + Gui.set_padding(list_table) + list_table.style.horizontally_stretchable = true + list_table.style.vertical_align = 'center' + list_table.style.cell_padding = 0 + + -- action bar which contains the different action buttons + local action_bar = + container.add{ + name='action_bar', + type='frame', + style='subfooter_frame' + } + Gui.set_padding(action_bar,1,1,3,3) + action_bar.style.horizontally_stretchable = true + action_bar.style.height = 35 + + return list_table, action_bar +end + +--- Adds buttons and permission flows to the action bar +local function generate_action_bar(player,element) + close_action_bar(element) + local action_player = Store.get_child(action_player_store,player.name) + + for action_name,buttons in pairs(config) do + local permission_flow = + element.add{ + type='flow', + name=action_name + } + + for _,button in ipairs(buttons) do + button(permission_flow) + end + + if not Roles.player_allowed(player,action_name) then + permission_flow.visible = false + end + + if buttons.auth and action_player and not buttons.auth(player,action_player) then + permission_flow.visible = false + end + end + + if not action_player then + element.visible = false + end +end + +--- Updates the action bar +local player_list_name +local function update_action_bar(player) + local frame = Gui.classes.left_frames.get_frame(player_list_name,player) + local element = frame.container.action_bar + local action_player = Store.get_child(action_player_store,player.name) + + if not action_player then + element.visible = false + else + element.visible = true + for action_name,buttons in pairs(config) do + if buttons.auth and not buttons.auth(player,action_player) then + element[action_name].visible = false + else + element[action_name].visible = true + end + end + end +end + +local function add_player(list_table,player,role_name) + open_action_bar(list_table,player.name) + + -- player name with the tooltip of their highest role and in they colour + local player_name = + list_table.add{ + type='label', + caption=player.name, + tooltip=role_name + } + Gui.set_padding(player_name,0,0,0,2) + player_name.style.font_color = player.chat_color + + -- flow which allows right align for the play time + local time_flow = + list_table.add{ + type='flow' + } + Gui.set_padding(time_flow) + time_flow.style.horizontal_align = 'right' + time_flow.style.horizontally_stretchable = true + + -- time given in Xh Ym and is right aligned + local time = + time_flow.add{ + type='label', + caption=format_time(player.online_time) + } + Gui.set_padding(time) +end + +--- Adds fake players to the player list +local function add_fake_players(list_table,count) + local role_name = 'Fake Player' + for i = 1,count do + add_player(list_table,{ + name='Player '..i, + online_time=math.random(0,game.tick), + chat_color=table.get_random_dictionary_entry(Colors) + },role_name) + end +end + +--- Registers the player list +local player_list = +Gui.new_left_frame('gui/player-list') +:set_sprites('entity/character') +:set_open_by_default() +:set_direction('vertical') +:on_draw(function(player,element) + local list_table,action_bar = generate_container(element) + generate_action_bar(player,action_bar) + + local players = {} + for _,next_player in pairs(game.connected_players) do + local highest_role = Roles.get_player_highest_role(next_player) + if not players[highest_role.name] then + players[highest_role.name] = {} + end + table.insert(players[highest_role.name],next_player) + end + + for _,role_name in pairs(Roles.config.order) do + if players[role_name] then + for _,next_player in pairs(players[role_name]) do + add_player(list_table,next_player,role_name) + end + end + end + + add_fake_players(list_table,20) +end) + +player_list_name = player_list:uid() + +--- When the action player is changed the action bar will update +Store.register(action_player_store,function(value,category) + local player = Game.get_player_from_any(category) + update_action_bar(player) +end) + +--- Many events which trigger the gui to be re drawn +Event.add(defines.events.on_player_joined_game,player_list 'redraw_all') +Event.add(defines.events.on_player_left_game,player_list 'redraw_all') +Event.add(Roles.player_role_assigned,player_list 'redraw_all') +Event.add(Roles.player_role_unassigned,player_list 'redraw_all') + +return player_list \ No newline at end of file From 42de74fa4f625de648c74bcdf2a049ab5f0f9898 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 26 May 2019 19:57:28 +0100 Subject: [PATCH 3/5] Added Action Buttons --- config/action_buttons.lua | 110 +++++++++++++++++++++++++++++++++++- config/roles.lua | 2 + modules/gui/player-list.lua | 4 +- 3 files changed, 113 insertions(+), 3 deletions(-) diff --git a/config/action_buttons.lua b/config/action_buttons.lua index 402d6481..d6b169e2 100644 --- a/config/action_buttons.lua +++ b/config/action_buttons.lua @@ -2,6 +2,8 @@ local Gui = require 'expcore.gui' local Roles = require 'expcore.roles' local Store = require 'expcore.store' local Game = require 'utils.game' +local Reports = require 'modules.addons.reports-control' +local Jail = require 'modules.addons.jail-control' local action_player_store = 'gui.left.player-list.action-player' @@ -25,18 +27,124 @@ local function get_action_player(player) return action_player end +local function teleport(from_player,to_player) + local surface = to_player.surface + local position = surface.find_non_colliding_position('character',to_player.position,32,1) + if not position then return false end -- return false if no new position + if from_player.driving then from_player.driving = false end -- kicks a player out a vehicle if in one + from_player.teleport(position,surface) + return true +end + +local goto_player = +Gui.new_button() +:set_sprites('utility/export') +:set_tooltip('Goto player') +:set_style('tool_button',tool_button_style) +:on_click(function(player,element) + local action_player = get_action_player(player) + teleport(player,action_player) +end) + +local bring_player = +Gui.new_button() +:set_sprites('utility/import') +:set_tooltip('Bring player') +:set_style('tool_button',tool_button_style) +:on_click(function(player,element) + local action_player = get_action_player(player) + teleport(action_player,player) +end) + +local kill_player = +Gui.new_button() +:set_sprites('utility/too_far') +:set_tooltip('Kill player') +:set_style('tool_button',tool_button_style) +:on_click(function(player,element) + local action_player = get_action_player(player) + if action_player.character then + action_player.character.die() + end +end) + local report_player = Gui.new_button() -:set_sprites('utility/warning') +:set_sprites('utility/spawn_flag') :set_tooltip('Report player') :set_style('tool_button',tool_button_style) :on_click(function(player,element) local action_player = get_action_player(player) + Reports.report_player(action_player,reason,player.name) +end) + +local jail_player = +Gui.new_button() +:set_sprites('utility/item_editor_icon') +:set_tooltip('Jail player') +:set_style('tool_button',tool_button_style) +:on_click(function(player,element) + local action_player = get_action_player(player) + Jail.jail_player(action_player,player.name) +end) + +local temp_ban_player = +Gui.new_button() +:set_sprites('utility/clock') +:set_tooltip('Temp ban player') +:set_style('tool_button',tool_button_style) +:on_click(function(player,element) + local action_player = get_action_player(player) + Jail.temp_ban_player(action_player,player.name,reason) +end) + +local kick_player = +Gui.new_button() +:set_sprites('utility/warning_icon') +:set_tooltip('Kick player') +:set_style('tool_button',tool_button_style) +:on_click(function(player,element) + local action_player = get_action_player(player) + game.kick_player(action_player,reason) +end) + +local ban_player = +Gui.new_button() +:set_sprites('utility/danger_icon') +:set_tooltip('Ban player') +:set_style('tool_button',tool_button_style) +:on_click(function(player,element) + local action_player = get_action_player(player) + game.ban_player(action_player,reason) end) return { + ['command/teleport'] = { + goto_player, + bring_player + }, + ['command/kill/always'] = { + auth=auth_lower_role, + kill_player + }, ['command/report'] = { auth=auth_lower_role, report_player + }, + ['command/jail'] = { + auth=auth_lower_role, + jail_player + }, + ['command/temp-ban'] = { + auth=auth_lower_role, + temp_ban_player + }, + ['command/kick'] = { + auth=auth_lower_role, + kick_player + }, + ['command/ban'] = { + auth=auth_lower_role, + ban_player } } \ No newline at end of file diff --git a/config/roles.lua b/config/roles.lua index 6ea8ddc9..3fe9c615 100644 --- a/config/roles.lua +++ b/config/roles.lua @@ -94,6 +94,8 @@ Roles.new_role('Trainee','TrMod') 'command/give-warning', 'command/get-warnings', 'command/get-reports', + 'command/kick', + 'command/ban', } --- Trusted Roles diff --git a/modules/gui/player-list.lua b/modules/gui/player-list.lua index a434f1eb..d240fb0a 100644 --- a/modules/gui/player-list.lua +++ b/modules/gui/player-list.lua @@ -122,7 +122,7 @@ local function generate_action_bar(player,element) end if buttons.auth and action_player and not buttons.auth(player,action_player) then - permission_flow.visible = false + --permission_flow.visible = false end end @@ -144,7 +144,7 @@ local function update_action_bar(player) element.visible = true for action_name,buttons in pairs(config) do if buttons.auth and not buttons.auth(player,action_player) then - element[action_name].visible = false + --element[action_name].visible = false else element[action_name].visible = true end From e7353e331f41710da20824493203e6122eb4983d Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 26 May 2019 20:38:51 +0100 Subject: [PATCH 4/5] Added reason entry --- config/action_buttons.lua | 49 +++++++++++++++++++++++++----- modules/gui/player-list.lua | 60 +++++++++++++++++++++++++++++++++++-- 2 files changed, 99 insertions(+), 10 deletions(-) diff --git a/config/action_buttons.lua b/config/action_buttons.lua index d6b169e2..f3e553db 100644 --- a/config/action_buttons.lua +++ b/config/action_buttons.lua @@ -4,8 +4,10 @@ local Store = require 'expcore.store' local Game = require 'utils.game' local Reports = require 'modules.addons.reports-control' local Jail = require 'modules.addons.jail-control' +local format_chat_player_name = ext_require('expcore.common','format_chat_player_name') local action_player_store = 'gui.left.player-list.action-player' +local action_name_store = 'gui.left.player-list.action-name' local function tool_button_style(style) Gui.set_padding_style(style,-1,-1,-1,-1) @@ -24,7 +26,8 @@ end local function get_action_player(player) local action_player_name = Store.get_child(action_player_store,player.name) local action_player = Game.get_player_from_any(action_player_name) - return action_player + local action_player_name_color = format_chat_player_name(action_player) + return action_player,action_player_name_color end local function teleport(from_player,to_player) @@ -74,29 +77,46 @@ Gui.new_button() :set_tooltip('Report player') :set_style('tool_button',tool_button_style) :on_click(function(player,element) - local action_player = get_action_player(player) - Reports.report_player(action_player,reason,player.name) + Store.set_child(action_name_store,player.name,'command/report') end) +local function report_player_callback(player,reason) + local action_player,action_player_name_color = get_action_player(player) + local by_player_name_color = format_chat_player_name(player) + game.print{'expcom-report.non-admin',action_player_name_color,reason} + Roles.print_to_roles_higher('Trainee',{'expcom-report.admin',action_player_name_color,by_player_name_color,reason}) + Reports.report_player(action_player,reason,player.name) +end + local jail_player = Gui.new_button() :set_sprites('utility/item_editor_icon') :set_tooltip('Jail player') :set_style('tool_button',tool_button_style) :on_click(function(player,element) - local action_player = get_action_player(player) - Jail.jail_player(action_player,player.name) + Store.set_child(action_name_store,player.name,'command/jail') end) +local function jail_player_callback(player,reason) + local action_player,action_player_name_color = get_action_player(player) + local by_player_name_color = format_chat_player_name(player) + game.print{'expcom-jail.give',action_player_name_color,by_player_name_color,reason} + Jail.jail_player(action_player,player.name) +end + local temp_ban_player = Gui.new_button() :set_sprites('utility/clock') :set_tooltip('Temp ban player') :set_style('tool_button',tool_button_style) :on_click(function(player,element) + Store.set_child(action_name_store,player.name,'command/temp-ban') +end) + +local function temp_ban_player_callback(player,reason) local action_player = get_action_player(player) Jail.temp_ban_player(action_player,player.name,reason) -end) +end local kick_player = Gui.new_button() @@ -104,9 +124,13 @@ Gui.new_button() :set_tooltip('Kick player') :set_style('tool_button',tool_button_style) :on_click(function(player,element) + Store.set_child(action_name_store,player.name,'command/kick') +end) + +local function kick_player_callback(player,reason) local action_player = get_action_player(player) game.kick_player(action_player,reason) -end) +end local ban_player = Gui.new_button() @@ -114,9 +138,13 @@ Gui.new_button() :set_tooltip('Ban player') :set_style('tool_button',tool_button_style) :on_click(function(player,element) + Store.set_child(action_name_store,player.name,'command/ban') +end) + +local function ban_player_callback(player,reason) local action_player = get_action_player(player) game.ban_player(action_player,reason) -end) +end return { ['command/teleport'] = { @@ -129,22 +157,27 @@ return { }, ['command/report'] = { auth=auth_lower_role, + reason_callback=report_player_callback, report_player }, ['command/jail'] = { auth=auth_lower_role, + reason_callback=jail_player_callback, jail_player }, ['command/temp-ban'] = { auth=auth_lower_role, + reason_callback=temp_ban_player_callback, temp_ban_player }, ['command/kick'] = { auth=auth_lower_role, + reason_callback=kick_player_callback, kick_player }, ['command/ban'] = { auth=auth_lower_role, + reason_callback=ban_player_callback, ban_player } } \ No newline at end of file diff --git a/modules/gui/player-list.lua b/modules/gui/player-list.lua index d240fb0a..0b8d1eaa 100644 --- a/modules/gui/player-list.lua +++ b/modules/gui/player-list.lua @@ -9,6 +9,7 @@ local config = require 'config.action_buttons' local Colors = require 'resources.color_presets' local action_player_store = 'gui.left.player-list.action-player' +local action_name_store = 'gui.left.player-list.action-name' --- Button used to open the action bar local open_action_bar = @@ -39,6 +40,26 @@ Gui.new_button() end) :on_click(function(player,element) Store.set_child(action_player_store,player.name,nil) + Store.set_child(action_name_store,player.name,nil) +end) + +--- Button used to confirm a reason +local reason_confrim = +Gui.new_button() +:set_sprites('utility/confirm_slot') +:set_tooltip('Confirm Reason') +:set_style('tool_button',function(style) + Gui.set_padding_style(style,-1,-1,-1,-1) + style.height = 28 + style.width = 28 +end) +:on_click(function(player,element) + local reason = element.parent.entry.text or 'Non Given' + local action_name = Store.get_child(action_name_store,player.name) + local reason_callback = config[action_name].reason_callback + reason_callback(player,reason) + Store.set_child(action_player_store,player.name,nil) + Store.set_child(action_name_store,player.name,nil) end) --[[ Creates the main gui areas for the player list @@ -48,7 +69,7 @@ end) >>> table >> action_bar ]] -local function generate_container(element) +local function generate_container(player,element) Gui.set_padding(element,2,2,2,2) element.style.minimal_width = 200 @@ -98,6 +119,33 @@ local function generate_container(element) action_bar.style.horizontally_stretchable = true action_bar.style.height = 35 + -- reason bar which contains the reason text field and confirm button + local reason_bar = + container.add{ + name='reason_bar', + type='frame', + style='subfooter_frame' + } + Gui.set_padding(reason_bar,-1,-1,3,3) + reason_bar.style.horizontally_stretchable = true + reason_bar.style.height = 35 + local action_name = Store.get_child(action_name_store,player.name) + reason_bar.visible = action_name ~= nil + + -- text entry for the reason bar + local reason_field = + reason_bar.add{ + name='entry', + type='textfield', + style='stretchable_textfield', + tooltip='Enter reason' + } + Gui.set_padding(reason_field) + reason_field.style.height = 28 + reason_field.style.minimal_width = 160 + + reason_confrim(reason_bar) + return list_table, action_bar end @@ -202,7 +250,7 @@ Gui.new_left_frame('gui/player-list') :set_open_by_default() :set_direction('vertical') :on_draw(function(player,element) - local list_table,action_bar = generate_container(element) + local list_table,action_bar = generate_container(player,element) generate_action_bar(player,action_bar) local players = {} @@ -233,6 +281,14 @@ Store.register(action_player_store,function(value,category) update_action_bar(player) end) +--- When the action name is changed the reason input will update +Store.register(action_name_store,function(value,category) + local player = Game.get_player_from_any(category) + local frame = Gui.classes.left_frames.get_frame(player_list_name,player) + local element = frame.container.reason_bar + element.visible = value ~= nil +end) + --- Many events which trigger the gui to be re drawn Event.add(defines.events.on_player_joined_game,player_list 'redraw_all') Event.add(defines.events.on_player_left_game,player_list 'redraw_all') From 77fc58c8a0472f89dfbb6258a9094cff176e0991 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 26 May 2019 21:44:39 +0100 Subject: [PATCH 5/5] Final Touch --- config/action_buttons.lua | 33 +++++++++++++++++---------- expcore/gui/left.lua | 5 ++++- locale/en/gui.cfg | 14 ++++++++++++ modules/gui/player-list.lua | 45 +++++++++++++++++++++++++++---------- 4 files changed, 72 insertions(+), 25 deletions(-) create mode 100644 locale/en/gui.cfg diff --git a/config/action_buttons.lua b/config/action_buttons.lua index f3e553db..401854c8 100644 --- a/config/action_buttons.lua +++ b/config/action_buttons.lua @@ -15,9 +15,9 @@ local function tool_button_style(style) style.width = 28 end -local function auth_lower_role(player,action_player) +local function auth_lower_role(player,action_player_name) local player_highest = Roles.get_player_highest_role(player) - local action_player_highest = Roles.get_player_highest_role(action_player) + local action_player_highest = Roles.get_player_highest_role(action_player_name) if player_highest.index < action_player_highest.index then return true end @@ -42,7 +42,7 @@ end local goto_player = Gui.new_button() :set_sprites('utility/export') -:set_tooltip('Goto player') +:set_tooltip{'player-list.goto-player'} :set_style('tool_button',tool_button_style) :on_click(function(player,element) local action_player = get_action_player(player) @@ -52,7 +52,7 @@ end) local bring_player = Gui.new_button() :set_sprites('utility/import') -:set_tooltip('Bring player') +:set_tooltip{'player-list.bring-player'} :set_style('tool_button',tool_button_style) :on_click(function(player,element) local action_player = get_action_player(player) @@ -62,7 +62,7 @@ end) local kill_player = Gui.new_button() :set_sprites('utility/too_far') -:set_tooltip('Kill player') +:set_tooltip{'player-list.kill-player'} :set_style('tool_button',tool_button_style) :on_click(function(player,element) local action_player = get_action_player(player) @@ -74,7 +74,7 @@ end) local report_player = Gui.new_button() :set_sprites('utility/spawn_flag') -:set_tooltip('Report player') +:set_tooltip{'player-list.report-player'} :set_style('tool_button',tool_button_style) :on_click(function(player,element) Store.set_child(action_name_store,player.name,'command/report') @@ -91,7 +91,7 @@ end local jail_player = Gui.new_button() :set_sprites('utility/item_editor_icon') -:set_tooltip('Jail player') +:set_tooltip{'player-list.jail-player'} :set_style('tool_button',tool_button_style) :on_click(function(player,element) Store.set_child(action_name_store,player.name,'command/jail') @@ -107,7 +107,7 @@ end local temp_ban_player = Gui.new_button() :set_sprites('utility/clock') -:set_tooltip('Temp ban player') +:set_tooltip{'player-list.temp-ban-player'} :set_style('tool_button',tool_button_style) :on_click(function(player,element) Store.set_child(action_name_store,player.name,'command/temp-ban') @@ -121,7 +121,7 @@ end local kick_player = Gui.new_button() :set_sprites('utility/warning_icon') -:set_tooltip('Kick player') +:set_tooltip{'player-list.kick-player'} :set_style('tool_button',tool_button_style) :on_click(function(player,element) Store.set_child(action_name_store,player.name,'command/kick') @@ -135,7 +135,7 @@ end local ban_player = Gui.new_button() :set_sprites('utility/danger_icon') -:set_tooltip('Ban player') +:set_tooltip{'player-list.ban-player'} :set_style('tool_button',tool_button_style) :on_click(function(player,element) Store.set_child(action_name_store,player.name,'command/ban') @@ -148,11 +148,20 @@ end return { ['command/teleport'] = { + auth=function(player,action_player_name) + return player.name ~= action_player_name + end, goto_player, bring_player }, - ['command/kill/always'] = { - auth=auth_lower_role, + ['command/kill'] = { + auth=function(player,action_player_name) + if player.name == action_player_name then + return true + elseif Roles.player_allowed(player,'command/kill/always') then + return auth_lower_role(player,action_player_name) + end + end, kill_player }, ['command/report'] = { diff --git a/expcore/gui/left.lua b/expcore/gui/left.lua index 63efb267..aeb528d3 100644 --- a/expcore/gui/left.lua +++ b/expcore/gui/left.lua @@ -240,7 +240,10 @@ end function LeftFrames._prototype:event_handler(action) action = action or 'update' return function(event) - local player = Game.get_player_by_index(event.player_index) + local player + if event.player_index then + player = Game.get_player_by_index(event.player_index) + end self[action](self,player) end end diff --git a/locale/en/gui.cfg b/locale/en/gui.cfg new file mode 100644 index 00000000..bc5ea253 --- /dev/null +++ b/locale/en/gui.cfg @@ -0,0 +1,14 @@ +[player-list] +open-action-bar=Options +close-action-bar=Close Options +reason-confirm=Confirm Reason +reason-entry=Enter Reason +goto-player=Goto player +bring-player=Bring player +kill-player=Kill player +report-player=Report player +jail-player=Jail player +temp-ban-player=Temp ban player +kick-player=Kick player +ban-player=Ban player +afk-time=__1__% of total map time\nLast moved __2__ ago \ No newline at end of file diff --git a/modules/gui/player-list.lua b/modules/gui/player-list.lua index 0b8d1eaa..ba976685 100644 --- a/modules/gui/player-list.lua +++ b/modules/gui/player-list.lua @@ -15,7 +15,7 @@ local action_name_store = 'gui.left.player-list.action-name' local open_action_bar = Gui.new_button() :set_sprites('utility/expand_dots_white') -:set_tooltip('Options') +:set_tooltip{'player-list.open-action-bar'} :set_embeded_flow(function(element,action_player_name) return action_player_name end) @@ -32,7 +32,7 @@ end) local close_action_bar = Gui.new_button() :set_sprites('utility/close_black') -:set_tooltip('Close options') +:set_tooltip{'player-list.close-action-bar'} :set_style('tool_button',function(style) Gui.set_padding_style(style,-1,-1,-1,-1) style.height = 28 @@ -44,10 +44,10 @@ end) end) --- Button used to confirm a reason -local reason_confrim = +local reasonc_confirm = Gui.new_button() :set_sprites('utility/confirm_slot') -:set_tooltip('Confirm Reason') +:set_tooltip{'player-list.reason-confirm'} :set_style('tool_button',function(style) Gui.set_padding_style(style,-1,-1,-1,-1) style.height = 28 @@ -60,6 +60,7 @@ end) reason_callback(player,reason) Store.set_child(action_player_store,player.name,nil) Store.set_child(action_name_store,player.name,nil) + element.parent.entry.text = '' end) --[[ Creates the main gui areas for the player list @@ -138,13 +139,13 @@ local function generate_container(player,element) name='entry', type='textfield', style='stretchable_textfield', - tooltip='Enter reason' + tooltip={'player-list.reason-entry'} } Gui.set_padding(reason_field) reason_field.style.height = 28 reason_field.style.minimal_width = 160 - reason_confrim(reason_bar) + reasonc_confirm(reason_bar) return list_table, action_bar end @@ -170,7 +171,7 @@ local function generate_action_bar(player,element) end if buttons.auth and action_player and not buttons.auth(player,action_player) then - --permission_flow.visible = false + permission_flow.visible = false end end @@ -192,7 +193,7 @@ local function update_action_bar(player) element.visible = true for action_name,buttons in pairs(config) do if buttons.auth and not buttons.auth(player,action_player) then - --element[action_name].visible = false + element[action_name].visible = false else element[action_name].visible = true end @@ -208,7 +209,7 @@ local function add_player(list_table,player,role_name) list_table.add{ type='label', caption=player.name, - tooltip=role_name + tooltip=player.name..' '..player.tag..'\n'..role_name } Gui.set_padding(player_name,0,0,0,2) player_name.style.font_color = player.chat_color @@ -216,6 +217,7 @@ local function add_player(list_table,player,role_name) -- flow which allows right align for the play time local time_flow = list_table.add{ + name='player-time-'..player.index, type='flow' } Gui.set_padding(time_flow) @@ -223,10 +225,14 @@ local function add_player(list_table,player,role_name) time_flow.style.horizontally_stretchable = true -- time given in Xh Ym and is right aligned + local tick = game.tick > 0 and game.tick or 1 + local percent = math.round(player.online_time/tick,3)*100 local time = time_flow.add{ + name='label', type='label', - caption=format_time(player.online_time) + caption=format_time(player.online_time), + tooltip={'player-list.afk-time',percent,format_time(player.afk_time,{minutes=true,long=true})} } Gui.set_padding(time) end @@ -238,6 +244,7 @@ local function add_fake_players(list_table,count) add_player(list_table,{ name='Player '..i, online_time=math.random(0,game.tick), + afk_time=math.random(0,game.tick), chat_color=table.get_random_dictionary_entry(Colors) },role_name) end @@ -270,7 +277,20 @@ Gui.new_left_frame('gui/player-list') end end - add_fake_players(list_table,20) + --add_fake_players(list_table,20) +end) +:on_update(function(player,element) + local list = element.container.scroll.table + for _,next_player in pairs(game.connected_players) do + local time_element_name = 'player-time-'..next_player.index + local time_element = list[time_element_name] + if time_element and time_element.valid then + time_element.label.caption = format_time(next_player.online_time) + local tick = game.tick > 0 and game.tick or 1 + local percent = math.round(player.online_time/tick,3)*100 + time_element.label.tooltip = {'player-list.afk-time',percent,format_time(player.afk_time,{minutes=true,long=true})} + end + end end) player_list_name = player_list:uid() @@ -289,7 +309,8 @@ Store.register(action_name_store,function(value,category) element.visible = value ~= nil end) ---- Many events which trigger the gui to be re drawn +--- Many events which trigger the gui to be re drawn, it will also update the times every 30 seconds +Event.on_nth_tick(1800,player_list 'update_all') Event.add(defines.events.on_player_joined_game,player_list 'redraw_all') Event.add(defines.events.on_player_left_game,player_list 'redraw_all') Event.add(Roles.player_role_assigned,player_list 'redraw_all')