1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 17:07:38 +08:00

Improvements in transformCount handling

This commit is contained in:
Adonais Romero González 2016-10-12 21:33:55 -05:00
parent bf832ebe71
commit 55420d4356
4 changed files with 57 additions and 8 deletions

View File

@ -43,17 +43,23 @@ namespace osu.Game.Graphics.UserInterface
SetCountWithoutRolling(0); SetCountWithoutRolling(0);
} }
protected override void transformCount(ulong currentValue, ulong newValue) protected override void transformCount(ulong visibleValue, ulong prevValue, ulong currentValue, ulong newValue)
{ {
// Animate rollover only when going backwards // Animate rollover only when going backwards
if (newValue > currentValue) if (newValue > currentValue)
{ {
updateTransforms(typeof(TransformULongCounter)); updateTransforms(typeof(TransformULongCounter));
removeTransforms(typeof(TransformULongCounter)); removeTransforms(typeof(TransformULongCounter));
// If was decreasing, stops roll before increasing
if (currentValue < prevValue)
VisibleCount = currentValue;
VisibleCount = newValue; VisibleCount = newValue;
} }
else if (currentValue != 0) // Also, animate only if was not rollbacking already
transformCount(new TransformULongCounter(Clock), currentValue, newValue); else if (currentValue > prevValue)
transformCount(new TransformULongCounter(Clock), visibleValue, newValue);
} }
protected override ulong getProportionalDuration(ulong currentValue, ulong newValue) protected override ulong getProportionalDuration(ulong currentValue, ulong newValue)

View File

@ -25,6 +25,29 @@ namespace osu.Game.Graphics.UserInterface
return count.ToString("#,0"); return count.ToString("#,0");
} }
protected override void transformCount(ulong visibleValue, ulong prevValue, ulong currentValue, ulong newValue)
{
// Animate rollover only when going backwards
if (newValue > currentValue)
{
updateTransforms(typeof(TransformULongCounter));
removeTransforms(typeof(TransformULongCounter));
// If was decreasing, stops roll before increasing
if (currentValue < prevValue)
VisibleCount = currentValue;
VisibleCount = newValue;
}
// Also, animate only if was not rollbacking already
else if (currentValue > prevValue)
{
// Backwards pop-up animation has no tint colour
popOutSpriteText.Colour = countSpriteText.Colour;
transformCount(new TransformULongCounter(Clock), visibleValue, newValue);
}
}
protected override void transformCount(ulong currentValue, ulong newValue) protected override void transformCount(ulong currentValue, ulong newValue)
{ {
// Animate rollover only when going backwards // Animate rollover only when going backwards

View File

@ -75,6 +75,7 @@ namespace osu.Game.Graphics.UserInterface
} }
} }
protected T prevPrevCount;
protected T prevCount; protected T prevCount;
protected T count; protected T count;
@ -89,6 +90,7 @@ namespace osu.Game.Graphics.UserInterface
} }
set set
{ {
prevPrevCount = prevCount;
prevCount = count; prevCount = count;
count = value; count = value;
if (IsLoaded) if (IsLoaded)
@ -97,7 +99,7 @@ namespace osu.Game.Graphics.UserInterface
IsRollingProportional IsRollingProportional
? getProportionalDuration(VisibleCount, value) ? getProportionalDuration(VisibleCount, value)
: RollingDuration; : RollingDuration;
transformCount(IsRollingContinuous ? VisibleCount : prevCount, value); transformCount(visibleCount, prevPrevCount, prevCount, value);
} }
} }
} }
@ -183,6 +185,19 @@ namespace osu.Game.Graphics.UserInterface
Transforms.RemoveAll(t => t.GetType() == type); Transforms.RemoveAll(t => t.GetType() == type);
} }
/// <summary>
/// Called when the count is updated to add a transformer that changes the value of the visible count (i.e.
/// implement the rollover animation).
/// </summary>
/// <param name="visibleValue">Count value currently visible to user.</param>
/// <param name="currentValue">Count value before previous modification.</param>
/// <param name="currentValue">Count value before modification.</param>
/// <param name="newValue">Expected count value after modification.</param>
protected virtual void transformCount(T visibleValue, T prevValue, T currentValue, T newValue)
{
transformCount(IsRollingContinuous ? visibleValue : currentValue, newValue);
}
/// <summary> /// <summary>
/// Called when the count is updated to add a transformer that changes the value of the visible count (i.e. /// Called when the count is updated to add a transformer that changes the value of the visible count (i.e.
/// implement the rollover animation). /// implement the rollover animation).

View File

@ -75,18 +75,23 @@ namespace osu.Game.Graphics.UserInterface
popOutSpriteText.TextSize = this.TextSize; popOutSpriteText.TextSize = this.TextSize;
} }
protected override void transformCount(ulong currentValue, ulong newValue) protected override void transformCount(ulong visibleValue, ulong prevValue, ulong currentValue, ulong newValue)
{ {
// Animate rollover only when going backwards // Animate rollover only when going backwards
if (newValue > currentValue) if (newValue > currentValue)
{ {
updateTransforms(typeof(TransformULongCounter)); updateTransforms(typeof(TransformULongCounter));
removeTransforms(typeof(TransformULongCounter)); removeTransforms(typeof(TransformULongCounter));
// If was decreasing, stops roll before increasing
if (currentValue < prevValue)
VisibleCount = currentValue;
VisibleCount = newValue; VisibleCount = newValue;
} }
// Also, ignore rollback if already rollbacking // Also, animate only if was not rollbacking already
else if (currentValue != 0) else if (currentValue > prevValue)
transformCount(new TransformULongCounter(Clock), currentValue, newValue); transformCount(new TransformULongCounter(Clock), visibleValue, newValue);
} }
protected override ulong getProportionalDuration(ulong currentValue, ulong newValue) protected override ulong getProportionalDuration(ulong currentValue, ulong newValue)