mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 11:42:54 +08:00
Merge pull request #26531 from smallketchup82/multiplayer-difficulty-tooltip
Implement difficulty tooltips for multiplayer lobbies
This commit is contained in:
commit
49b7f0e3a7
60
osu.Game.Tests/Visual/Beatmaps/TestSceneDifficultyIcon.cs
Normal file
60
osu.Game.Tests/Visual/Beatmaps/TestSceneDifficultyIcon.cs
Normal file
@ -0,0 +1,60 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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<DifficultyIcon> fill = null!;
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
Child = fill = new FillFlowContainer<DifficultyIcon>
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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 <see cref="DifficultyIcon"/>. Will use provided beatmap's <see cref="BeatmapInfo.StarRating"/> for initial value.
|
||||
/// </summary>
|
||||
/// <param name="beatmap">The beatmap to be displayed in the tooltip, and to be used for the initial star rating value.</param>
|
||||
/// <param name="mods">An array of mods to account for in the calculations</param>
|
||||
/// <param name="ruleset">An optional ruleset to be used for the icon display, in place of the beatmap's ruleset.</param>
|
||||
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<DifficultyIconTooltipContent>.
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// No tooltip.
|
||||
/// </summary>
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// Star rating only.
|
||||
/// </summary>
|
||||
StarRating,
|
||||
|
||||
/// <summary>
|
||||
/// Star rating, OD, HP, CS, AR, length, BPM, and max combo.
|
||||
/// </summary>
|
||||
Extended,
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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<DifficultyIconTooltipContent>
|
||||
{
|
||||
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<IApplicableToRate>())
|
||||
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<IApplicableToDifficulty>())
|
||||
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<StarDifficulty> Difficulty;
|
||||
public readonly IRulesetInfo Ruleset;
|
||||
public readonly Mod[]? Mods;
|
||||
public readonly DifficultyIconTooltipType TooltipType;
|
||||
|
||||
public DifficultyIconTooltipContent(IBeatmapInfo beatmapInfo, IBindable<StarDifficulty> difficulty)
|
||||
public DifficultyIconTooltipContent(IBeatmapInfo beatmapInfo, IBindable<StarDifficulty> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user