Apply suggested changes

- Change difficultyicon mods parameter docstring to be more professional
- Add a parameter for controlling whether the difficulty statistics show or not. Defaults to false
- Round the BPM in the tooltip to make sure it displays correctly
This commit is contained in:
smallketchup82 2024-01-17 09:07:17 -05:00
parent 0237c9c6d7
commit b6422bc8bd
3 changed files with 26 additions and 20 deletions

View File

@ -42,6 +42,8 @@ namespace osu.Game.Beatmaps.Drawables
private readonly Mod[]? mods;
private readonly bool showTooltip;
private Drawable background = null!;
private readonly Container iconContainer;
@ -61,13 +63,15 @@ 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">The mods type beat</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, Mod[]? mods = null)
/// <param name="showTooltip">Whether to display a tooltip on hover. Defaults to false.</param>
public DifficultyIcon(IBeatmapInfo beatmap, IRulesetInfo? ruleset = null, Mod[]? mods = null, bool showTooltip = false)
: this(ruleset ?? beatmap.Ruleset)
{
this.beatmap = beatmap;
this.mods = mods;
this.showTooltip = showTooltip;
Current.Value = new StarDifficulty(beatmap.StarRating, 0);
}
@ -134,6 +138,6 @@ namespace osu.Game.Beatmaps.Drawables
GetCustomTooltip() => new DifficultyIconTooltip();
DifficultyIconTooltipContent IHasCustomTooltip<DifficultyIconTooltipContent>.
TooltipContent => (ShowTooltip && beatmap != null ? new DifficultyIconTooltipContent(beatmap, Current, ruleset, mods) : null)!;
TooltipContent => (ShowTooltip && beatmap != null ? new DifficultyIconTooltipContent(beatmap, Current, ruleset, mods, showTooltip) : null)!;
}
}

View File

@ -31,6 +31,9 @@ namespace osu.Game.Beatmaps.Drawables
private OsuSpriteText maxCombo;
private OsuSpriteText length;
private FillFlowContainer difficultyFillFlowContainer;
private FillFlowContainer miscFillFlowContainer;
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
@ -69,21 +72,16 @@ namespace osu.Game.Beatmaps.Drawables
Origin = Anchor.Centre,
},
// Difficulty stats
new FillFlowContainer
difficultyFillFlowContainer = new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Alpha = 0,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5),
Children = new Drawable[]
{
new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold),
},
circleSize = new OsuSpriteText
{
Anchor = Anchor.Centre,
@ -111,21 +109,16 @@ namespace osu.Game.Beatmaps.Drawables
}
},
// Misc stats
new FillFlowContainer
miscFillFlowContainer = new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Alpha = 0,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5),
Children = new Drawable[]
{
new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold),
},
length = new OsuSpriteText
{
Anchor = Anchor.Centre,
@ -164,6 +157,13 @@ namespace osu.Game.Beatmaps.Drawables
starRating.Current.BindTarget = displayedContent.Difficulty;
difficultyName.Text = displayedContent.BeatmapInfo.DifficultyName;
// Don't show difficulty stats if showTooltip is false
if (!displayedContent.ShowTooltip) return;
// Show the difficulty stats if showTooltip is true
difficultyFillFlowContainer.Show();
miscFillFlowContainer.Show();
double rate = 1;
if (displayedContent.Mods != null)
@ -195,7 +195,7 @@ namespace osu.Game.Beatmaps.Drawables
// Misc row
length.Text = "Length: " + TimeSpan.FromMilliseconds(displayedContent.BeatmapInfo.Length / rate).ToString("mm\\:ss");
bpm.Text = " BPM: " + bpmAdjusted;
bpm.Text = " BPM: " + Math.Round(bpmAdjusted, 0);
maxCombo.Text = " Max Combo: " + displayedContent.BeatmapInfo.TotalObjectCount;
}
@ -212,13 +212,15 @@ namespace osu.Game.Beatmaps.Drawables
public readonly IBindable<StarDifficulty> Difficulty;
public readonly IRulesetInfo Ruleset;
public readonly Mod[] Mods;
public readonly bool ShowTooltip;
public DifficultyIconTooltipContent(IBeatmapInfo beatmapInfo, IBindable<StarDifficulty> difficulty, IRulesetInfo rulesetInfo, Mod[] mods)
public DifficultyIconTooltipContent(IBeatmapInfo beatmapInfo, IBindable<StarDifficulty> difficulty, IRulesetInfo rulesetInfo, Mod[] mods, bool showTooltip = false)
{
BeatmapInfo = beatmapInfo;
Difficulty = difficulty;
Ruleset = rulesetInfo;
Mods = mods;
ShowTooltip = showTooltip;
}
}
}

View File

@ -283,7 +283,7 @@ namespace osu.Game.Screens.OnlinePlay
}
if (beatmap != null)
difficultyIconContainer.Child = new DifficultyIcon(beatmap, ruleset, requiredMods) { Size = new Vector2(icon_height) };
difficultyIconContainer.Child = new DifficultyIcon(beatmap, ruleset, requiredMods, true) { Size = new Vector2(icon_height) };
else
difficultyIconContainer.Clear();