1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 09:42:54 +08:00
osu-lazer/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs

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

137 lines
4.6 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
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Utils;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Localisation.HUD;
2017-04-18 15:05:58 +08:00
using osu.Game.Rulesets.Objects;
using osuTK;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Screens.Play.HUD
{
public partial class DefaultSongProgress : SongProgress
{
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
private readonly DefaultSongProgressBar bar;
private readonly DefaultSongProgressGraph graph;
2017-04-28 09:56:34 +08:00
private readonly SongProgressInfo info;
2018-04-13 17:19:50 +08:00
[SettingSource(typeof(SongProgressStrings), nameof(SongProgressStrings.ShowGraph), nameof(SongProgressStrings.ShowGraphDescription))]
public Bindable<bool> ShowGraph { get; } = new BindableBool(true);
[Resolved]
private Player? player { get; set; }
2021-05-17 17:41:56 +08:00
public DefaultSongProgress()
{
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,
},
graph = new DefaultSongProgressGraph
2021-05-17 17:55:18 +08:00
{
RelativeSizeAxes = Axes.X,
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
Height = graph_height,
Margin = new MarginPadding { Bottom = bottom_bar_height },
},
bar = new DefaultSongProgressBar(bottom_bar_height, graph_height, handle_size)
2021-05-17 17:55:18 +08:00
{
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]
private void load(OsuColour colours)
{
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
{
Interactive.BindValueChanged(_ => updateBarVisibility(), true);
ShowGraph.BindValueChanged(_ => updateGraphVisibility(), true);
2018-04-13 17:19:50 +08:00
base.LoadComplete();
2017-03-23 17:37:12 +08:00
}
2018-04-13 17:19:50 +08:00
protected override void UpdateObjects(IEnumerable<HitObject> objects)
2017-04-07 14:20:39 +08:00
{
graph.Objects = objects;
2022-07-28 15:30:45 +08:00
info.StartTime = FirstHitTime;
info.EndTime = LastHitTime;
bar.StartTime = FirstHitTime;
bar.EndTime = LastHitTime;
}
2018-04-13 17:19:50 +08:00
protected override void UpdateProgress(double progress, bool isIntro)
{
bar.CurrentTime = GameplayClock.CurrentTime;
if (isIntro)
graph.Progress = 0;
else
graph.Progress = (int)(graph.ColumnCount * progress);
}
protected override void Update()
{
base.Update();
// to prevent unnecessary invalidations of the song progress graph due to changes in size, apply tolerance when updating the height.
float newHeight = bottom_bar_height + graph_height + handle_size.Y + info.Height - graph.Y;
if (!Precision.AlmostEquals(Height, newHeight, 5f))
Height = newHeight;
2017-04-07 14:20:39 +08:00
}
private void updateBarVisibility()
{
bar.Interactive = Interactive.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 + (Interactive.Value ? handle_size.Y : 0) + (ShowGraph.Value ? graph_height : 0);
info.TransformTo(nameof(info.Margin), new MarginPadding { Bottom = finalMargin }, transition_duration, Easing.In);
}
}
}