Fix various test scenes not adding EditorClock to the draw hierarchy

This commit is contained in:
Dean Herbert
2022-08-17 15:40:01 +09:00
parent 12d6d6793c
commit 4b72e55770
14 changed files with 174 additions and 165 deletions

View File

@ -6,6 +6,8 @@
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
using osu.Game.Beatmaps;
using osu.Game.Overlays;
@ -24,30 +26,39 @@ namespace osu.Game.Tests.Visual
protected readonly BindableBeatDivisor BeatDivisor = new BindableBeatDivisor();
[Cached]
protected new readonly EditorClock Clock;
protected EditorClock EditorClock;
private readonly Bindable<double> frequencyAdjustment = new BindableDouble(1);
private IBeatmap editorClockBeatmap;
protected virtual bool ScrollUsingMouseWheel => true;
protected EditorClockTestScene()
{
Clock = new EditorClock(new Beatmap(), BeatDivisor) { IsCoupled = false };
}
protected override Container<Drawable> Content => content;
private readonly Container<Drawable> content = new Container { RelativeSizeAxes = Axes.Both };
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
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(Clock);
dependencies.CacheAs(EditorClock);
return dependencies;
}
protected override void LoadComplete()
{
Beatmap.Value = CreateWorkingBeatmap(editorClockBeatmap);
base.LoadComplete();
Beatmap.BindValueChanged(beatmapChanged, true);
@ -55,22 +66,13 @@ namespace osu.Game.Tests.Visual
AddSliderStep("editor clock rate", 0.0, 2.0, 1.0, v => frequencyAdjustment.Value = v);
}
protected virtual IBeatmap CreateEditorClockBeatmap() => new Beatmap();
private void beatmapChanged(ValueChangedEvent<WorkingBeatmap> e)
{
e.OldValue?.Track.RemoveAdjustment(AdjustableProperty.Frequency, frequencyAdjustment);
Clock.Beatmap = e.NewValue.Beatmap;
Clock.ChangeSource(e.NewValue.Track);
Clock.ProcessFrame();
e.NewValue.Track.AddAdjustment(AdjustableProperty.Frequency, frequencyAdjustment);
}
protected override void Update()
{
base.Update();
Clock.ProcessFrame();
EditorClock.ChangeSource(e.NewValue.Track);
}
protected override bool OnScroll(ScrollEvent e)
@ -79,9 +81,9 @@ namespace osu.Game.Tests.Visual
return false;
if (e.ScrollDelta.Y > 0)
Clock.SeekBackward(true);
EditorClock.SeekBackward(true);
else
Clock.SeekForward(true);
EditorClock.SeekForward(true);
return true;
}