1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-27 08:33:00 +08:00
osu-lazer/osu.Game/Screens/Play/SongProgress.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

248 lines
8.4 KiB
C#
Raw Normal View History

// 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
2022-06-17 15:37:17 +08:00
#nullable disable
2017-03-23 17:37:12 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Timing;
using osu.Game.Configuration;
using osu.Game.Graphics;
2017-04-18 15:05:58 +08:00
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.UI;
using osu.Game.Skinning;
using osuTK;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Screens.Play
{
public class SongProgress : OverlayContainer, ISkinnableDrawable
{
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;
private const float graph_height = SquareGraph.Column.WIDTH * 6;
private const float handle_height = 18;
private static readonly Vector2 handle_size = new Vector2(10, handle_height);
2018-04-13 17:19:50 +08:00
private const float transition_duration = 200;
2018-04-13 17:19:50 +08:00
2017-03-24 11:41:56 +08:00
private readonly SongProgressBar bar;
private readonly SongProgressGraph graph;
2017-04-28 09:56:34 +08:00
private readonly SongProgressInfo info;
2018-04-13 17:19:50 +08:00
public Action<double> RequestSeek;
/// <summary>
/// Whether seeking is allowed and the progress bar should be shown.
/// </summary>
public readonly Bindable<bool> AllowSeeking = new Bindable<bool>();
[SettingSource("Show difficulty graph", "Whether a graph displaying difficulty throughout the beatmap should be shown")]
public Bindable<bool> ShowGraph { get; } = new BindableBool(true);
2018-04-13 17:19:50 +08:00
public override bool HandleNonPositionalInput => AllowSeeking.Value;
public override bool HandlePositionalInput => AllowSeeking.Value;
2018-04-13 17:19:50 +08:00
protected override bool BlockScrollInput => false;
private double firstHitTime => objects.First().StartTime;
2018-04-13 17:19:50 +08: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;
private IEnumerable<HitObject> objects;
2018-04-13 17:19:50 +08:00
public IEnumerable<HitObject> Objects
{
set
{
graph.Objects = objects = value;
2018-04-13 17:19:50 +08:00
2017-05-09 11:05:37 +08:00
info.StartTime = firstHitTime;
info.EndTime = lastHitTime;
2018-04-13 17:19:50 +08:00
2017-06-23 00:42:29 +08:00
bar.StartTime = firstHitTime;
bar.EndTime = lastHitTime;
}
}
2018-04-13 17:19:50 +08:00
2021-05-17 17:41:56 +08:00
[Resolved(canBeNull: true)]
private Player player { get; set; }
[Resolved]
2021-05-17 17:41:56 +08:00
private GameplayClock gameplayClock { get; set; }
[Resolved(canBeNull: true)]
private DrawableRuleset drawableRuleset { get; set; }
2021-05-17 17:41:56 +08:00
private IClock referenceClock;
public bool UsesFixedAnchor { get; set; }
public SongProgress()
{
RelativeSizeAxes = Axes.X;
Anchor = Anchor.BottomRight;
Origin = Anchor.BottomRight;
Children = new Drawable[]
{
2021-05-17 17:55:18 +08:00
info = new SongProgressInfo
{
2021-05-17 17:55:18 +08: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),
2017-03-23 19:13:03 +08:00
},
};
}
2018-04-13 17:19:50 +08:00
[BackgroundDependencyLoader(true)]
private void load(OsuColour colours)
{
base.LoadComplete();
2018-04-13 17:19:50 +08:00
if (drawableRuleset != null)
{
if (player?.Configuration.AllowUserInteraction == true)
2021-08-16 15:27:19 +08:00
((IBindable<bool>)AllowSeeking).BindTo(drawableRuleset.HasReplayLoaded);
2021-05-17 17:41:56 +08:00
referenceClock = drawableRuleset.FrameStableClock;
Objects = drawableRuleset.Objects;
}
graph.FillColour = bar.FillColour = colours.BlueLighter;
}
2018-04-13 17:19:50 +08:00
protected override void LoadComplete()
2017-03-23 17:37:12 +08:00
{
Show();
2018-04-13 17:19:50 +08:00
AllowSeeking.BindValueChanged(_ => updateBarVisibility(), true);
ShowGraph.BindValueChanged(_ => updateGraphVisibility(), true);
migrateSettingFromConfig();
}
[Resolved]
private OsuConfigManager config { get; set; }
[Resolved]
private SkinManager skinManager { get; set; }
/// <summary>
/// This setting has been migrated to a per-component level.
/// Only take the value from the config if it is in a non-default state (then reset it to default so it only applies once).
///
/// Can be removed 20221027.
/// </summary>
private void migrateSettingFromConfig()
{
Bindable<bool> configShowGraph = config.GetBindable<bool>(OsuSetting.ShowProgressGraph);
if (!configShowGraph.IsDefault)
{
ShowGraph.Value = configShowGraph.Value;
// This is pretty ugly, but the only way to make this stick...
if (skinManager != null)
{
var skinnableTarget = this.FindClosestParent<ISkinnableTarget>();
if (skinnableTarget != null)
{
// If the skin is not mutable, a mutable instance will be created, causing this migration logic to run again on the correct skin.
// Therefore we want to avoid resetting the config value on this invocation.
if (skinManager.EnsureMutableSkin())
return;
2022-04-28 13:29:57 +08:00
// If `EnsureMutableSkin` actually changed the skin, default layout may take a frame to apply.
// See `SkinnableTargetComponentsContainer`'s use of ScheduleAfterChildren.
ScheduleAfterChildren(() =>
{
var skin = skinManager.CurrentSkin.Value;
skin.UpdateDrawableTarget(skinnableTarget);
skinManager.Save(skin);
});
configShowGraph.SetDefault();
}
}
}
}
2018-04-13 17:19:50 +08:00
protected override void PopIn()
{
2017-07-23 02:50:25 +08:00
this.FadeIn(500, Easing.OutQuint);
2017-03-23 17:37:12 +08:00
}
2018-04-13 17:19:50 +08:00
2017-03-23 17:37:12 +08:00
protected override void PopOut()
{
this.FadeOut(100);
2017-03-23 17:37:12 +08:00
}
2018-04-13 17:19:50 +08:00
2017-04-07 14:20:39 +08:00
protected override void Update()
{
base.Update();
2018-04-13 17:19:50 +08:00
if (objects == null)
return;
2018-04-13 17:19:50 +08:00
double gameplayTime = gameplayClock?.CurrentTime ?? Time.Current;
2021-05-17 17:41:56 +08:00
double frameStableTime = referenceClock?.CurrentTime ?? gameplayTime;
double progress = Math.Min(1, (frameStableTime - firstHitTime) / (lastHitTime - firstHitTime));
2018-04-13 17:19:50 +08:00
bar.CurrentTime = gameplayTime;
graph.Progress = (int)(graph.ColumnCount * progress);
Height = bottom_bar_height + graph_height + handle_size.Y + info_height - graph.Y;
2017-04-07 14:20:39 +08:00
}
private void updateBarVisibility()
{
bar.ShowHandle = AllowSeeking.Value;
updateInfoMargin();
}
private void updateGraphVisibility()
{
float barHeight = bottom_bar_height + handle_size.Y;
bar.ResizeHeightTo(ShowGraph.Value ? barHeight + graph_height : barHeight, transition_duration, Easing.In);
graph.FadeTo(ShowGraph.Value ? 1 : 0, transition_duration, Easing.In);
updateInfoMargin();
}
private void updateInfoMargin()
{
float finalMargin = bottom_bar_height + (AllowSeeking.Value ? handle_size.Y : 0) + (ShowGraph.Value ? graph_height : 0);
info.TransformTo(nameof(info.Margin), new MarginPadding { Bottom = finalMargin }, transition_duration, Easing.In);
}
}
}