mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Extract UpdateServerFriends
function, cache friends on server
Calculate the number of friends on each server when refreshing the friend state of the server info instead of every time the server entry is rendered.
This commit is contained in:
parent
7e8442d394
commit
cf35594fa4
|
@ -408,14 +408,7 @@ void CServerBrowser::Filter()
|
|||
|
||||
if(!Filtered)
|
||||
{
|
||||
// check for friend
|
||||
Info.m_FriendState = IFriends::FRIEND_NO;
|
||||
for(int p = 0; p < minimum(Info.m_NumClients, (int)MAX_CLIENTS); p++)
|
||||
{
|
||||
Info.m_aClients[p].m_FriendState = m_pFriends->GetFriendState(Info.m_aClients[p].m_aName,
|
||||
Info.m_aClients[p].m_aClan);
|
||||
Info.m_FriendState = maximum(Info.m_FriendState, Info.m_aClients[p].m_FriendState);
|
||||
}
|
||||
UpdateServerFriends(&Info);
|
||||
|
||||
if(!g_Config.m_BrFilterFriends || Info.m_FriendState != IFriends::FRIEND_NO)
|
||||
m_pSortedServerlist[m_NumSortedServers++] = i;
|
||||
|
@ -1330,6 +1323,19 @@ void CServerBrowser::UpdateServerFilteredPlayers(CServerInfo *pInfo) const
|
|||
}
|
||||
}
|
||||
|
||||
void CServerBrowser::UpdateServerFriends(CServerInfo *pInfo) const
|
||||
{
|
||||
pInfo->m_FriendState = IFriends::FRIEND_NO;
|
||||
pInfo->m_FriendNum = 0;
|
||||
for(int ClientIndex = 0; ClientIndex < minimum(pInfo->m_NumReceivedClients, (int)MAX_CLIENTS); ClientIndex++)
|
||||
{
|
||||
pInfo->m_aClients[ClientIndex].m_FriendState = m_pFriends->GetFriendState(pInfo->m_aClients[ClientIndex].m_aName, pInfo->m_aClients[ClientIndex].m_aClan);
|
||||
pInfo->m_FriendState = maximum(pInfo->m_FriendState, pInfo->m_aClients[ClientIndex].m_FriendState);
|
||||
if(pInfo->m_aClients[ClientIndex].m_FriendState != IFriends::FRIEND_NO)
|
||||
pInfo->m_FriendNum++;
|
||||
}
|
||||
}
|
||||
|
||||
const char *CServerBrowser::GetTutorialServer()
|
||||
{
|
||||
// Use DDNet tab as default after joining tutorial, also makes sure Find() actually works
|
||||
|
|
|
@ -60,6 +60,7 @@ public:
|
|||
void LoadDDNetInfoJson();
|
||||
const json_value *LoadDDNetInfo();
|
||||
void UpdateServerFilteredPlayers(CServerInfo *pInfo) const;
|
||||
void UpdateServerFriends(CServerInfo *pInfo) const;
|
||||
CServerInfo::ERankState HasRank(const char *pMap);
|
||||
|
||||
const std::vector<CCommunity> &Communities() const override;
|
||||
|
|
|
@ -80,6 +80,7 @@ public:
|
|||
|
||||
int m_QuickSearchHit;
|
||||
int m_FriendState;
|
||||
int m_FriendNum;
|
||||
|
||||
int m_MaxClients;
|
||||
int m_NumClients;
|
||||
|
|
|
@ -248,19 +248,6 @@ void CMenus::RenderServerbrowserServerList(CUIRect View, bool &WasListboxItemAct
|
|||
if(ListItem.m_Selected)
|
||||
m_SelectedIndex = i;
|
||||
|
||||
// update friend counter
|
||||
int FriendsOnServer = 0;
|
||||
if(pItem->m_FriendState != IFriends::FRIEND_NO)
|
||||
{
|
||||
for(int j = 0; j < pItem->m_NumReceivedClients; ++j)
|
||||
{
|
||||
if(pItem->m_aClients[j].m_FriendState != IFriends::FRIEND_NO)
|
||||
{
|
||||
FriendsOnServer++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!ListItem.m_Visible)
|
||||
{
|
||||
// reset active item, if not visible
|
||||
|
@ -374,9 +361,9 @@ void CMenus::RenderServerbrowserServerList(CUIRect View, bool &WasListboxItemAct
|
|||
Button.VSplitRight(50.0f, &Icon, &Button);
|
||||
Icon.Margin(2.0f, &Icon);
|
||||
RenderBrowserIcons(*pUiElement->Rect(UI_ELEM_FRIEND_ICON), &Icon, ColorRGBA(0.94f, 0.4f, 0.4f, 1.0f), TextRender()->DefaultTextOutlineColor(), FONT_ICON_HEART, TEXTALIGN_MC);
|
||||
if(FriendsOnServer > 1)
|
||||
if(pItem->m_FriendNum > 1)
|
||||
{
|
||||
str_from_int(FriendsOnServer, aTemp);
|
||||
str_from_int(pItem->m_FriendNum, aTemp);
|
||||
TextRender()->TextColor(0.94f, 0.8f, 0.8f, 1.0f);
|
||||
UI()->DoLabel(&Icon, aTemp, 9.0f, TEXTALIGN_MC);
|
||||
TextRender()->TextColor(TextRender()->DefaultTextColor());
|
||||
|
|
Loading…
Reference in a new issue