1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 09:32:55 +08:00

Removed BeatmapInfo in StarRatingDisplay

This commit is contained in:
Denrage 2021-04-21 14:02:09 +02:00
parent 9fba87f67a
commit d6928e91fd
2 changed files with 20 additions and 39 deletions

View File

@ -29,13 +29,19 @@ namespace osu.Game.Screens.Ranking.Expanded
private OsuColour colours { get; set; } private OsuColour colours { get; set; }
private CircularContainer colorContainer; private CircularContainer colorContainer;
private CancellationTokenSource cancellationTokenSource;
private IBindable<StarDifficulty?> bindableStarDifficulty;
private OsuSpriteText wholePartText; private OsuSpriteText wholePartText;
private OsuSpriteText fractionPartText; private OsuSpriteText fractionPartText;
private StarDifficulty starDifficulty;
private readonly StarDifficulty starDifficulty; public StarDifficulty StarDifficulty
private readonly BeatmapInfo beatmapInfo; {
get => starDifficulty;
set
{
starDifficulty = value;
setDifficulty(starDifficulty);
}
}
/// <summary> /// <summary>
/// Creates a new <see cref="StarRatingDisplay"/> using an already computed <see cref="StarDifficulty"/>. /// Creates a new <see cref="StarRatingDisplay"/> using an already computed <see cref="StarDifficulty"/>.
@ -46,15 +52,6 @@ namespace osu.Game.Screens.Ranking.Expanded
this.starDifficulty = starDifficulty; this.starDifficulty = starDifficulty;
} }
/// <summary>
/// Creates a new <see cref="StarRatingDisplay"/> using a <see cref="BeatmapInfo"/> to use a bindable for the difficulty.
/// </summary>
/// <param name="beatmapInfo">The <see cref="BeatmapInfo"/> to use to create a bindable for <see cref="StarDifficulty"/></param>
public StarRatingDisplay(BeatmapInfo beatmapInfo)
{
this.beatmapInfo = beatmapInfo;
}
private void setDifficulty(StarDifficulty difficulty) private void setDifficulty(StarDifficulty difficulty)
{ {
var starRatingParts = difficulty.Stars.ToString("0.00", CultureInfo.InvariantCulture).Split('.'); var starRatingParts = difficulty.Stars.ToString("0.00", CultureInfo.InvariantCulture).Split('.');
@ -71,21 +68,12 @@ namespace osu.Game.Screens.Ranking.Expanded
wholePartText.Text = $"{wholePart}"; wholePartText.Text = $"{wholePart}";
fractionPartText.Text = $"{separator}{fractionPart}"; fractionPartText.Text = $"{separator}{fractionPart}";
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(BeatmapDifficultyCache difficultyCache) private void load(BeatmapDifficultyCache difficultyCache)
{ {
if (beatmapInfo != null)
{
cancellationTokenSource?.Cancel();
cancellationTokenSource = new CancellationTokenSource();
bindableStarDifficulty?.UnbindAll();
bindableStarDifficulty = difficultyCache.GetBindableDifficulty(beatmapInfo, cancellationTokenSource.Token);
}
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
@ -144,16 +132,7 @@ namespace osu.Game.Screens.Ranking.Expanded
} }
}; };
if (bindableStarDifficulty != null) setDifficulty(starDifficulty);
bindableStarDifficulty.BindValueChanged(valueChanged => setDifficulty(valueChanged.NewValue ?? new StarDifficulty()), true);
else
setDifficulty(starDifficulty);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
cancellationTokenSource?.Cancel();
} }
} }
} }

View File

@ -178,7 +178,7 @@ namespace osu.Game.Screens.Select
private ILocalisedBindableString titleBinding; private ILocalisedBindableString titleBinding;
private ILocalisedBindableString artistBinding; private ILocalisedBindableString artistBinding;
private FillFlowContainer infoLabelContainer; private FillFlowContainer infoLabelContainer;
private Drawable starRatingDisplay; private StarRatingDisplay starRatingDisplay;
private Container bpmLabelContainer; private Container bpmLabelContainer;
private ModSettingChangeTracker settingChangeTracker; private ModSettingChangeTracker settingChangeTracker;
private CancellationTokenSource cancellationTokenSource; private CancellationTokenSource cancellationTokenSource;
@ -246,9 +246,9 @@ namespace osu.Game.Screens.Select
Padding = new MarginPadding { Top = 14, Right = shear_width / 2 }, Padding = new MarginPadding { Top = 14, Right = shear_width / 2 },
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Shear = wedged_container_shear, Shear = wedged_container_shear,
Children = new[] Children = new Drawable[]
{ {
starRatingDisplay = new StarRatingDisplay(beatmapInfo) starRatingDisplay = new StarRatingDisplay(starDifficulty.Value ?? new StarDifficulty())
{ {
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight, Origin = Anchor.TopRight,
@ -311,19 +311,21 @@ namespace osu.Game.Screens.Select
titleBinding.BindValueChanged(_ => setMetadata(metadata.Source)); titleBinding.BindValueChanged(_ => setMetadata(metadata.Source));
artistBinding.BindValueChanged(_ => setMetadata(metadata.Source), true); artistBinding.BindValueChanged(_ => setMetadata(metadata.Source), true);
starDifficulty.BindValueChanged(_ => setStarRatingDisplayVisibility(), true); starDifficulty.BindValueChanged(updateStarRatingDisplay, true);
// no difficulty means it can't have a status to show // no difficulty means it can't have a status to show
if (beatmapInfo.Version == null) if (beatmapInfo.Version == null)
StatusPill.Hide(); StatusPill.Hide();
} }
private void setStarRatingDisplayVisibility() private void updateStarRatingDisplay(ValueChangedEvent<StarDifficulty?> valueChanged)
{ {
if (starDifficulty.Value.HasValue && starDifficulty.Value.Value.Stars > 0) if (valueChanged.NewValue.HasValue && valueChanged.NewValue.Value.Stars > 0)
starRatingDisplay.Show(); starRatingDisplay.Show();
else else
starRatingDisplay.Hide(); starRatingDisplay.Hide();
starRatingDisplay.StarDifficulty = valueChanged.NewValue ?? new StarDifficulty();
} }
private InfoLabel[] getRulesetInfoLabels() private InfoLabel[] getRulesetInfoLabels()