1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 07:47:27 +08:00
osu-lazer/osu.Game/Screens/Edit/Screens/Compose/Timeline/Timeline.cs

124 lines
3.7 KiB
C#
Raw Normal View History

2018-05-18 12:05:58 +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
2018-05-23 11:00:11 +08:00
using osu.Framework.Allocation;
2018-05-18 12:05:58 +08:00
using osu.Framework.Configuration;
using osu.Framework.Graphics;
2018-05-23 11:00:11 +08:00
using osu.Framework.Input;
using osu.Framework.Timing;
2018-05-18 12:05:58 +08:00
using osu.Game.Beatmaps;
using osu.Game.Graphics;
namespace osu.Game.Screens.Edit.Screens.Compose.Timeline
{
public class Timeline : ZoomableScrollContainer
{
public readonly Bindable<bool> WaveformVisible = new Bindable<bool>();
public readonly Bindable<WorkingBeatmap> Beatmap = new Bindable<WorkingBeatmap>();
2018-05-23 11:00:11 +08:00
private IAdjustableClock adjustableClock;
2018-05-18 12:05:58 +08:00
public Timeline()
{
2018-05-18 16:53:09 +08:00
ZoomDuration = 200;
ZoomEasing = Easing.OutQuint;
Zoom = 10;
2018-05-18 12:05:58 +08:00
BeatmapWaveformGraph waveform;
Child = waveform = new BeatmapWaveformGraph
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.FromHex("222"),
Depth = float.MaxValue
};
waveform.Beatmap.BindTo(Beatmap);
WaveformVisible.ValueChanged += visible => waveform.FadeTo(visible ? 1 : 0, 200, Easing.OutQuint);
}
2018-05-23 11:00:11 +08:00
[BackgroundDependencyLoader]
private void load(IAdjustableClock adjustableClock)
{
this.adjustableClock = adjustableClock;
}
private bool handlingUserInput;
private bool trackWasPlaying;
2018-05-18 12:05:58 +08:00
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 };
2018-05-23 11:00:11 +08:00
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);
}
2018-05-18 12:05:58 +08:00
}
}
}