Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions osu.Game/Beatmaps/BeatmapDifficultyCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,19 @@ private void updateBindable(BindableStarDifficulty bindable, IRulesetInfo? rules
var ruleset = rulesetInfo.CreateInstance();
Debug.Assert(ruleset != null);

PlayableCachedWorkingBeatmap workingBeatmap = new PlayableCachedWorkingBeatmap(beatmapManager.GetWorkingBeatmap(key.BeatmapInfo));
IBeatmap playableBeatmap = workingBeatmap.GetPlayableBeatmap(ruleset.RulesetInfo, key.OrderedMods, cancellationToken);
WorkingBeatmap workingBeatmap = beatmapManager.GetWorkingBeatmap(key.BeatmapInfo);
PlayableCachedWorkingBeatmap playableCachedWorkingBeatmap = new PlayableCachedWorkingBeatmap(workingBeatmap);
IBeatmap playableBeatmap = playableCachedWorkingBeatmap.GetPlayableBeatmap(ruleset.RulesetInfo, key.OrderedMods, cancellationToken);

var difficulty = ruleset.CreateDifficultyCalculator(workingBeatmap).Calculate(key.OrderedMods, cancellationToken);
var noModDifficulty = ruleset.CreateDifficultyCalculator(workingBeatmap).Calculate(key.OrderedMods.OfType<ModTouchDevice>(), cancellationToken);
cancellationToken.ThrowIfCancellationRequested();

var difficulty = ruleset.CreateDifficultyCalculator(playableCachedWorkingBeatmap).Calculate(key.OrderedMods, cancellationToken);
cancellationToken.ThrowIfCancellationRequested();

var performanceCalculator = ruleset.CreatePerformanceCalculator();
if (performanceCalculator == null)
return new StarDifficulty(difficulty, new PerformanceAttributes());
return new StarDifficulty(difficulty, new PerformanceAttributes(), noModDifficulty);

ScoreProcessor scoreProcessor = ruleset.CreateScoreProcessor();
scoreProcessor.Mods.Value = key.OrderedMods;
Expand All @@ -281,7 +285,7 @@ private void updateBindable(BindableStarDifficulty bindable, IRulesetInfo? rules
var performance = performanceCalculator.Calculate(perfectScore, difficulty);
cancellationToken.ThrowIfCancellationRequested();

return new StarDifficulty(difficulty, performance);
return new StarDifficulty(difficulty, performance, noModDifficulty);
}
catch (OperationCanceledException)
{
Expand Down
41 changes: 40 additions & 1 deletion osu.Game/Beatmaps/Drawables/StarRatingDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
Expand All @@ -22,12 +23,13 @@ namespace osu.Game.Beatmaps.Drawables
/// <summary>
/// A pill that displays the star rating of a beatmap.
/// </summary>
public partial class StarRatingDisplay : CompositeDrawable, IHasCurrentValue<StarDifficulty>
public partial class StarRatingDisplay : CompositeDrawable, IHasCurrentValue<StarDifficulty>, IHasCustomTooltip<StarDifficulty>
{
private readonly bool animated;
private readonly Box background;
private readonly SpriteIcon starIcon;
private readonly OsuSpriteText starsText;
private readonly SpriteIcon valueIcon;

private readonly BindableWithCurrent<StarDifficulty> current = new BindableWithCurrent<StarDifficulty>();

Expand Down Expand Up @@ -109,6 +111,8 @@ public StarRatingDisplay(StarDifficulty starDifficulty, StarRatingDisplaySize si
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.Absolute, 3f),
new Dimension(GridSizeMode.AutoSize, minSize: 25f),
new Dimension(GridSizeMode.Absolute, 2f),
new Dimension(GridSizeMode.AutoSize),
},
RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) },
Content = new[]
Expand All @@ -132,6 +136,17 @@ public StarRatingDisplay(StarDifficulty starDifficulty, StarRatingDisplaySize si
Font = OsuFont.Torus.With(size: 14.4f, weight: FontWeight.Bold, fixedWidth: true),
Shadow = false,
},
Empty(),
valueIcon = new SpriteIcon
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding
{
Top = -1f,
},
Size = new Vector2(8),
},
}
}
},
Expand Down Expand Up @@ -162,8 +177,32 @@ protected override void LoadComplete()

starIcon.Colour = s.NewValue >= OsuColour.STAR_DIFFICULTY_DEFINED_COLOUR_CUTOFF ? colours.Orange1 : colourProvider?.Background5 ?? Color4Extensions.FromHex("303d47");
starsText.Colour = s.NewValue >= OsuColour.STAR_DIFFICULTY_DEFINED_COLOUR_CUTOFF ? colours.Orange1 : colourProvider?.Background5 ?? Color4.Black.Opacity(0.75f);

