2019-01-24 16:43:03 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-11-06 14:46:36 +08:00
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
using osu.Framework.Bindables;
|
2018-11-06 14:46:36 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Lists;
|
|
|
|
using osu.Game.Configuration;
|
|
|
|
using osu.Game.Rulesets.Timing;
|
|
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
|
|
|
using osu.Game.Rulesets.UI.Scrolling.Algorithms;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// A container which provides a <see cref="IScrollingInfo"/> to children.
|
|
|
|
/// This should only be used when testing
|
|
|
|
/// </summary>
|
|
|
|
public class ScrollingTestContainer : Container
|
|
|
|
{
|
2018-11-07 15:51:28 +08:00
|
|
|
public SortedList<MultiplierControlPoint> ControlPoints => scrollingInfo.Algorithm.ControlPoints;
|
2018-11-06 14:46:36 +08:00
|
|
|
|
2019-02-28 12:31:40 +08:00
|
|
|
public ScrollVisualisationMethod ScrollAlgorithm
|
|
|
|
{
|
|
|
|
set => scrollingInfo.Algorithm.Algorithm = value;
|
|
|
|
}
|
2018-11-06 14:46:36 +08:00
|
|
|
|
2019-02-28 12:31:40 +08:00
|
|
|
public double TimeRange
|
|
|
|
{
|
|
|
|
set => scrollingInfo.TimeRange.Value = value;
|
|
|
|
}
|
2018-11-07 16:24:05 +08:00
|
|
|
|
2018-11-12 18:41:06 +08:00
|
|
|
public IScrollingInfo ScrollingInfo => scrollingInfo;
|
|
|
|
|
2018-11-06 14:46:36 +08:00
|
|
|
[Cached(Type = typeof(IScrollingInfo))]
|
|
|
|
private readonly TestScrollingInfo scrollingInfo = new TestScrollingInfo();
|
|
|
|
|
|
|
|
public ScrollingTestContainer(ScrollingDirection direction)
|
|
|
|
{
|
|
|
|
scrollingInfo.Direction.Value = direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Flip() => scrollingInfo.Direction.Value = scrollingInfo.Direction.Value == ScrollingDirection.Up ? ScrollingDirection.Down : ScrollingDirection.Up;
|
|
|
|
|
|
|
|
private class TestScrollingInfo : IScrollingInfo
|
|
|
|
{
|
|
|
|
public readonly Bindable<ScrollingDirection> Direction = new Bindable<ScrollingDirection>();
|
|
|
|
IBindable<ScrollingDirection> IScrollingInfo.Direction => Direction;
|
2018-11-07 15:51:28 +08:00
|
|
|
|
2018-11-07 16:24:05 +08:00
|
|
|
public readonly Bindable<double> TimeRange = new Bindable<double>(1000) { Value = 1000 };
|
|
|
|
IBindable<double> IScrollingInfo.TimeRange => TimeRange;
|
|
|
|
|
2018-11-07 15:51:28 +08:00
|
|
|
public readonly TestScrollAlgorithm Algorithm = new TestScrollAlgorithm();
|
|
|
|
IScrollAlgorithm IScrollingInfo.Algorithm => Algorithm;
|
2018-11-06 14:46:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private class TestScrollAlgorithm : IScrollAlgorithm
|
|
|
|
{
|
|
|
|
public readonly SortedList<MultiplierControlPoint> ControlPoints = new SortedList<MultiplierControlPoint>();
|
|
|
|
|
|
|
|
private IScrollAlgorithm implementation;
|
|
|
|
|
|
|
|
public TestScrollAlgorithm()
|
|
|
|
{
|
2018-11-12 16:36:19 +08:00
|
|
|
Algorithm = ScrollVisualisationMethod.Constant;
|
2018-11-06 14:46:36 +08:00
|
|
|
}
|
|
|
|
|
2018-11-12 16:36:19 +08:00
|
|
|
public ScrollVisualisationMethod Algorithm
|
2018-11-06 14:46:36 +08:00
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
|
|
|
switch (value)
|
|
|
|
{
|
2018-11-12 16:36:19 +08:00
|
|
|
case ScrollVisualisationMethod.Constant:
|
2018-11-06 14:46:36 +08:00
|
|
|
implementation = new ConstantScrollAlgorithm();
|
|
|
|
break;
|
2018-11-12 16:36:19 +08:00
|
|
|
case ScrollVisualisationMethod.Overlapping:
|
2018-11-06 14:46:36 +08:00
|
|
|
implementation = new OverlappingScrollAlgorithm(ControlPoints);
|
|
|
|
break;
|
2018-11-12 16:36:19 +08:00
|
|
|
case ScrollVisualisationMethod.Sequential:
|
2018-11-06 14:46:36 +08:00
|
|
|
implementation = new SequentialScrollAlgorithm(ControlPoints);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public double GetDisplayStartTime(double time, double timeRange)
|
|
|
|
=> implementation.GetDisplayStartTime(time, timeRange);
|
|
|
|
|
|
|
|
public float GetLength(double startTime, double endTime, double timeRange, float scrollLength)
|
|
|
|
=> implementation.GetLength(startTime, endTime, timeRange, scrollLength);
|
|
|
|
|
|
|
|
public float PositionAt(double time, double currentTime, double timeRange, float scrollLength)
|
|
|
|
=> implementation.PositionAt(time, currentTime, timeRange, scrollLength);
|
|
|
|
|
2018-11-12 17:24:18 +08:00
|
|
|
public double TimeAt(float position, double currentTime, double timeRange, float scrollLength)
|
|
|
|
=> implementation.TimeAt(position, currentTime, timeRange, scrollLength);
|
|
|
|
|
2018-11-06 14:46:36 +08:00
|
|
|
public void Reset()
|
|
|
|
=> implementation.Reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|