2019-01-24 16:43:03 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using System.Linq;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-05-09 17:06:11 +08:00
|
|
|
|
using osu.Framework.Timing;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
|
|
|
|
using osu.Game.Rulesets.UI;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
|
{
|
|
|
|
|
public class SongProgress : OverlayContainer
|
|
|
|
|
{
|
|
|
|
|
private const int bottom_bar_height = 5;
|
|
|
|
|
|
2018-10-31 01:56:25 +08:00
|
|
|
|
private static readonly Vector2 handle_size = new Vector2(10, 18);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
private const float transition_duration = 200;
|
|
|
|
|
|
|
|
|
|
private readonly SongProgressBar bar;
|
|
|
|
|
private readonly SongProgressGraph graph;
|
|
|
|
|
private readonly SongProgressInfo info;
|
|
|
|
|
|
2019-03-05 12:26:54 +08:00
|
|
|
|
public Action<double> RequestSeek;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-09-26 13:01:15 +08:00
|
|
|
|
public override bool HandleNonPositionalInput => AllowSeeking;
|
|
|
|
|
public override bool HandlePositionalInput => AllowSeeking;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
private double lastHitTime => ((objects.Last() as IHasEndTime)?.EndTime ?? objects.Last().StartTime) + 1;
|
|
|
|
|
|
|
|
|
|
private double firstHitTime => objects.First().StartTime;
|
|
|
|
|
|
|
|
|
|
private IEnumerable<HitObject> objects;
|
|
|
|
|
|
|
|
|
|
public IEnumerable<HitObject> Objects
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
graph.Objects = objects = value;
|
|
|
|
|
|
|
|
|
|
info.StartTime = firstHitTime;
|
|
|
|
|
info.EndTime = lastHitTime;
|
|
|
|
|
|
|
|
|
|
bar.StartTime = firstHitTime;
|
|
|
|
|
bar.EndTime = lastHitTime;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly BindableBool replayLoaded = new BindableBool();
|
|
|
|
|
|
2019-05-09 17:06:11 +08:00
|
|
|
|
public IClock ReferenceClock;
|
|
|
|
|
|
|
|
|
|
private IClock gameplayClock;
|
2019-03-05 12:26:54 +08:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader(true)]
|
|
|
|
|
private void load(OsuColour colours, GameplayClock clock)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-03-05 12:26:54 +08:00
|
|
|
|
if (clock != null)
|
|
|
|
|
gameplayClock = clock;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
graph.FillColour = bar.FillColour = colours.BlueLighter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SongProgress()
|
|
|
|
|
{
|
|
|
|
|
const float graph_height = SquareGraph.Column.WIDTH * 6;
|
|
|
|
|
|
|
|
|
|
Height = bottom_bar_height + graph_height + handle_size.Y;
|
|
|
|
|
Y = bottom_bar_height;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
info = new SongProgressInfo
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Margin = new MarginPadding { Bottom = bottom_bar_height + graph_height },
|
|
|
|
|
},
|
|
|
|
|
graph = new SongProgressGraph
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Height = graph_height,
|
|
|
|
|
Margin = new MarginPadding { Bottom = bottom_bar_height },
|
|
|
|
|
},
|
|
|
|
|
bar = new SongProgressBar(bottom_bar_height, graph_height, handle_size)
|
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
2019-02-27 20:07:17 +08:00
|
|
|
|
Origin = Anchor.BottomLeft,
|
2019-03-05 12:26:54 +08:00
|
|
|
|
OnSeek = time => RequestSeek?.Invoke(time),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
2019-06-11 13:28:52 +08:00
|
|
|
|
Show();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-02-22 16:51:39 +08:00
|
|
|
|
replayLoaded.ValueChanged += loaded => AllowSeeking = loaded.NewValue;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
replayLoaded.TriggerChange();
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 13:49:33 +08:00
|
|
|
|
public void BindDrawableRuleset(DrawableRuleset drawableRuleset)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-03-19 22:44:15 +08:00
|
|
|
|
replayLoaded.BindTo(drawableRuleset.HasReplayLoaded);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool allowSeeking;
|
|
|
|
|
|
|
|
|
|
public bool AllowSeeking
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => allowSeeking;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (allowSeeking == value) return;
|
|
|
|
|
|
|
|
|
|
allowSeeking = value;
|
|
|
|
|
updateBarVisibility();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateBarVisibility()
|
|
|
|
|
{
|
|
|
|
|
bar.FadeTo(allowSeeking ? 1 : 0, transition_duration, Easing.In);
|
|
|
|
|
this.MoveTo(new Vector2(0, allowSeeking ? 0 : bottom_bar_height), transition_duration, Easing.In);
|
2018-10-30 20:32:12 +08:00
|
|
|
|
|
|
|
|
|
info.Margin = new MarginPadding { Bottom = Height - (allowSeeking ? 0 : handle_size.Y) };
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
updateBarVisibility();
|
|
|
|
|
this.FadeIn(500, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
|
|
|
|
this.FadeOut(100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
if (objects == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2019-05-09 17:06:11 +08:00
|
|
|
|
double gameplayTime = gameplayClock?.CurrentTime ?? Time.Current;
|
|
|
|
|
double frameStableTime = ReferenceClock?.CurrentTime ?? gameplayTime;
|
|
|
|
|
|
|
|
|
|
double progress = Math.Min(1, (frameStableTime - firstHitTime) / (lastHitTime - firstHitTime));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-05-09 17:06:11 +08:00
|
|
|
|
bar.CurrentTime = gameplayTime;
|
2019-03-05 12:26:54 +08:00
|
|
|
|
graph.Progress = (int)(graph.ColumnCount * progress);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|