osu/osu.Game/Tests/Visual/EditorClockTestScene.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
2.5 KiB
C#
Raw Normal View History

// 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 09:19:50 +00:00
2018-04-06 09:12:44 +00:00
using osu.Framework.Allocation;
2019-02-21 10:04:31 +00:00
using osu.Framework.Bindables;
2018-10-02 03:02:47 +00:00
using osu.Framework.Input.Events;
2018-04-06 09:12:44 +00:00
using osu.Game.Beatmaps;
using osu.Game.Overlays;
2022-05-25 14:30:53 +00:00
using osu.Game.Rulesets.Edit;
2018-04-06 09:12:44 +00:00
using osu.Game.Screens.Edit;
2018-04-13 09:19:50 +00:00
2018-04-06 09:12:44 +00:00
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>
2020-04-28 09:35:37 +00:00
public abstract class EditorClockTestScene : OsuManualInputManagerTestScene
2018-04-06 09:12:44 +00:00
{
[Cached]
private readonly OverlayColourProvider overlayColour = new OverlayColourProvider(OverlayColourScheme.Aquamarine);
2022-05-25 14:30:53 +00:00
[Cached(typeof(EditorBeatmap))]
[Cached(typeof(IBeatSnapProvider))]
private readonly EditorBeatmap editorBeatmap;
2018-04-06 09:12:44 +00:00
protected readonly BindableBeatDivisor BeatDivisor = new BindableBeatDivisor();
2019-04-25 08:36:17 +00:00
protected new readonly EditorClock Clock;
2018-04-13 09:19:50 +00:00
protected virtual bool ScrollUsingMouseWheel => true;
protected EditorClockTestScene()
{
2022-05-25 14:30:53 +00:00
editorBeatmap = new EditorBeatmap(new Beatmap());
Clock = new EditorClock(editorBeatmap, BeatDivisor) { IsCoupled = false };
}
2018-04-13 09:19:50 +00:00
2018-07-11 08:07:14 +00:00
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
2018-07-11 08:07:14 +00:00
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
dependencies.Cache(BeatDivisor);
dependencies.CacheAs(Clock);
return dependencies;
}
protected override void LoadComplete()
2018-04-06 09:12:44 +00:00
{
base.LoadComplete();
2018-06-07 07:46:54 +00:00
Beatmap.BindValueChanged(beatmapChanged, true);
2018-04-06 09:12:44 +00:00
}
2018-04-13 09:19:50 +00:00
2019-02-21 09:56:34 +00:00
private void beatmapChanged(ValueChangedEvent<WorkingBeatmap> e)
{
Clock.Beatmap = e.NewValue.Beatmap;
Clock.ChangeSource(e.NewValue.Track);
Clock.ProcessFrame();
}
2018-04-13 09:19:50 +00:00
protected override void Update()
{
base.Update();
2018-04-13 09:19:50 +00:00
Clock.ProcessFrame();
}
2018-04-13 09:19:50 +00:00
2018-10-02 03:02:47 +00:00
protected override bool OnScroll(ScrollEvent e)
2018-04-06 09:12:44 +00:00
{
if (!ScrollUsingMouseWheel)
return false;
if (e.ScrollDelta.Y > 0)
2018-04-06 09:12:44 +00:00
Clock.SeekBackward(true);
else
Clock.SeekForward(true);
2018-04-13 09:19:50 +00:00
2018-04-06 09:12:44 +00:00
return true;
}
}
}