Skip to content

Commit 968576f

Browse files
committed
Reimplement legacy DDNet and KoG tabs
1 parent df7eeee commit 968576f

File tree

3 files changed

+128
-43
lines changed

3 files changed

+128
-43
lines changed

src/engine/client/serverbrowser.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,6 +1734,28 @@ std::vector<const CCommunity *> CServerBrowser::SelectedCommunities() const
17341734

17351735
std::vector<const CCommunity *> CServerBrowser::FavoriteCommunities() const
17361736
{
1737+
if(g_Config.m_ClEnableCommunities == 0)
1738+
{
1739+
std::vector<const CCommunity *> vpFavorites;
1740+
auto FindCommunity = [this](const char *pCommunityId) -> const CCommunity * {
1741+
const auto CommunityIt = std::find_if(Communities().begin(), Communities().end(), [pCommunityId](const auto &Elem) {
1742+
return str_comp(Elem.Id(), pCommunityId) == 0;
1743+
});
1744+
return CommunityIt == Communities().end() ? nullptr : &(*CommunityIt);
1745+
};
1746+
static const std::vector<CCommunityId> vHardcoded{CCommunityId(IServerBrowser::COMMUNITY_DDNET), CCommunityId("kog")};
1747+
1748+
for(const auto &CommunityId : vHardcoded)
1749+
{
1750+
const CCommunity *pCommunity = FindCommunity(CommunityId.Id());
1751+
if(pCommunity)
1752+
{
1753+
vpFavorites.push_back(pCommunity);
1754+
}
1755+
}
1756+
return vpFavorites;
1757+
}
1758+
17371759
// This is done differently than SelectedCommunities because the favorite
17381760
// communities should be returned in the order specified by the user.
17391761
std::vector<const CCommunity *> vpFavorites;

src/game/client/components/menus.cpp

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ int CMenus::DoButton_MenuTab(CButtonContainer *pButtonContainer, const char *pTe
229229
}
230230
}
231231

232-
if(pCommunityIcon)
232+
if(pCommunityIcon && g_Config.m_ClPreferIconButtons)
233233
{
234234
CUIRect CommunityIcon;
235235
Rect.Margin(2.0f, &CommunityIcon);
@@ -662,6 +662,31 @@ void CMenus::RenderMenubar(CUIRect Box, IClient::EClientState ClientState)
662662
NewPage = PAGE_FAVORITES;
663663
}
664664
GameClient()->m_Tooltips.DoToolTip(&s_FavoritesButton, &Button, Localize("Favorites"));
665+
666+
size_t FavoriteCommunityIndex = 0;
667+
static CButtonContainer s_aFavoriteCommunityButtons[5];
668+
static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)PAGE_FAVORITE_COMMUNITY_5 - PAGE_FAVORITE_COMMUNITY_1 + 1);
669+
static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)BIT_TAB_FAVORITE_COMMUNITY_5 - BIT_TAB_FAVORITE_COMMUNITY_1 + 1);
670+
static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)IServerBrowser::TYPE_FAVORITE_COMMUNITY_5 - IServerBrowser::TYPE_FAVORITE_COMMUNITY_1 + 1);
671+
for(const CCommunity *pCommunity : ServerBrowser()->FavoriteCommunities())
672+
{
673+
if(Box.w < BrowserButtonWidth)
674+
break;
675+
Box.VSplitLeft(BrowserButtonWidth, &Button, &Box);
676+
const int Page = PAGE_FAVORITE_COMMUNITY_1 + FavoriteCommunityIndex;
677+
if(DoButton_MenuTab(&s_aFavoriteCommunityButtons[FavoriteCommunityIndex], FONT_ICON_ELLIPSIS, ActivePage == Page, &Button, IGraphics::CORNER_T, &m_aAnimatorsBigPage[BIT_TAB_FAVORITE_COMMUNITY_1 + FavoriteCommunityIndex], nullptr, nullptr, nullptr, 10.0f, FindCommunityIcon(pCommunity->Id())))
678+
{
679+
NewPage = Page;
680+
}
681+
GameClient()->m_Tooltips.DoToolTip(&s_aFavoriteCommunityButtons[FavoriteCommunityIndex], &Button, pCommunity->Name());
682+
683+
++FavoriteCommunityIndex;
684+
if(FavoriteCommunityIndex >= std::size(s_aFavoriteCommunityButtons))
685+
break;
686+
}
687+
688+
TextRender()->SetRenderFlags(0);
689+
TextRender()->SetFontPreset(EFontPreset::DEFAULT_FONT);
665690
}
666691
else
667692
{
@@ -688,8 +713,42 @@ void CMenus::RenderMenubar(CUIRect Box, IClient::EClientState ClientState)
688713
{
689714
NewPage = PAGE_FAVORITES;
690715
}
691-
TextRender()->SetFontPreset(EFontPreset::ICON_FONT);
692-
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);
716+
717+
size_t FavoriteCommunityIndex = 0;
718+
static CButtonContainer s_aFavoriteCommunityButtons[5];
719+
static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)PAGE_FAVORITE_COMMUNITY_5 - PAGE_FAVORITE_COMMUNITY_1 + 1);
720+
static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)BIT_TAB_FAVORITE_COMMUNITY_5 - BIT_TAB_FAVORITE_COMMUNITY_1 + 1);
721+
static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)IServerBrowser::TYPE_FAVORITE_COMMUNITY_5 - IServerBrowser::TYPE_FAVORITE_COMMUNITY_1 + 1);
722+
for(const CCommunity *pCommunity : ServerBrowser()->FavoriteCommunities())
723+
{
724+
if(Box.w < BrowserButtonWidth)
725+
break;
726+
Box.VSplitLeft(BrowserButtonWidth, &Button, &Box);
727+
const int Page = PAGE_FAVORITE_COMMUNITY_1 + FavoriteCommunityIndex;
728+
const char *pName = pCommunity->Name();
729+
730+
if(g_Config.m_ClEnableCommunities == 0)
731+
{
732+
if(str_comp(pCommunity->Id(), IServerBrowser::COMMUNITY_DDNET) == 0)
733+
{
734+
pName = "DDNet";
735+
}
736+
else if(str_comp(pCommunity->Id(), "kog") == 0)
737+
{
738+
pName = "KoG";
739+
}
740+
}
741+
742+
if(DoButton_MenuTab(&s_aFavoriteCommunityButtons[FavoriteCommunityIndex], pName, ActivePage == Page, &Button, IGraphics::CORNER_T, &m_aAnimatorsBigPage[BIT_TAB_FAVORITE_COMMUNITY_1 + FavoriteCommunityIndex], nullptr, nullptr, nullptr, 10.0f, FindCommunityIcon(pCommunity->Id())))
743+
{
744+
NewPage = Page;
745+
}
746+
GameClient()->m_Tooltips.DoToolTip(&s_aFavoriteCommunityButtons[FavoriteCommunityIndex], &Button, pCommunity->Name());
747+
748+
++FavoriteCommunityIndex;
749+
if(FavoriteCommunityIndex >= std::size(s_aFavoriteCommunityButtons))
750+
break;
751+
}
693752
}
694753

