mirror of
https://github.com/ppy/osu
synced 2025-01-09 23:59:44 +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
|
namespace osu.Game.Tests.Visual
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class TestCaseEditorComposeTimeline : OsuTestCase
|
public class TestCaseEditorComposeTimeline : EditorClockTestCase
|
||||||
{
|
{
|
||||||
public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(TimelineArea), typeof(Timeline), typeof(BeatmapWaveformGraph), typeof(TimelineButton) };
|
public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(TimelineArea), typeof(Timeline), typeof(BeatmapWaveformGraph), typeof(TimelineButton) };
|
||||||
|
|
||||||
private readonly TimelineArea timelineArea;
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OsuGameBase osuGame)
|
||||||
public TestCaseEditorComposeTimeline()
|
|
||||||
{
|
{
|
||||||
|
TimelineArea timelineArea;
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new MusicController
|
new MusicController
|
||||||
@ -38,11 +39,7 @@ namespace osu.Game.Tests.Visual
|
|||||||
Size = new Vector2(0.8f, 100)
|
Size = new Vector2(0.8f, 100)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load(OsuGameBase osuGame)
|
|
||||||
{
|
|
||||||
timelineArea.Beatmap.BindTo(osuGame.Beatmap);
|
timelineArea.Beatmap.BindTo(osuGame.Beatmap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Configuration;
|
using osu.Framework.Configuration;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Input;
|
||||||
|
using osu.Framework.Timing;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Graphics;
|
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<bool> WaveformVisible = new Bindable<bool>();
|
||||||
public readonly Bindable<WorkingBeatmap> Beatmap = new Bindable<WorkingBeatmap>();
|
public readonly Bindable<WorkingBeatmap> Beatmap = new Bindable<WorkingBeatmap>();
|
||||||
|
|
||||||
|
private IAdjustableClock adjustableClock;
|
||||||
|
|
||||||
public Timeline()
|
public Timeline()
|
||||||
{
|
{
|
||||||
ZoomDuration = 200;
|
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);
|
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()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
base.Update();
|
base.Update();
|
||||||
|
|
||||||
// We want time = 0 to be at the centre of the container when scrolled to the start
|
// We want time = 0 to be at the centre of the container when scrolled to the start
|
||||||
Content.Margin = new MarginPadding { Horizontal = DrawWidth / 2 };
|
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