2018-01-05 11:21:19 +00:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-03-02 11:20:27 +00:00
|
|
|
|
// 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;
|
2017-03-23 09:37:12 +00:00
|
|
|
|
using System;
|
2017-04-14 08:58:30 +00:00
|
|
|
|
using System.Collections.Generic;
|
2017-03-24 03:41:14 +00:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Framework.Allocation;
|
2017-04-14 08:58:30 +00:00
|
|
|
|
using System.Linq;
|
2017-04-14 09:23:34 +00:00
|
|
|
|
using osu.Framework.Timing;
|
2017-04-18 07:05:58 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2017-03-02 11:20:27 +00:00
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
|
{
|
2017-04-14 09:23:34 +00:00
|
|
|
|
public class SongProgress : OverlayContainer
|
2017-03-02 11:20:27 +00:00
|
|
|
|
{
|
2017-04-18 09:29:24 +00:00
|
|
|
|
private const int bottom_bar_height = 5;
|
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-04-28 01:56:34 +00:00
|
|
|
|
private readonly SongProgressInfo info;
|
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-05-17 12:57:01 +00:00
|
|
|
|
public override bool HandleInput => AllowSeeking;
|
|
|
|
|
|
2017-05-09 03:05:37 +00:00
|
|
|
|
private IClock audioClock;
|
2017-05-10 00:45:31 +00:00
|
|
|
|
public IClock AudioClock { set { audioClock = info.AudioClock = value; } }
|
2017-04-14 09:23:34 +00:00
|
|
|
|
|
|
|
|
|
private double lastHitTime => ((objects.Last() as IHasEndTime)?.EndTime ?? objects.Last().StartTime) + 1;
|
|
|
|
|
|
2017-04-26 09:17:17 +00:00
|
|
|
|
private double firstHitTime => objects.First().StartTime;
|
|
|
|
|
|
2017-04-14 09:23:34 +00:00
|
|
|
|
private IEnumerable<HitObject> objects;
|
2017-03-02 11:20:27 +00:00
|
|
|
|
|
2017-04-14 08:58:30 +00:00
|
|
|
|
public IEnumerable<HitObject> Objects
|
2017-03-02 11:20:27 +00:00
|
|
|
|
{
|
2017-04-14 08:58:30 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
2017-04-18 09:40:02 +00:00
|
|
|
|
graph.Objects = objects = value;
|
2017-05-09 03:05:37 +00:00
|
|
|
|
|
|
|
|
|
info.StartTime = firstHitTime;
|
|
|
|
|
info.EndTime = lastHitTime;
|
2017-06-22 16:42:29 +00:00
|
|
|
|
|
|
|
|
|
bar.StartTime = firstHitTime;
|
|
|
|
|
bar.EndTime = lastHitTime;
|
2017-04-14 08:58:30 +00:00
|
|
|
|
}
|
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()
|
|
|
|
|
{
|
2017-04-18 10:22:45 +00:00
|
|
|
|
const float graph_height = SquareGraph.Column.WIDTH * 6;
|
|
|
|
|
|
|
|
|
|
Height = bottom_bar_height + graph_height + handle_size.Y;
|
2017-04-18 09:29:24 +00:00
|
|
|
|
Y = bottom_bar_height;
|
2017-03-02 11:20:27 +00:00
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-04-28 01:56:34 +00:00
|
|
|
|
info = new SongProgressInfo
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2017-05-09 03:05:37 +00:00
|
|
|
|
Margin = new MarginPadding { Bottom = bottom_bar_height + graph_height },
|
2017-04-28 01:56:34 +00:00
|
|
|
|
},
|
2017-03-02 11:20:27 +00:00
|
|
|
|
graph = new SongProgressGraph
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2017-03-23 11:13:03 +00:00
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
2017-04-18 10:22:45 +00:00
|
|
|
|
Height = graph_height,
|
2017-04-18 09:29:24 +00:00
|
|
|
|
Margin = new MarginPadding { Bottom = bottom_bar_height },
|
2017-03-02 11:20:27 +00:00
|
|
|
|
},
|
2017-04-18 10:22:45 +00:00
|
|
|
|
bar = new SongProgressBar(bottom_bar_height, graph_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-06-23 17:24:46 +00:00
|
|
|
|
OnSeek = position => 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-04-25 10:07:07 +00:00
|
|
|
|
private bool allowSeeking;
|
2017-04-14 05:40:52 +00:00
|
|
|
|
|
2017-04-25 10:07:07 +00:00
|
|
|
|
public bool AllowSeeking
|
2017-03-23 09:37:12 +00:00
|
|
|
|
{
|
2017-04-25 10:07:07 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return allowSeeking;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (allowSeeking == value) return;
|
|
|
|
|
|
|
|
|
|
allowSeeking = value;
|
|
|
|
|
updateBarVisibility();
|
|
|
|
|
}
|
2017-04-14 05:40:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateBarVisibility()
|
|
|
|
|
{
|
2017-07-22 18:50:25 +00:00
|
|
|
|
bar.FadeTo(allowSeeking ? 1 : 0, transition_duration, Easing.In);
|
|
|
|
|
this.MoveTo(new Vector2(0, allowSeeking ? 0 : bottom_bar_height), transition_duration, Easing.In);
|
2017-04-14 05:40:52 +00:00
|
|
|
|
}
|
2017-03-23 10:15:53 +00:00
|
|
|
|
|
2017-04-14 05:40:52 +00:00
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
updateBarVisibility();
|
2017-07-22 18:50:25 +00:00
|
|
|
|
this.FadeIn(500, Easing.OutQuint);
|
2017-03-23 09:37:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
2017-07-14 16:18:12 +00:00
|
|
|
|
this.FadeOut(100);
|
2017-03-23 09:37:12 +00:00
|
|
|
|
}
|
2017-04-07 06:20:39 +00:00
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2017-04-18 09:09:37 +00:00
|
|
|
|
if (objects == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-06-22 16:42:29 +00:00
|
|
|
|
double position = audioClock?.CurrentTime ?? Time.Current;
|
|
|
|
|
double progress = (position - firstHitTime) / (lastHitTime - firstHitTime);
|
2017-04-14 09:23:34 +00:00
|
|
|
|
|
2017-06-08 06:35:10 +00:00
|
|
|
|
if (progress < 1)
|
2017-05-10 22:48:46 +00:00
|
|
|
|
{
|
2017-06-22 16:42:29 +00:00
|
|
|
|
bar.CurrentTime = position;
|
2017-05-10 22:48:46 +00:00
|
|
|
|
graph.Progress = (int)(graph.ColumnCount * progress);
|
|
|
|
|
}
|
2017-04-07 06:20:39 +00:00
|
|
|
|
}
|
2017-03-02 11:20:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|