A game framework written with osu! in mind.
at master 49 lines 1.5 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using osu.Framework.Graphics.Containers; 5using osu.Framework.Graphics.Transforms; 6 7namespace osu.Framework.Graphics.UserInterface 8{ 9 /// <summary> 10 /// A drawable object that supports counting to values. 11 /// </summary> 12 public class Counter : CompositeDrawable 13 { 14 private double count; 15 16 /// <summary> 17 /// The current count. 18 /// </summary> 19 protected double Count 20 { 21 get => count; 22 private set 23 { 24 if (count == value) 25 return; 26 27 count = value; 28 29 OnCountChanged(count); 30 } 31 } 32 33 /// <summary> 34 /// Invoked when <see cref="Count"/> has changed. 35 /// </summary> 36 protected virtual void OnCountChanged(double count) 37 { 38 } 39 40 public TransformSequence<Counter> CountTo(double endCount, double duration = 0, Easing easing = Easing.None) 41 => this.TransformTo(nameof(Count), endCount, duration, easing); 42 } 43 44 public static class CounterTransformSequenceExtensions 45 { 46 public static TransformSequence<Counter> CountTo(this TransformSequence<Counter> t, double endCount, double duration = 0, Easing easing = Easing.None) 47 => t.Append(o => o.CountTo(endCount, duration, easing)); 48 } 49}