From 2f441baeacc8e9421d4914a7d5a69eba9f87793d Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 10 Mar 2020 00:50:12 +0300 Subject: [PATCH] Make UserHistoryGraph non-abstract --- .../Visual/Online/TestSceneUserHistoryGraph.cs | 15 +++------------ .../Profile/Header/Components/RankGraph.cs | 5 ++++- .../Sections/Historical/UserHistoryGraph.cs | 16 ++++++++++++++-- osu.Game/Overlays/Profile/UserGraph.cs | 10 +++------- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneUserHistoryGraph.cs b/osu.Game.Tests/Visual/Online/TestSceneUserHistoryGraph.cs index 26f6ac199b..83607bea6a 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneUserHistoryGraph.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneUserHistoryGraph.cs @@ -25,14 +25,15 @@ namespace osu.Game.Tests.Visual.Online public TestSceneUserHistoryGraph() { - TestGraph graph; + UserHistoryGraph graph; - Add(graph = new TestGraph + Add(graph = new UserHistoryGraph { RelativeSizeAxes = Axes.X, Height = 200, Anchor = Anchor.Centre, Origin = Anchor.Centre, + TooltipCounterName = "Test" }); var values = new[] @@ -60,15 +61,5 @@ namespace osu.Game.Tests.Visual.Online AddStep("Set null values", () => graph.Values = null); AddStep("Set empty values", () => graph.Values = Array.Empty()); } - - private class TestGraph : UserHistoryGraph - { - protected override UserGraphTooltip GetTooltip() => new TestTooltip(); - - private class TestTooltip : HistoryGraphTooltip - { - protected override string TooltipCounterName => "Test Counter"; - } - } } } diff --git a/osu.Game/Overlays/Profile/Header/Components/RankGraph.cs b/osu.Game/Overlays/Profile/Header/Components/RankGraph.cs index 13fbaa7f85..73ae91e345 100644 --- a/osu.Game/Overlays/Profile/Header/Components/RankGraph.cs +++ b/osu.Game/Overlays/Profile/Header/Components/RankGraph.cs @@ -74,7 +74,10 @@ namespace osu.Game.Overlays.Profile.Header.Components private class RankGraphTooltip : UserGraphTooltip { - protected override string TooltipCounterName => @"Global Ranking"; + public RankGraphTooltip() + : base(@"Global Ranking") + { + } public override bool SetContent(object content) { diff --git a/osu.Game/Overlays/Profile/Sections/Historical/UserHistoryGraph.cs b/osu.Game/Overlays/Profile/Sections/Historical/UserHistoryGraph.cs index 6de1b8e0f0..5f6f6cc3e4 100644 --- a/osu.Game/Overlays/Profile/Sections/Historical/UserHistoryGraph.cs +++ b/osu.Game/Overlays/Profile/Sections/Historical/UserHistoryGraph.cs @@ -8,15 +8,22 @@ using static osu.Game.Users.User; namespace osu.Game.Overlays.Profile.Sections.Historical { - public abstract class UserHistoryGraph : UserGraph + public class UserHistoryGraph : UserGraph { public UserHistoryCount[] Values { set => Data = value?.Select(v => new KeyValuePair(v.Date, v.Count)).ToArray(); } + /// + /// Text describing the value being plotted on the graph, which will be displayed as a prefix to the value in the + /// + public string TooltipCounterName { get; set; } = @"Plays"; + protected override float GetDataPointHeight(long playCount) => playCount; + protected override UserGraphTooltip GetTooltip() => new HistoryGraphTooltip(TooltipCounterName); + protected override object GetTooltipContent(DateTime date, long playCount) { return new TooltipDisplayContent @@ -26,8 +33,13 @@ namespace osu.Game.Overlays.Profile.Sections.Historical }; } - protected abstract class HistoryGraphTooltip : UserGraphTooltip + protected class HistoryGraphTooltip : UserGraphTooltip { + public HistoryGraphTooltip(string tooltipCounterName) + : base(tooltipCounterName) + { + } + public override bool SetContent(object content) { if (!(content is TooltipDisplayContent info)) diff --git a/osu.Game/Overlays/Profile/UserGraph.cs b/osu.Game/Overlays/Profile/UserGraph.cs index cea4600523..c19844960b 100644 --- a/osu.Game/Overlays/Profile/UserGraph.cs +++ b/osu.Game/Overlays/Profile/UserGraph.cs @@ -197,12 +197,7 @@ namespace osu.Game.Overlays.Profile protected readonly OsuSpriteText Counter, BottomText; private readonly Box background; - /// - /// Text which will be shown near the . - /// - protected abstract string TooltipCounterName { get; } - - protected UserGraphTooltip() + protected UserGraphTooltip(string tooltipCounterName) { AutoSizeAxes = Axes.Both; Masking = true; @@ -225,12 +220,13 @@ namespace osu.Game.Overlays.Profile { AutoSizeAxes = Axes.Both, Direction = FillDirection.Horizontal, + Spacing = new Vector2(3, 0), Children = new Drawable[] { new OsuSpriteText { Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold), - Text = $"{TooltipCounterName} " + Text = tooltipCounterName }, Counter = new OsuSpriteText {