This commit is contained in:
def 2018-10-29 22:03:57 +01:00
parent 5b436adff8
commit faf388b853
4 changed files with 32 additions and 33 deletions

View file

@ -147,7 +147,7 @@ bool CServerBrowser::SortCompareNumPlayers(int Index1, int Index2) const
{ {
CServerEntry *a = m_ppServerlist[Index1]; CServerEntry *a = m_ppServerlist[Index1];
CServerEntry *b = m_ppServerlist[Index2]; CServerEntry *b = m_ppServerlist[Index2];
return FilteredPlayers(a->m_Info) < FilteredPlayers(b->m_Info); return a->m_Info.m_NumFilteredPlayers < b->m_Info.m_NumFilteredPlayers;
} }
bool CServerBrowser::SortCompareNumClients(int Index1, int Index2) const bool CServerBrowser::SortCompareNumClients(int Index1, int Index2) const
@ -157,32 +157,6 @@ bool CServerBrowser::SortCompareNumClients(int Index1, int Index2) const
return a->m_Info.m_NumClients < b->m_Info.m_NumClients; return a->m_Info.m_NumClients < b->m_Info.m_NumClients;
} }
int CServerBrowser::FilteredPlayers(const CServerInfo &Item) const
{
int NumPlayers = 0;
for(int i = 0; i < MAX_CLIENTS; i++)
{
const CServerInfo::CClient &Client = Item.m_aClients[i];
if(Client.m_aName[0] == '\0')
continue;
if(g_Config.m_BrFilterSpectators && !Client.m_Player)
continue;
if(g_Config.m_BrFilterFriends && Client.m_FriendState == IFriends::FRIEND_NO)
continue;
if(g_Config.m_BrFilterConnectingPlayers && str_comp(Client.m_aName, "(connecting)") == 0 && Client.m_aClan[0] == '\0' && Client.m_Country == -1 && Client.m_Score == 0)
continue;
NumPlayers++;
}
return NumPlayers;
}
void CServerBrowser::Filter() void CServerBrowser::Filter()
{ {
int i = 0, p = 0; int i = 0, p = 0;
@ -202,7 +176,7 @@ void CServerBrowser::Filter()
{ {
int Filtered = 0; int Filtered = 0;
if(g_Config.m_BrFilterEmpty && FilteredPlayers(m_ppServerlist[i]->m_Info) == 0) if(g_Config.m_BrFilterEmpty && m_ppServerlist[i]->m_Info.m_NumFilteredPlayers == 0)
Filtered = 1; Filtered = 1;
else if(g_Config.m_BrFilterFull && Players(m_ppServerlist[i]->m_Info) == Max(m_ppServerlist[i]->m_Info)) else if(g_Config.m_BrFilterFull && Players(m_ppServerlist[i]->m_Info) == Max(m_ppServerlist[i]->m_Info))
Filtered = 1; Filtered = 1;
@ -360,10 +334,37 @@ int CServerBrowser::SortHash() const
return i; return i;
} }
void SetFilteredPlayers(const CServerInfo &Item)
{
Item.m_NumFilteredPlayers = 0;
for(int i = 0; i < MAX_CLIENTS; i++)
{
const CServerInfo::CClient &Client = Item.m_aClients[i];
if(Client.m_aName[0] == '\0')
continue;
if(g_Config.m_BrFilterSpectators && !Client.m_Player)
continue;
if(g_Config.m_BrFilterConnectingPlayers && str_comp(Client.m_aName, "(connecting)") == 0 && Client.m_aClan[0] == '\0' && Client.m_Country == -1 && Client.m_Score == 0)
continue;
Item.m_NumFilteredPlayers++;
}
}
void CServerBrowser::Sort() void CServerBrowser::Sort()
{ {
int i; int i;
// fill m_NumFilteredPlayers
for(i = 0; i < m_NumServers; i++)
{
SetFilteredPlayers(m_ppServerlist[i]->m_Info);
}
// create filtered list // create filtered list
Filter(); Filter();

View file

@ -68,8 +68,6 @@ public:
int NumServers() const { return m_NumServers; } int NumServers() const { return m_NumServers; }
int FilteredPlayers(const CServerInfo &Item) const;
int Players(const CServerInfo &Item) const int Players(const CServerInfo &Item) const
{ {
return g_Config.m_BrFilterSpectators ? Item.m_NumPlayers : Item.m_NumClients; return g_Config.m_BrFilterSpectators ? Item.m_NumPlayers : Item.m_NumClients;

View file

@ -59,6 +59,7 @@ public:
char m_aVersion[32]; char m_aVersion[32];
char m_aAddress[NETADDR_MAXSTRSIZE]; char m_aAddress[NETADDR_MAXSTRSIZE];
CClient m_aClients[MAX_CLIENTS]; CClient m_aClients[MAX_CLIENTS];
mutable int m_NumFilteredPlayers;
}; };
bool IsVanilla(const CServerInfo *pInfo); bool IsVanilla(const CServerInfo *pInfo);
@ -116,7 +117,6 @@ public:
virtual int NumServers() const = 0; virtual int NumServers() const = 0;
virtual int FilteredPlayers(const CServerInfo &Item) const = 0;
virtual int Players(const CServerInfo &Item) const = 0; virtual int Players(const CServerInfo &Item) const = 0;
virtual int Max(const CServerInfo &Item) const = 0; virtual int Max(const CServerInfo &Item) const = 0;

View file

@ -243,7 +243,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
{ {
int ItemIndex = i; int ItemIndex = i;
const CServerInfo *pItem = ServerBrowser()->SortedGet(ItemIndex); const CServerInfo *pItem = ServerBrowser()->SortedGet(ItemIndex);
NumPlayers += ServerBrowser()->FilteredPlayers(*pItem); NumPlayers += pItem->m_NumFilteredPlayers;
CUIRect Row; CUIRect Row;
CUIRect SelectHitBox; CUIRect SelectHitBox;
@ -407,7 +407,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
DoButton_Icon(IMAGE_BROWSEICONS, SPRITE_BROWSE_HEART, &Icon); DoButton_Icon(IMAGE_BROWSEICONS, SPRITE_BROWSE_HEART, &Icon);
} }
str_format(aTemp, sizeof(aTemp), "%i/%i", ServerBrowser()->FilteredPlayers(*pItem), ServerBrowser()->Max(*pItem)); str_format(aTemp, sizeof(aTemp), "%i/%i", pItem->m_NumFilteredPlayers, ServerBrowser()->Max(*pItem));
if(g_Config.m_BrFilterString[0] && (pItem->m_QuickSearchHit&IServerBrowser::QUICK_PLAYER)) if(g_Config.m_BrFilterString[0] && (pItem->m_QuickSearchHit&IServerBrowser::QUICK_PLAYER))
TextRender()->TextColor(0.4f,0.4f,1.0f,1); TextRender()->TextColor(0.4f,0.4f,1.0f,1);
UI()->DoLabelScaled(&Button, aTemp, 12.0f, 1); UI()->DoLabelScaled(&Button, aTemp, 12.0f, 1);