40
40
#define CORE_MTA_DISABLED_ALPHA 0 .4f
41
41
#define CORE_MTA_ENABLED_ALPHA 1 .0f
42
42
43
- #define CORE_MTA_ANIMATION_TIME 200
43
+ #define CORE_MTA_ANIMATION_TIME_IN 200
44
+ #define CORE_MTA_ANIMATION_TIME_OUT 100
44
45
#define CORE_MTA_MOVE_ANIM_TIME 600
45
46
46
47
#define CORE_MTA_STATIC_BG " cgui\\ images\\ background.png"
@@ -517,11 +518,9 @@ void CMainMenu::Update()
517
518
518
519
if (m_pHoveredItem)
519
520
{
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);
523
522
MapRemove (m_unhoveredItems, m_pHoveredItem);
524
- SetItemHoverProgress (m_pHoveredItem, fProgress , true );
523
+ SetItemHoverProgress (m_pHoveredItem, progress , true );
525
524
}
526
525
}
527
526
else if (m_pHoveredItem)
@@ -534,11 +533,10 @@ void CMainMenu::Update()
534
533
std::set<sMenuItem *>::iterator it = m_unhoveredItems.begin ();
535
534
while (it != m_unhoveredItems.end ())
536
535
{
537
- float fProgress = ((*it)->image ->GetAlpha () - CORE_MTA_NORMAL_ALPHA) / (CORE_MTA_HOVER_ALPHA - CORE_MTA_NORMAL_ALPHA);
538
536
// Let's work out what the target progress should be by working out the time passed
539
537
// 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 ))
542
540
{
543
541
std::set<sMenuItem *>::iterator itToErase = it++;
544
542
m_unhoveredItems.erase (itToErase);
@@ -1101,8 +1099,10 @@ bool CMainMenu::SetItemHoverProgress(sMenuItem* pItem, float fProgress, bool bHo
1101
1099
{
1102
1100
fProgress = Clamp<float >(0 , fProgress , 1 );
1103
1101
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 );
1106
1106
1107
1107
// Work out the target scale
1108
1108
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
1121
1121
pItem->image ->SetSize (CVector2D (iSizeX, iSizeY), false );
1122
1122
1123
1123
// 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 );
1125
1125
}
1126
1126
1127
1127
void CMainMenu::SetNewsHeadline (int iIndex, const SString& strHeadline, const SString& strDate, bool bIsNew)
0 commit comments