From 6cc678f497b1cdb1aa461ebd4749e145fdc5c80f Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 14 May 2021 16:01:25 +0300 Subject: [PATCH] Remove nullability and transition support from star rating display --- .../Ranking/TestSceneStarRatingDisplay.cs | 23 +++++-------- .../Ranking/Expanded/StarRatingDisplay.cs | 33 +++++-------------- 2 files changed, 17 insertions(+), 39 deletions(-) diff --git a/osu.Game.Tests/Visual/Ranking/TestSceneStarRatingDisplay.cs b/osu.Game.Tests/Visual/Ranking/TestSceneStarRatingDisplay.cs index 7730d6868d..ef077970d6 100644 --- a/osu.Game.Tests/Visual/Ranking/TestSceneStarRatingDisplay.cs +++ b/osu.Game.Tests/Visual/Ranking/TestSceneStarRatingDisplay.cs @@ -33,33 +33,28 @@ namespace osu.Game.Tests.Visual.Ranking }); } - [Test] - public void TestNullStarRatingDisplay() - { - AddStep("load null", () => Child = new StarRatingDisplay - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Scale = new Vector2(3f), - }); - } - [Test] public void TestChangingStarRatingDisplay() { StarRatingDisplay starRating = null; - AddStep("load display", () => Child = starRating = new StarRatingDisplay + AddStep("load display", () => Child = starRating = new StarRatingDisplay(new StarDifficulty(5.55, 1)) { Anchor = Anchor.Centre, Origin = Anchor.Centre, Scale = new Vector2(3f), }); - AddRepeatStep("change display value", () => + AddRepeatStep("set random value", () => { - starRating.Current.Value = new StarDifficulty(RNG.NextDouble(0.0, 11.0), RNG.Next(2000)); + starRating.Current.Value = new StarDifficulty(RNG.NextDouble(0.0, 11.0), 1); }, 10); + + AddSliderStep("set exact stars", 0.0, 11.0, 5.55, d => + { + if (starRating != null) + starRating.Current.Value = new StarDifficulty(d, 1); + }); } } } diff --git a/osu.Game/Screens/Ranking/Expanded/StarRatingDisplay.cs b/osu.Game/Screens/Ranking/Expanded/StarRatingDisplay.cs index 422833555f..625bdaf888 100644 --- a/osu.Game/Screens/Ranking/Expanded/StarRatingDisplay.cs +++ b/osu.Game/Screens/Ranking/Expanded/StarRatingDisplay.cs @@ -22,7 +22,7 @@ namespace osu.Game.Screens.Ranking.Expanded /// /// A pill that displays the star rating of a . /// - public class StarRatingDisplay : CompositeDrawable, IHasCurrentValue + public class StarRatingDisplay : CompositeDrawable, IHasCurrentValue { private Box background; private OsuTextFlowContainer textFlow; @@ -30,21 +30,14 @@ namespace osu.Game.Screens.Ranking.Expanded [Resolved] private OsuColour colours { get; set; } - private readonly BindableWithCurrent current = new BindableWithCurrent(); + private readonly BindableWithCurrent current = new BindableWithCurrent(); - public Bindable Current + public Bindable Current { get => current.Current; set => current.Current = value; } - /// - /// Creates a new without any set, displaying a placeholder until is changed. - /// - public StarRatingDisplay() - { - } - /// /// Creates a new using an already computed . /// @@ -112,26 +105,16 @@ namespace osu.Game.Screens.Ranking.Expanded private void updateDisplay() { - const double duration = 400; - const Easing easing = Easing.OutQuint; - - double stars = Current.Value?.Stars ?? 0.00f; - - var starRatingParts = stars.ToString("0.00", CultureInfo.InvariantCulture).Split('.'); + var starRatingParts = Current.Value.Stars.ToString("0.00", CultureInfo.InvariantCulture).Split('.'); string wholePart = starRatingParts[0]; string fractionPart = starRatingParts[1]; string separator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator; - if (Current.Value == null) - background.FadeColour(Color4.SlateGray.Opacity(0.3f)); - else - { - var rating = Current.Value.Value.DifficultyRating; + var rating = Current.Value.DifficultyRating; - background.FadeColour(rating == DifficultyRating.ExpertPlus - ? ColourInfo.GradientVertical(Color4Extensions.FromHex("#C1C1C1"), Color4Extensions.FromHex("#595959")) - : (ColourInfo)colours.ForDifficultyRating(rating), duration, easing); - } + background.Colour = rating == DifficultyRating.ExpertPlus + ? ColourInfo.GradientVertical(Color4Extensions.FromHex("#C1C1C1"), Color4Extensions.FromHex("#595959")) + : (ColourInfo)colours.ForDifficultyRating(rating); textFlow.Clear();