From 1548c0dc25d192b5c3faeb802f4b7f07f68bef9e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 10 Nov 2020 07:27:27 +0900 Subject: [PATCH 1/3] Ensure graph hover state is updated after data changes --- .../Overlays/Profile/Header/Components/RankGraph.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/osu.Game/Overlays/Profile/Header/Components/RankGraph.cs b/osu.Game/Overlays/Profile/Header/Components/RankGraph.cs index ffc060b3f1..51a13a1231 100644 --- a/osu.Game/Overlays/Profile/Header/Components/RankGraph.cs +++ b/osu.Game/Overlays/Profile/Header/Components/RankGraph.cs @@ -94,13 +94,18 @@ namespace osu.Game.Overlays.Profile.Header.Components } graph.FadeTo(ranks.Length > 1 ? 1 : 0, fade_duration, Easing.Out); + + if (IsHovered) + graph.UpdateBallPosition(lastHoverPosition); } + private float lastHoverPosition; + protected override bool OnHover(HoverEvent e) { if (ranks?.Length > 1) { - graph.UpdateBallPosition(e.MousePosition.X); + graph.UpdateBallPosition(lastHoverPosition = e.MousePosition.X); graph.ShowBar(); } @@ -117,11 +122,7 @@ namespace osu.Game.Overlays.Profile.Header.Components protected override void OnHoverLost(HoverLostEvent e) { - if (ranks?.Length > 1) - { - graph.HideBar(); - } - + graph.HideBar(); base.OnHoverLost(e); } From 37feedae7a5226c41d2c4cf9ea27d37bce88d3f8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 10 Nov 2020 07:27:38 +0900 Subject: [PATCH 2/3] Fix potential crash due to stale index --- .../Overlays/Profile/Header/Components/RankGraph.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/Profile/Header/Components/RankGraph.cs b/osu.Game/Overlays/Profile/Header/Components/RankGraph.cs index 51a13a1231..ffa918e4e8 100644 --- a/osu.Game/Overlays/Profile/Header/Components/RankGraph.cs +++ b/osu.Game/Overlays/Profile/Header/Components/RankGraph.cs @@ -30,7 +30,7 @@ namespace osu.Game.Overlays.Profile.Header.Components private readonly OsuSpriteText placeholder; private KeyValuePair[] ranks; - private int dayIndex; + private int hoveredIndex = -1; public readonly Bindable Statistics = new Bindable(); public RankGraph() @@ -55,7 +55,7 @@ namespace osu.Game.Overlays.Profile.Header.Components } }; - graph.OnBallMove += i => dayIndex = i; + graph.OnBallMove += i => hoveredIndex = i; } [BackgroundDependencyLoader] @@ -74,6 +74,7 @@ namespace osu.Game.Overlays.Profile.Header.Components private void updateStatistics(UserStatistics statistics) { placeholder.FadeIn(fade_duration, Easing.Out); + hoveredIndex = -1; if (statistics?.Ranks.Global == null) { @@ -201,14 +202,14 @@ namespace osu.Game.Overlays.Profile.Header.Components { get { - if (Statistics.Value?.Ranks.Global == null) + if (ranks == null || hoveredIndex == -1) return null; - var days = ranked_days - ranks[dayIndex].Key + 1; + var days = ranked_days - ranks[hoveredIndex].Key + 1; return new TooltipDisplayContent { - Rank = $"#{ranks[dayIndex].Value:#,##0}", + Rank = $"#{ranks[hoveredIndex].Value:#,##0}", Time = days == 0 ? "now" : $"{days} days ago" }; } From 833c0b223ef0a184314c46f9d756c2c3a6ca43d5 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 10 Nov 2020 18:08:12 +0900 Subject: [PATCH 3/3] Clamp index to valid bounds --- osu.Game/Overlays/Profile/Header/Components/RankGraph.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Overlays/Profile/Header/Components/RankGraph.cs b/osu.Game/Overlays/Profile/Header/Components/RankGraph.cs index ffa918e4e8..26126bca58 100644 --- a/osu.Game/Overlays/Profile/Header/Components/RankGraph.cs +++ b/osu.Game/Overlays/Profile/Header/Components/RankGraph.cs @@ -189,7 +189,7 @@ namespace osu.Game.Overlays.Profile.Header.Components public void HideBar() => bar.FadeOut(fade_duration); - private int calculateIndex(float mouseXPosition) => (int)MathF.Round(mouseXPosition / DrawWidth * (DefaultValueCount - 1)); + private int calculateIndex(float mouseXPosition) => (int)Math.Clamp(MathF.Round(mouseXPosition / DrawWidth * (DefaultValueCount - 1)), 0, DefaultValueCount - 1); private Vector2 calculateBallPosition(int index) {