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