1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 14:32:55 +08:00
osu-lazer/osu.Game/Tests/Visual/EditorClockTestScene.cs

92 lines
3.1 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 17:19:50 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
2018-04-13 17:19:50 +08:00
using osu.Framework.Allocation;
using osu.Framework.Audio;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2018-10-02 11:02:47 +08:00
using osu.Framework.Input.Events;
2018-04-13 17:19:50 +08:00
using osu.Game.Beatmaps;
using osu.Game.Overlays;
2018-04-13 17:19:50 +08:00
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>
2022-11-24 13:32:20 +08:00
public abstract partial class EditorClockTestScene : OsuManualInputManagerTestScene
2018-04-13 17:19:50 +08:00
{
[Cached]
private readonly OverlayColourProvider overlayColour = new OverlayColourProvider(OverlayColourScheme.Aquamarine);
2018-04-13 17:19:50 +08:00
protected readonly BindableBeatDivisor BeatDivisor = new BindableBeatDivisor();
2022-05-26 17:30:37 +08:00
protected EditorClock EditorClock;
2018-04-13 17:19:50 +08:00
private readonly Bindable<double> frequencyAdjustment = new BindableDouble(1);
private IBeatmap editorClockBeatmap;
protected virtual bool ScrollUsingMouseWheel => true;
protected override Container<Drawable> Content => content;
private readonly Container<Drawable> content = new Container { RelativeSizeAxes = Axes.Both };
2018-04-13 17:19:50 +08:00
2018-07-11 16:07:14 +08:00
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
2018-07-11 16:07:14 +08:00
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
editorClockBeatmap = CreateEditorClockBeatmap();
base.Content.AddRange(new Drawable[]
{
EditorClock = new EditorClock(editorClockBeatmap, BeatDivisor),
content
});
dependencies.Cache(BeatDivisor);
dependencies.CacheAs(EditorClock);
return dependencies;
}
protected override void LoadComplete()
2018-04-13 17:19:50 +08:00
{
Beatmap.Value = CreateWorkingBeatmap(editorClockBeatmap);
base.LoadComplete();
2018-06-07 15:46:54 +08:00
Beatmap.BindValueChanged(beatmapChanged, true);
AddSliderStep("editor clock rate", 0.0, 2.0, 1.0, v => frequencyAdjustment.Value = v);
2018-04-13 17:19:50 +08:00
}
protected virtual IBeatmap CreateEditorClockBeatmap() => new Beatmap();
2019-02-21 17:56:34 +08:00
private void beatmapChanged(ValueChangedEvent<WorkingBeatmap> e)
2018-04-13 17:19:50 +08:00
{
e.OldValue?.Track.RemoveAdjustment(AdjustableProperty.Frequency, frequencyAdjustment);
e.NewValue.Track.AddAdjustment(AdjustableProperty.Frequency, frequencyAdjustment);
EditorClock.ChangeSource(e.NewValue.Track);
2018-04-13 17:19:50 +08:00
}
2018-10-02 11:02:47 +08:00
protected override bool OnScroll(ScrollEvent e)
2018-04-13 17:19:50 +08:00
{
if (!ScrollUsingMouseWheel)
return false;
if (e.ScrollDelta.Y > 0)
EditorClock.SeekBackward(true);
2018-04-13 17:19:50 +08:00
else
EditorClock.SeekForward(true);
2018-04-13 17:19:50 +08:00
return true;
}
}
}