Improved code

This commit is contained in:
Adonais Romero González
2016-10-13 17:13:20 -05:00
parent 1d8d2fa9c9
commit ce07a45456
12 changed files with 487 additions and 421 deletions

View File

@ -2,6 +2,10 @@
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Transformations;
using osu.Framework.MathUtils;
using osu.Framework.Timing;
using System;
using System.Collections.Generic;
using System.Linq;
@ -10,8 +14,10 @@ using System.Threading.Tasks;
namespace osu.Game.Graphics.UserInterface
{
public class ScoreCounter : ULongCounter
public class ScoreCounter : RollingCounter<ulong>
{
protected override Type transformType => typeof(TransformScore);
/// <summary>
/// How many leading zeroes the counter has.
/// </summary>
@ -36,9 +42,40 @@ namespace osu.Game.Graphics.UserInterface
base.Load(game);
}
protected override ulong getProportionalDuration(ulong currentValue, ulong newValue)
{
return currentValue > newValue ? currentValue - newValue : newValue - currentValue;
}
protected override string formatCount(ulong count)
{
return count.ToString("D" + LeadingZeroes);
}
protected class TransformScore : Transform<ulong>
{
public override ulong CurrentValue
{
get
{
double time = Time;
if (time < StartTime) return StartValue;
if (time >= EndTime) return EndValue;
return (ulong)Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing);
}
}
public override void Apply(Drawable d)
{
base.Apply(d);
(d as ScoreCounter).VisibleCount = CurrentValue;
}
public TransformScore(IClock clock)
: base(clock)
{
}
}
}
}