From 7d0e9e86c10219c16b71adebdc1ea058ea24d84c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 23 Jan 2024 22:31:01 +0100 Subject: [PATCH] Extract `CMenus::DoButton_Favorite` function To render star-icon favorite button like for favorite skins. --- src/game/client/components/menus.cpp | 18 ++++++++++++++++++ src/game/client/components/menus.h | 1 + src/game/client/components/menus_settings.cpp | 19 +------------------ 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 39e3acaeb..3a50623df 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -250,6 +250,24 @@ int CMenus::DoButton_GridHeader(const void *pID, const char *pText, int Checked, return UI()->DoButtonLogic(pID, Checked, pRect); } +int CMenus::DoButton_Favorite(const void *pButtonId, const void *pParentId, bool Checked, const CUIRect *pRect) +{ + if(Checked || (pParentId != nullptr && UI()->HotItem() == pParentId) || UI()->HotItem() == pButtonId) + { + 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); + const float Alpha = UI()->HotItem() == pButtonId ? 0.2f : 0.0f; + TextRender()->TextColor(Checked ? ColorRGBA(1.0f, 0.85f, 0.3f, 0.8f + Alpha) : ColorRGBA(0.5f, 0.5f, 0.5f, 0.8f + Alpha)); + SLabelProperties Props; + Props.m_MaxWidth = pRect->w; + UI()->DoLabel(pRect, FONT_ICON_STAR, 12.0f, TEXTALIGN_MC, Props); + TextRender()->TextColor(TextRender()->DefaultTextColor()); + TextRender()->SetRenderFlags(0); + TextRender()->SetFontPreset(EFontPreset::DEFAULT_FONT); + } + return UI()->DoButtonLogic(pButtonId, 0, pRect); +} + int CMenus::DoButton_CheckBox_Common(const void *pID, const char *pText, const char *pBoxText, const CUIRect *pRect) { CUIRect Box, Label; diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index 2d4b7fa14..ceb41b5fc 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -72,6 +72,7 @@ class CMenus : public CComponent ColorHSLA DoButton_ColorPicker(const CUIRect *pRect, unsigned int *pHslaColor, bool Alpha); void DoLaserPreview(const CUIRect *pRect, ColorHSLA OutlineColor, ColorHSLA InnerColor, const int LaserType); int DoButton_GridHeader(const void *pID, const char *pText, int Checked, const CUIRect *pRect); + int DoButton_Favorite(const void *pButtonId, const void *pParentId, bool Checked, const CUIRect *pRect); int DoKeyReader(const void *pID, const CUIRect *pRect, int Key, int ModifierCombination, int *pNewModifierCombination); diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index edc560dcd..e6875c490 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -801,19 +801,6 @@ void CMenus::RenderSettingsTee(CUIRect MainView) m_SkinListNeedsUpdate = false; } - const auto &&RenderFavIcon = [&](const CUIRect &FavIcon, bool AsFav, bool Hot) { - 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); - TextRender()->TextColor(AsFav ? ColorRGBA(1.0f, 0.85f, 0.3f, 0.8f + (Hot ? 0.2f : 0.0f)) : ColorRGBA(0.5f, 0.5f, 0.5f, 0.8f + (Hot ? 0.2f : 0.0f))); - TextRender()->TextOutlineColor(TextRender()->DefaultTextOutlineColor()); - SLabelProperties Props; - Props.m_MaxWidth = FavIcon.w; - UI()->DoLabel(&FavIcon, FONT_ICON_STAR, 12.0f, TEXTALIGN_MR, Props); - TextRender()->TextColor(TextRender()->DefaultTextColor()); - TextRender()->SetRenderFlags(0); - TextRender()->SetFontPreset(EFontPreset::DEFAULT_FONT); - }; - int OldSelected = -1; s_ListBox.DoStart(50.0f, s_vSkinList.size(), 4, 1, OldSelected, &MainView); for(size_t i = 0; i < s_vSkinList.size(); ++i) @@ -861,11 +848,7 @@ void CMenus::RenderSettingsTee(CUIRect MainView) CUIRect FavIcon; Item.m_Rect.HSplitTop(20.0f, &FavIcon, nullptr); FavIcon.VSplitRight(20.0f, nullptr, &FavIcon); - if(IsFav || UI()->HotItem() == pSkinToBeDraw || UI()->HotItem() == &pSkinToBeDraw->m_Metrics.m_Body) - { - RenderFavIcon(FavIcon, IsFav, UI()->HotItem() == &pSkinToBeDraw->m_Metrics.m_Body); - } - if(UI()->DoButtonLogic(&pSkinToBeDraw->m_Metrics.m_Body, 0, &FavIcon)) + if(DoButton_Favorite(&pSkinToBeDraw->m_Metrics.m_Body, pSkinToBeDraw, IsFav, &FavIcon)) { if(IsFav) {