add sort by number of friends to server browser

This commit is contained in:
dobrykafe 2024-03-03 02:01:28 +01:00
parent 9620a9d3d9
commit 13f324ccf4
4 changed files with 34 additions and 9 deletions

View file

@ -388,6 +388,17 @@ bool CServerBrowser::SortCompareNumClients(int Index1, int Index2) const
return pIndex1->m_Info.m_NumClients > pIndex2->m_Info.m_NumClients;
}
bool CServerBrowser::SortCompareNumFriends(int Index1, int Index2) const
{
CServerEntry *pIndex1 = m_ppServerlist[Index1];
CServerEntry *pIndex2 = m_ppServerlist[Index2];
if(pIndex1->m_Info.m_FriendNum == pIndex2->m_Info.m_FriendNum)
return pIndex1->m_Info.m_NumFilteredPlayers > pIndex2->m_Info.m_NumFilteredPlayers;
else
return pIndex1->m_Info.m_FriendNum > pIndex2->m_Info.m_FriendNum;
}
bool CServerBrowser::SortCompareNumPlayersAndPing(int Index1, int Index2) const
{
CServerEntry *pIndex1 = m_ppServerlist[Index1];
@ -609,6 +620,8 @@ void CServerBrowser::Sort()
std::stable_sort(m_pSortedServerlist, m_pSortedServerlist + m_NumSortedServers, CSortWrap(this, &CServerBrowser::SortComparePing));
else if(g_Config.m_BrSort == IServerBrowser::SORT_MAP)
std::stable_sort(m_pSortedServerlist, m_pSortedServerlist + m_NumSortedServers, CSortWrap(this, &CServerBrowser::SortCompareMap));
else if(g_Config.m_BrSort == IServerBrowser::SORT_NUMFRIENDS)
std::stable_sort(m_pSortedServerlist, m_pSortedServerlist + m_NumSortedServers, CSortWrap(this, &CServerBrowser::SortCompareNumFriends));
else if(g_Config.m_BrSort == IServerBrowser::SORT_NUMPLAYERS)
std::stable_sort(m_pSortedServerlist, m_pSortedServerlist + m_NumSortedServers, CSortWrap(this, &CServerBrowser::SortCompareNumPlayers));
else if(g_Config.m_BrSort == IServerBrowser::SORT_GAMETYPE)

View file

@ -346,6 +346,7 @@ private:
bool SortCompareGametype(int Index1, int Index2) const;
bool SortCompareNumPlayers(int Index1, int Index2) const;
bool SortCompareNumClients(int Index1, int Index2) const;
bool SortCompareNumFriends(int Index1, int Index2) const;
bool SortCompareNumPlayersAndPing(int Index1, int Index2) const;
//

View file

@ -257,6 +257,7 @@ public:
SORT_MAP - Sort by map
SORT_GAMETYPE - Sort by game type. DM, TDM etc.
SORT_NUMPLAYERS - Sort after how many players there are on the server.
SORT_NUMFRIENDS - Sort after how many friends there are on the server.
*/
enum
{
@ -265,6 +266,7 @@ public:
SORT_MAP,
SORT_GAMETYPE,
SORT_NUMPLAYERS,
SORT_NUMFRIENDS,
QUICK_SERVERNAME = 1,
QUICK_PLAYER = 2,

View file

@ -108,6 +108,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View, bool &WasListboxItemAct
COL_NAME,
COL_GAMETYPE,
COL_MAP,
COL_FRIENDS,
COL_PLAYERS,
COL_PING,
@ -135,7 +136,8 @@ void CMenus::RenderServerbrowserServerList(CUIRect View, bool &WasListboxItemAct
{COL_NAME, IServerBrowser::SORT_NAME, Localizable("Name"), 0, 50.0f, {0}},
{COL_GAMETYPE, IServerBrowser::SORT_GAMETYPE, Localizable("Type"), 1, 50.0f, {0}},
{COL_MAP, IServerBrowser::SORT_MAP, Localizable("Map"), 1, 120.0f + (Headers.w - 480) / 8, {0}},
{COL_PLAYERS, IServerBrowser::SORT_NUMPLAYERS, Localizable("Players"), 1, 85.0f, {0}},
{COL_FRIENDS, IServerBrowser::SORT_NUMFRIENDS, "", 1, 20.0f, {0}},
{COL_PLAYERS, IServerBrowser::SORT_NUMPLAYERS, Localizable("Players"), 1, 60.0f, {0}},
{-1, -1, "", 1, 4.0f, {0}},
{COL_PING, IServerBrowser::SORT_PING, Localizable("Ping"), 1, 40.0f, {0}},
};
@ -191,6 +193,15 @@ void CMenus::RenderServerbrowserServerList(CUIRect View, bool &WasListboxItemAct
g_Config.m_BrSort = Col.m_Sort;
}
}
if(Col.m_ID == COL_FRIENDS)
{
TextRender()->SetFontPreset(EFontPreset::ICON_FONT);
TextRender()->SetRenderFlags(ETextRenderFlags::TEXT_RENDER_FLAG_ONLY_ADVANCE_WIDTH | ETextRenderFlags::TEXT_RENDER_FLAG_NO_X_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_Y_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_PIXEL_ALIGMENT | ETextRenderFlags::TEXT_RENDER_FLAG_NO_OVERSIZE);
UI()->DoLabel(&Col.m_Rect, FONT_ICON_HEART, 14.0f, TEXTALIGN_MC);
TextRender()->SetRenderFlags(0);
TextRender()->SetFontPreset(EFontPreset::DEFAULT_FONT);
}
}
const int NumServers = ServerBrowser()->NumSortedServers();
@ -374,25 +385,23 @@ void CMenus::RenderServerbrowserServerList(CUIRect View, bool &WasListboxItemAct
if(!Printed)
UI()->DoLabelStreamed(*pUiElement->Rect(UI_ELEM_MAP_1), &Button, pItem->m_aMap, FontSize, TEXTALIGN_ML, Props);
}
else if(ID == COL_PLAYERS)
else if(ID == COL_FRIENDS)
{
Button.VMargin(2.0f, &Button);
if(pItem->m_FriendState != IFriends::FRIEND_NO)
{
CUIRect Icon;
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);
RenderBrowserIcons(*pUiElement->Rect(UI_ELEM_FRIEND_ICON), &Button, ColorRGBA(0.94f, 0.4f, 0.4f, 1.0f), TextRender()->DefaultTextOutlineColor(), FONT_ICON_HEART, TEXTALIGN_MC);
if(pItem->m_FriendNum > 1)
{
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);
UI()->DoLabel(&Button, aTemp, 9.0f, TEXTALIGN_MC);
TextRender()->TextColor(TextRender()->DefaultTextColor());
}
}
}
else if(ID == COL_PLAYERS)
{
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))
{