mirror of
https://github.com/ppy/osu
synced 2025-01-09 15:49:32 +00:00
Couple the timeline to the audio
This commit is contained in:
parent
1dfa3ff995
commit
49f893d5e4
@ -14,14 +14,15 @@ using osu.Game.Screens.Edit.Screens.Compose.Timeline;
|
||||
namespace osu.Game.Tests.Visual
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestCaseEditorComposeTimeline : OsuTestCase
|
||||
public class TestCaseEditorComposeTimeline : EditorClockTestCase
|
||||
{
|
||||
public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(TimelineArea), typeof(Timeline), typeof(BeatmapWaveformGraph), typeof(TimelineButton) };
|
||||
|
||||
private readonly TimelineArea timelineArea;
|
||||
|
||||
public TestCaseEditorComposeTimeline()
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuGameBase osuGame)
|
||||
{
|
||||
TimelineArea timelineArea;
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new MusicController
|
||||
@ -38,11 +39,7 @@ namespace osu.Game.Tests.Visual
|
||||
Size = new Vector2(0.8f, 100)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuGameBase osuGame)
|
||||
{
|
||||
timelineArea.Beatmap.BindTo(osuGame.Beatmap);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics;
|
||||
|
||||
@ -13,6 +16,8 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Timeline
|
||||
public readonly Bindable<bool> WaveformVisible = new Bindable<bool>();
|
||||
public readonly Bindable<WorkingBeatmap> Beatmap = new Bindable<WorkingBeatmap>();
|
||||
|
||||
private IAdjustableClock adjustableClock;
|
||||
|
||||
public Timeline()
|
||||
{
|
||||
ZoomDuration = 200;
|
||||
@ -32,12 +37,87 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Timeline
|
||||
WaveformVisible.ValueChanged += visible => waveform.FadeTo(visible ? 1 : 0, 200, Easing.OutQuint);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(IAdjustableClock adjustableClock)
|
||||
{
|
||||
this.adjustableClock = adjustableClock;
|
||||
}
|
||||
|
||||
private bool handlingUserInput;
|
||||
private bool trackWasPlaying;
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
// We want time = 0 to be at the centre of the container when scrolled to the start
|
||||
Content.Margin = new MarginPadding { Horizontal = DrawWidth / 2 };
|
||||
|
||||
if (!handlingUserInput)
|
||||
ScrollTo((float)(adjustableClock.CurrentTime / Beatmap.Value.Track.Length) * Content.DrawWidth, false);
|
||||
else
|
||||
adjustableClock.Seek(Current / Content.DrawWidth * Beatmap.Value.Track.Length);
|
||||
}
|
||||
|
||||
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
||||
{
|
||||
if (base.OnMouseDown(state, args))
|
||||
{
|
||||
beginUserInput();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
|
||||
{
|
||||
endUserInput();
|
||||
return base.OnMouseUp(state, args);
|
||||
}
|
||||
|
||||
private void beginUserInput()
|
||||
{
|
||||
handlingUserInput = true;
|
||||
trackWasPlaying = adjustableClock.IsRunning;
|
||||
adjustableClock.Stop();
|
||||
}
|
||||
|
||||
private void endUserInput()
|
||||
{
|
||||
handlingUserInput = false;
|
||||
if (trackWasPlaying)
|
||||
adjustableClock.Start();
|
||||
}
|
||||
|
||||
protected override ScrollbarContainer CreateScrollbar(Direction direction) => new TimelineScrollbar(this, direction);
|
||||
|
||||
private class TimelineScrollbar : ScrollbarContainer
|
||||
{
|
||||
private readonly Timeline timeline;
|
||||
|
||||
public TimelineScrollbar(Timeline timeline, Direction scrollDir)
|
||||
: base(scrollDir)
|
||||
{
|
||||
this.timeline = timeline;
|
||||
}
|
||||
|
||||
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
||||
{
|
||||
if (base.OnMouseDown(state, args))
|
||||
{
|
||||
timeline.beginUserInput();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
|
||||
{
|
||||
timeline.endUserInput();
|
||||
return base.OnMouseUp(state, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user