4040#define CORE_MTA_DISABLED_ALPHA 0 .4f
4141#define CORE_MTA_ENABLED_ALPHA 1 .0f
4242
43- #define CORE_MTA_ANIMATION_TIME 200
43+ #define CORE_MTA_ANIMATION_TIME_IN 200
44+ #define CORE_MTA_ANIMATION_TIME_OUT 100
4445#define CORE_MTA_MOVE_ANIM_TIME 600
4546
4647#define CORE_MTA_STATIC_BG " cgui\\ images\\ background.png"
@@ -517,11 +518,9 @@ void CMainMenu::Update()
517518
518519 if (m_pHoveredItem)
519520 {
520- float fProgress = (m_pHoveredItem->image ->GetAlpha () - CORE_MTA_NORMAL_ALPHA) / (CORE_MTA_HOVER_ALPHA - CORE_MTA_NORMAL_ALPHA);
521- // Let's work out what the target progress should be by working out the time passed
522- fProgress = ((float )ulTimePassed / CORE_MTA_ANIMATION_TIME) * (CORE_MTA_HOVER_ALPHA - CORE_MTA_NORMAL_ALPHA) + fProgress ;
521+ float progress = m_pHoveredItem->animProgress + ((float )ulTimePassed / CORE_MTA_ANIMATION_TIME_IN);
523522 MapRemove (m_unhoveredItems, m_pHoveredItem);
524- SetItemHoverProgress (m_pHoveredItem, fProgress , true );
523+ SetItemHoverProgress (m_pHoveredItem, progress , true );
525524 }
526525 }
527526 else if (m_pHoveredItem)
@@ -534,11 +533,10 @@ void CMainMenu::Update()
534533 std::set<sMenuItem *>::iterator it = m_unhoveredItems.begin ();
535534 while (it != m_unhoveredItems.end ())
536535 {
537- float fProgress = ((*it)->image ->GetAlpha () - CORE_MTA_NORMAL_ALPHA) / (CORE_MTA_HOVER_ALPHA - CORE_MTA_NORMAL_ALPHA);
538536 // Let's work out what the target progress should be by working out the time passed
539537 // Min of 0.5 progress fixes occasional graphical glitchekal
540- fProgress = fProgress - std::min (0 .5f , ((float )ulTimePassed / CORE_MTA_ANIMATION_TIME ) * (CORE_MTA_HOVER_ALPHA - CORE_MTA_NORMAL_ALPHA));
541- if (SetItemHoverProgress ((*it), fProgress , false ))
538+ float newProgress = (*it)-> animProgress - std::min (0 .5f , ((float )ulTimePassed / CORE_MTA_ANIMATION_TIME_OUT ) * (CORE_MTA_HOVER_ALPHA - CORE_MTA_NORMAL_ALPHA));
539+ if (SetItemHoverProgress ((*it), newProgress , false ))
542540 {
543541 std::set<sMenuItem *>::iterator itToErase = it++;
544542 m_unhoveredItems.erase (itToErase);
@@ -1101,8 +1099,10 @@ bool CMainMenu::SetItemHoverProgress(sMenuItem* pItem, float fProgress, bool bHo
11011099{
11021100 fProgress = Clamp<float >(0 , fProgress , 1 );
11031101
1104- // Use OutQuad equation for easing, or OutQuad for unhovering
1105- fProgress = bHovering ? -fProgress * (fProgress - 2 ) : fProgress * fProgress ;
1102+ pItem->animProgress = fProgress ;
1103+
1104+ // Always use OutQuad for both hovering and unhovering, to avoid animation glitches.
1105+ fProgress = -fProgress * (fProgress - 2 );
11061106
11071107 // Work out the target scale
11081108 float fTargetScale = (CORE_MTA_HOVER_SCALE - CORE_MTA_NORMAL_SCALE) * (fProgress ) + CORE_MTA_NORMAL_SCALE;
@@ -1121,7 +1121,7 @@ bool CMainMenu::SetItemHoverProgress(sMenuItem* pItem, float fProgress, bool bHo
11211121 pItem->image ->SetSize (CVector2D (iSizeX, iSizeY), false );
11221122
11231123 // Return whether the hovering has maxed out
1124- return bHovering ? (fProgress == 1 ) : (fProgress == 0 );
1124+ return bHovering ? (pItem-> animProgress >= 1.0 ) : (pItem-> animProgress <= 0 . 0f );
11251125}
11261126
11271127void CMainMenu::SetNewsHeadline (int iIndex, const SString& strHeadline, const SString& strDate, bool bIsNew)
0 commit comments