From d06c67ad8f921b02990b954256c95c22c5e70f22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 22 Feb 2024 11:57:40 +0100 Subject: [PATCH] Substitute two jank interdependent bool flags for single tri-state enums --- .../Beatmaps/TestSceneDifficultyIcon.cs | 12 ++------ osu.Game/Beatmaps/Drawables/DifficultyIcon.cs | 29 ++++++++++++++----- .../Drawables/DifficultyIconTooltip.cs | 11 ++++--- osu.Game/Overlays/BeatmapSet/BeatmapPicker.cs | 2 +- .../OnlinePlay/DrawableRoomPlaylistItem.cs | 2 +- .../Carousel/DrawableCarouselBeatmap.cs | 2 +- 6 files changed, 34 insertions(+), 24 deletions(-) diff --git a/osu.Game.Tests/Visual/Beatmaps/TestSceneDifficultyIcon.cs b/osu.Game.Tests/Visual/Beatmaps/TestSceneDifficultyIcon.cs index e544177d50..6a226c2b8c 100644 --- a/osu.Game.Tests/Visual/Beatmaps/TestSceneDifficultyIcon.cs +++ b/osu.Game.Tests/Visual/Beatmaps/TestSceneDifficultyIcon.cs @@ -50,18 +50,12 @@ public void CreateDifficultyIcon() fill.Add(difficultyIcon = new DifficultyIcon(beatmapInfo, rulesetInfo) { Scale = new Vector2(2), - ShowTooltip = true, - ShowExtendedTooltip = true }); }, 10); - AddStep("hide extended tooltip", () => difficultyIcon.ShowExtendedTooltip = false); - - AddStep("hide tooltip", () => difficultyIcon.ShowTooltip = false); - - AddStep("show tooltip", () => difficultyIcon.ShowTooltip = true); - - AddStep("show extended tooltip", () => difficultyIcon.ShowExtendedTooltip = true); + AddStep("no tooltip", () => difficultyIcon.TooltipType = DifficultyIconTooltipType.None); + AddStep("basic tooltip", () => difficultyIcon.TooltipType = DifficultyIconTooltipType.StarRating); + AddStep("extended tooltip", () => difficultyIcon.TooltipType = DifficultyIconTooltipType.Extended); } } } diff --git a/osu.Game/Beatmaps/Drawables/DifficultyIcon.cs b/osu.Game/Beatmaps/Drawables/DifficultyIcon.cs index 73073a8286..2e7f894d12 100644 --- a/osu.Game/Beatmaps/Drawables/DifficultyIcon.cs +++ b/osu.Game/Beatmaps/Drawables/DifficultyIcon.cs @@ -32,14 +32,9 @@ public partial class DifficultyIcon : CompositeDrawable, IHasCustomTooltip - /// Whether to display a tooltip on hover. Only works if a beatmap was provided at construction time. + /// Which type of tooltip to show. Only works if a beatmap was provided at construction time. /// - public bool ShowTooltip { get; set; } = true; - - /// - /// Whether to include the difficulty stats in the tooltip or not. Defaults to false. Has no effect if is false. - /// - public bool ShowExtendedTooltip { get; set; } + public DifficultyIconTooltipType TooltipType { get; set; } = DifficultyIconTooltipType.StarRating; private readonly IBeatmapInfo? beatmap; @@ -138,6 +133,24 @@ ITooltip IHasCustomTooltip new DifficultyIconTooltip(); DifficultyIconTooltipContent IHasCustomTooltip. - TooltipContent => (ShowTooltip && beatmap != null ? new DifficultyIconTooltipContent(beatmap, Current, ruleset, mods, ShowExtendedTooltip) : null)!; + TooltipContent => (TooltipType != DifficultyIconTooltipType.None && beatmap != null ? new DifficultyIconTooltipContent(beatmap, Current, ruleset, mods, TooltipType) : null)!; + } + + public enum DifficultyIconTooltipType + { + /// + /// No tooltip. + /// + None, + + /// + /// Star rating only. + /// + StarRating, + + /// + /// Star rating, OD, HP, CS, AR, length, BPM, and max combo. + /// + Extended, } } diff --git a/osu.Game/Beatmaps/Drawables/DifficultyIconTooltip.cs b/osu.Game/Beatmaps/Drawables/DifficultyIconTooltip.cs index 71366de654..952f71332f 100644 --- a/osu.Game/Beatmaps/Drawables/DifficultyIconTooltip.cs +++ b/osu.Game/Beatmaps/Drawables/DifficultyIconTooltip.cs @@ -113,7 +113,7 @@ public void SetContent(DifficultyIconTooltipContent content) starRating.Current.BindTarget = displayedContent.Difficulty; difficultyName.Text = displayedContent.BeatmapInfo.DifficultyName; - if (!displayedContent.ShowExtendedTooltip) + if (displayedContent.TooltipType == DifficultyIconTooltipType.StarRating) { difficultyFillFlowContainer.Hide(); miscFillFlowContainer.Hide(); @@ -166,15 +166,18 @@ internal class DifficultyIconTooltipContent public readonly IBindable Difficulty; public readonly IRulesetInfo Ruleset; public readonly Mod[]? Mods; - public readonly bool ShowExtendedTooltip; + public readonly DifficultyIconTooltipType TooltipType; - public DifficultyIconTooltipContent(IBeatmapInfo beatmapInfo, IBindable difficulty, IRulesetInfo rulesetInfo, Mod[]? mods, bool showExtendedTooltip = false) + public DifficultyIconTooltipContent(IBeatmapInfo beatmapInfo, IBindable difficulty, IRulesetInfo rulesetInfo, Mod[]? mods, DifficultyIconTooltipType tooltipType) { + if (tooltipType == DifficultyIconTooltipType.None) + throw new ArgumentOutOfRangeException(nameof(tooltipType), tooltipType, "Cannot instantiate a tooltip without a type"); + BeatmapInfo = beatmapInfo; Difficulty = difficulty; Ruleset = rulesetInfo; Mods = mods; - ShowExtendedTooltip = showExtendedTooltip; + TooltipType = tooltipType; } } } diff --git a/osu.Game/Overlays/BeatmapSet/BeatmapPicker.cs b/osu.Game/Overlays/BeatmapSet/BeatmapPicker.cs index 1f38e2ed6c..5f021803b0 100644 --- a/osu.Game/Overlays/BeatmapSet/BeatmapPicker.cs +++ b/osu.Game/Overlays/BeatmapSet/BeatmapPicker.cs @@ -297,7 +297,7 @@ public DifficultySelectorButton(APIBeatmap beatmapInfo, IRulesetInfo? ruleset) }, icon = new DifficultyIcon(beatmapInfo, ruleset) { - ShowTooltip = false, + TooltipType = DifficultyIconTooltipType.None, Current = { Value = new StarDifficulty(beatmapInfo.StarRating, 0) }, Anchor = Anchor.Centre, Origin = Anchor.Centre, diff --git a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs index 44e91c6975..1b8e2d8be6 100644 --- a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs +++ b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs @@ -285,7 +285,7 @@ private void refresh() difficultyIconContainer.Child = new DifficultyIcon(beatmap, ruleset, requiredMods) { Size = new Vector2(icon_height), - ShowExtendedTooltip = true + TooltipType = DifficultyIconTooltipType.Extended, }; } else diff --git a/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs b/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs index baf0a14062..01e58d4ab2 100644 --- a/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs +++ b/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs @@ -122,7 +122,7 @@ private void load(BeatmapManager? manager, SongSelect? songSelect) { difficultyIcon = new DifficultyIcon(beatmapInfo) { - ShowTooltip = false, + TooltipType = DifficultyIconTooltipType.None, Scale = new Vector2(1.8f), }, new FillFlowContainer