Skip to content

Commit

Permalink
Reimplement legacy DDNet and KoG tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaffeine committed Jul 13, 2024
1 parent 1f7cae0 commit 4579916
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 40 deletions.
22 changes: 22 additions & 0 deletions src/engine/client/serverbrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,28 @@ std::vector<const CCommunity *> CServerBrowser::SelectedCommunities() const

std::vector<const CCommunity *> CServerBrowser::FavoriteCommunities() const
{
if(g_Config.m_ClEnableCommunities == 0)
{
std::vector<const CCommunity *> vpFavorites;
auto FindCommunity = [this](const char *pCommunityId) -> const CCommunity * {
const auto CommunityIt = std::find_if(Communities().begin(), Communities().end(), [pCommunityId](const auto &Elem) {
return str_comp(Elem.Id(), pCommunityId) == 0;
});
return CommunityIt == Communities().end() ? nullptr : &(*CommunityIt);
};
static const std::vector<CCommunityId> vHardcoded{CCommunityId(IServerBrowser::COMMUNITY_DDNET), CCommunityId("kog")};

for(const auto &CommunityId : vHardcoded)
{
const CCommunity *pCommunity = FindCommunity(CommunityId.Id());
if(pCommunity)
{
vpFavorites.push_back(pCommunity);
}
}
return vpFavorites;
}

// This is done differently than SelectedCommunities because the favorite
// communities should be returned in the order specified by the user.
std::vector<const CCommunity *> vpFavorites;
Expand Down
84 changes: 59 additions & 25 deletions src/game/client/components/menus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ int CMenus::DoButton_MenuTab(CButtonContainer *pButtonContainer, const char *pTe
}
}

if(pCommunityIcon)
if(pCommunityIcon && g_Config.m_ClPreferIconButtons)
{
CUIRect CommunityIcon;
Rect.Margin(2.0f, &CommunityIcon);
Expand Down Expand Up @@ -657,6 +657,31 @@ void CMenus::RenderMenubar(CUIRect Box, IClient::EClientState ClientState)
NewPage = PAGE_FAVORITES;
}
GameClient()->m_Tooltips.DoToolTip(&s_FavoritesButton, &Button, Localize("Favorites"));

size_t FavoriteCommunityIndex = 0;
static CButtonContainer s_aFavoriteCommunityButtons[5];
static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)PAGE_FAVORITE_COMMUNITY_5 - PAGE_FAVORITE_COMMUNITY_1 + 1);
static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)BIT_TAB_FAVORITE_COMMUNITY_5 - BIT_TAB_FAVORITE_COMMUNITY_1 + 1);
static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)IServerBrowser::TYPE_FAVORITE_COMMUNITY_5 - IServerBrowser::TYPE_FAVORITE_COMMUNITY_1 + 1);
for(const CCommunity *pCommunity : ServerBrowser()->FavoriteCommunities())
{
if(Box.w < BrowserButtonWidth)
break;
Box.VSplitLeft(BrowserButtonWidth, &Button, &Box);
const int Page = PAGE_FAVORITE_COMMUNITY_1 + FavoriteCommunityIndex;
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())))
{
NewPage = Page;
}
GameClient()->m_Tooltips.DoToolTip(&s_aFavoriteCommunityButtons[FavoriteCommunityIndex], &Button, pCommunity->Name());

++FavoriteCommunityIndex;
if(FavoriteCommunityIndex >= std::size(s_aFavoriteCommunityButtons))
break;
}

TextRender()->SetRenderFlags(0);
TextRender()->SetFontPreset(EFontPreset::DEFAULT_FONT);
}
else
{
Expand All @@ -683,34 +708,43 @@ void CMenus::RenderMenubar(CUIRect Box, IClient::EClientState ClientState)
{
NewPage = PAGE_FAVORITES;
}
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);
}

size_t FavoriteCommunityIndex = 0;
static CButtonContainer s_aFavoriteCommunityButtons[5];
static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)PAGE_FAVORITE_COMMUNITY_5 - PAGE_FAVORITE_COMMUNITY_1 + 1);
static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)BIT_TAB_FAVORITE_COMMUNITY_5 - BIT_TAB_FAVORITE_COMMUNITY_1 + 1);
static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)IServerBrowser::TYPE_FAVORITE_COMMUNITY_5 - IServerBrowser::TYPE_FAVORITE_COMMUNITY_1 + 1);
for(const CCommunity *pCommunity : ServerBrowser()->FavoriteCommunities())
{
if(Box.w < BrowserButtonWidth)
break;
Box.VSplitLeft(BrowserButtonWidth, &Button, &Box);
const int Page = PAGE_FAVORITE_COMMUNITY_1 + FavoriteCommunityIndex;
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())))
size_t FavoriteCommunityIndex = 0;
static CButtonContainer s_aFavoriteCommunityButtons[5];
static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)PAGE_FAVORITE_COMMUNITY_5 - PAGE_FAVORITE_COMMUNITY_1 + 1);
static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)BIT_TAB_FAVORITE_COMMUNITY_5 - BIT_TAB_FAVORITE_COMMUNITY_1 + 1);
static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)IServerBrowser::TYPE_FAVORITE_COMMUNITY_5 - IServerBrowser::TYPE_FAVORITE_COMMUNITY_1 + 1);
for(const CCommunity *pCommunity : ServerBrowser()->FavoriteCommunities())
{
NewPage = Page;
if(Box.w < BrowserButtonWidth)
break;
Box.VSplitLeft(BrowserButtonWidth, &Button, &Box);
const int Page = PAGE_FAVORITE_COMMUNITY_1 + FavoriteCommunityIndex;
const char *pName = pCommunity->Name();

if(g_Config.m_ClEnableCommunities == 0)
{
if(str_comp(pCommunity->Id(), IServerBrowser::COMMUNITY_DDNET) == 0)
{
pName = "DDNet";
}
else if(str_comp(pCommunity->Id(), "kog") == 0)
{
pName = "KoG";
}
}

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())))
{
NewPage = Page;
}
GameClient()->m_Tooltips.DoToolTip(&s_aFavoriteCommunityButtons[FavoriteCommunityIndex], &Button, pCommunity->Name());

