osu/osu.Game/Graphics/UserInterface/ScoreCounter.cs

79 lines
2.4 KiB
C#
Raw Normal View History

2016-10-07 07:24:46 +00:00
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2016-10-13 22:13:20 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Transformations;
using osu.Framework.MathUtils;
using osu.Framework.Timing;
2016-10-07 07:24:46 +00:00
using System;
2016-10-07 07:05:02 +00:00
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.Graphics.UserInterface
{
2016-10-13 22:13:20 +00:00
public class ScoreCounter : RollingCounter<ulong>
2016-10-07 07:05:02 +00:00
{
2016-10-14 23:23:27 +00:00
protected override Type TransformType => typeof(TransformScore);
2016-10-18 02:40:50 +00:00
protected override double RollingDuration => 1000;
protected override EasingTypes RollingEasing => EasingTypes.Out;
2016-10-13 22:13:20 +00:00
2016-10-07 07:05:02 +00:00
/// <summary>
/// How many leading zeroes the counter has.
2016-10-07 07:05:02 +00:00
/// </summary>
public uint LeadingZeroes
{
get;
protected set;
}
2016-10-07 07:05:02 +00:00
/// <summary>
/// Displays score.
/// </summary>
/// <param name="leading">How many leading zeroes the counter will have.</param>
2016-10-13 02:46:51 +00:00
public ScoreCounter(uint leading = 0)
2016-10-12 19:33:04 +00:00
{
2016-10-16 00:07:07 +00:00
DisplayedCountSpriteText.FixedWidth = true;
LeadingZeroes = leading;
2016-10-12 19:33:04 +00:00
}
2016-10-14 23:23:27 +00:00
protected override double GetProportionalDuration(ulong currentValue, ulong newValue)
2016-10-13 22:13:20 +00:00
{
return currentValue > newValue ? currentValue - newValue : newValue - currentValue;
}
2016-10-14 23:23:27 +00:00
protected override string FormatCount(ulong count)
2016-10-07 07:05:02 +00:00
{
return count.ToString("D" + LeadingZeroes);
}
2016-10-13 22:13:20 +00:00
public override void Increment(ulong amount)
{
Count = Count + amount;
}
2016-10-13 22:13:20 +00:00
protected class TransformScore : Transform<ulong>
{
2016-10-28 08:42:00 +00:00
protected override ulong CurrentValue
2016-10-13 22:13:20 +00:00
{
get
{
double time = Time?.Current ?? 0;
2016-10-13 22:13:20 +00:00
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);
2016-10-16 00:07:07 +00:00
(d as ScoreCounter).DisplayedCount = CurrentValue;
2016-10-13 22:13:20 +00:00
}
}
2016-10-07 07:05:02 +00:00
}
}