mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 02:22:56 +08:00
Fix AdjustedAttributesTooltip
being broken by design
Fixes issue described in the following comment: https://github.com/ppy/osu/pull/25759#issuecomment-1855954637 That is just not how the tooltip system is supposed to be used. To name the individual sins: - Caching and returning a tooltip instance like the classes that used tooltips is incorrect. The lifetime of tooltip instances is managed by the tooltip container. `GetCustomTooltip()` is called by it exclusively. It should return a fresh instance every time. - Not putting actual data in `IHasCustomTooltip.TooltipContent` is wrong. - Having `Tooltip.SetContent()` be a no-op is *grossly and flagrantly* wrong. I'm not even sure which particular combination of the above transgressions caused the issue as it presented itself, but at this time I frankly do not care.
This commit is contained in:
parent
73c0a0ecb4
commit
9e5b6b97ff
@ -16,14 +16,13 @@ using osuTK;
|
||||
|
||||
namespace osu.Game.Overlays.Mods
|
||||
{
|
||||
public partial class AdjustedAttributesTooltip : VisibilityContainer, ITooltip
|
||||
public partial class AdjustedAttributesTooltip : VisibilityContainer, ITooltip<AdjustedAttributesTooltip.Data?>
|
||||
{
|
||||
private FillFlowContainer attributesFillFlow = null!;
|
||||
|
||||
private Container content = null!;
|
||||
|
||||
private BeatmapDifficulty? originalDifficulty;
|
||||
private BeatmapDifficulty? adjustedDifficulty;
|
||||
private Data? data;
|
||||
|
||||
[Resolved]
|
||||
private OsuColour colours { get; set; } = null!;
|
||||
@ -73,26 +72,17 @@ namespace osu.Game.Overlays.Mods
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
public void UpdateAttributes(BeatmapDifficulty original, BeatmapDifficulty adjusted)
|
||||
{
|
||||
originalDifficulty = original;
|
||||
adjustedDifficulty = adjusted;
|
||||
|
||||
if (IsLoaded)
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
private void updateDisplay()
|
||||
{
|
||||
attributesFillFlow.Clear();
|
||||
|
||||
if (originalDifficulty == null || adjustedDifficulty == null)
|
||||
return;
|
||||
|
||||
attemptAdd("CS", bd => bd.CircleSize);
|
||||
attemptAdd("HP", bd => bd.DrainRate);
|
||||
attemptAdd("OD", bd => bd.OverallDifficulty);
|
||||
attemptAdd("AR", bd => bd.ApproachRate);
|
||||
if (data != null)
|
||||
{
|
||||
attemptAdd("CS", bd => bd.CircleSize);
|
||||
attemptAdd("HP", bd => bd.DrainRate);
|
||||
attemptAdd("OD", bd => bd.OverallDifficulty);
|
||||
attemptAdd("AR", bd => bd.ApproachRate);
|
||||
}
|
||||
|
||||
if (attributesFillFlow.Any())
|
||||
content.Show();
|
||||
@ -101,16 +91,21 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
void attemptAdd(string name, Func<BeatmapDifficulty, double> lookup)
|
||||
{
|
||||
double a = lookup(originalDifficulty);
|
||||
double b = lookup(adjustedDifficulty);
|
||||
double originalValue = lookup(data.OriginalDifficulty);
|
||||
double adjustedValue = lookup(data.AdjustedDifficulty);
|
||||
|
||||
if (!Precision.AlmostEquals(a, b))
|
||||
attributesFillFlow.Add(new AttributeDisplay(name, a, b));
|
||||
if (!Precision.AlmostEquals(originalValue, adjustedValue))
|
||||
attributesFillFlow.Add(new AttributeDisplay(name, originalValue, adjustedValue));
|
||||
}
|
||||
}
|
||||
|
||||
public void SetContent(object content)
|
||||
public void SetContent(Data? data)
|
||||
{
|
||||
if (this.data == data)
|
||||
return;
|
||||
|
||||
this.data = data;
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
protected override void PopIn() => this.FadeIn(200, Easing.OutQuint);
|
||||
@ -118,6 +113,18 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
public void Move(Vector2 pos) => Position = pos;
|
||||
|
||||
public class Data
|
||||
{
|
||||
public BeatmapDifficulty OriginalDifficulty { get; }
|
||||
public BeatmapDifficulty AdjustedDifficulty { get; }
|
||||
|
||||
public Data(BeatmapDifficulty originalDifficulty, BeatmapDifficulty adjustedDifficulty)
|
||||
{
|
||||
OriginalDifficulty = originalDifficulty;
|
||||
AdjustedDifficulty = adjustedDifficulty;
|
||||
}
|
||||
}
|
||||
|
||||
private partial class AttributeDisplay : CompositeDrawable
|
||||
{
|
||||
public AttributeDisplay(string name, double original, double adjusted)
|
||||
|
@ -27,7 +27,7 @@ namespace osu.Game.Overlays.Mods
|
||||
/// On the mod select overlay, this provides a local updating view of BPM, star rating and other
|
||||
/// difficulty attributes so the user can have a better insight into what mods are changing.
|
||||
/// </summary>
|
||||
public partial class BeatmapAttributesDisplay : ModFooterInformationDisplay, IHasCustomTooltip
|
||||
public partial class BeatmapAttributesDisplay : ModFooterInformationDisplay, IHasCustomTooltip<AdjustedAttributesTooltip.Data?>
|
||||
{
|
||||
private StarRatingDisplay starRatingDisplay = null!;
|
||||
private BPMDisplay bpmDisplay = null!;
|
||||
@ -57,11 +57,9 @@ namespace osu.Game.Overlays.Mods
|
||||
private CancellationTokenSource? cancellationSource;
|
||||
private IBindable<StarDifficulty?> starDifficulty = null!;
|
||||
|
||||
private AdjustedAttributesTooltip rateAdjustTooltip = null!;
|
||||
public ITooltip<AdjustedAttributesTooltip.Data?> GetCustomTooltip() => new AdjustedAttributesTooltip();
|
||||
|
||||
public ITooltip GetCustomTooltip() => rateAdjustTooltip;
|
||||
|
||||
public object TooltipContent => this;
|
||||
public AdjustedAttributesTooltip.Data? TooltipContent { get; private set; }
|
||||
|
||||
private const float transition_duration = 250;
|
||||
|
||||
@ -70,8 +68,6 @@ namespace osu.Game.Overlays.Mods
|
||||
{
|
||||
const float shear = ShearedOverlayContainer.SHEAR;
|
||||
|
||||
rateAdjustTooltip = new AdjustedAttributesTooltip();
|
||||
|
||||
LeftContent.AddRange(new Drawable[]
|
||||
{
|
||||
starRatingDisplay = new StarRatingDisplay(default, animated: true)
|
||||
@ -182,7 +178,7 @@ namespace osu.Game.Overlays.Mods
|
||||
Ruleset ruleset = gameRuleset.Value.CreateInstance();
|
||||
BeatmapDifficulty adjustedDifficulty = ruleset.GetRateAdjustedDisplayDifficulty(originalDifficulty, rate);
|
||||
|
||||
rateAdjustTooltip.UpdateAttributes(originalDifficulty, adjustedDifficulty);
|
||||
TooltipContent = new AdjustedAttributesTooltip.Data(originalDifficulty, adjustedDifficulty);
|
||||
|
||||
approachRateDisplay.AdjustType.Value = VerticalAttributeDisplay.CalculateEffect(originalDifficulty.ApproachRate, adjustedDifficulty.ApproachRate);
|
||||
overallDifficultyDisplay.AdjustType.Value = VerticalAttributeDisplay.CalculateEffect(originalDifficulty.OverallDifficulty, adjustedDifficulty.OverallDifficulty);
|
||||
|
@ -30,7 +30,7 @@ using osu.Game.Overlays.Mods;
|
||||
|
||||
namespace osu.Game.Screens.Select.Details
|
||||
{
|
||||
public partial class AdvancedStats : Container, IHasCustomTooltip
|
||||
public partial class AdvancedStats : Container, IHasCustomTooltip<AdjustedAttributesTooltip.Data>
|
||||
{
|
||||
[Resolved]
|
||||
private BeatmapDifficultyCache difficultyCache { get; set; }
|
||||
@ -46,9 +46,8 @@ namespace osu.Game.Screens.Select.Details
|
||||
protected readonly StatisticRow FirstValue, HpDrain, Accuracy, ApproachRate;
|
||||
private readonly StatisticRow starDifficulty;
|
||||
|
||||
private AdjustedAttributesTooltip rateAdjustTooltip;
|
||||
public ITooltip GetCustomTooltip() => rateAdjustTooltip;
|
||||
public object TooltipContent => this;
|
||||
public ITooltip<AdjustedAttributesTooltip.Data> GetCustomTooltip() => new AdjustedAttributesTooltip();
|
||||
public AdjustedAttributesTooltip.Data TooltipContent { get; private set; }
|
||||
|
||||
private IBeatmapInfo beatmapInfo;
|
||||
|
||||
@ -86,7 +85,6 @@ namespace osu.Game.Screens.Select.Details
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
starDifficulty.AccentColour = colours.Yellow;
|
||||
rateAdjustTooltip = new AdjustedAttributesTooltip();
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
@ -144,7 +142,7 @@ namespace osu.Game.Screens.Select.Details
|
||||
|
||||
adjustedDifficulty = ruleset.CreateInstance().GetRateAdjustedDisplayDifficulty(originalDifficulty, rate);
|
||||
|
||||
rateAdjustTooltip.UpdateAttributes(originalDifficulty, adjustedDifficulty);
|
||||
TooltipContent = new AdjustedAttributesTooltip.Data(originalDifficulty, adjustedDifficulty);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user