1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 00:02:54 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/ScoreCounter.cs

81 lines
2.5 KiB
C#
Raw Normal View History

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