mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 14:46:38 +09:00
Display performance breakdown in a tooltip
This commit is contained in:
@ -7,12 +7,14 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Rulesets.Difficulty;
|
||||
using osu.Game.Scoring;
|
||||
|
||||
namespace osu.Game.Screens.Ranking.Expanded.Statistics
|
||||
{
|
||||
public class PerformanceStatistic : StatisticDisplay
|
||||
public class PerformanceStatistic : StatisticDisplay, IHasCustomTooltip<PerformanceAttributes>
|
||||
{
|
||||
private readonly ScoreInfo score;
|
||||
|
||||
@ -22,6 +24,8 @@ namespace osu.Game.Screens.Ranking.Expanded.Statistics
|
||||
|
||||
private RollingCounter<int> counter;
|
||||
|
||||
private PerformanceAttributes attributes;
|
||||
|
||||
public PerformanceStatistic(ScoreInfo score)
|
||||
: base("PP")
|
||||
{
|
||||
@ -31,21 +35,17 @@ namespace osu.Game.Screens.Ranking.Expanded.Statistics
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(ScorePerformanceCache performanceCache)
|
||||
{
|
||||
if (score.PP.HasValue)
|
||||
{
|
||||
setPerformanceValue(score.PP.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
performanceCache.CalculatePerformanceAsync(score, cancellationTokenSource.Token)
|
||||
.ContinueWith(t => Schedule(() => setPerformanceValue(t.GetResultSafely())), cancellationTokenSource.Token);
|
||||
}
|
||||
performanceCache.CalculatePerformanceAsync(score, cancellationTokenSource.Token)
|
||||
.ContinueWith(t => Schedule(() => setPerformanceValue(t.GetResultSafely())), cancellationTokenSource.Token);
|
||||
}
|
||||
|
||||
private void setPerformanceValue(double? pp)
|
||||
private void setPerformanceValue(PerformanceAttributes pp)
|
||||
{
|
||||
if (pp.HasValue)
|
||||
performance.Value = (int)Math.Round(pp.Value, MidpointRounding.AwayFromZero);
|
||||
if (pp != null)
|
||||
{
|
||||
attributes = pp;
|
||||
performance.Value = (int)Math.Round(pp.Total, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Appear()
|
||||
@ -65,5 +65,9 @@ namespace osu.Game.Screens.Ranking.Expanded.Statistics
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopCentre
|
||||
};
|
||||
|
||||
public ITooltip<PerformanceAttributes> GetCustomTooltip() => new PerformanceStatisticTooltip();
|
||||
|
||||
public PerformanceAttributes TooltipContent => attributes;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,80 @@
|
||||
// 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.
|
||||
using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Rulesets.Difficulty;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.Ranking.Expanded.Statistics
|
||||
{
|
||||
public class PerformanceStatisticTooltip : VisibilityContainer, ITooltip<PerformanceAttributes>
|
||||
{
|
||||
private readonly Box background;
|
||||
|
||||
protected override Container<Drawable> Content { get; }
|
||||
|
||||
public PerformanceStatisticTooltip()
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
Masking = true;
|
||||
CornerRadius = 5;
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
background = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both
|
||||
},
|
||||
Content = new FillFlowContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Vertical,
|
||||
Padding = new MarginPadding { Left = 10, Right = 10, Top = 5, Bottom = 5 }
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
background.Colour = colours.Gray3;
|
||||
}
|
||||
|
||||
protected override void PopIn() => this.FadeIn(200, Easing.OutQuint);
|
||||
protected override void PopOut() => this.FadeOut(200, Easing.OutQuint);
|
||||
|
||||
private PerformanceAttributes lastAttributes;
|
||||
|
||||
public void SetContent(PerformanceAttributes attributes)
|
||||
{
|
||||
if (attributes == lastAttributes)
|
||||
return;
|
||||
|
||||
lastAttributes = attributes;
|
||||
|
||||
UpdateDisplay(attributes);
|
||||
}
|
||||
|
||||
protected virtual void UpdateDisplay(PerformanceAttributes attributes)
|
||||
{
|
||||
Content.Clear();
|
||||
|
||||
foreach (PerformanceDisplayAttribute attr in attributes.GetAttributesForDisplay())
|
||||
{
|
||||
Content.Add(new OsuSpriteText
|
||||
{
|
||||
Font = OsuFont.GetFont(weight: FontWeight.Regular),
|
||||
Text = $"{attr.DisplayName}: {(int)Math.Round(attr.Value, MidpointRounding.AwayFromZero)}"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void Move(Vector2 pos) => Position = pos;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user