3409: Menu tabs animations r=def- a=Banana090

Cool menu tabs animations, please merge


Co-authored-by: Дядя Женя <spy090@yandex.ru>
Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
bors[bot] 2020-12-15 13:55:16 +00:00 committed by GitHub
commit 0f9f71d73c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 137 additions and 27 deletions

View file

@ -96,6 +96,26 @@ CMenus::CMenus()
m_ServerProcess.Process = 0;
m_ServerProcess.Initialized = false;
for(SUIAnimator &animator : m_aAnimatorsSettingsTab)
{
animator.m_YOffset = -2.5f;
animator.m_HOffset = 5.0f;
animator.m_WOffset = 5.0f;
animator.m_RepositionLabel = true;
}
for(SUIAnimator &animator : m_aAnimatorsBigPage)
{
animator.m_YOffset = -5.0f;
animator.m_HOffset = 5.0f;
}
for(SUIAnimator &animator : m_aAnimatorsSmallPage)
{
animator.m_YOffset = -2.5f;
animator.m_HOffset = 2.5f;
}
}
float CMenus::ButtonColorMul(const void *pID)
@ -198,14 +218,43 @@ void CMenus::DoButton_KeySelect(const void *pID, const char *pText, int Checked,
UI()->DoLabel(&Temp, pText, Temp.h * ms_FontmodHeight, 0);
}
int CMenus::DoButton_MenuTab(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Corners, const ColorRGBA *pDefaultColor, const ColorRGBA *pActiveColor, const ColorRGBA *pHoverColor, float EdgeRounding, int AlignVertically)
int CMenus::DoButton_MenuTab(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Corners, SUIAnimator *pAnimator, const ColorRGBA *pDefaultColor, const ColorRGBA *pActiveColor, const ColorRGBA *pHoverColor, float EdgeRounding, int AlignVertically)
{
bool MouseInside = UI()->MouseInside(pRect);
CUIRect Rect = *pRect;
if(pAnimator != NULL)
{
int64 Time = time_get_microseconds();
if(pAnimator->m_Time + (int64)100000 < Time)
{
pAnimator->m_Value = pAnimator->m_Active ? 1 : 0;
pAnimator->m_Time = Time;
}
pAnimator->m_Active = Checked || MouseInside;
if(pAnimator->m_Active)
pAnimator->m_Value = clamp<float>(pAnimator->m_Value + (Time - pAnimator->m_Time) / 100000.f, 0, 1);
else
pAnimator->m_Value = clamp<float>(pAnimator->m_Value - (Time - pAnimator->m_Time) / 100000.f, 0, 1);
Rect.w += pAnimator->m_Value * pAnimator->m_WOffset;
Rect.h += pAnimator->m_Value * pAnimator->m_HOffset;
Rect.x += pAnimator->m_Value * pAnimator->m_XOffset;
Rect.y += pAnimator->m_Value * pAnimator->m_YOffset;
pAnimator->m_Time = Time;
}
if(Checked)
{
ColorRGBA ColorMenuTab = ms_ColorTabbarActive;
if(pActiveColor)
ColorMenuTab = *pActiveColor;
RenderTools()->DrawUIRect(pRect, ColorMenuTab, Corners, EdgeRounding);
RenderTools()->DrawUIRect(&Rect, ColorMenuTab, Corners, EdgeRounding);
}
else
{
@ -214,18 +263,37 @@ int CMenus::DoButton_MenuTab(const void *pID, const char *pText, int Checked, co
ColorRGBA HoverColorMenuTab = ms_ColorTabbarHover;
if(pHoverColor)
HoverColorMenuTab = *pHoverColor;
RenderTools()->DrawUIRect(pRect, HoverColorMenuTab, Corners, EdgeRounding);
RenderTools()->DrawUIRect(&Rect, HoverColorMenuTab, Corners, EdgeRounding);
}
else
{
ColorRGBA ColorMenuTab = ms_ColorTabbarInactive;
if(pDefaultColor)
ColorMenuTab = *pDefaultColor;
RenderTools()->DrawUIRect(pRect, ColorMenuTab, Corners, EdgeRounding);
RenderTools()->DrawUIRect(&Rect, ColorMenuTab, Corners, EdgeRounding);
}
}
CUIRect Temp;
pRect->HMargin(2.0f, &Temp);
if(pAnimator != NULL)
{
if(pAnimator->m_RepositionLabel)
{
Rect.x += Rect.w - pRect->w + Rect.x - pRect->x;
Rect.y += Rect.h - pRect->h + Rect.y - pRect->y;
}
if(!pAnimator->m_ScaleLabel)
{
Rect.w = pRect->w;
Rect.h = pRect->h;
}
}
Rect.HMargin(2.0f, &Temp);
UI()->DoLabel(&Temp, pText, Temp.h * ms_FontmodHeight, 0, -1, AlignVertically);
return UI()->DoButtonLogic(pID, pText, Checked, pRect);
@ -802,7 +870,7 @@ int CMenus::RenderMenubar(CUIRect r)
pHomeButtonColorHover = &HomeButtonColorAlertHover;
}
if(DoButton_MenuTab(&s_StartButton, pHomeScreenButtonLabel, false, &Button, CUI::CORNER_T, pHomeButtonColor, pHomeButtonColor, pHomeButtonColorHover, 10.0f, 0))
if(DoButton_MenuTab(&s_StartButton, pHomeScreenButtonLabel, false, &Button, CUI::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_HOME], pHomeButtonColor, pHomeButtonColor, pHomeButtonColorHover, 10.0f, 0))
{
m_ShowStart = true;
m_DoubleClickIndex = -1;
@ -818,7 +886,7 @@ int CMenus::RenderMenubar(CUIRect r)
{
Box.VSplitLeft(100.0f, &Button, &Box);
static int s_NewsButton = 0;
if(DoButton_MenuTab(&s_NewsButton, Localize("News"), m_ActivePage == PAGE_NEWS, &Button, CUI::CORNER_T))
if(DoButton_MenuTab(&s_NewsButton, Localize("News"), m_ActivePage == PAGE_NEWS, &Button, CUI::CORNER_T, &m_aAnimatorsBigPage[BIG_TAB_NEWS]))
{
NewPage = PAGE_NEWS;
m_DoubleClickIndex = -1;
@ -828,7 +896,7 @@ int CMenus::RenderMenubar(CUIRect r)
{
Box.VSplitLeft(100.0f, &Button, &Box);
static int s_DemosButton = 0;
if(DoButton_MenuTab(&s_DemosButton, Localize("Demos"), m_ActivePage == PAGE_DEMOS, &Button, CUI::CORNER_T))
if(DoButton_MenuTab(&s_DemosButton, Localize("Demos"), m_ActivePage == PAGE_DEMOS, &Button, CUI::CORNER_T, &m_aAnimatorsBigPage[BIG_TAB_DEMOS]))
{
DemolistPopulate();
NewPage = PAGE_DEMOS;
@ -839,7 +907,7 @@ int CMenus::RenderMenubar(CUIRect r)
{
Box.VSplitLeft(100.0f, &Button, &Box);
static int s_InternetButton = 0;
if(DoButton_MenuTab(&s_InternetButton, Localize("Internet"), m_ActivePage == PAGE_INTERNET, &Button, CUI::CORNER_TL))
if(DoButton_MenuTab(&s_InternetButton, Localize("Internet"), m_ActivePage == PAGE_INTERNET, &Button, CUI::CORNER_T, &m_aAnimatorsBigPage[BIG_TAB_INTERNET]))
{
if(ServerBrowser()->GetCurrentType() != IServerBrowser::TYPE_INTERNET)
ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET);
@ -849,7 +917,7 @@ int CMenus::RenderMenubar(CUIRect r)
Box.VSplitLeft(100.0f, &Button, &Box);
static int s_LanButton = 0;
if(DoButton_MenuTab(&s_LanButton, Localize("LAN"), m_ActivePage == PAGE_LAN, &Button, 0))
if(DoButton_MenuTab(&s_LanButton, Localize("LAN"), m_ActivePage == PAGE_LAN, &Button, CUI::CORNER_T, &m_aAnimatorsBigPage[BIG_TAB_LAN]))
{
if(ServerBrowser()->GetCurrentType() != IServerBrowser::TYPE_LAN)
ServerBrowser()->Refresh(IServerBrowser::TYPE_LAN);
@ -859,7 +927,7 @@ int CMenus::RenderMenubar(CUIRect r)
Box.VSplitLeft(100.0f, &Button, &Box);
static int s_FavoritesButton = 0;
if(DoButton_MenuTab(&s_FavoritesButton, Localize("Favorites"), m_ActivePage == PAGE_FAVORITES, &Button, 0))
if(DoButton_MenuTab(&s_FavoritesButton, Localize("Favorites"), m_ActivePage == PAGE_FAVORITES, &Button, CUI::CORNER_T, &m_aAnimatorsBigPage[BIG_TAB_FAVORITES]))
{
if(ServerBrowser()->GetCurrentType() != IServerBrowser::TYPE_FAVORITES)
ServerBrowser()->Refresh(IServerBrowser::TYPE_FAVORITES);
@ -869,7 +937,7 @@ int CMenus::RenderMenubar(CUIRect r)
Box.VSplitLeft(90.0f, &Button, &Box);
static int s_DDNetButton = 0;
if(DoButton_MenuTab(&s_DDNetButton, "DDNet", m_ActivePage == PAGE_DDNET, &Button, 0))
if(DoButton_MenuTab(&s_DDNetButton, "DDNet", m_ActivePage == PAGE_DDNET, &Button, CUI::CORNER_T, &m_aAnimatorsBigPage[BIG_TAB_DDNET]))
{
if(ServerBrowser()->GetCurrentType() != IServerBrowser::TYPE_DDNET)
{
@ -882,7 +950,7 @@ int CMenus::RenderMenubar(CUIRect r)
Box.VSplitLeft(90.0f, &Button, &Box);
static int s_KoGButton = 0;
if(DoButton_MenuTab(&s_KoGButton, "KoG", m_ActivePage == PAGE_KOG, &Button, CUI::CORNER_TR))
if(DoButton_MenuTab(&s_KoGButton, "KoG", m_ActivePage == PAGE_KOG, &Button, CUI::CORNER_T, &m_aAnimatorsBigPage[BIG_TAB_KOG]))
{
if(ServerBrowser()->GetCurrentType() != IServerBrowser::TYPE_KOG)
{
@ -940,7 +1008,7 @@ int CMenus::RenderMenubar(CUIRect r)
Box.VSplitRight(33.0f, &Box, &Button);
static int s_QuitButton = 0;
ColorRGBA QuitColor(1, 0, 0, 0.5f);
if(DoButton_MenuTab(&s_QuitButton, "\xEE\x97\x8D", 0, &Button, CUI::CORNER_T, NULL, NULL, &QuitColor, 10.0f, 0))
if(DoButton_MenuTab(&s_QuitButton, "\xEE\x97\x8D", 0, &Button, CUI::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_QUIT], NULL, NULL, &QuitColor, 10.0f, 0))
{
if(m_pClient->Editor()->HasUnsavedData() || (Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmQuitTime && g_Config.m_ClConfirmQuitTime >= 0))
{
@ -956,13 +1024,13 @@ int CMenus::RenderMenubar(CUIRect r)
Box.VSplitRight(33.0f, &Box, &Button);
static int s_SettingsButton = 0;
if(DoButton_MenuTab(&s_SettingsButton, "\xEE\xA2\xB8", m_ActivePage == PAGE_SETTINGS, &Button, CUI::CORNER_T, NULL, NULL, NULL, 10.0f, 0))
if(DoButton_MenuTab(&s_SettingsButton, "\xEE\xA2\xB8", m_ActivePage == PAGE_SETTINGS, &Button, CUI::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_SETTINGS], NULL, NULL, NULL, 10.0f, 0))
NewPage = PAGE_SETTINGS;
Box.VSplitRight(10.0f, &Box, &Button);
Box.VSplitRight(33.0f, &Box, &Button);
static int s_EditorButton = 0;
if(DoButton_MenuTab(&s_EditorButton, "\xEE\x8F\x89", 0, &Button, CUI::CORNER_T, NULL, NULL, NULL, 10.0f, 0))
if(DoButton_MenuTab(&s_EditorButton, "\xEE\x8F\x89", 0, &Button, CUI::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_EDITOR], NULL, NULL, NULL, 10.0f, 0))
{
g_Config.m_ClEditor = 1;
}
@ -973,14 +1041,14 @@ int CMenus::RenderMenubar(CUIRect r)
Box.VSplitRight(33.0f, &Box, &Button);
static int s_DemoButton = 0;
if(DoButton_MenuTab(&s_DemoButton, "\xEE\x80\xAC", m_ActivePage == PAGE_DEMOS, &Button, CUI::CORNER_T, NULL, NULL, NULL, 10.0f, 0))
if(DoButton_MenuTab(&s_DemoButton, "\xEE\x80\xAC", m_ActivePage == PAGE_DEMOS, &Button, CUI::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_DEMOBUTTON], NULL, NULL, NULL, 10.0f, 0))
NewPage = PAGE_DEMOS;
Box.VSplitRight(10.0f, &Box, &Button);
Box.VSplitRight(33.0f, &Box, &Button);
static int s_ServerButton = 0;
if(DoButton_MenuTab(&s_ServerButton, "\xEE\xA0\x8B", m_ActivePage == g_Config.m_UiPage, &Button, CUI::CORNER_T, NULL, NULL, NULL, 10.0f, 0))
if(DoButton_MenuTab(&s_ServerButton, "\xEE\xA0\x8B", m_ActivePage == g_Config.m_UiPage, &Button, CUI::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_SERVER], NULL, NULL, NULL, 10.0f, 0))
NewPage = g_Config.m_UiPage;
}

View file

@ -60,7 +60,7 @@ class CMenus : public CComponent
int DoButton_Sprite(const void *pID, int ImageID, int SpriteID, int Checked, const CUIRect *pRect, int Corners);
int DoButton_Toggle(const void *pID, int Checked, const CUIRect *pRect, bool Active);
int DoButton_Menu(const void *pID, const char *pText, int Checked, const CUIRect *pRect, const char *pImageName = 0, int Corners = CUI::CORNER_ALL, float r = 5.0f, float FontFactor = 0.0f, vec4 ColorHot = vec4(1.0f, 1.0f, 1.0f, 0.75f), vec4 Color = vec4(1, 1, 1, 0.5f), int AlignVertically = 1);
int DoButton_MenuTab(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Corners, const ColorRGBA *pDefaultColor = NULL, const ColorRGBA *pActiveColor = NULL, const ColorRGBA *pHoverColor = NULL, float EdgeRounding = 10, int AlignVertically = 1);
int DoButton_MenuTab(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Corners, SUIAnimator *pAnimator = NULL, const ColorRGBA *pDefaultColor = NULL, const ColorRGBA *pActiveColor = NULL, const ColorRGBA *pHoverColor = NULL, float EdgeRounding = 10, int AlignVertically = 1);
int DoButton_CheckBox_Common(const void *pID, const char *pText, const char *pBoxText, const CUIRect *pRect);
int DoButton_CheckBox(const void *pID, const char *pText, int Checked, const CUIRect *pRect);
@ -538,6 +538,8 @@ public:
PAGE_NETWORK,
PAGE_GHOST,
PAGE_LENGTH,
SETTINGS_LANGUAGE = 0,
SETTINGS_GENERAL,
SETTINGS_PLAYER,
@ -548,8 +550,33 @@ public:
SETTINGS_SOUND,
SETTINGS_DDNET,
SETTINGS_ASSETS,
SETTINGS_LENGTH,
BIG_TAB_NEWS = 0,
BIG_TAB_INTERNET,
BIG_TAB_LAN,
BIG_TAB_FAVORITES,
BIG_TAB_DDNET,
BIG_TAB_KOG,
BIG_TAB_DEMOS,
BIG_TAB_LENGTH,
SMALL_TAB_HOME = 0,
SMALL_TAB_QUIT,
SMALL_TAB_SETTINGS,
SMALL_TAB_EDITOR,
SMALL_TAB_DEMOBUTTON,
SMALL_TAB_SERVER,
SMALL_TAB_LENGTH,
};
SUIAnimator m_aAnimatorsBigPage[BIG_TAB_LENGTH];
SUIAnimator m_aAnimatorsSmallPage[SMALL_TAB_LENGTH];
SUIAnimator m_aAnimatorsSettingsTab[SETTINGS_LENGTH];
// DDRace
int DoButton_CheckBox_DontCare(const void *pID, const char *pText, int Checked, const CUIRect *pRect);
sorted_array<CDemoItem> m_lDemos;

View file

@ -1368,15 +1368,15 @@ void CMenus::RenderServerbrowser(CUIRect MainView)
ms_ColorTabbarInactive = ColorRGBA(0.0f, 0.0f, 0.0f, 0.15f);
static int s_FiltersTab = 0;
if(DoButton_MenuTab(&s_FiltersTab, Localize("Filter"), ToolboxPage == 0, &TabButton0, CUI::CORNER_BL, NULL, NULL, NULL, 4.0f))
if(DoButton_MenuTab(&s_FiltersTab, Localize("Filter"), ToolboxPage == 0, &TabButton0, CUI::CORNER_BL, NULL, NULL, NULL, NULL, 4.0f))
ToolboxPage = 0;
static int s_InfoTab = 0;
if(DoButton_MenuTab(&s_InfoTab, Localize("Info"), ToolboxPage == 1, &TabButton1, 0, NULL, NULL, NULL, 4.0f))
if(DoButton_MenuTab(&s_InfoTab, Localize("Info"), ToolboxPage == 1, &TabButton1, 0, NULL, NULL, NULL, NULL, 4.0f))
ToolboxPage = 1;
static int s_FriendsTab = 0;
if(DoButton_MenuTab(&s_FriendsTab, Localize("Friends"), ToolboxPage == 2, &TabButton2, CUI::CORNER_BR, NULL, NULL, NULL, 4.0f))
if(DoButton_MenuTab(&s_FriendsTab, Localize("Friends"), ToolboxPage == 2, &TabButton2, CUI::CORNER_BR, NULL, NULL, NULL, NULL, 4.0f))
ToolboxPage = 2;
ms_ColorTabbarActive = Active;

View file

@ -1495,7 +1495,7 @@ void CMenus::RenderSettings(CUIRect MainView)
{
TabBar.HSplitTop(10, &Button, &TabBar);
TabBar.HSplitTop(26, &Button, &TabBar);
if(DoButton_MenuTab(aTabs[i], aTabs[i], g_Config.m_UiSettingsPage == i, &Button, CUI::CORNER_R))
if(DoButton_MenuTab(aTabs[i], aTabs[i], g_Config.m_UiSettingsPage == i, &Button, CUI::CORNER_R, &m_aAnimatorsSettingsTab[i]))
g_Config.m_UiSettingsPage = i;
}

View file

@ -310,13 +310,13 @@ void CMenus::RenderSettingsCustom(CUIRect MainView)
Page2Tab.VSplitLeft(TabsW / 4, &Page2Tab, &Page3Tab);
Page3Tab.VSplitLeft(TabsW / 4, &Page3Tab, &Page4Tab);
if(DoButton_MenuTab((void *)&Page1Tab, Localize("Entities"), s_CurCustomTab == 0, &Page1Tab, 5, NULL, NULL, NULL, 4))
if(DoButton_MenuTab((void *)&Page1Tab, Localize("Entities"), s_CurCustomTab == 0, &Page1Tab, 5, NULL, NULL, NULL, NULL, 4))
s_CurCustomTab = 0;
if(DoButton_MenuTab((void *)&Page2Tab, Localize("Game"), s_CurCustomTab == 1, &Page2Tab, 0, NULL, NULL, NULL, 4))
if(DoButton_MenuTab((void *)&Page2Tab, Localize("Game"), s_CurCustomTab == 1, &Page2Tab, 0, NULL, NULL, NULL, NULL, 4))
s_CurCustomTab = 1;
if(DoButton_MenuTab((void *)&Page3Tab, Localize("Emoticons"), s_CurCustomTab == 2, &Page3Tab, 0, NULL, NULL, NULL, 4))
if(DoButton_MenuTab((void *)&Page3Tab, Localize("Emoticons"), s_CurCustomTab == 2, &Page3Tab, 0, NULL, NULL, NULL, NULL, 4))
s_CurCustomTab = 2;
if(DoButton_MenuTab((void *)&Page4Tab, Localize("Particles"), s_CurCustomTab == 3, &Page4Tab, 10, NULL, NULL, NULL, 4))
if(DoButton_MenuTab((void *)&Page4Tab, Localize("Particles"), s_CurCustomTab == 3, &Page4Tab, 10, NULL, NULL, NULL, NULL, 4))
s_CurCustomTab = 3;
if(s_CurCustomTab == 0)

View file

@ -102,6 +102,21 @@ public:
void HMargin(float Cut, CUIRect *pOtherRect) const;
};
struct SUIAnimator
{
bool m_Active;
bool m_ScaleLabel;
bool m_RepositionLabel;
int64 m_Time;
float m_Value;
float m_XOffset;
float m_YOffset;
float m_WOffset;
float m_HOffset;
};
class CUI;
class CUIElement