diff --git a/osu.Game.Tests/Visual/Beatmaps/TestSceneDifficultyIcon.cs b/osu.Game.Tests/Visual/Beatmaps/TestSceneDifficultyIcon.cs new file mode 100644 index 0000000000..fb6bebe50d --- /dev/null +++ b/osu.Game.Tests/Visual/Beatmaps/TestSceneDifficultyIcon.cs @@ -0,0 +1,60 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using NUnit.Framework; +using osu.Framework.Extensions.IEnumerableExtensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Utils; +using osu.Game.Beatmaps.Drawables; +using osu.Game.Rulesets.Osu; +using osu.Game.Tests.Beatmaps; +using osuTK; + +namespace osu.Game.Tests.Visual.Beatmaps +{ + public partial class TestSceneDifficultyIcon : OsuTestScene + { + private FillFlowContainer fill = null!; + + protected override void LoadComplete() + { + base.LoadComplete(); + + Child = fill = new FillFlowContainer + { + AutoSizeAxes = Axes.Y, + Width = 300, + Direction = FillDirection.Full, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + }; + } + + [Test] + public void CreateDifficultyIcon() + { + AddRepeatStep("create difficulty icon", () => + { + var rulesetInfo = new OsuRuleset().RulesetInfo; + var beatmapInfo = new TestBeatmap(rulesetInfo).BeatmapInfo; + + beatmapInfo.Difficulty.ApproachRate = RNG.Next(0, 10); + beatmapInfo.Difficulty.CircleSize = RNG.Next(0, 10); + beatmapInfo.Difficulty.OverallDifficulty = RNG.Next(0, 10); + beatmapInfo.Difficulty.DrainRate = RNG.Next(0, 10); + beatmapInfo.StarRating = RNG.NextSingle(0, 10); + beatmapInfo.BPM = RNG.Next(60, 300); + + fill.Add(new DifficultyIcon(beatmapInfo, rulesetInfo) + { + Scale = new Vector2(2), + }); + }, 10); + + AddStep("no tooltip", () => fill.ForEach(icon => icon.TooltipType = DifficultyIconTooltipType.None)); + AddStep("basic tooltip", () => fill.ForEach(icon => icon.TooltipType = DifficultyIconTooltipType.StarRating)); + AddStep("extended tooltip", () => fill.ForEach(icon => icon.TooltipType = DifficultyIconTooltipType.Extended)); + } + } +} diff --git a/osu.Game/Beatmaps/Drawables/DifficultyIcon.cs b/osu.Game/Beatmaps/Drawables/DifficultyIcon.cs index eecf79aa34..2e7f894d12 100644 --- a/osu.Game/Beatmaps/Drawables/DifficultyIcon.cs +++ b/osu.Game/Beatmaps/Drawables/DifficultyIcon.cs @@ -14,6 +14,7 @@ using osu.Framework.Graphics.UserInterface; using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Rulesets; +using osu.Game.Rulesets.Mods; using osuTK; using osuTK.Graphics; @@ -31,14 +32,16 @@ namespace osu.Game.Beatmaps.Drawables } /// - /// 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; + public DifficultyIconTooltipType TooltipType { get; set; } = DifficultyIconTooltipType.StarRating; private readonly IBeatmapInfo? beatmap; private readonly IRulesetInfo ruleset; + private readonly Mod[]? mods; + private Drawable background = null!; private readonly Container iconContainer; @@ -58,11 +61,14 @@ namespace osu.Game.Beatmaps.Drawables /// Creates a new . Will use provided beatmap's for initial value. /// /// The beatmap to be displayed in the tooltip, and to be used for the initial star rating value. + /// An array of mods to account for in the calculations /// An optional ruleset to be used for the icon display, in place of the beatmap's ruleset. - public DifficultyIcon(IBeatmapInfo beatmap, IRulesetInfo? ruleset = null) + public DifficultyIcon(IBeatmapInfo beatmap, IRulesetInfo? ruleset = null, Mod[]? mods = null) : this(ruleset ?? beatmap.Ruleset) { this.beatmap = beatmap; + this.mods = mods; + Current.Value = new StarDifficulty(beatmap.StarRating, 0); } @@ -127,6 +133,24 @@ namespace osu.Game.Beatmaps.Drawables GetCustomTooltip() => new DifficultyIconTooltip(); DifficultyIconTooltipContent IHasCustomTooltip. - TooltipContent => (ShowTooltip && beatmap != null ? new DifficultyIconTooltipContent(beatmap, Current) : 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 3fa24bcc3e..1f3dcfee8c 100644 --- a/osu.Game/Beatmaps/Drawables/DifficultyIconTooltip.cs +++ b/osu.Game/Beatmaps/Drawables/DifficultyIconTooltip.cs @@ -1,8 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - +using System; +using System.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -11,14 +11,25 @@ using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Shapes; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; +using osu.Game.Rulesets; +using osu.Game.Rulesets.Mods; using osuTK; namespace osu.Game.Beatmaps.Drawables { internal partial class DifficultyIconTooltip : VisibilityContainer, ITooltip { - private OsuSpriteText difficultyName; - private StarRatingDisplay starRating; + private OsuSpriteText difficultyName = null!; + private StarRatingDisplay starRating = null!; + private OsuSpriteText overallDifficulty = null!; + private OsuSpriteText drainRate = null!; + private OsuSpriteText circleSize = null!; + private OsuSpriteText approachRate = null!; + private OsuSpriteText bpm = null!; + private OsuSpriteText length = null!; + + private FillFlowContainer difficultyFillFlowContainer = null!; + private FillFlowContainer miscFillFlowContainer = null!; [BackgroundDependencyLoader] private void load(OsuColour colours) @@ -31,7 +42,6 @@ namespace osu.Game.Beatmaps.Drawables { new Box { - Alpha = 0.9f, Colour = colours.Gray3, RelativeSizeAxes = Axes.Both }, @@ -49,19 +59,49 @@ namespace osu.Game.Beatmaps.Drawables { Anchor = Anchor.Centre, Origin = Anchor.Centre, - Font = OsuFont.GetFont(size: 16, weight: FontWeight.Bold), + Font = OsuFont.GetFont(size: 16, weight: FontWeight.Bold) }, starRating = new StarRatingDisplay(default, StarRatingDisplaySize.Small) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre + }, + difficultyFillFlowContainer = new FillFlowContainer { Anchor = Anchor.Centre, Origin = Anchor.Centre, + Alpha = 0, + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + Spacing = new Vector2(5), + Children = new Drawable[] + { + circleSize = new OsuSpriteText { Font = OsuFont.GetFont(size: 14) }, + drainRate = new OsuSpriteText { Font = OsuFont.GetFont(size: 14) }, + overallDifficulty = new OsuSpriteText { Font = OsuFont.GetFont(size: 14) }, + approachRate = new OsuSpriteText { Font = OsuFont.GetFont(size: 14) }, + } + }, + miscFillFlowContainer = new FillFlowContainer + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Alpha = 0, + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + Spacing = new Vector2(5), + Children = new Drawable[] + { + length = new OsuSpriteText { Font = OsuFont.GetFont(size: 14) }, + bpm = new OsuSpriteText { Font = OsuFont.GetFont(size: 14) }, + } } } } }; } - private DifficultyIconTooltipContent displayedContent; + private DifficultyIconTooltipContent? displayedContent; public void SetContent(DifficultyIconTooltipContent content) { @@ -72,6 +112,45 @@ namespace osu.Game.Beatmaps.Drawables starRating.Current.BindTarget = displayedContent.Difficulty; difficultyName.Text = displayedContent.BeatmapInfo.DifficultyName; + + if (displayedContent.TooltipType == DifficultyIconTooltipType.StarRating) + { + difficultyFillFlowContainer.Hide(); + miscFillFlowContainer.Hide(); + return; + } + + difficultyFillFlowContainer.Show(); + miscFillFlowContainer.Show(); + + double rate = 1; + + if (displayedContent.Mods != null) + { + foreach (var mod in displayedContent.Mods.OfType()) + rate = mod.ApplyToRate(0, rate); + } + + double bpmAdjusted = displayedContent.BeatmapInfo.BPM * rate; + + BeatmapDifficulty originalDifficulty = new BeatmapDifficulty(displayedContent.BeatmapInfo.Difficulty); + + if (displayedContent.Mods != null) + { + foreach (var mod in displayedContent.Mods.OfType()) + mod.ApplyToDifficulty(originalDifficulty); + } + + Ruleset ruleset = displayedContent.Ruleset.CreateInstance(); + BeatmapDifficulty adjustedDifficulty = ruleset.GetRateAdjustedDisplayDifficulty(originalDifficulty, rate); + + circleSize.Text = @"CS: " + adjustedDifficulty.CircleSize.ToString(@"0.##"); + drainRate.Text = @" HP: " + adjustedDifficulty.DrainRate.ToString(@"0.##"); + approachRate.Text = @" AR: " + adjustedDifficulty.ApproachRate.ToString(@"0.##"); + overallDifficulty.Text = @" OD: " + adjustedDifficulty.OverallDifficulty.ToString(@"0.##"); + + length.Text = "Length: " + TimeSpan.FromMilliseconds(displayedContent.BeatmapInfo.Length / rate).ToString(@"mm\:ss"); + bpm.Text = " BPM: " + Math.Round(bpmAdjusted, 0); } public void Move(Vector2 pos) => Position = pos; @@ -85,11 +164,20 @@ namespace osu.Game.Beatmaps.Drawables { public readonly IBeatmapInfo BeatmapInfo; public readonly IBindable Difficulty; + public readonly IRulesetInfo Ruleset; + public readonly Mod[]? Mods; + public readonly DifficultyIconTooltipType TooltipType; - public DifficultyIconTooltipContent(IBeatmapInfo beatmapInfo, IBindable difficulty) + 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; + 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 @@ namespace osu.Game.Overlays.BeatmapSet }, 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 800c73cceb..1b8e2d8be6 100644 --- a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs +++ b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs @@ -281,7 +281,13 @@ namespace osu.Game.Screens.OnlinePlay } if (beatmap != null) - difficultyIconContainer.Child = new DifficultyIcon(beatmap, ruleset) { Size = new Vector2(icon_height) }; + { + difficultyIconContainer.Child = new DifficultyIcon(beatmap, ruleset, requiredMods) + { + Size = new Vector2(icon_height), + TooltipType = DifficultyIconTooltipType.Extended, + }; + } else difficultyIconContainer.Clear(); 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 @@ namespace osu.Game.Screens.Select.Carousel { difficultyIcon = new DifficultyIcon(beatmapInfo) { - ShowTooltip = false, + TooltipType = DifficultyIconTooltipType.None, Scale = new Vector2(1.8f), }, new FillFlowContainer