695754
int MaxPage = PAGE_FAVORITES + ServerBrowser()->FavoriteCommunities().size();
@@ -712,31 +771,6 @@ void CMenus::RenderMenubar(CUIRect Box, IClient::EClientState ClientState)
712771
NewPage = MaxPage;
713772
}
714773
}
715-
716-
size_t FavoriteCommunityIndex = 0;
717-
static CButtonContainer s_aFavoriteCommunityButtons[5];
718-
static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)PAGE_FAVORITE_COMMUNITY_5 - PAGE_FAVORITE_COMMUNITY_1 + 1);
719-
static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)BIT_TAB_FAVORITE_COMMUNITY_5 - BIT_TAB_FAVORITE_COMMUNITY_1 + 1);
720-
static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)IServerBrowser::TYPE_FAVORITE_COMMUNITY_5 - IServerBrowser::TYPE_FAVORITE_COMMUNITY_1 + 1);
721-
for(const CCommunity *pCommunity : ServerBrowser()->FavoriteCommunities())
722-
{
723-
if(Box.w < BrowserButtonWidth)
724-
break;
725-
Box.VSplitLeft(BrowserButtonWidth, &Button, &Box);
726-
const int Page = PAGE_FAVORITE_COMMUNITY_1 + FavoriteCommunityIndex;
727-
if(DoButton_MenuTab(&s_aFavoriteCommunityButtons[FavoriteCommunityIndex], FONT_ICON_ELLIPSIS, ActivePage == Page, &Button, IGraphics::CORNER_T, &m_aAnimatorsBigPage[BIT_TAB_FAVORITE_COMMUNITY_1 + FavoriteCommunityIndex], nullptr, nullptr, nullptr, 10.0f, FindCommunityIcon(pCommunity->Id())))
728-
{
729-
NewPage = Page;
730-
}
731-
GameClient()->m_Tooltips.DoToolTip(&s_aFavoriteCommunityButtons[FavoriteCommunityIndex], &Button, pCommunity->Name());
732-
733-
++FavoriteCommunityIndex;
734-
if(FavoriteCommunityIndex >= std::size(s_aFavoriteCommunityButtons))
735-
break;
736-
}
737-
738-
TextRender()->SetRenderFlags(0);
739-
TextRender()->SetFontPreset(EFontPreset::DEFAULT_FONT);
740774
}
741775
else
742776
{

src/game/client/components/menus_ingame.cpp

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,24 @@ void CMenus::RenderInGameNetwork(CUIRect MainView)
10861086
NewPage = PAGE_FAVORITES;
10871087
}
10881088
GameClient()->m_Tooltips.DoToolTip(&s_FavoritesButton, &Button, Localize("Favorites"));
1089+
1090+
size_t FavoriteCommunityIndex = 0;
1091+
static CButtonContainer s_aFavoriteCommunityButtons[5];
1092+
static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)PAGE_FAVORITE_COMMUNITY_5 - PAGE_FAVORITE_COMMUNITY_1 + 1);
1093+
for(const CCommunity *pCommunity : ServerBrowser()->FavoriteCommunities())
1094+
{
1095+
TabBar.VSplitLeft(75.0f, &Button, &TabBar);
1096+
const int Page = PAGE_FAVORITE_COMMUNITY_1 + FavoriteCommunityIndex;
1097+
if(DoButton_MenuTab(&s_aFavoriteCommunityButtons[FavoriteCommunityIndex], FONT_ICON_ELLIPSIS, g_Config.m_UiPage == Page, &Button, IGraphics::CORNER_NONE, nullptr, nullptr, nullptr, nullptr, 10.0f, FindCommunityIcon(pCommunity->Id())))
1098+
{
1099+
NewPage = Page;
1100+
}
1101+
GameClient()->m_Tooltips.DoToolTip(&s_aFavoriteCommunityButtons[FavoriteCommunityIndex], &Button, pCommunity->Name());
1102+
1103+
++FavoriteCommunityIndex;
1104+
if(FavoriteCommunityIndex >= std::size(s_aFavoriteCommunityButtons))
1105+
break;
1106+
}
10891107
}
10901108
else
10911109
{
@@ -1112,24 +1130,35 @@ void CMenus::RenderInGameNetwork(CUIRect MainView)
11121130
{
11131131
NewPage = PAGE_FAVORITES;
11141132
}
1115-
}
11161133

