From 1b6442fc9e5c5faf3011c0156df031bb3786cd51 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Sun, 26 Jun 2022 23:25:04 +0200 Subject: [PATCH] Show player/server count in server list --- data/ui_scripts/server_list/serverlist.lua | 27 ++++++++++++++++++++++ src/client/component/server_list.hpp | 3 +++ src/client/component/ui_scripting.cpp | 7 ++++++ 3 files changed, 37 insertions(+) diff --git a/data/ui_scripts/server_list/serverlist.lua b/data/ui_scripts/server_list/serverlist.lua index daed0300..10e48598 100644 --- a/data/ui_scripts/server_list/serverlist.lua +++ b/data/ui_scripts/server_list/serverlist.lua @@ -7,6 +7,8 @@ end game:addlocalizedstring("MENU_NUMPLAYERS", "Players") game:addlocalizedstring("MENU_PING", "Ping") +game:addlocalizedstring("SERVERLIST_PLAYER_COUNT", "&&1 Players") +game:addlocalizedstring("SERVERLIST_SERVER_COUNT", "&&1 Servers") local columns = { { @@ -195,8 +197,33 @@ function menu_systemlink_join(f19_arg0, f19_arg1) SystemLinkJoinMenu.UpdateCounterText(menu, nil) Lobby.BuildServerList(Engine.GetFirstActiveController()) + local playercount = LUI.UIText.new({ + rightAnchor = true, + topAnchor = true, + height = 18, + bottom = 58, + font = CoD.TextSettings.BodyFont.Font, + width = 300, + alignment = LUI.Alignment.Right, + }) + menu:addElement(playercount) + + local servercount = LUI.UIText.new({ + rightAnchor = true, + topAnchor = true, + height = 18, + bottom = 58 - 25, + font = CoD.TextSettings.BodyFont.Font, + width = 300, + alignment = LUI.Alignment.Right, + }) + menu:addElement(servercount) + menu.list:registerEventHandler(LUI.UIScrollIndicator.UpdateEvent, function(element, event) SystemLinkJoinMenu.UpdateCounterText(menu, event) + + playercount:setText(Engine.Localize("@SERVERLIST_PLAYER_COUNT", serverlist:getplayercount())) + servercount:setText(Engine.Localize("@SERVERLIST_SERVER_COUNT", serverlist:getservercount())) end) SystemLinkJoinMenu.UpdateGameList(menu) diff --git a/src/client/component/server_list.hpp b/src/client/component/server_list.hpp index d9974cfa..14119c2d 100644 --- a/src/client/component/server_list.hpp +++ b/src/client/component/server_list.hpp @@ -9,4 +9,7 @@ namespace server_list void handle_info_response(const game::netadr_s& address, const utils::info_string& info); bool sl_key_event(int key, int down); + + int get_player_count(); + int get_server_count(); } \ No newline at end of file diff --git a/src/client/component/ui_scripting.cpp b/src/client/component/ui_scripting.cpp index ec6418c3..7c2e8ea8 100644 --- a/src/client/component/ui_scripting.cpp +++ b/src/client/component/ui_scripting.cpp @@ -17,6 +17,7 @@ #include "fastfiles.hpp" #include "scripting.hpp" #include "updater.hpp" +#include "server_list.hpp" #include "game/ui_scripting/execution.hpp" #include "game/scripting/execution.hpp" @@ -342,6 +343,12 @@ namespace ui_scripting ::game::Dvar_SetFromStringByNameFromSource("virtualLobbyPresentable", "1", ::game::DvarSetSource::DVAR_SOURCE_INTERNAL); }; + auto server_list_table = table(); + lua["serverlist"] = server_list_table; + + server_list_table["getplayercount"] = server_list::get_player_count; + server_list_table["getservercount"] = server_list::get_server_count; + auto updater_table = table(); lua["updater"] = updater_table;