mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 10:33:30 +08:00
Display performance breakdown in a tooltip
This commit is contained in:
parent
2ad0ea35be
commit
511a607599
@ -1,6 +1,7 @@
|
||||
// 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.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Game.Rulesets.Difficulty;
|
||||
|
||||
@ -16,5 +17,15 @@ namespace osu.Game.Rulesets.Mania.Difficulty
|
||||
|
||||
[JsonProperty("scaled_score")]
|
||||
public double ScaledScore { get; set; }
|
||||
|
||||
public override IEnumerable<PerformanceDisplayAttribute> GetAttributesForDisplay()
|
||||
{
|
||||
foreach (var attribute in base.GetAttributesForDisplay())
|
||||
yield return attribute;
|
||||
|
||||
yield return new PerformanceDisplayAttribute("Difficulty", Difficulty);
|
||||
yield return new PerformanceDisplayAttribute("Accuracy", Accuracy);
|
||||
yield return new PerformanceDisplayAttribute("Scaled Score", ScaledScore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
// 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.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Game.Rulesets.Difficulty;
|
||||
|
||||
@ -22,5 +23,17 @@ namespace osu.Game.Rulesets.Osu.Difficulty
|
||||
|
||||
[JsonProperty("effective_miss_count")]
|
||||
public double EffectiveMissCount { get; set; }
|
||||
|
||||
public override IEnumerable<PerformanceDisplayAttribute> GetAttributesForDisplay()
|
||||
{
|
||||
foreach (var attribute in base.GetAttributesForDisplay())
|
||||
yield return attribute;
|
||||
|
||||
yield return new PerformanceDisplayAttribute("Aim", Aim);
|
||||
yield return new PerformanceDisplayAttribute("Speed", Speed);
|
||||
yield return new PerformanceDisplayAttribute("Accuracy", Accuracy);
|
||||
yield return new PerformanceDisplayAttribute("Flashlight Bonus", Flashlight);
|
||||
yield return new PerformanceDisplayAttribute("Effective Miss Count", EffectiveMissCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
// 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.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Game.Rulesets.Difficulty;
|
||||
|
||||
@ -13,5 +14,14 @@ namespace osu.Game.Rulesets.Taiko.Difficulty
|
||||
|
||||
[JsonProperty("accuracy")]
|
||||
public double Accuracy { get; set; }
|
||||
|
||||
public override IEnumerable<PerformanceDisplayAttribute> GetAttributesForDisplay()
|
||||
{
|
||||
foreach (var attribute in base.GetAttributesForDisplay())
|
||||
yield return attribute;
|
||||
|
||||
yield return new PerformanceDisplayAttribute("Difficulty", Difficulty);
|
||||
yield return new PerformanceDisplayAttribute("Accuracy", Accuracy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
// 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.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace osu.Game.Rulesets.Difficulty
|
||||
@ -12,5 +13,14 @@ namespace osu.Game.Rulesets.Difficulty
|
||||
/// </summary>
|
||||
[JsonProperty("pp")]
|
||||
public double Total { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Return a <see cref="PerformanceDisplayAttribute"/> for each attribute so that a performance breakdown can be displayed.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<PerformanceDisplayAttribute> GetAttributesForDisplay()
|
||||
{
|
||||
yield return new PerformanceDisplayAttribute("Total", Total);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
26
osu.Game/Rulesets/Difficulty/PerformanceDisplayAttribute.cs
Normal file
26
osu.Game/Rulesets/Difficulty/PerformanceDisplayAttribute.cs
Normal file
@ -0,0 +1,26 @@
|
||||
// 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.
|
||||
namespace osu.Game.Rulesets.Difficulty
|
||||
{
|
||||
/// <summary>
|
||||
/// Data for displaying a performance attribute to user. Includes a display name for clarity.
|
||||
/// </summary>
|
||||
public class PerformanceDisplayAttribute
|
||||
{
|
||||
/// <summary>
|
||||
/// A custom display name for the attribute.
|
||||
/// </summary>
|
||||
public string DisplayName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The associated attribute value.
|
||||
/// </summary>
|
||||
public double Value { get; }
|
||||
|
||||
public PerformanceDisplayAttribute(string displayName, double value)
|
||||
{
|
||||
DisplayName = displayName;
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ using JetBrains.Annotations;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Rulesets.Difficulty;
|
||||
|
||||
namespace osu.Game.Scoring
|
||||
{
|
||||
@ -15,7 +16,7 @@ namespace osu.Game.Scoring
|
||||
/// A component which performs and acts as a central cache for performance calculations of locally databased scores.
|
||||
/// Currently not persisted between game sessions.
|
||||
/// </summary>
|
||||
public class ScorePerformanceCache : MemoryCachingComponent<ScorePerformanceCache.PerformanceCacheLookup, double?>
|
||||
public class ScorePerformanceCache : MemoryCachingComponent<ScorePerformanceCache.PerformanceCacheLookup, PerformanceAttributes>
|
||||
{
|
||||
[Resolved]
|
||||
private BeatmapDifficultyCache difficultyCache { get; set; }
|
||||
@ -27,10 +28,10 @@ namespace osu.Game.Scoring
|
||||
/// </summary>
|
||||
/// <param name="score">The score to do the calculation on. </param>
|
||||
/// <param name="token">An optional <see cref="CancellationToken"/> to cancel the operation.</param>
|
||||
public Task<double?> CalculatePerformanceAsync([NotNull] ScoreInfo score, CancellationToken token = default) =>
|
||||
public Task<PerformanceAttributes> CalculatePerformanceAsync([NotNull] ScoreInfo score, CancellationToken token = default) =>
|
||||
GetAsync(new PerformanceCacheLookup(score), token);
|
||||
|
||||
protected override async Task<double?> ComputeValueAsync(PerformanceCacheLookup lookup, CancellationToken token = default)
|
||||
protected override async Task<PerformanceAttributes> ComputeValueAsync(PerformanceCacheLookup lookup, CancellationToken token = default)
|
||||
{
|
||||
var score = lookup.ScoreInfo;
|
||||
|
||||
@ -44,7 +45,7 @@ namespace osu.Game.Scoring
|
||||
|
||||
var calculator = score.Ruleset.CreateInstance().CreatePerformanceCalculator(attributes.Value.Attributes, score);
|
||||
|
||||
return calculator?.Calculate().Total;
|
||||
return calculator?.Calculate();
|
||||
}
|
||||
|
||||
public readonly struct PerformanceCacheLookup
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user