1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-17 00:23:22 +08:00
osu-lazer/osu.Game.Tests/Visual/Editing/TimelineTestScene.cs

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

160 lines
4.8 KiB
C#
Raw Normal View History

2020-01-27 15:54:36 +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.
2022-06-17 15:37:17 +08:00
#nullable disable
2022-07-12 09:41:03 +08:00
using System.Diagnostics;
2020-01-27 15:54:36 +08:00
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Testing;
2020-01-27 15:54:36 +08:00
using osu.Game.Beatmaps;
2022-05-29 20:22:23 +08:00
using osu.Game.Graphics.Cursor;
2020-01-27 15:54:36 +08:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Edit;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Compose.Components.Timeline;
using osu.Game.Storyboards;
2020-01-27 15:54:36 +08:00
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Tests.Visual.Editing
2020-01-27 15:54:36 +08:00
{
public abstract partial class TimelineTestScene : EditorClockTestScene
{
protected TimelineArea TimelineArea { get; private set; }
2020-11-13 16:51:01 +08:00
protected HitObjectComposer Composer { get; private set; }
2021-01-22 05:07:08 +08:00
protected EditorBeatmap EditorBeatmap { get; private set; }
[Resolved]
private AudioManager audio { get; set; }
protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard = null) => new WaveformTestBeatmap(audio);
protected override void LoadComplete()
2020-01-27 15:54:36 +08:00
{
base.LoadComplete();
2020-01-27 15:54:36 +08:00
var playable = Beatmap.Value.GetPlayableBeatmap(Beatmap.Value.BeatmapInfo.Ruleset);
2021-01-22 05:07:08 +08:00
EditorBeatmap = new EditorBeatmap(playable);
2021-01-22 05:07:08 +08:00
Dependencies.Cache(EditorBeatmap);
Dependencies.CacheAs<IBeatSnapProvider>(EditorBeatmap);
2020-01-27 15:54:36 +08:00
Composer = playable.BeatmapInfo.Ruleset.CreateInstance().CreateHitObjectComposer();
Debug.Assert(Composer != null);
Composer.Alpha = 0;
2020-01-27 15:54:36 +08:00
2022-05-29 20:22:23 +08:00
Add(new OsuContextMenuContainer
2020-01-27 15:54:36 +08:00
{
2022-05-29 20:22:23 +08:00
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
2020-01-27 15:54:36 +08:00
{
2022-05-29 20:22:23 +08:00
EditorBeatmap,
Composer,
new FillFlowContainer
2020-01-27 15:54:36 +08:00
{
2022-05-29 20:22:23 +08:00
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 5),
Children = new Drawable[]
{
new StartStopButton(),
new AudioVisualiser(),
}
},
TimelineArea = new TimelineArea(CreateTestComponent())
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2020-01-27 15:54:36 +08:00
}
}
});
}
[SetUpSteps]
public void SetUpSteps()
{
AddUntilStep("wait for track loaded", () => MusicController.TrackLoaded);
AddStep("seek forward", () => EditorClock.Seek(2500));
}
2020-01-27 15:54:36 +08:00
public abstract Drawable CreateTestComponent();
private partial class AudioVisualiser : CompositeDrawable
{
private readonly Drawable marker;
[Resolved]
private IBindable<WorkingBeatmap> beatmap { get; set; }
[Resolved]
2020-05-22 18:49:49 +08:00
private EditorClock editorClock { get; set; }
2020-01-27 15:54:36 +08:00
public AudioVisualiser()
{
Size = new Vector2(250, 25);
InternalChildren = new[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0.25f,
},
marker = new Box
{
RelativePositionAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
Width = 2,
}
};
}
protected override void Update()
{
base.Update();
if (beatmap.Value.Track.IsLoaded)
2020-05-22 18:49:49 +08:00
marker.X = (float)(editorClock.CurrentTime / beatmap.Value.Track.Length);
2020-01-27 15:54:36 +08:00
}
}
private partial class StartStopButton : OsuButton
{
2020-05-22 17:23:24 +08:00
[Resolved]
private EditorClock editorClock { get; set; }
2020-01-27 15:54:36 +08:00
public StartStopButton()
{
BackgroundColour = Color4.SlateGray;
Size = new Vector2(100, 50);
Text = "Start";
Action = onClick;
}
private void onClick()
{
if (editorClock.IsRunning)
2020-05-22 17:23:24 +08:00
editorClock.Stop();
2020-01-27 15:54:36 +08:00
else
2020-05-22 17:23:24 +08:00
editorClock.Start();
2020-03-22 03:15:20 +08:00
}
protected override void Update()
{
base.Update();
2020-01-27 15:54:36 +08:00
Text = editorClock.IsRunning ? "Stop" : "Start";
2020-01-27 15:54:36 +08:00
}
}
}
}