From e40539c9fd87a4da06442353db299b7ff90ef934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D1=8F=D0=B4=D1=8F=20=D0=96=D0=B5=D0=BD=D1=8F?= Date: Mon, 26 Oct 2020 04:10:55 +0300 Subject: [PATCH 1/7] Settings Tabs Animations --- src/game/client/components/menus.cpp | 56 +++++++++++++++---- src/game/client/components/menus.h | 6 +- src/game/client/components/menus_browser.cpp | 6 +- src/game/client/components/menus_settings.cpp | 2 +- .../components/menus_settings_assets.cpp | 8 +-- src/game/client/ui.h | 7 +++ 6 files changed, 64 insertions(+), 21 deletions(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 52380d56c..4fe738ee4 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -196,14 +196,41 @@ 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) { + int Time = 0; + bool MouseInside = UI()->MouseInside(pRect); + CUIRect Rect = *pRect; + + if(pAnimator != NULL) + { + Time = time(); + + if(pAnimator->m_Time + 1000000.f < 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(pAnimator->m_Value + (Time - pAnimator->m_Time) / 1000000.f, 0, 1); + else + pAnimator->m_Value = clamp(pAnimator->m_Value - (Time - pAnimator->m_Time) / 1000000.f, 0, 1); + + Rect.w += pAnimator->m_Value * 5; + Rect.y -= pAnimator->m_Value * 2.5f; + Rect.h += pAnimator->m_Value * 5; + } + if(Checked) { ColorRGBA ColorMenuTab = ms_ColorTabbarActive; if(pActiveColor) ColorMenuTab = *pActiveColor; - RenderTools()->DrawUIRect(pRect, ColorMenuTab, Corners, EdgeRounding); + + RenderTools()->DrawUIRect(&Rect, ColorMenuTab, Corners, EdgeRounding); } else { @@ -212,18 +239,25 @@ 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); } } + + if(pAnimator != NULL) + pAnimator->m_Time = Time; + CUIRect Temp; - pRect->HMargin(2.0f, &Temp); + Rect.HMargin(2.0f, &Temp); UI()->DoLabel(&Temp, pText, Temp.h * ms_FontmodHeight, 0, -1, AlignVertically); return UI()->DoButtonLogic(pID, pText, Checked, pRect); @@ -818,7 +852,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, NULL, pHomeButtonColor, pHomeButtonColor, pHomeButtonColorHover, 10.0f, 0)) { m_ShowStart = true; m_DoubleClickIndex = -1; @@ -956,7 +990,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, NULL, NULL, NULL, &QuitColor, 10.0f, 0)) { if(m_pClient->Editor()->HasUnsavedData() || (Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmQuitTime && g_Config.m_ClConfirmQuitTime >= 0)) { @@ -972,13 +1006,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, NULL, 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, NULL, NULL, NULL, NULL, 10.0f, 0)) { g_Config.m_ClEditor = 1; } @@ -989,14 +1023,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, NULL, 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, NULL, NULL, NULL, NULL, 10.0f, 0)) NewPage = g_Config.m_UiPage; } diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index 79df6207b..ef12e1660 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -54,7 +54,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); @@ -186,6 +186,8 @@ protected: char m_aMessageBody[512]; char m_aMessageButton[512]; + SUIAnimator m_aUIAnimators[10]; + void PopupMessage(const char *pTopic, const char *pBody, const char *pButton); // TODO: this is a bit ugly but.. well.. yeah @@ -449,7 +451,7 @@ public: SETTINGS_GRAPHICS, SETTINGS_SOUND, SETTINGS_DDNET, - SETTINGS_ASSETS, + SETTINGS_ASSETS }; // DDRace diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index d7ebf876a..be0c7bd1a 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -1392,15 +1392,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; diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index 1abeea02e..2cc8ef72f 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -1496,7 +1496,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_aUIAnimators[i])) g_Config.m_UiSettingsPage = i; } diff --git a/src/game/client/components/menus_settings_assets.cpp b/src/game/client/components/menus_settings_assets.cpp index 539480243..25799ce4b 100644 --- a/src/game/client/components/menus_settings_assets.cpp +++ b/src/game/client/components/menus_settings_assets.cpp @@ -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) diff --git a/src/game/client/ui.h b/src/game/client/ui.h index 22afe4480..f1b0c94f9 100644 --- a/src/game/client/ui.h +++ b/src/game/client/ui.h @@ -97,6 +97,13 @@ public: void HMargin(float Cut, CUIRect *pOtherRect) const; }; +struct SUIAnimator +{ + float m_Time; + float m_Value; + bool m_Active; +}; + class CUI { const void *m_pHotItem; From c02086a6891c10571a6ff5a11ba72ec9bbf2210c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D1=8F=D0=B4=D1=8F=20=D0=96=D0=B5=D0=BD=D1=8F?= Date: Mon, 26 Oct 2020 04:43:34 +0300 Subject: [PATCH 2/7] Fixes --- src/game/client/components/menus.cpp | 8 +++----- src/game/client/components/menus.h | 5 +++-- src/game/client/components/menus_settings.cpp | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 4fe738ee4..3dee8e59a 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -204,7 +204,7 @@ int CMenus::DoButton_MenuTab(const void *pID, const char *pText, int Checked, co if(pAnimator != NULL) { - Time = time(); + Time = time(); if(pAnimator->m_Time + 1000000.f < Time) { @@ -222,6 +222,8 @@ int CMenus::DoButton_MenuTab(const void *pID, const char *pText, int Checked, co Rect.w += pAnimator->m_Value * 5; Rect.y -= pAnimator->m_Value * 2.5f; Rect.h += pAnimator->m_Value * 5; + + pAnimator->m_Time = Time; } if(Checked) @@ -240,7 +242,6 @@ int CMenus::DoButton_MenuTab(const void *pID, const char *pText, int Checked, co if(pHoverColor) HoverColorMenuTab = *pHoverColor; - RenderTools()->DrawUIRect(&Rect, HoverColorMenuTab, Corners, EdgeRounding); } else @@ -253,9 +254,6 @@ int CMenus::DoButton_MenuTab(const void *pID, const char *pText, int Checked, co } } - if(pAnimator != NULL) - pAnimator->m_Time = Time; - CUIRect Temp; Rect.HMargin(2.0f, &Temp); UI()->DoLabel(&Temp, pText, Temp.h * ms_FontmodHeight, 0, -1, AlignVertically); diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index ef12e1660..be874fbfe 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -186,7 +186,7 @@ protected: char m_aMessageBody[512]; char m_aMessageButton[512]; - SUIAnimator m_aUIAnimators[10]; + SUIAnimator m_aSettingsTabAnimators[10]; void PopupMessage(const char *pTopic, const char *pBody, const char *pButton); @@ -451,7 +451,8 @@ public: SETTINGS_GRAPHICS, SETTINGS_SOUND, SETTINGS_DDNET, - SETTINGS_ASSETS + SETTINGS_ASSETS, + SETTINGS_LENGTH }; // DDRace diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index 2cc8ef72f..6eddc4e27 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -1496,7 +1496,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, &m_aUIAnimators[i])) + if(DoButton_MenuTab(aTabs[i], aTabs[i], g_Config.m_UiSettingsPage == i, &Button, CUI::CORNER_R, &m_aSettingsTabAnimators[i])) g_Config.m_UiSettingsPage = i; } From 9b3d9965fb701ed38f8104ec450588d1a81da7a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D1=8F=D0=B4=D1=8F=20=D0=96=D0=B5=D0=BD=D1=8F?= Date: Mon, 26 Oct 2020 05:48:05 +0300 Subject: [PATCH 3/7] More UI Animation settings, more tabs animated --- src/game/client/components/menus.cpp | 68 ++++++++++++++----- src/game/client/components/menus.h | 30 +++++++- src/game/client/components/menus_settings.cpp | 2 +- src/game/client/ui.h | 10 ++- 4 files changed, 88 insertions(+), 22 deletions(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 3dee8e59a..4f28369b8 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -94,6 +94,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_ScaleLabel = 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) @@ -219,9 +239,10 @@ int CMenus::DoButton_MenuTab(const void *pID, const char *pText, int Checked, co else pAnimator->m_Value = clamp(pAnimator->m_Value - (Time - pAnimator->m_Time) / 1000000.f, 0, 1); - Rect.w += pAnimator->m_Value * 5; - Rect.y -= pAnimator->m_Value * 2.5f; - Rect.h += pAnimator->m_Value * 5; + 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; } @@ -255,7 +276,20 @@ int CMenus::DoButton_MenuTab(const void *pID, const char *pText, int Checked, co } CUIRect Temp; - Rect.HMargin(2.0f, &Temp); + + if(pAnimator != NULL) + { + if(!pAnimator->m_ScaleLabel) + { + Rect.w = pRect->w; + Rect.h = pRect->h; + } + + Rect.HMargin(2.0f, &Temp); + } + else + pRect->HMargin(2.0f, &Temp); + UI()->DoLabel(&Temp, pText, Temp.h * ms_FontmodHeight, 0, -1, AlignVertically); return UI()->DoButtonLogic(pID, pText, Checked, pRect); @@ -850,7 +884,7 @@ int CMenus::RenderMenubar(CUIRect r) pHomeButtonColorHover = &HomeButtonColorAlertHover; } - if(DoButton_MenuTab(&s_StartButton, pHomeScreenButtonLabel, false, &Button, CUI::CORNER_T, NULL, 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; @@ -866,7 +900,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; @@ -876,7 +910,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; @@ -887,7 +921,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); @@ -897,7 +931,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); @@ -907,7 +941,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); @@ -917,7 +951,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) { @@ -930,7 +964,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) { @@ -988,7 +1022,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, 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)) { @@ -1004,13 +1038,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, 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, 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; } @@ -1021,14 +1055,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, 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, 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; } diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index be874fbfe..33e697b98 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -186,8 +186,6 @@ protected: char m_aMessageBody[512]; char m_aMessageButton[512]; - SUIAnimator m_aSettingsTabAnimators[10]; - void PopupMessage(const char *pTopic, const char *pBody, const char *pButton); // TODO: this is a bit ugly but.. well.. yeah @@ -442,6 +440,8 @@ public: PAGE_NETWORK, PAGE_GHOST, + PAGE_LENGTH, + SETTINGS_LANGUAGE = 0, SETTINGS_GENERAL, SETTINGS_PLAYER, @@ -452,9 +452,33 @@ public: SETTINGS_SOUND, SETTINGS_DDNET, SETTINGS_ASSETS, - SETTINGS_LENGTH + + 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 m_lDemos; diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index 6eddc4e27..a86c23a94 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -1496,7 +1496,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, &m_aSettingsTabAnimators[i])) + if(DoButton_MenuTab(aTabs[i], aTabs[i], g_Config.m_UiSettingsPage == i, &Button, CUI::CORNER_R, &m_aAnimatorsSettingsTab[i])) g_Config.m_UiSettingsPage = i; } diff --git a/src/game/client/ui.h b/src/game/client/ui.h index f1b0c94f9..ee97f96cd 100644 --- a/src/game/client/ui.h +++ b/src/game/client/ui.h @@ -99,9 +99,17 @@ public: struct SUIAnimator { + bool m_Active; + bool m_ScaleLabel; + float m_Time; float m_Value; - bool m_Active; + + float m_XOffset; + float m_YOffset; + float m_WOffset; + float m_HOffset; + }; class CUI From b6d94a85f3acfa7bc43af8993ac81d2458b44cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D1=8F=D0=B4=D1=8F=20=D0=96=D0=B5=D0=BD=D1=8F?= Date: Mon, 26 Oct 2020 06:10:58 +0300 Subject: [PATCH 4/7] Visual Improvements, Fixed check-style --- src/game/client/components/menus.cpp | 8 +++++++- src/game/client/ui.h | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 4f28369b8..7b87b576c 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -100,7 +100,7 @@ CMenus::CMenus() animator.m_YOffset = -2.5f; animator.m_HOffset = 5.0f; animator.m_WOffset = 5.0f; - animator.m_ScaleLabel = true; + animator.m_RepositionLabel = true; } for(SUIAnimator &animator : m_aAnimatorsBigPage) @@ -279,6 +279,12 @@ int CMenus::DoButton_MenuTab(const void *pID, const char *pText, int Checked, co 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; diff --git a/src/game/client/ui.h b/src/game/client/ui.h index ee97f96cd..6dc159b26 100644 --- a/src/game/client/ui.h +++ b/src/game/client/ui.h @@ -101,6 +101,7 @@ struct SUIAnimator { bool m_Active; bool m_ScaleLabel; + bool m_RepositionLabel; float m_Time; float m_Value; @@ -109,7 +110,6 @@ struct SUIAnimator float m_YOffset; float m_WOffset; float m_HOffset; - }; class CUI From b18d72db1fc59a8ad733b134bf2ee6c9c92bc7ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D1=8F=D0=B4=D1=8F=20=D0=96=D0=B5=D0=BD=D1=8F?= Date: Mon, 26 Oct 2020 17:47:26 +0300 Subject: [PATCH 5/7] using time_get_mircoseconds and storing it as int64 val --- src/game/client/components/menus.cpp | 16 ++++++---------- src/game/client/ui.h | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 7b87b576c..3c21bc2d6 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -218,15 +218,14 @@ void CMenus::DoButton_KeySelect(const void *pID, const char *pText, int Checked, 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) { - int Time = 0; bool MouseInside = UI()->MouseInside(pRect); CUIRect Rect = *pRect; if(pAnimator != NULL) { - Time = time(); + int64 Time = time_get_microseconds(); - if(pAnimator->m_Time + 1000000.f < Time) + if(pAnimator->m_Time + 100000 < Time) { pAnimator->m_Value = pAnimator->m_Active ? 1 : 0; pAnimator->m_Time = Time; @@ -235,9 +234,9 @@ int CMenus::DoButton_MenuTab(const void *pID, const char *pText, int Checked, co pAnimator->m_Active = Checked || MouseInside; if(pAnimator->m_Active) - pAnimator->m_Value = clamp(pAnimator->m_Value + (Time - pAnimator->m_Time) / 1000000.f, 0, 1); + pAnimator->m_Value = clamp(pAnimator->m_Value + (Time - pAnimator->m_Time) / 100000.f, 0, 1); else - pAnimator->m_Value = clamp(pAnimator->m_Value - (Time - pAnimator->m_Time) / 1000000.f, 0, 1); + pAnimator->m_Value = clamp(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; @@ -290,12 +289,9 @@ int CMenus::DoButton_MenuTab(const void *pID, const char *pText, int Checked, co Rect.w = pRect->w; Rect.h = pRect->h; } - - Rect.HMargin(2.0f, &Temp); } - else - pRect->HMargin(2.0f, &Temp); - + + Rect.HMargin(2.0f, &Temp); UI()->DoLabel(&Temp, pText, Temp.h * ms_FontmodHeight, 0, -1, AlignVertically); return UI()->DoButtonLogic(pID, pText, Checked, pRect); diff --git a/src/game/client/ui.h b/src/game/client/ui.h index 6dc159b26..7b8887272 100644 --- a/src/game/client/ui.h +++ b/src/game/client/ui.h @@ -103,7 +103,7 @@ struct SUIAnimator bool m_ScaleLabel; bool m_RepositionLabel; - float m_Time; + long long m_Time; float m_Value; float m_XOffset; From 7e180f93cb06b3d4e160afd206799aa039dea05b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D1=8F=D0=B4=D1=8F=20=D0=96=D0=B5=D0=BD=D1=8F?= Date: Sat, 31 Oct 2020 01:45:46 +0300 Subject: [PATCH 6/7] Fix rarest bug and typedef in UI animations --- src/game/client/components/menus.cpp | 2 +- src/game/client/ui.h | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 3c21bc2d6..746eea096 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -225,7 +225,7 @@ int CMenus::DoButton_MenuTab(const void *pID, const char *pText, int Checked, co { int64 Time = time_get_microseconds(); - if(pAnimator->m_Time + 100000 < Time) + if(pAnimator->m_Time + (int64)100000 < Time) { pAnimator->m_Value = pAnimator->m_Active ? 1 : 0; pAnimator->m_Time = Time; diff --git a/src/game/client/ui.h b/src/game/client/ui.h index 7b8887272..ccba1acdd 100644 --- a/src/game/client/ui.h +++ b/src/game/client/ui.h @@ -3,6 +3,8 @@ #ifndef GAME_CLIENT_UI_H #define GAME_CLIENT_UI_H +#include "base/system.h" + class CUIRect { // TODO: Refactor: Redo UI scaling @@ -103,7 +105,7 @@ struct SUIAnimator bool m_ScaleLabel; bool m_RepositionLabel; - long long m_Time; + int64 m_Time; float m_Value; float m_XOffset; From 82faad33e901a628a939df8eadd6bdc99ff69fad Mon Sep 17 00:00:00 2001 From: def Date: Sun, 13 Dec 2020 19:31:37 +0100 Subject: [PATCH 7/7] Fix clang-format --- src/game/client/components/menus.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 8da97f652..72e576093 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -285,14 +285,14 @@ int CMenus::DoButton_MenuTab(const void *pID, const char *pText, int Checked, co 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);