1117-
size_t FavoriteCommunityIndex = 0;
1118-
static CButtonContainer s_aFavoriteCommunityButtons[5];
1119-
static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)PAGE_FAVORITE_COMMUNITY_5 - PAGE_FAVORITE_COMMUNITY_1 + 1);
1120-
for(const CCommunity *pCommunity : ServerBrowser()->FavoriteCommunities())
1121-
{
1122-
TabBar.VSplitLeft(75.0f, &Button, &TabBar);
1123-
const int Page = PAGE_FAVORITE_COMMUNITY_1 + FavoriteCommunityIndex;
1124-
if(DoButton_MenuTab(&s_aFavoriteCommunityButtons[FavoriteCommunityIndex], FONT_ICON_ELLIPSIS, g_Config.m_UiPage == Page, &Button, IGraphics::CORNER_NONE, nullptr, nullptr, nullptr, nullptr, 10.0f, FindCommunityIcon(pCommunity->Id())))
1134+
size_t FavoriteCommunityIndex = 0;
1135+
static CButtonContainer s_aFavoriteCommunityButtons[5];
1136+
static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)PAGE_FAVORITE_COMMUNITY_5 - PAGE_FAVORITE_COMMUNITY_1 + 1);
1137+
for(const CCommunity *pCommunity : ServerBrowser()->FavoriteCommunities())
11251138
{
1126-
NewPage = Page;
1127-
}
1128-
GameClient()->m_Tooltips.DoToolTip(&s_aFavoriteCommunityButtons[FavoriteCommunityIndex], &Button, pCommunity->Name());
1139+
TabBar.VSplitLeft(75.0f, &Button, &TabBar);
1140+
const int Page = PAGE_FAVORITE_COMMUNITY_1 + FavoriteCommunityIndex;
1141+
const char *pName = pCommunity->Name();
1142+
if(g_Config.m_ClEnableCommunities == 0)
1143+
{
1144+
if(str_comp(pCommunity->Id(), IServerBrowser::COMMUNITY_DDNET) == 0)
1145+
{
1146+
pName = "DDNet";
1147+
}
1148+
else if(str_comp(pCommunity->Id(), "kog") == 0)
1149+
{
1150+
pName = "KoG";
1151+
}
1152+
}
1153+
if(DoButton_MenuTab(&s_aFavoriteCommunityButtons[FavoriteCommunityIndex], pName, g_Config.m_UiPage == Page, &Button, IGraphics::CORNER_NONE, nullptr, nullptr, nullptr, nullptr, 10.0f, FindCommunityIcon(pCommunity->Id())))
1154+
{
1155+
NewPage = Page;
1156+
}
11291157

1130-
++FavoriteCommunityIndex;
1131-
if(FavoriteCommunityIndex >= std::size(s_aFavoriteCommunityButtons))
1132-
break;
1158+
++FavoriteCommunityIndex;
1159+
if(FavoriteCommunityIndex >= std::size(s_aFavoriteCommunityButtons))
1160+
break;
1161+
}
11331162
}
11341163

11351164
TextRender()->SetRenderFlags(0);

0 commit comments

Comments
 (0)