1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 03:52:55 +08:00
osu-lazer/osu.Game.Tests/Visual/TestCaseEditorComposeTimeline.cs

141 lines
4.0 KiB
C#
Raw Normal View History

2018-04-13 17:19:50 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
2018-04-13 17:19:50 +08:00
using OpenTK;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
2018-04-13 17:19:50 +08:00
using osu.Game.Screens.Edit.Screens.Compose.Timeline;
using OpenTK.Graphics;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Tests.Visual
{
[TestFixture]
2018-05-23 11:00:11 +08:00
public class TestCaseEditorComposeTimeline : EditorClockTestCase
2018-04-13 17:19:50 +08:00
{
2018-05-24 14:23:59 +08:00
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(TimelineArea),
typeof(Timeline),
typeof(TimelineButton),
typeof(CentreMarker)
};
2018-04-13 17:19:50 +08:00
[BackgroundDependencyLoader]
private void load()
2018-04-13 17:19:50 +08:00
{
Beatmap.Value = new WaveformTestBeatmap();
2018-04-13 17:19:50 +08:00
Children = new Drawable[]
{
new FillFlowContainer
2018-04-13 17:19:50 +08:00
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 5),
Children = new Drawable[]
{
new StartStopButton(),
new AudioVisualiser(),
}
2018-04-13 17:19:50 +08:00
},
new TimelineArea
2018-04-13 17:19:50 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X,
Size = new Vector2(0.8f, 100)
2018-04-13 17:19:50 +08:00
}
};
}
private class AudioVisualiser : CompositeDrawable
{
private readonly Drawable marker;
private readonly IBindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
private IAdjustableClock adjustableClock;
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,
}
};
}
[BackgroundDependencyLoader]
private void load(IAdjustableClock adjustableClock, IBindableBeatmap beatmap)
{
this.adjustableClock = adjustableClock;
this.beatmap.BindTo(beatmap);
}
protected override void Update()
{
base.Update();
if (beatmap.Value.Track.IsLoaded)
marker.X = (float)(adjustableClock.CurrentTime / beatmap.Value.Track.Length);
}
}
private class StartStopButton : Button
{
private IAdjustableClock adjustableClock;
private bool started;
public StartStopButton()
{
BackgroundColour = Color4.SlateGray;
Size = new Vector2(100, 50);
Text = "Start";
Action = onClick;
}
[BackgroundDependencyLoader]
private void load(IAdjustableClock adjustableClock)
{
this.adjustableClock = adjustableClock;
}
private void onClick()
{
if (started)
{
adjustableClock.Stop();
Text = "Start";
}
else
{
adjustableClock.Start();
Text = "Stop";
}
started = !started;
}
}
2018-04-13 17:19:50 +08:00
}
}