mirror of
https://github.com/SK-la/osu-framework.git
synced 2026-03-13 11:20:31 +00:00
101 lines
3.7 KiB
C#
101 lines
3.7 KiB
C#
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using OpenTK;
|
|
using osu.Framework.Configuration;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Sprites;
|
|
using osu.Framework.Graphics.UserInterface;
|
|
using osu.Framework.Testing;
|
|
|
|
namespace osu.Framework.Tests.Visual
|
|
{
|
|
public class TestCaseCountingText : TestCase
|
|
{
|
|
private readonly Bindable<CountType> countType = new Bindable<CountType>();
|
|
|
|
public TestCaseCountingText()
|
|
{
|
|
Counter counter;
|
|
|
|
BasicDropdown<CountType> typeDropdown;
|
|
Children = new Drawable[]
|
|
{
|
|
typeDropdown = new BasicDropdown<CountType>
|
|
{
|
|
Position = new Vector2(10),
|
|
Width = 150,
|
|
},
|
|
counter = new TestTextCounter(createResult)
|
|
{
|
|
Position = new Vector2(180)
|
|
}
|
|
};
|
|
|
|
typeDropdown.Items = Enum.GetNames(typeof(CountType)).Select(n => new KeyValuePair<string, CountType>(n, (CountType)Enum.Parse(typeof(CountType), n)));
|
|
countType.BindTo(typeDropdown.Current);
|
|
countType.ValueChanged += v => beginStep(lastStep)();
|
|
|
|
AddStep("1 -> 4 | 1 sec", beginStep(() => counter.CountTo(1).CountTo(4, 1000)));
|
|
AddStep("1 -> 4 | 3 sec", beginStep(() => counter.CountTo(1).CountTo(4, 3000)));
|
|
AddStep("4 -> 1 | 1 sec", beginStep(() => counter.CountTo(4).CountTo(1, 1000)));
|
|
AddStep("4 -> 1 | 3 sec", beginStep(() => counter.CountTo(4).CountTo(1, 3000)));
|
|
AddStep("1 -> 4 -> 1 | 6 sec", beginStep(() => counter.CountTo(1).CountTo(4, 3000).Then().CountTo(1, 3000)));
|
|
AddStep("1 -> 4 -> 1 | 2 sec", beginStep(() => counter.CountTo(1).CountTo(4, 1000).Then().CountTo(1, 1000)));
|
|
AddStep("1 -> 100 | 5 sec | OutQuint", beginStep(() => counter.CountTo(1).CountTo(100, 5000, Easing.OutQuint)));
|
|
}
|
|
|
|
private Action lastStep;
|
|
private Action beginStep(Action stepAction) => () =>
|
|
{
|
|
lastStep = stepAction;
|
|
stepAction?.Invoke();
|
|
};
|
|
|
|
private string createResult(double value)
|
|
{
|
|
switch (countType.Value)
|
|
{
|
|
default:
|
|
case CountType.AsDouble:
|
|
return value.ToString(CultureInfo.InvariantCulture);
|
|
case CountType.AsInteger:
|
|
return ((int)value).ToString();
|
|
case CountType.AsIntegerCeiling:
|
|
return ((int)Math.Ceiling(value)).ToString();
|
|
case CountType.AsDouble2:
|
|
return Math.Round(value, 2).ToString(CultureInfo.InvariantCulture);
|
|
case CountType.AsDouble4:
|
|
return Math.Round(value, 4).ToString(CultureInfo.InvariantCulture);
|
|
}
|
|
}
|
|
|
|
private enum CountType
|
|
{
|
|
AsInteger,
|
|
AsIntegerCeiling,
|
|
AsDouble,
|
|
AsDouble2,
|
|
AsDouble4,
|
|
}
|
|
}
|
|
|
|
public class TestTextCounter : Counter
|
|
{
|
|
private readonly Func<double, string> resultFunction;
|
|
private readonly SpriteText text;
|
|
|
|
public TestTextCounter(Func<double, string> resultFunction)
|
|
{
|
|
this.resultFunction = resultFunction;
|
|
AddInternal(text = new SpriteText { TextSize = 24 });
|
|
}
|
|
|
|
protected override void OnCountChanged(double count) => text.Text = resultFunction(count);
|
|
}
|
|
}
|