mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Settings Tabs Animations
This commit is contained in:
parent
d0b64ad800
commit
e40539c9fd
|
@ -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<float>(pAnimator->m_Value + (Time - pAnimator->m_Time) / 1000000.f, 0, 1);
|
||||
else
|
||||
pAnimator->m_Value = clamp<float>(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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue