//Copyright (c) 2007-2016 ppy Pty Ltd . //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; using System.Text; using System.Threading.Tasks; namespace osu.Game.Graphics.UserInterface { public class ScoreCounter : RollingCounter { protected override Type transformType => typeof(TransformScore); /// /// How many leading zeroes the counter has. /// public uint LeadingZeroes { get; protected set; } /// /// Displays score. /// /// How many leading zeroes the counter will have. public ScoreCounter(uint leading = 0) { countSpriteText.FixedWidth = true; LeadingZeroes = leading; RollingDuration = 1000; RollingEasing = EasingTypes.Out; } public override void Load(BaseGame game) { base.Load(game); } protected override double 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 { 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) { } } } }