1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-14 05:47:20 +08:00

Remove tooltip from performance statistic

This commit is contained in:
Henry Lin 2022-02-05 21:18:23 +08:00
parent 2e1a9f1379
commit c35ef917a1
2 changed files with 14 additions and 241 deletions

View File

@ -2,21 +2,17 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Linq;
using System.Threading;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Cursor;
using osu.Game.Beatmaps;
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, IHasCustomTooltip<PerformanceBreakdown>
public class PerformanceStatistic : StatisticDisplay
{
private readonly ScoreInfo score;
@ -26,15 +22,6 @@ namespace osu.Game.Screens.Ranking.Expanded.Statistics
private RollingCounter<int> counter;
[Resolved]
private ScorePerformanceCache performanceCache { get; set; }
[Resolved]
private BeatmapDifficultyCache difficultyCache { get; set; }
[Resolved]
private BeatmapManager beatmapManager { get; set; }
public PerformanceStatistic(ScoreInfo score)
: base("PP")
{
@ -42,21 +29,23 @@ namespace osu.Game.Screens.Ranking.Expanded.Statistics
}
[BackgroundDependencyLoader]
private void load()
private void load(ScorePerformanceCache performanceCache)
{
new PerformanceBreakdownCalculator(beatmapManager, difficultyCache, performanceCache)
.CalculateAsync(score, cancellationTokenSource.Token)
.ContinueWith(t => Schedule(() => setPerformanceValue(t.GetResultSafely())));
if (score.PP.HasValue)
{
setPerformanceValue(score.PP.Value);
}
else
{
performanceCache.CalculatePerformanceAsync(score, cancellationTokenSource.Token)
.ContinueWith(t => Schedule(() => setPerformanceValue(t.GetResultSafely().Total)), cancellationTokenSource.Token);
}
}
private void setPerformanceValue(PerformanceBreakdown breakdown)
private void setPerformanceValue(double? pp)
{
// Don't display the tooltip if "Total" is the only item
if (breakdown != null && breakdown.Performance.GetAttributesForDisplay().Count() > 1)
{
TooltipContent = breakdown;
performance.Value = (int)Math.Round(breakdown.Performance.Total, MidpointRounding.AwayFromZero);
}
if (pp.HasValue)
performance.Value = (int)Math.Round(pp.Value, MidpointRounding.AwayFromZero);
}
public override void Appear()
@ -76,9 +65,5 @@ namespace osu.Game.Screens.Ranking.Expanded.Statistics
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre
};
public ITooltip<PerformanceBreakdown> GetCustomTooltip() => new PerformanceStatisticTooltip();
public PerformanceBreakdown TooltipContent { get; private set; }
}
}

View File

@ -1,212 +0,0 @@
// 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 System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Extensions.LocalisationExtensions;
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.Graphics.UserInterface;
using osu.Game.Rulesets.Difficulty;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Ranking.Expanded.Statistics
{
public class PerformanceStatisticTooltip : VisibilityContainer, ITooltip<PerformanceBreakdown>
{
private readonly Box background;
private Colour4 titleColor;
private Colour4 textColour;
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;
titleColor = colours.Blue;
textColour = colours.BlueLighter;
}
protected override void PopIn() => this.FadeIn(200, Easing.OutQuint);
protected override void PopOut() => this.FadeOut(200, Easing.OutQuint);
private PerformanceBreakdown currentPerformance;
public void SetContent(PerformanceBreakdown performance)
{
if (performance == currentPerformance)
return;
currentPerformance = performance;
UpdateDisplay(performance);
}
private Drawable createItemForTotal(PerformanceDisplayAttribute attribute, PerformanceDisplayAttribute perfectAttribute)
{
return
new GridContainer
{
AutoSizeAxes = Axes.Both,
Margin = new MarginPadding { Bottom = 10 },
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.Absolute, 250),
new Dimension(GridSizeMode.AutoSize)
},
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.AutoSize)
},
Content = new[]
{
new Drawable[]
{
new OsuSpriteText
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
Font = OsuFont.GetFont(weight: FontWeight.Regular),
Text = attribute.DisplayName,
Colour = titleColor
},
new OsuSpriteText
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
Font = OsuFont.GetFont(weight: FontWeight.SemiBold),
Text = Math.Round(attribute.Value, MidpointRounding.AwayFromZero).ToLocalisableString(),
Colour = titleColor
}
},
new Drawable[]
{
new OsuSpriteText
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
Font = OsuFont.GetFont(weight: FontWeight.Regular),
Text = "Maximum",
Colour = OsuColour.Gray(0.7f)
},
new OsuSpriteText
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
Font = OsuFont.GetFont(weight: FontWeight.Regular),
Text = Math.Round(perfectAttribute.Value, MidpointRounding.AwayFromZero).ToLocalisableString(),
Colour = OsuColour.Gray(0.7f)
}
}
}
};
}
private Drawable createItemForAttribute(PerformanceDisplayAttribute attribute, PerformanceDisplayAttribute perfectAttribute)
{
float percentage = (float)(attribute.Value / perfectAttribute.Value);
if (float.IsNaN(percentage))
return null;
return new GridContainer
{
AutoSizeAxes = Axes.Both,
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.Absolute, 110),
new Dimension(GridSizeMode.Absolute, 140),
new Dimension(GridSizeMode.AutoSize)
},
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize)
},
Content = new[]
{
new Drawable[]
{
new OsuSpriteText
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
Font = OsuFont.GetFont(weight: FontWeight.Regular),
Text = attribute.DisplayName,
Colour = textColour
},
new Bar
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
Width = 130,
Height = 5,
BackgroundColour = Color4.White.Opacity(0.5f),
Colour = textColour,
Length = percentage,
Margin = new MarginPadding { Left = 5, Right = 5 }
},
new OsuSpriteText
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
Font = OsuFont.GetFont(weight: FontWeight.SemiBold),
Text = percentage.ToLocalisableString("0%"),
Colour = textColour
}
}
}
};
}
protected virtual void UpdateDisplay(PerformanceBreakdown performance)
{
Content.Clear();
var displayAttributes = performance.Performance.GetAttributesForDisplay();
var perfectDisplayAttributes = performance.PerfectPerformance.GetAttributesForDisplay();
foreach (PerformanceDisplayAttribute attr in displayAttributes)
{
var attributeItem = attr.PropertyName == nameof(PerformanceAttributes.Total)
? createItemForTotal(attr, perfectDisplayAttributes.First(a => a.PropertyName == attr.PropertyName))
: createItemForAttribute(attr, perfectDisplayAttributes.First(a => a.PropertyName == attr.PropertyName));
if (attributeItem != null)
Content.Add(attributeItem);
}
}
public void Move(Vector2 pos) => Position = pos;
}
}