2017-02-07 04:59:30 +00: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 07:24:46 +00:00
|
|
|
|
|
2016-10-13 22:13:20 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2017-02-25 12:12:39 +00:00
|
|
|
|
using osu.Framework.Graphics.Transforms;
|
2016-10-13 22:13:20 +00:00
|
|
|
|
using osu.Framework.MathUtils;
|
2016-10-07 07:24:46 +00:00
|
|
|
|
using System;
|
2016-10-07 07:05:02 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
2017-03-10 04:08:59 +00:00
|
|
|
|
public class ScoreCounter : RollingCounter<double>
|
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
|
|
|
|
|
2017-04-14 11:09:01 +00:00
|
|
|
|
public bool UseCommaSeparator;
|
|
|
|
|
|
2016-10-07 07:05:02 +00:00
|
|
|
|
/// <summary>
|
2016-10-13 01:57:06 +00:00
|
|
|
|
/// How many leading zeroes the counter has.
|
2016-10-07 07:05:02 +00:00
|
|
|
|
/// </summary>
|
2016-10-13 01:57:06 +00:00
|
|
|
|
public uint LeadingZeroes
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
protected set;
|
|
|
|
|
}
|
2016-10-07 07:05:02 +00:00
|
|
|
|
|
2016-10-13 01:57:06 +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;
|
2016-10-13 01:57:06 +00:00
|
|
|
|
LeadingZeroes = leading;
|
2016-10-12 19:33:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-10 04:08:59 +00:00
|
|
|
|
protected override double GetProportionalDuration(double currentValue, double newValue)
|
2016-10-13 22:13:20 +00:00
|
|
|
|
{
|
|
|
|
|
return currentValue > newValue ? currentValue - newValue : newValue - currentValue;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-10 04:08:59 +00:00
|
|
|
|
protected override string FormatCount(double count)
|
2016-10-07 07:05:02 +00:00
|
|
|
|
{
|
2017-04-12 11:28:04 +00:00
|
|
|
|
string format = new string('0', (int)LeadingZeroes);
|
2017-04-14 11:09:01 +00:00
|
|
|
|
if (UseCommaSeparator)
|
|
|
|
|
for (int i = format.Length - 3; i > 0; i -= 3)
|
|
|
|
|
format = format.Insert(i, @",");
|
2017-04-12 11:28:04 +00:00
|
|
|
|
|
|
|
|
|
return ((long)count).ToString(format);
|
2016-10-07 07:05:02 +00:00
|
|
|
|
}
|
2016-10-13 22:13:20 +00:00
|
|
|
|
|
2017-03-10 04:08:59 +00:00
|
|
|
|
public override void Increment(double amount)
|
2016-10-19 10:44:03 +00:00
|
|
|
|
{
|
2017-03-10 04:08:59 +00:00
|
|
|
|
Current.Value = Current + amount;
|
2016-10-19 10:44:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-10 04:08:59 +00:00
|
|
|
|
protected class TransformScore : Transform<double>
|
2016-10-13 22:13:20 +00:00
|
|
|
|
{
|
2017-03-31 03:58:54 +00:00
|
|
|
|
public override double CurrentValue
|
2016-10-13 22:13:20 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-11-06 07:25:21 +00:00
|
|
|
|
double time = Time?.Current ?? 0;
|
2016-10-13 22:13:20 +00:00
|
|
|
|
if (time < StartTime) return StartValue;
|
|
|
|
|
if (time >= EndTime) return EndValue;
|
|
|
|
|
|
2017-03-10 04:08:59 +00:00
|
|
|
|
return Interpolation.ValueAt(time, (float)StartValue, (float)EndValue, StartTime, EndTime, Easing);
|
2016-10-13 22:13:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Apply(Drawable d)
|
|
|
|
|
{
|
|
|
|
|
base.Apply(d);
|
2017-03-07 01:59:19 +00:00
|
|
|
|
((ScoreCounter)d).DisplayedCount = CurrentValue;
|
2016-10-13 22:13:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-07 07:05:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|