++FavoriteCommunityIndex;
if(FavoriteCommunityIndex >= std::size(s_aFavoriteCommunityButtons))
break;
}
GameClient()->m_Tooltips.DoToolTip(&s_aFavoriteCommunityButtons[FavoriteCommunityIndex], &Button, pCommunity->Name());

++FavoriteCommunityIndex;
if(FavoriteCommunityIndex >= std::size(s_aFavoriteCommunityButtons))
break;
}

TextRender()->SetRenderFlags(0);
TextRender()->SetFontPreset(EFontPreset::DEFAULT_FONT);
}
else
{
Expand Down
59 changes: 44 additions & 15 deletions src/game/client/components/menus_ingame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,24 @@ void CMenus::RenderInGameNetwork(CUIRect MainView)
NewPage = PAGE_FAVORITES;
}
GameClient()->m_Tooltips.DoToolTip(&s_FavoritesButton, &Button, Localize("Favorites"));

size_t FavoriteCommunityIndex = 0;
static CButtonContainer s_aFavoriteCommunityButtons[5];
static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)PAGE_FAVORITE_COMMUNITY_5 - PAGE_FAVORITE_COMMUNITY_1 + 1);
for(const CCommunity *pCommunity : ServerBrowser()->FavoriteCommunities())
{
TabBar.VSplitLeft(75.0f, &Button, &TabBar);
const int Page = PAGE_FAVORITE_COMMUNITY_1 + FavoriteCommunityIndex;
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())))
{
NewPage = Page;
}
GameClient()->m_Tooltips.DoToolTip(&s_aFavoriteCommunityButtons[FavoriteCommunityIndex], &Button, pCommunity->Name());

++FavoriteCommunityIndex;
if(FavoriteCommunityIndex >= std::size(s_aFavoriteCommunityButtons))
break;
}
}
else
{
Expand All @@ -903,24 +921,35 @@ void CMenus::RenderInGameNetwork(CUIRect MainView)
{
NewPage = PAGE_FAVORITES;
}
}

size_t FavoriteCommunityIndex = 0;
static CButtonContainer s_aFavoriteCommunityButtons[5];
static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)PAGE_FAVORITE_COMMUNITY_5 - PAGE_FAVORITE_COMMUNITY_1 + 1);
for(const CCommunity *pCommunity : ServerBrowser()->FavoriteCommunities())
{
TabBar.VSplitLeft(75.0f, &Button, &TabBar);
const int Page = PAGE_FAVORITE_COMMUNITY_1 + FavoriteCommunityIndex;
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())))
size_t FavoriteCommunityIndex = 0;
static CButtonContainer s_aFavoriteCommunityButtons[5];
static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)PAGE_FAVORITE_COMMUNITY_5 - PAGE_FAVORITE_COMMUNITY_1 + 1);
for(const CCommunity *pCommunity : ServerBrowser()->FavoriteCommunities())
{
NewPage = Page;
}
GameClient()->m_Tooltips.DoToolTip(&s_aFavoriteCommunityButtons[FavoriteCommunityIndex], &Button, pCommunity->Name());
TabBar.VSplitLeft(75.0f, &Button, &TabBar);
const int Page = PAGE_FAVORITE_COMMUNITY_1 + FavoriteCommunityIndex;
const char *pName = pCommunity->Name();
if(g_Config.m_ClEnableCommunities == 0)
{
if(str_comp(pCommunity->Id(), IServerBrowser::COMMUNITY_DDNET) == 0)
{
pName = "DDNet";
}
else if(str_comp(pCommunity->Id(), "kog") == 0)
{
pName = "KoG";
}
}
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())))
{
NewPage = Page;
}

++FavoriteCommunityIndex;
if(FavoriteCommunityIndex >= std::size(s_aFavoriteCommunityButtons))
break;
++FavoriteCommunityIndex;
if(FavoriteCommunityIndex >= std::size(s_aFavoriteCommunityButtons))
break;
}
}

TextRender()->SetRenderFlags(0);
Expand Down

0 comments on commit 4579916

Please sign in to comment.