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-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 17:56:34 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Timing;
|
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
|
|
|
|
using osu.Game.Screens.Edit;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Provides a clock, beat-divisor, and scrolling capability for test cases of editor components that
|
|
|
|
|
/// are preferrably tested within the presence of a clock and seek controls.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract class EditorClockTestCase : OsuTestCase
|
|
|
|
|
{
|
|
|
|
|
protected readonly BindableBeatDivisor BeatDivisor = new BindableBeatDivisor();
|
|
|
|
|
protected readonly EditorClock Clock;
|
|
|
|
|
|
|
|
|
|
protected EditorClockTestCase()
|
|
|
|
|
{
|
2018-05-08 21:37:06 +08:00
|
|
|
|
Clock = new EditorClock(new ControlPointInfo(), 5000, BeatDivisor) { IsCoupled = false };
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-11 16:07:14 +08:00
|
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
2018-06-12 18:51:35 +08:00
|
|
|
|
{
|
2018-07-11 16:07:14 +08:00
|
|
|
|
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
2018-06-12 18:51:35 +08:00
|
|
|
|
|
|
|
|
|
dependencies.Cache(BeatDivisor);
|
|
|
|
|
dependencies.CacheAs<IFrameBasedClock>(Clock);
|
|
|
|
|
dependencies.CacheAs<IAdjustableClock>(Clock);
|
|
|
|
|
|
|
|
|
|
return dependencies;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2018-05-23 16:37:39 +08:00
|
|
|
|
private void load()
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-06-07 15:46:54 +08:00
|
|
|
|
Beatmap.BindValueChanged(beatmapChanged, true);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 17:56:34 +08:00
|
|
|
|
private void beatmapChanged(ValueChangedEvent<WorkingBeatmap> e)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-02-21 17:56:34 +08:00
|
|
|
|
Clock.ControlPointInfo = e.NewValue.Beatmap.ControlPointInfo;
|
|
|
|
|
Clock.ChangeSource((IAdjustableClock)e.NewValue.Track ?? new StopwatchClock());
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Clock.ProcessFrame();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
Clock.ProcessFrame();
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnScroll(ScrollEvent e)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-09-19 19:52:57 +08:00
|
|
|
|
if (e.ScrollDelta.Y > 0)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Clock.SeekBackward(true);
|
|
|
|
|
else
|
|
|
|
|
Clock.SeekForward(true);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|