2019-01-24 08:43:03 +00: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 09:19:50 +00:00
|
|
|
|
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
2018-04-13 09:19:50 +00: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 10:04:31 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-05-09 09:06:11 +00:00
|
|
|
|
using osu.Framework.Timing;
|
2019-07-04 09:59:38 +00:00
|
|
|
|
using osu.Game.Configuration;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
|
using osu.Game.Rulesets.UI;
|
2021-05-17 09:26:15 +00:00
|
|
|
|
using osu.Game.Skinning;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
|
{
|
2021-05-17 09:26:15 +00:00
|
|
|
|
public class SongProgress : OverlayContainer, ISkinnableDrawable
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2021-05-18 06:50:40 +00:00
|
|
|
|
public const float MAX_HEIGHT = info_height + bottom_bar_height + graph_height + handle_height;
|
|
|
|
|
|
|
|
|
|
private const float info_height = 20;
|
|
|
|
|
private const float bottom_bar_height = 5;
|
2019-07-04 09:59:38 +00:00
|
|
|
|
private const float graph_height = SquareGraph.Column.WIDTH * 6;
|
2021-05-18 06:50:40 +00:00
|
|
|
|
private const float handle_height = 18;
|
|
|
|
|
|
|
|
|
|
private static readonly Vector2 handle_size = new Vector2(10, handle_height);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
private const float transition_duration = 200;
|
|
|
|
|
|
|
|
|
|
private readonly SongProgressBar bar;
|
|
|
|
|
private readonly SongProgressGraph graph;
|
|
|
|
|
private readonly SongProgressInfo info;
|
|
|
|
|
|
2019-03-05 04:26:54 +00:00
|
|
|
|
public Action<double> RequestSeek;
|
2019-07-05 06:48:40 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether seeking is allowed and the progress bar should be shown.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public readonly Bindable<bool> AllowSeeking = new Bindable<bool>();
|
|
|
|
|
|
2019-07-05 07:16:50 +00:00
|
|
|
|
public readonly Bindable<bool> ShowGraph = new Bindable<bool>();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-07-05 06:48:40 +00:00
|
|
|
|
public override bool HandleNonPositionalInput => AllowSeeking.Value;
|
|
|
|
|
public override bool HandlePositionalInput => AllowSeeking.Value;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-04-12 07:41:36 +00:00
|
|
|
|
protected override bool BlockScrollInput => false;
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
private double firstHitTime => objects.First().StartTime;
|
|
|
|
|
|
2021-05-17 09:26:15 +00:00
|
|
|
|
//TODO: this isn't always correct (consider mania where a non-last object may last for longer than the last in the list).
|
|
|
|
|
private double lastHitTime => objects.Last().GetEndTime() + 1;
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-17 09:41:56 +00:00
|
|
|
|
[Resolved(canBeNull: true)]
|
|
|
|
|
private Player player { get; set; }
|
|
|
|
|
|
|
|
|
|
[Resolved(canBeNull: true)]
|
|
|
|
|
private GameplayClock gameplayClock { get; set; }
|
|
|
|
|
|
|
|
|
|
private IClock referenceClock;
|
2019-05-09 09:06:11 +00:00
|
|
|
|
|
2021-06-08 12:22:35 +00:00
|
|
|
|
public bool UsesFixedAnchor { get; set; }
|
2021-06-07 03:47:47 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public SongProgress()
|
|
|
|
|
{
|
2021-05-17 09:26:15 +00:00
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
Anchor = Anchor.BottomRight;
|
|
|
|
|
Origin = Anchor.BottomRight;
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2021-05-17 09:55:18 +00:00
|
|
|
|
info = new SongProgressInfo
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2021-05-17 09:55:18 +00:00
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = info_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)
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
OnSeek = time => player?.Seek(time),
|
2018-04-13 09:19:50 +00:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-04 09:59:38 +00:00
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2021-05-17 09:26:15 +00:00
|
|
|
|
private void load(OsuColour colours, OsuConfigManager config, DrawableRuleset drawableRuleset)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-10-28 09:34:58 +00:00
|
|
|
|
base.LoadComplete();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-05-17 09:26:15 +00:00
|
|
|
|
if (drawableRuleset != null)
|
|
|
|
|
{
|
2021-08-16 07:48:40 +00:00
|
|
|
|
if (player?.Configuration.AllowUserInteraction == true)
|
2021-08-16 07:27:19 +00:00
|
|
|
|
((IBindable<bool>)AllowSeeking).BindTo(drawableRuleset.HasReplayLoaded);
|
2021-05-17 09:41:56 +00:00
|
|
|
|
|
|
|
|
|
referenceClock = drawableRuleset.FrameStableClock;
|
2021-05-17 09:26:15 +00:00
|
|
|
|
Objects = drawableRuleset.Objects;
|
|
|
|
|
}
|
2020-01-24 05:21:22 +00:00
|
|
|
|
|
2019-07-05 07:16:50 +00:00
|
|
|
|
config.BindWith(OsuSetting.ShowProgressGraph, ShowGraph);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-07-04 09:59:38 +00:00
|
|
|
|
graph.FillColour = bar.FillColour = colours.BlueLighter;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-04 09:59:38 +00:00
|
|
|
|
protected override void LoadComplete()
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-07-04 09:59:38 +00:00
|
|
|
|
Show();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-07-05 06:48:40 +00:00
|
|
|
|
AllowSeeking.BindValueChanged(_ => updateBarVisibility(), true);
|
2019-07-05 07:16:50 +00:00
|
|
|
|
ShowGraph.BindValueChanged(_ => updateGraphVisibility(), true);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
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 09:06:11 +00:00
|
|
|
|
double gameplayTime = gameplayClock?.CurrentTime ?? Time.Current;
|
2021-05-17 09:41:56 +00:00
|
|
|
|
double frameStableTime = referenceClock?.CurrentTime ?? gameplayTime;
|
2019-05-09 09:06:11 +00:00
|
|
|
|
|
|
|
|
|
double progress = Math.Min(1, (frameStableTime - firstHitTime) / (lastHitTime - firstHitTime));
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-05-09 09:06:11 +00:00
|
|
|
|
bar.CurrentTime = gameplayTime;
|
2019-03-05 04:26:54 +00:00
|
|
|
|
graph.Progress = (int)(graph.ColumnCount * progress);
|
2020-10-14 09:15:58 +00:00
|
|
|
|
|
|
|
|
|
Height = bottom_bar_height + graph_height + handle_size.Y + info_height - graph.Y;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
2019-07-04 09:59:38 +00:00
|
|
|
|
|
|
|
|
|
private void updateBarVisibility()
|
|
|
|
|
{
|
2020-01-24 05:21:22 +00:00
|
|
|
|
bar.ShowHandle = AllowSeeking.Value;
|
2019-07-04 09:59:38 +00:00
|
|
|
|
|
|
|
|
|
updateInfoMargin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateGraphVisibility()
|
|
|
|
|
{
|
|
|
|
|
float barHeight = bottom_bar_height + handle_size.Y;
|
|
|
|
|
|
2019-07-05 07:16:50 +00:00
|
|
|
|
bar.ResizeHeightTo(ShowGraph.Value ? barHeight + graph_height : barHeight, transition_duration, Easing.In);
|
2021-07-30 06:41:01 +00:00
|
|
|
|
graph.FadeTo(ShowGraph.Value ? 1 : 0, transition_duration, Easing.In);
|
2019-07-04 09:59:38 +00:00
|
|
|
|
|
|
|
|
|
updateInfoMargin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateInfoMargin()
|
|
|
|
|
{
|
2019-07-05 07:16:50 +00:00
|
|
|
|
float finalMargin = bottom_bar_height + (AllowSeeking.Value ? handle_size.Y : 0) + (ShowGraph.Value ? graph_height : 0);
|
2019-07-04 09:59:38 +00:00
|
|
|
|
info.TransformTo(nameof(info.Margin), new MarginPadding { Bottom = finalMargin }, transition_duration, Easing.In);
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|