2017-03-02 19:20:27 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
using osu.Framework.Graphics;
|
2017-02-09 04:22:31 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2017-03-02 19:20:27 +08:00
|
|
|
|
using osu.Framework.Graphics.Transforms;
|
2017-03-23 17:37:12 +08:00
|
|
|
|
using System;
|
2017-03-02 19:20:27 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
|
{
|
|
|
|
|
public class SongProgress : OverlayContainer
|
|
|
|
|
{
|
2017-03-23 18:24:43 +08:00
|
|
|
|
private const int bar_height = 5;
|
|
|
|
|
private readonly Vector2 handleSize = new Vector2(14, 25);
|
|
|
|
|
private readonly Color4 fillColour = new Color4(221, 255, 255, 255);
|
2017-03-23 18:15:53 +08:00
|
|
|
|
private const float transition_duration = 200;
|
2017-03-02 19:20:27 +08:00
|
|
|
|
|
2017-03-23 18:24:43 +08:00
|
|
|
|
private readonly SongProgressBar bar;
|
|
|
|
|
private readonly SongProgressGraph graph;
|
2017-03-02 19:20:27 +08:00
|
|
|
|
|
2017-03-23 17:37:12 +08:00
|
|
|
|
public Action<double> OnSeek;
|
2017-03-02 19:20:27 +08:00
|
|
|
|
|
2017-03-23 17:37:12 +08:00
|
|
|
|
private double currentTime;
|
|
|
|
|
public double CurrentTime
|
2017-03-02 19:20:27 +08:00
|
|
|
|
{
|
2017-03-23 17:37:12 +08:00
|
|
|
|
get { return currentTime; }
|
|
|
|
|
set
|
2017-03-02 19:20:27 +08:00
|
|
|
|
{
|
2017-03-23 17:37:12 +08:00
|
|
|
|
currentTime = value;
|
|
|
|
|
updateProgress();
|
2017-03-02 19:20:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 18:15:53 +08:00
|
|
|
|
private double length;
|
|
|
|
|
public double Length
|
2017-03-02 19:20:27 +08:00
|
|
|
|
{
|
2017-03-23 18:15:53 +08:00
|
|
|
|
get { return length; }
|
2017-03-23 17:37:12 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2017-03-23 18:15:53 +08:00
|
|
|
|
length = value;
|
2017-03-23 17:37:12 +08:00
|
|
|
|
updateProgress();
|
|
|
|
|
}
|
2017-03-02 19:20:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 18:15:53 +08:00
|
|
|
|
public int[] Values
|
2017-03-02 19:20:27 +08:00
|
|
|
|
{
|
2017-03-23 18:15:53 +08:00
|
|
|
|
get { return graph.Values; }
|
|
|
|
|
set { graph.Values = value; }
|
2017-03-02 19:20:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SongProgress()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2017-03-23 19:13:03 +08:00
|
|
|
|
Height = bar_height + SongProgressGraph.Column.HEIGHT + handleSize.Y;
|
2017-03-02 19:20:27 +08:00
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
graph = new SongProgressGraph
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2017-03-23 19:13:03 +08:00
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Height = SongProgressGraph.Column.HEIGHT,
|
2017-03-02 19:20:27 +08:00
|
|
|
|
Margin = new MarginPadding
|
|
|
|
|
{
|
2017-03-23 19:13:03 +08:00
|
|
|
|
Bottom = bar_height,
|
|
|
|
|
},
|
2017-03-02 19:20:27 +08:00
|
|
|
|
},
|
2017-03-23 19:13:03 +08:00
|
|
|
|
bar = new SongProgressBar(bar_height, SongProgressGraph.Column.HEIGHT, handleSize, fillColour)
|
2017-03-02 19:20:27 +08:00
|
|
|
|
{
|
2017-03-23 19:13:03 +08:00
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
2017-03-02 19:20:27 +08:00
|
|
|
|
SeekRequested = delegate (float position)
|
|
|
|
|
{
|
2017-03-23 18:15:53 +08:00
|
|
|
|
OnSeek?.Invoke(Length * position);
|
2017-03-23 19:13:03 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
2017-02-10 07:08:23 +08:00
|
|
|
|
};
|
2017-03-02 19:20:27 +08:00
|
|
|
|
}
|
2017-03-23 17:37:12 +08:00
|
|
|
|
|
|
|
|
|
private void updateProgress()
|
|
|
|
|
{
|
2017-03-23 18:15:53 +08:00
|
|
|
|
float currentProgress = (float)(CurrentTime / Length);
|
2017-03-23 17:37:12 +08:00
|
|
|
|
bar.UpdatePosition(currentProgress);
|
|
|
|
|
graph.Progress = (int)(graph.ColumnCount * currentProgress);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
2017-03-23 18:15:53 +08:00
|
|
|
|
bar.IsEnabled = true;
|
|
|
|
|
updateProgress(); //in case progress was changed while the bar was hidden
|
|
|
|
|
|
2017-03-23 19:32:24 +08:00
|
|
|
|
bar.FadeIn(transition_duration, EasingTypes.In);
|
2017-03-23 17:37:12 +08:00
|
|
|
|
MoveTo(Vector2.Zero, transition_duration, EasingTypes.In);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
2017-03-23 18:15:53 +08:00
|
|
|
|
bar.IsEnabled = false;
|
2017-03-23 19:32:24 +08:00
|
|
|
|
bar.FadeOut(transition_duration, EasingTypes.In);
|
2017-03-23 17:37:12 +08:00
|
|
|
|
MoveTo(new Vector2(0f, bar_height), transition_duration, EasingTypes.In);
|
|
|
|
|
}
|
2017-03-02 19:20:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|