From 13f324ccf498355bbd00f0cb695d8dd0dc8ecb7a Mon Sep 17 00:00:00 2001 From: dobrykafe Date: Sun, 3 Mar 2024 02:01:28 +0100 Subject: [PATCH] add sort by number of friends to server browser --- src/engine/client/serverbrowser.cpp | 13 ++++++++++ src/engine/client/serverbrowser.h | 1 + src/engine/serverbrowser.h | 2 ++ src/game/client/components/menus_browser.cpp | 27 +++++++++++++------- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/engine/client/serverbrowser.cpp b/src/engine/client/serverbrowser.cpp index b75d56b57..9f2a0802f 100644 --- a/src/engine/client/serverbrowser.cpp +++ b/src/engine/client/serverbrowser.cpp @@ -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) diff --git a/src/engine/client/serverbrowser.h b/src/engine/client/serverbrowser.h index b2c57d402..0e3c8683e 100644 --- a/src/engine/client/serverbrowser.h +++ b/src/engine/client/serverbrowser.h @@ -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; // diff --git a/src/engine/serverbrowser.h b/src/engine/serverbrowser.h index f358764d1..919ee10fb 100644 --- a/src/engine/serverbrowser.h +++ b/src/engine/serverbrowser.h @@ -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, diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index a46dc28c2..b9d7b7372 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -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)) {