Show player/server count in server list

This commit is contained in:
Federico Cecchetto 2022-06-26 23:25:04 +02:00
parent 58aab6af6f
commit 0211bfb41b
3 changed files with 37 additions and 0 deletions

View File

@ -7,6 +7,8 @@ end
game:addlocalizedstring("MENU_NUMPLAYERS", "Players") game:addlocalizedstring("MENU_NUMPLAYERS", "Players")
game:addlocalizedstring("MENU_PING", "Ping") game:addlocalizedstring("MENU_PING", "Ping")
game:addlocalizedstring("SERVERLIST_PLAYER_COUNT", "&&1 Players")
game:addlocalizedstring("SERVERLIST_SERVER_COUNT", "&&1 Servers")
local columns = { local columns = {
{ {
@ -195,8 +197,33 @@ function menu_systemlink_join(f19_arg0, f19_arg1)
SystemLinkJoinMenu.UpdateCounterText(menu, nil) SystemLinkJoinMenu.UpdateCounterText(menu, nil)
Lobby.BuildServerList(Engine.GetFirstActiveController()) 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) menu.list:registerEventHandler(LUI.UIScrollIndicator.UpdateEvent, function(element, event)
SystemLinkJoinMenu.UpdateCounterText(menu, event) SystemLinkJoinMenu.UpdateCounterText(menu, event)
playercount:setText(Engine.Localize("@SERVERLIST_PLAYER_COUNT", serverlist:getplayercount()))
servercount:setText(Engine.Localize("@SERVERLIST_SERVER_COUNT", serverlist:getservercount()))
end) end)
SystemLinkJoinMenu.UpdateGameList(menu) SystemLinkJoinMenu.UpdateGameList(menu)

View File

@ -9,4 +9,7 @@ namespace server_list
void handle_info_response(const game::netadr_s& address, const utils::info_string& info); void handle_info_response(const game::netadr_s& address, const utils::info_string& info);
bool sl_key_event(int key, int down); bool sl_key_event(int key, int down);
int get_player_count();
int get_server_count();
} }

View File

@ -17,6 +17,7 @@
#include "fastfiles.hpp" #include "fastfiles.hpp"
#include "scripting.hpp" #include "scripting.hpp"
#include "updater.hpp" #include "updater.hpp"
#include "server_list.hpp"
#include "game/ui_scripting/execution.hpp" #include "game/ui_scripting/execution.hpp"
#include "game/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); ::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(); auto updater_table = table();
lua["updater"] = updater_table; lua["updater"] = updater_table;