1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 12:47:25 +08:00
osu-lazer/osu.Game/Screens/Play/SongProgress.cs

108 lines
3.4 KiB
C#
Raw Normal View History

// 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;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Transforms;
2017-03-23 17:37:12 +08:00
using System;
namespace osu.Game.Screens.Play
{
public class SongProgress : OverlayContainer
{
2017-03-24 10:38:23 +08:00
private const int progress_height = 5;
2017-03-23 18:24:43 +08:00
private readonly Vector2 handleSize = new Vector2(14, 25);
private readonly Color4 fillColour = new Color4(221, 255, 255, 255);
private const float transition_duration = 200;
2017-03-23 18:24:43 +08:00
private readonly SongProgressBar bar;
private readonly SongProgressGraph graph;
2017-03-23 17:37:12 +08:00
public Action<double> OnSeek;
2017-03-23 17:37:12 +08:00
private double currentTime;
public double CurrentTime
{
2017-03-23 17:37:12 +08:00
get { return currentTime; }
set
{
2017-03-23 17:37:12 +08:00
currentTime = value;
updateProgress();
}
}
private double length;
public double Length
{
get { return length; }
2017-03-23 17:37:12 +08:00
set
{
length = value;
2017-03-23 17:37:12 +08:00
updateProgress();
}
}
public int[] Values
{
get { return graph.Values; }
set { graph.Values = value; }
}
public SongProgress()
{
RelativeSizeAxes = Axes.X;
2017-03-24 10:38:23 +08:00
Height = progress_height + SongProgressGraph.Column.HEIGHT + handleSize.Y;
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,
Margin = new MarginPadding
{
2017-03-24 10:38:23 +08:00
Bottom = progress_height,
2017-03-23 19:13:03 +08:00
},
},
2017-03-24 10:38:23 +08:00
bar = new SongProgressBar(progress_height, SongProgressGraph.Column.HEIGHT, handleSize, fillColour)
{
2017-03-23 19:13:03 +08:00
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
SeekRequested = delegate (float position)
{
OnSeek?.Invoke(Length * position);
2017-03-23 19:13:03 +08:00
},
},
};
}
2017-03-23 17:37:12 +08:00
private void updateProgress()
{
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()
{
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()
{
bar.IsEnabled = false;
2017-03-23 19:32:24 +08:00
bar.FadeOut(transition_duration, EasingTypes.In);
2017-03-24 10:38:23 +08:00
MoveTo(new Vector2(0f, progress_height), transition_duration, EasingTypes.In);
2017-03-23 17:37:12 +08:00
}
}
}