From 701ad7cb678cf382430ac6063adb874d74b31ed3 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 27 Mar 2020 17:51:08 +0000 Subject: [PATCH 1/3] Added server ups --- config/_file_loader.lua | 1 + config/roles.lua | 1 + modules/gui/server-ups.lua | 62 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 modules/gui/server-ups.lua diff --git a/config/_file_loader.lua b/config/_file_loader.lua index 35a07946..73be7622 100644 --- a/config/_file_loader.lua +++ b/config/_file_loader.lua @@ -48,6 +48,7 @@ return { 'modules.gui.warp-list', 'modules.gui.task-list', 'modules.gui.player-list', + 'modules.gui.server-ups', 'modules.commands.debug', -- Config Files 'config.expcore-commands.auth_admin', -- commands tagged with admin_only are blocked for non admins diff --git a/config/roles.lua b/config/roles.lua index ff40131f..22fba6e9 100644 --- a/config/roles.lua +++ b/config/roles.lua @@ -216,6 +216,7 @@ local default = Roles.new_role('Guest','') 'command/find-on-map', 'command/report', 'command/ratio', + 'command/server-ups', 'gui/player-list', 'gui/rocket-info', 'gui/science-info', diff --git a/modules/gui/server-ups.lua b/modules/gui/server-ups.lua new file mode 100644 index 00000000..021dee03 --- /dev/null +++ b/modules/gui/server-ups.lua @@ -0,0 +1,62 @@ +--[[-- Gui Module - Server UPS + - Adds a server ups counter in the top right and a command to toggle is + @gui sverer-ups + @alias sverer_ups +]] + +local Gui = require 'expcore.gui' --- @dep expcore.gui +local Event = require 'utils.event' --- @dep utils.event +local Commands = require 'expcore.commands' --- @dep expcore.commands + +--- Label to show the server ups +-- @element sverer_ups +local sverer_ups = +Gui.element{ + type = 'label', + caption = 'Server UPS = 60.0' +} +:style{ + font = 'default-game' +} + +--- Toggles if the server ups is visbile +-- @command server-ups +Commands.new_command('server-ups','Toggle the server ups display') +:add_alias('sups','ups') +:register(function(player) + local label = player.gui.screen[sverer_ups.name] + label.visible = not label.visible +end) + +-- Set the location of the label +-- 1920x1080: x=1455, y=30 (ui scale 100%) +local function set_location(event) + local player = game.players[event.player_index] + local label = player.gui.screen[sverer_ups.name] + local res = player.display_resolution + local uis = player.display_scale + label.location = { x=res.width-465*uis, y=30*uis } +end + +-- Draw the label when the player joins +Event.add(defines.events.on_player_created,function(event) + local player = game.players[event.player_index] + local label = sverer_ups(player.gui.screen) + label.visible = false + set_location(event) +end) + +-- Update the caption for all online players +Event.on_nth_tick(60,function() + local caption = 'Server UPS = 60.0' + if global.ext and global.ext.server_ups then + caption = 'Server UPS = '..global.ext.server_ups + end + for _,player in pairs(game.connected_players) do + player.gui.screen[sverer_ups.name].caption = caption + end +end) + +-- Update when res or ui scale changes +Event.add(defines.events.on_player_display_resolution_changed,set_location) +Event.add(defines.events.on_player_display_scale_changed,set_location) \ No newline at end of file From e8f86ac054a31928284c61c302bd15113e39adf6 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 27 Mar 2020 17:54:46 +0000 Subject: [PATCH 2/3] Made check for ext --- locale/en/commands.cfg | 2 ++ modules/gui/server-ups.lua | 12 +++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/locale/en/commands.cfg b/locale/en/commands.cfg index ab475d4b..4f25d450 100644 --- a/locale/en/commands.cfg +++ b/locale/en/commands.cfg @@ -74,3 +74,5 @@ home-set=Your home point has been set to x: __1__ y: __2__ return-set=Your return point has been set to x: __1__ y: __2__ home-get=Your home point is at x: __1__ y: __2__ +[expcom-server-ups] +no-ext=No external source was found, cannot display server ups. \ No newline at end of file diff --git a/modules/gui/server-ups.lua b/modules/gui/server-ups.lua index 021dee03..5c48b019 100644 --- a/modules/gui/server-ups.lua +++ b/modules/gui/server-ups.lua @@ -25,6 +25,9 @@ Commands.new_command('server-ups','Toggle the server ups display') :add_alias('sups','ups') :register(function(player) local label = player.gui.screen[sverer_ups.name] + if not global.ext or not global.ext.server_ups then + return Commands.error{'expcom-server-ups.no-ext'} + end label.visible = not label.visible end) @@ -48,12 +51,11 @@ end) -- Update the caption for all online players Event.on_nth_tick(60,function() - local caption = 'Server UPS = 60.0' if global.ext and global.ext.server_ups then - caption = 'Server UPS = '..global.ext.server_ups - end - for _,player in pairs(game.connected_players) do - player.gui.screen[sverer_ups.name].caption = caption + local caption = 'Server UPS = '..global.ext.server_ups + for _,player in pairs(game.connected_players) do + player.gui.screen[sverer_ups.name].caption = caption + end end end) From 7c1943d0c9550bc8659c9b2edb688e28beb46c42 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sat, 28 Mar 2020 02:46:13 +0000 Subject: [PATCH 3/3] Fixed server mis-spell --- modules/gui/server-ups.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/gui/server-ups.lua b/modules/gui/server-ups.lua index 5c48b019..cba75d89 100644 --- a/modules/gui/server-ups.lua +++ b/modules/gui/server-ups.lua @@ -1,7 +1,7 @@ --[[-- Gui Module - Server UPS - Adds a server ups counter in the top right and a command to toggle is - @gui sverer-ups - @alias sverer_ups + @gui server-ups + @alias server_ups ]] local Gui = require 'expcore.gui' --- @dep expcore.gui @@ -9,8 +9,8 @@ local Event = require 'utils.event' --- @dep utils.event local Commands = require 'expcore.commands' --- @dep expcore.commands --- Label to show the server ups --- @element sverer_ups -local sverer_ups = +-- @element server_ups +local server_ups = Gui.element{ type = 'label', caption = 'Server UPS = 60.0' @@ -24,7 +24,7 @@ Gui.element{ Commands.new_command('server-ups','Toggle the server ups display') :add_alias('sups','ups') :register(function(player) - local label = player.gui.screen[sverer_ups.name] + local label = player.gui.screen[server_ups.name] if not global.ext or not global.ext.server_ups then return Commands.error{'expcom-server-ups.no-ext'} end @@ -35,7 +35,7 @@ end) -- 1920x1080: x=1455, y=30 (ui scale 100%) local function set_location(event) local player = game.players[event.player_index] - local label = player.gui.screen[sverer_ups.name] + local label = player.gui.screen[server_ups.name] local res = player.display_resolution local uis = player.display_scale label.location = { x=res.width-465*uis, y=30*uis } @@ -44,7 +44,7 @@ end -- Draw the label when the player joins Event.add(defines.events.on_player_created,function(event) local player = game.players[event.player_index] - local label = sverer_ups(player.gui.screen) + local label = server_ups(player.gui.screen) label.visible = false set_location(event) end) @@ -54,7 +54,7 @@ Event.on_nth_tick(60,function() if global.ext and global.ext.server_ups then local caption = 'Server UPS = '..global.ext.server_ups for _,player in pairs(game.connected_players) do - player.gui.screen[sverer_ups.name].caption = caption + player.gui.screen[server_ups.name].caption = caption end end end)