2017-03-02 11:20:27 +00: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 osu.Framework.Graphics;
|
2017-02-08 20:22:31 +00:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2017-03-23 09:37:12 +00:00
|
|
|
|
using System;
|
2017-03-24 03:41:14 +00:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Framework.Allocation;
|
2017-03-02 11:20:27 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
|
{
|
2017-04-14 05:40:52 +00:00
|
|
|
|
public class SongProgress : OverlayContainer
|
2017-03-02 11:20:27 +00:00
|
|
|
|
{
|
2017-03-24 02:38:23 +00:00
|
|
|
|
private const int progress_height = 5;
|
2017-04-07 06:20:39 +00:00
|
|
|
|
|
2017-04-14 06:27:24 +00:00
|
|
|
|
protected override bool HideOnEscape => false;
|
|
|
|
|
|
2017-04-07 06:20:39 +00:00
|
|
|
|
private static readonly Vector2 handle_size = new Vector2(14, 25);
|
|
|
|
|
|
2017-03-23 10:15:53 +00:00
|
|
|
|
private const float transition_duration = 200;
|
2017-03-02 11:20:27 +00:00
|
|
|
|
|
2017-03-24 03:41:56 +00:00
|
|
|
|
private readonly SongProgressBar bar;
|
|
|
|
|
private readonly SongProgressGraph graph;
|
2017-03-02 11:20:27 +00:00
|
|
|
|
|
2017-03-23 09:37:12 +00:00
|
|
|
|
public Action<double> OnSeek;
|
2017-03-02 11:20:27 +00:00
|
|
|
|
|
2017-04-07 06:20:39 +00:00
|
|
|
|
private double progress;
|
|
|
|
|
public double Progress
|
2017-03-02 11:20:27 +00:00
|
|
|
|
{
|
2017-04-07 06:20:39 +00:00
|
|
|
|
get { return progress; }
|
2017-03-23 09:37:12 +00:00
|
|
|
|
set
|
2017-03-02 11:20:27 +00:00
|
|
|
|
{
|
2017-04-07 06:20:39 +00:00
|
|
|
|
progress = value;
|
2017-03-23 09:37:12 +00:00
|
|
|
|
updateProgress();
|
|
|
|
|
}
|
2017-03-02 11:20:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 10:15:53 +00:00
|
|
|
|
public int[] Values
|
2017-03-02 11:20:27 +00:00
|
|
|
|
{
|
2017-03-23 10:15:53 +00:00
|
|
|
|
get { return graph.Values; }
|
|
|
|
|
set { graph.Values = value; }
|
2017-03-02 11:20:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-24 03:41:14 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
graph.FillColour = bar.FillColour = colours.BlueLighter;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-02 11:20:27 +00:00
|
|
|
|
public SongProgress()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2017-04-07 06:20:39 +00:00
|
|
|
|
Height = progress_height + SongProgressGraph.Column.HEIGHT + handle_size.Y;
|
2017-04-14 05:40:52 +00:00
|
|
|
|
Y = progress_height;
|
2017-03-02 11:20:27 +00:00
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
graph = new SongProgressGraph
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2017-03-23 11:13:03 +00:00
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Height = SongProgressGraph.Column.HEIGHT,
|
2017-03-24 03:41:14 +00:00
|
|
|
|
Margin = new MarginPadding { Bottom = progress_height },
|
2017-03-02 11:20:27 +00:00
|
|
|
|
},
|
2017-04-07 06:20:39 +00:00
|
|
|
|
bar = new SongProgressBar(progress_height, SongProgressGraph.Column.HEIGHT, handle_size)
|
2017-03-02 11:20:27 +00:00
|
|
|
|
{
|
2017-04-14 05:40:52 +00:00
|
|
|
|
Alpha = 0,
|
2017-03-23 11:13:03 +00:00
|
|
|
|
Anchor = Anchor.BottomLeft,
|
2017-04-14 05:40:52 +00:00
|
|
|
|
Origin = Anchor.BottomLeft,
|
2017-03-02 11:20:27 +00:00
|
|
|
|
SeekRequested = delegate (float position)
|
|
|
|
|
{
|
2017-04-07 06:20:39 +00:00
|
|
|
|
OnSeek?.Invoke(position);
|
2017-03-23 11:13:03 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
2017-02-09 23:08:23 +00:00
|
|
|
|
};
|
2017-03-02 11:20:27 +00:00
|
|
|
|
}
|
2017-03-23 09:37:12 +00:00
|
|
|
|
|
2017-04-14 05:40:52 +00:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
State = Visibility.Visible;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 09:37:12 +00:00
|
|
|
|
private void updateProgress()
|
|
|
|
|
{
|
2017-04-07 06:20:39 +00:00
|
|
|
|
bar.UpdatePosition((float)progress);
|
|
|
|
|
graph.Progress = (int)(graph.ColumnCount * progress);
|
2017-03-23 09:37:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-14 05:40:52 +00:00
|
|
|
|
private bool barVisible;
|
|
|
|
|
|
|
|
|
|
public void ToggleBar()
|
2017-03-23 09:37:12 +00:00
|
|
|
|
{
|
2017-04-14 05:40:52 +00:00
|
|
|
|
barVisible = !barVisible;
|
|
|
|
|
updateBarVisibility();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateBarVisibility()
|
|
|
|
|
{
|
|
|
|
|
bar.FadeTo(barVisible ? 1 : 0, transition_duration, EasingTypes.In);
|
|
|
|
|
MoveTo(new Vector2(0, barVisible ? 0 : progress_height), transition_duration, EasingTypes.In);
|
|
|
|
|
}
|
2017-03-23 10:15:53 +00:00
|
|
|
|
|
2017-04-14 05:40:52 +00:00
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
updateBarVisibility();
|
2017-04-14 06:27:24 +00:00
|
|
|
|
FadeIn(500, EasingTypes.OutQuint);
|
2017-03-23 09:37:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
2017-04-14 05:40:52 +00:00
|
|
|
|
FadeOut(100);
|
2017-03-23 09:37:12 +00:00
|
|
|
|
}
|
2017-04-07 06:20:39 +00:00
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
updateProgress();
|
|
|
|
|
}
|
2017-03-02 11:20:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|