[ServerList] Show server/playercount

This commit is contained in:
momo5502 2017-02-26 15:27:02 +01:00
parent 6ec79bb6dd
commit a8931fcc56
2 changed files with 36 additions and 2 deletions

View File

@ -640,11 +640,13 @@ namespace Components
Network::SendCommand(server->target, "getinfo", server->challenge);
// Display in the menu, like in COD4
Localization::Set("MPUI_SERVERQUERIED", Utils::String::VA("Sent requests: %d/%d", ServerList::RefreshContainer.sentCount, ServerList::RefreshContainer.sendCount));
//Localization::Set("MPUI_SERVERQUERIED", Utils::String::VA("Sent requests: %d/%d", ServerList::RefreshContainer.sentCount, ServerList::RefreshContainer.sendCount));
if (SendServers <= 0) break;
}
ServerList::UpdateVisibleInfo();
ServerList::RefreshContainer.mutex.unlock();
}
@ -680,9 +682,38 @@ namespace Components
ServerList::RefreshVisibleList(UIScript::Token());
}
void ServerList::UpdateVisibleInfo()
{
static int servers = 0;
static int players = 0;
auto list = ServerList::GetList();
if (list)
{
int newSevers = list->size();
int newPlayers = 0;
for (unsigned int i = 0; i < list->size(); ++i)
{
newPlayers += list->at(i).clients;
}
if (newSevers != servers || newPlayers != players)
{
servers = newSevers;
players = newPlayers;
Localization::Set("MPUI_SERVERQUERIED", Utils::String::VA("Servers: %i\nPlayers: %i", servers, players));
}
}
}
ServerList::ServerList()
{
ServerList::OnlineList.clear();
ServerList::OfflineList.clear();
ServerList::FavouriteList.clear();
ServerList::VisibleList.clear();
Dvar::OnInit([] ()
@ -691,7 +722,8 @@ namespace Components
Dvar::Register<const char*>("ui_serverSelectedMap", "mp_afghan", Game::dvar_flag::DVAR_FLAG_NONE, "Map of the selected server");
});
Localization::Set("MPUI_SERVERQUERIED", "Sent requests: 0/0");
//Localization::Set("MPUI_SERVERQUERIED", "Sent requests: 0/0");
Localization::Set("MPUI_SERVERQUERIED", "Servers: 0\nPlayers: 0");
Network::Handle("getServersResponse", [] (Network::Address address, std::string data)
{

View File

@ -51,6 +51,8 @@ namespace Components
static void Frame();
static std::vector<ServerInfo>* GetList();
static void UpdateVisibleInfo();
private:
enum Column
{