1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-17 08:42:56 +08:00

Merge pull request #30078 from CloneWith/update/progresshover

Add progress tooltip for ArgonSongProgressBar
This commit is contained in:
Dan Balasescu 2024-10-07 15:20:50 +09:00 committed by GitHub
commit 944f8f5f67
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,15 +6,17 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Framework.Utils;
using osu.Game.Graphics;
using osuTK;
namespace osu.Game.Screens.Play.HUD
{
public partial class ArgonSongProgressBar : SongProgressBar
public partial class ArgonSongProgressBar : SongProgressBar, IHasTooltip
{
// Parent will handle restricting the area of valid input.
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
@ -33,6 +35,23 @@ namespace osu.Game.Screens.Play.HUD
private double trackTime => (EndTime - StartTime) * Progress;
private float lastMouseX;
public LocalisableString TooltipText
{
get
{
double progress = Math.Clamp(lastMouseX, 0, DrawWidth) / DrawWidth;
TimeSpan currentSpan = TimeSpan.FromMilliseconds(Math.Round((EndTime - StartTime) * progress));
int seconds = currentSpan.Duration().Seconds;
int minutes = (int)Math.Floor(currentSpan.Duration().TotalMinutes);
return $"{minutes}:{seconds:D2} ({progress:P0})";
}
}
public ArgonSongProgressBar(float barHeight)
{
RelativeSizeAxes = Axes.X;
@ -84,6 +103,14 @@ namespace osu.Game.Screens.Play.HUD
playfieldBar.TransformTo(nameof(playfieldBar.AccentColour), mainColour, 200, Easing.In);
}
protected override bool OnMouseMove(MouseMoveEvent e)
{
base.OnMouseMove(e);
lastMouseX = e.MousePosition.X;
return false;
}
protected override bool OnHover(HoverEvent e)
{
if (Interactive)