osu/osu.Game/Screens/Play/SongProgress.cs
Dean Herbert 7e99fc47e2
wip
2017-04-07 16:54:54 +09:00

107 lines
3.2 KiB
C#

// 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;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using System;
using osu.Game.Graphics;
using osu.Framework.Allocation;
namespace osu.Game.Screens.Play
{
public class SongProgress : OverlayContainer
{
private const int progress_height = 5;
private static readonly Vector2 handle_size = new Vector2(14, 25);
private const float transition_duration = 200;
private readonly SongProgressBar bar;
private readonly SongProgressGraph graph;
public Action<double> OnSeek;
private double progress;
public double Progress
{
get { return progress; }
set
{
progress = value;
updateProgress();
}
}
public int[] Values
{
get { return graph.Values; }
set { graph.Values = value; }
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
graph.FillColour = bar.FillColour = colours.BlueLighter;
}
public SongProgress()
{
RelativeSizeAxes = Axes.X;
Height = progress_height + SongProgressGraph.Column.HEIGHT + handle_size.Y;
Children = new Drawable[]
{
graph = new SongProgressGraph
{
RelativeSizeAxes = Axes.X,
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
Height = SongProgressGraph.Column.HEIGHT,
Margin = new MarginPadding { Bottom = progress_height },
},
bar = new SongProgressBar(progress_height, SongProgressGraph.Column.HEIGHT, handle_size)
{
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
SeekRequested = delegate (float position)
{
OnSeek?.Invoke(position);
},
},
};
}
private void updateProgress()
{
bar.UpdatePosition((float)progress);
graph.Progress = (int)(graph.ColumnCount * progress);
}
protected override void PopIn()
{
bar.IsEnabled = true;
updateProgress(); //in case progress was changed while the bar was hidden
bar.FadeIn(transition_duration, EasingTypes.In);
MoveTo(Vector2.Zero, transition_duration, EasingTypes.In);
}
protected override void PopOut()
{
bar.IsEnabled = false;
bar.FadeOut(transition_duration, EasingTypes.In);
MoveTo(new Vector2(0f, progress_height), transition_duration, EasingTypes.In);
}
protected override void Update()
{
base.Update();
updateProgress();
}
}
}