updateDisplay();
}, true);
updateDisplay();
}

private void updateDisplay()
{
if (Current.Value.Stars == Current.Value.NoModStars)
{
valueIcon.ScaleTo(0, 300, Easing.OutQuint).OnComplete(_ =>
{
valueIcon.Hide();
});
}
else
{
valueIcon.Colour = starIcon.Colour;
valueIcon.Icon = Current.Value.Stars > Current.Value.NoModStars ? FontAwesome.Solid.SortUp : FontAwesome.Solid.SortDown;
valueIcon.ScaleTo(1, 300, Easing.OutQuint);
valueIcon.Show();
}
}

public ITooltip<StarDifficulty> GetCustomTooltip() => new StarRatingDisplayTooltip();
public StarDifficulty TooltipContent => Current.Value;
}

public enum StarRatingDisplaySize
Expand Down
97 changes: 97 additions & 0 deletions osu.Game/Beatmaps/Drawables/StarRatingDisplayTooltip.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Utils;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays;
using osuTK;

namespace osu.Game.Beatmaps.Drawables
{
public partial class StarRatingDisplayTooltip : VisibilityContainer, ITooltip<StarDifficulty>
{
private readonly OverlayColourProvider? colourProvider;

private Container content = null!;

private StarDifficulty starDifficulty;
private OsuSpriteText adjustedByModsText = null!;

[Resolved]
private OsuColour colours { get; set; } = null!;

public StarRatingDisplayTooltip(OverlayColourProvider? colourProvider = null)
{
this.colourProvider = colourProvider;
}

[BackgroundDependencyLoader]
private void load()
{
AutoSizeAxes = Axes.Both;

Masking = true;
CornerRadius = 5;

InternalChildren = new Drawable[]
{
content = new Container
{
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider?.Background4 ?? colours.Gray3,
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Padding = new MarginPadding { Vertical = 10, Horizontal = 15 },
Direction = FillDirection.Vertical,
Spacing = new Vector2(10),
Children = new Drawable[]
{
adjustedByModsText = new OsuSpriteText
{
Font = OsuFont.Style.Caption1.With(weight: FontWeight.Bold),
},
}
},
}
},
};

updateDisplay();
}

private void updateDisplay()
{
if (!Precision.AlmostEquals(starDifficulty.Stars, starDifficulty.NoModStars))
{
adjustedByModsText.Text = $"This value is being adjusted by mods ({starDifficulty.NoModStars:0.0#} → {starDifficulty.Stars:0.0#}).";
content.Show();
}
else
content.Hide();
}

public void SetContent(StarDifficulty starDifficulty)
{
this.starDifficulty = starDifficulty;
updateDisplay();
}

protected override void PopIn() => this.FadeIn(200, Easing.OutQuint);
protected override void PopOut() => this.FadeOut(200, Easing.OutQuint);

public void Move(Vector2 pos) => Position = pos;
}
}
9 changes: 8 additions & 1 deletion osu.Game/Beatmaps/StarDifficulty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public readonly struct StarDifficulty
/// </summary>
public readonly double Stars;

/// <summary>
/// The star difficulty rating for the given beatmap without any mods applied.
/// </summary>
public readonly double NoModStars;

/// <summary>
/// The maximum combo achievable on the given beatmap.
/// </summary>
Expand All @@ -33,9 +38,10 @@ public readonly struct StarDifficulty
/// <summary>
/// Creates a <see cref="StarDifficulty"/> structure.
/// </summary>
public StarDifficulty(DifficultyAttributes difficulty, PerformanceAttributes performance)
public StarDifficulty(DifficultyAttributes difficulty, PerformanceAttributes performance, DifficultyAttributes noModDifficulty)
{
Stars = double.IsFinite(difficulty.StarRating) ? difficulty.StarRating : 0;
NoModStars = double.IsFinite(noModDifficulty.StarRating) ? noModDifficulty.StarRating : 0;
MaxCombo = difficulty.MaxCombo;
DifficultyAttributes = difficulty;
PerformanceAttributes = performance;
Expand All @@ -49,6 +55,7 @@ public StarDifficulty(DifficultyAttributes difficulty, PerformanceAttributes per
public StarDifficulty(double starDifficulty, int maxCombo)
{
Stars = double.IsFinite(starDifficulty) ? starDifficulty : 0;
NoModStars = Stars;
MaxCombo = maxCombo;
}

Expand Down
Loading