diff --git a/osu.Game/Overlays/Mods/AdjustedAttributesTooltip.cs b/osu.Game/Overlays/Mods/AdjustedAttributesTooltip.cs index a56c09931a..ed12d917ad 100644 --- a/osu.Game/Overlays/Mods/AdjustedAttributesTooltip.cs +++ b/osu.Game/Overlays/Mods/AdjustedAttributesTooltip.cs @@ -1,29 +1,30 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Collections.Generic; +using System; using System.Linq; using osu.Framework.Allocation; -using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Shapes; -using osu.Game.Graphics.Sprites; -using osu.Game.Graphics; using osu.Framework.Utils; +using osu.Game.Beatmaps; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; using osuTK; namespace osu.Game.Overlays.Mods { public partial class AdjustedAttributesTooltip : VisibilityContainer, ITooltip { - private readonly Dictionary> attributes = new Dictionary>(); - - private FillFlowContainer? attributesFillFlow; + private FillFlowContainer attributesFillFlow = null!; private Container content = null!; + private BeatmapDifficulty? originalDifficulty; + private BeatmapDifficulty? adjustedDifficulty; + [Resolved] private OsuColour colours { get; set; } = null!; @@ -69,36 +70,43 @@ namespace osu.Game.Overlays.Mods }, }; - foreach (var attribute in attributes) - attributesFillFlow?.Add(new AttributeDisplay(attribute.Key, attribute.Value.GetBoundCopy())); - - updateVisibility(); + updateDisplay(); } - public void AddAttribute(string name) + public void UpdateAttributes(BeatmapDifficulty original, BeatmapDifficulty adjusted) { - Bindable newBindable = new Bindable(); - newBindable.BindValueChanged(_ => updateVisibility()); - attributes.Add(name, newBindable); + originalDifficulty = original; + adjustedDifficulty = adjusted; - attributesFillFlow?.Add(new AttributeDisplay(name, newBindable.GetBoundCopy())); + if (IsLoaded) + updateDisplay(); } - public void UpdateAttribute(string name, double oldValue, double newValue) + private void updateDisplay() { - if (!attributes.ContainsKey(name)) return; + attributesFillFlow.Clear(); - Bindable attribute = attributes[name]; + if (originalDifficulty == null || adjustedDifficulty == null) + return; - OldNewPair attributeValue = attribute.Value; - attributeValue.OldValue = oldValue; - attributeValue.NewValue = newValue; + attemptAdd("AR", bd => bd.ApproachRate); + attemptAdd("OD", bd => bd.OverallDifficulty); + attemptAdd("CS", bd => bd.CircleSize); + attemptAdd("HP", bd => bd.DrainRate); - attribute.Value = attributeValue; - } + if (attributesFillFlow.Any()) + content.Show(); + else + content.Hide(); - protected override void Update() - { + void attemptAdd(string name, Func lookup) + { + double a = lookup(originalDifficulty); + double b = lookup(adjustedDifficulty); + + if (!Precision.AlmostEquals(a, b)) + attributesFillFlow.Add(new AttributeDisplay(name, a, b)); + } } public void SetContent(object content) @@ -110,55 +118,18 @@ namespace osu.Game.Overlays.Mods public void Move(Vector2 pos) => Position = pos; - private void updateVisibility() - { - if (!IsLoaded) - return; - - if (attributes.Any(attribute => !Precision.AlmostEquals(attribute.Value.Value.OldValue, attribute.Value.Value.NewValue))) - content.Show(); - else - content.Hide(); - } - private partial class AttributeDisplay : CompositeDrawable { - public readonly Bindable AttributeValues; - public readonly string AttributeName; - - private readonly OsuSpriteText text; - - public AttributeDisplay(string name, Bindable values) + public AttributeDisplay(string name, double original, double adjusted) { AutoSizeAxes = Axes.Both; - AttributeName = name; - AttributeValues = values; - - InternalChild = text = new OsuSpriteText + InternalChild = new OsuSpriteText { - Font = OsuFont.Default.With(weight: FontWeight.Bold) + Font = OsuFont.Default.With(weight: FontWeight.Bold), + Text = $"{name}: {original:0.0#} → {adjusted:0.0#}" }; - - AttributeValues.BindValueChanged(_ => update(), true); } - - private void update() - { - if (Precision.AlmostEquals(AttributeValues.Value.OldValue, AttributeValues.Value.NewValue)) - { - Hide(); - return; - } - - Show(); - text.Text = $"{AttributeName}: {(AttributeValues.Value.OldValue):0.0#} → {(AttributeValues.Value.NewValue):0.0#}"; - } - } - - private struct OldNewPair - { - public double OldValue, NewValue; } } } diff --git a/osu.Game/Overlays/Mods/BeatmapAttributesDisplay.cs b/osu.Game/Overlays/Mods/BeatmapAttributesDisplay.cs index 0c35e55df5..dd3daa2b7a 100644 --- a/osu.Game/Overlays/Mods/BeatmapAttributesDisplay.cs +++ b/osu.Game/Overlays/Mods/BeatmapAttributesDisplay.cs @@ -60,6 +60,7 @@ namespace osu.Game.Overlays.Mods private AdjustedAttributesTooltip rateAdjustTooltip = null!; public ITooltip GetCustomTooltip() => rateAdjustTooltip; + public object TooltipContent => this; private const float transition_duration = 250; @@ -103,9 +104,6 @@ namespace osu.Game.Overlays.Mods { base.LoadComplete(); - rateAdjustTooltip.AddAttribute("AR"); - rateAdjustTooltip.AddAttribute("OD"); - mods.BindValueChanged(_ => { modSettingChangeTracker?.Dispose(); @@ -184,8 +182,7 @@ namespace osu.Game.Overlays.Mods Ruleset ruleset = gameRuleset.Value.CreateInstance(); BeatmapDifficulty adjustedDifficulty = ruleset.GetRateAdjustedDisplayDifficulty(originalDifficulty, rate); - rateAdjustTooltip.UpdateAttribute("AR", originalDifficulty.ApproachRate, adjustedDifficulty.ApproachRate); - rateAdjustTooltip.UpdateAttribute("OD", originalDifficulty.OverallDifficulty, adjustedDifficulty.OverallDifficulty); + rateAdjustTooltip.UpdateAttributes(originalDifficulty, adjustedDifficulty); approachRateDisplay.AdjustType.Value = VerticalAttributeDisplay.CalculateEffect(originalDifficulty.ApproachRate, adjustedDifficulty.ApproachRate); overallDifficultyDisplay.AdjustType.Value = VerticalAttributeDisplay.CalculateEffect(originalDifficulty.OverallDifficulty, adjustedDifficulty.OverallDifficulty); diff --git a/osu.Game/Screens/Select/Details/AdvancedStats.cs b/osu.Game/Screens/Select/Details/AdvancedStats.cs index 9433588b03..2a9e69f141 100644 --- a/osu.Game/Screens/Select/Details/AdvancedStats.cs +++ b/osu.Game/Screens/Select/Details/AdvancedStats.cs @@ -101,9 +101,6 @@ namespace osu.Game.Screens.Select.Details gameRuleset.BindValueChanged(_ => updateStatistics()); mods.BindValueChanged(modsChanged, true); - - rateAdjustTooltip.AddAttribute("AR"); - rateAdjustTooltip.AddAttribute("OD"); } private ModSettingChangeTracker modSettingChangeTracker; @@ -148,8 +145,7 @@ namespace osu.Game.Screens.Select.Details adjustedDifficulty = ruleset.CreateInstance().GetRateAdjustedDisplayDifficulty(originalDifficulty, rate); - rateAdjustTooltip.UpdateAttribute("AR", originalDifficulty.ApproachRate, adjustedDifficulty.ApproachRate); - rateAdjustTooltip.UpdateAttribute("OD", originalDifficulty.OverallDifficulty, adjustedDifficulty.OverallDifficulty); + rateAdjustTooltip.UpdateAttributes(originalDifficulty, adjustedDifficulty); } }