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 osu.Framework.Graphics;
|
2017-02-09 04:22:31 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2017-03-23 17:37:12 +08:00
|
|
|
|
using System;
|
2017-04-14 16:58:30 +08:00
|
|
|
|
using System.Collections.Generic;
|
2017-03-24 11:41:14 +08:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Framework.Allocation;
|
2017-04-14 16:58:30 +08:00
|
|
|
|
using System.Linq;
|
2017-04-14 17:23:34 +08:00
|
|
|
|
using osu.Framework.Timing;
|
2017-04-14 16:58:30 +08:00
|
|
|
|
using osu.Game.Modes.Objects;
|
|
|
|
|
using osu.Game.Modes.Objects.Types;
|
2017-03-02 19:20:27 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
|
{
|
2017-04-14 17:23:34 +08:00
|
|
|
|
public class SongProgress : OverlayContainer
|
2017-03-02 19:20:27 +08:00
|
|
|
|
{
|
2017-03-24 10:38:23 +08:00
|
|
|
|
private const int progress_height = 5;
|
2017-04-07 14:20:39 +08:00
|
|
|
|
|
2017-04-14 14:27:24 +08:00
|
|
|
|
protected override bool HideOnEscape => false;
|
|
|
|
|
|
2017-04-07 14:20:39 +08:00
|
|
|
|
private static readonly Vector2 handle_size = new Vector2(14, 25);
|
|
|
|
|
|
2017-03-23 18:15:53 +08:00
|
|
|
|
private const float transition_duration = 200;
|
2017-03-02 19:20:27 +08:00
|
|
|
|
|
2017-03-24 11:41:56 +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-04-14 17:23:34 +08:00
|
|
|
|
public IClock AudioClock;
|
|
|
|
|
|
|
|
|
|
private double lastHitTime => ((objects.Last() as IHasEndTime)?.EndTime ?? objects.Last().StartTime) + 1;
|
|
|
|
|
|
|
|
|
|
private IEnumerable<HitObject> objects;
|
2017-03-02 19:20:27 +08:00
|
|
|
|
|
2017-04-14 16:58:30 +08:00
|
|
|
|
public IEnumerable<HitObject> Objects
|
2017-03-02 19:20:27 +08:00
|
|
|
|
{
|
2017-04-14 16:58:30 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2017-04-14 17:23:34 +08:00
|
|
|
|
objects = value;
|
2017-04-14 16:58:30 +08:00
|
|
|
|
|
|
|
|
|
const int granularity = 200;
|
|
|
|
|
|
2017-04-14 17:23:34 +08:00
|
|
|
|
var interval = lastHitTime / granularity;
|
2017-04-14 16:58:30 +08:00
|
|
|
|
|
|
|
|
|
var values = new int[granularity];
|
|
|
|
|
|
|
|
|
|
foreach (var h in objects)
|
|
|
|
|
{
|
|
|
|
|
IHasEndTime end = h as IHasEndTime;
|
|
|
|
|
|
|
|
|
|
int startRange = (int)(h.StartTime / interval);
|
|
|
|
|
int endRange = (int)((end?.EndTime ?? h.StartTime) / interval);
|
|
|
|
|
for (int i = startRange; i <= endRange; i++)
|
|
|
|
|
values[i]++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
graph.Values = values;
|
|
|
|
|
}
|
2017-03-02 19:20:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-24 11:41:14 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
graph.FillColour = bar.FillColour = colours.BlueLighter;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-02 19:20:27 +08:00
|
|
|
|
public SongProgress()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2017-04-07 14:20:39 +08:00
|
|
|
|
Height = progress_height + SongProgressGraph.Column.HEIGHT + handle_size.Y;
|
2017-04-14 13:40:52 +08:00
|
|
|
|
Y = progress_height;
|
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-24 11:41:14 +08:00
|
|
|
|
Margin = new MarginPadding { Bottom = progress_height },
|
2017-03-02 19:20:27 +08:00
|
|
|
|
},
|
2017-04-07 14:20:39 +08:00
|
|
|
|
bar = new SongProgressBar(progress_height, SongProgressGraph.Column.HEIGHT, handle_size)
|
2017-03-02 19:20:27 +08:00
|
|
|
|
{
|
2017-04-14 13:40:52 +08:00
|
|
|
|
Alpha = 0,
|
2017-03-23 19:13:03 +08:00
|
|
|
|
Anchor = Anchor.BottomLeft,
|
2017-04-14 13:40:52 +08:00
|
|
|
|
Origin = Anchor.BottomLeft,
|
2017-03-02 19:20:27 +08:00
|
|
|
|
SeekRequested = delegate (float position)
|
|
|
|
|
{
|
2017-04-07 14:20:39 +08:00
|
|
|
|
OnSeek?.Invoke(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
|
|
|
|
|
2017-04-14 13:40:52 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
State = Visibility.Visible;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool barVisible;
|
|
|
|
|
|
|
|
|
|
public void ToggleBar()
|
2017-03-23 17:37:12 +08:00
|
|
|
|
{
|
2017-04-14 13:40:52 +08: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 18:15:53 +08:00
|
|
|
|
|
2017-04-14 13:40:52 +08:00
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
updateBarVisibility();
|
2017-04-14 14:27:24 +08:00
|
|
|
|
FadeIn(500, EasingTypes.OutQuint);
|
2017-03-23 17:37:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
2017-04-14 13:40:52 +08:00
|
|
|
|
FadeOut(100);
|
2017-03-23 17:37:12 +08:00
|
|
|
|
}
|
2017-04-07 14:20:39 +08:00
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2017-04-14 17:23:34 +08:00
|
|
|
|
double progress = (AudioClock?.CurrentTime ?? Time.Current) / lastHitTime;
|
|
|
|
|
|
|
|
|
|
bar.UpdatePosition((float)progress);
|
|
|
|
|
graph.Progress = (int)(graph.ColumnCount * progress);
|
|
|
|
|
|
2017-04-07 14:20:39 +08:00
|
|
|
|
}
|
2017-03-02 19:20:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|