mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 16:03:01 +08:00
Merge branch 'current-star-rating' into player-loader-star-rating
This commit is contained in:
commit
93007c1635
@ -7,6 +7,7 @@ using osu.Framework.Graphics.Containers;
|
|||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Screens.Ranking.Expanded;
|
using osu.Game.Screens.Ranking.Expanded;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Ranking
|
namespace osu.Game.Tests.Visual.Ranking
|
||||||
{
|
{
|
||||||
@ -15,29 +16,45 @@ namespace osu.Game.Tests.Visual.Ranking
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestDisplay()
|
public void TestDisplay()
|
||||||
{
|
{
|
||||||
StarRatingDisplay changingStarRating = null;
|
|
||||||
|
|
||||||
AddStep("load displays", () => Child = new FillFlowContainer
|
AddStep("load displays", () => Child = new FillFlowContainer
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new StarRatingDisplay(new StarDifficulty(1.23, 0)),
|
new StarRatingDisplay(new StarDifficulty(1.23, 0)) { Anchor = Anchor.Centre, Origin = Anchor.Centre },
|
||||||
new StarRatingDisplay(new StarDifficulty(2.34, 0)),
|
new StarRatingDisplay(new StarDifficulty(2.34, 0)) { Anchor = Anchor.Centre, Origin = Anchor.Centre },
|
||||||
new StarRatingDisplay(new StarDifficulty(3.45, 0)),
|
new StarRatingDisplay(new StarDifficulty(3.45, 0)) { Anchor = Anchor.Centre, Origin = Anchor.Centre },
|
||||||
new StarRatingDisplay(new StarDifficulty(4.56, 0)),
|
new StarRatingDisplay(new StarDifficulty(4.56, 0)) { Anchor = Anchor.Centre, Origin = Anchor.Centre },
|
||||||
new StarRatingDisplay(new StarDifficulty(5.67, 0)),
|
new StarRatingDisplay(new StarDifficulty(5.67, 0)) { Anchor = Anchor.Centre, Origin = Anchor.Centre },
|
||||||
new StarRatingDisplay(new StarDifficulty(6.78, 0)),
|
new StarRatingDisplay(new StarDifficulty(6.78, 0)) { Anchor = Anchor.Centre, Origin = Anchor.Centre },
|
||||||
new StarRatingDisplay(new StarDifficulty(10.11, 0)),
|
new StarRatingDisplay(new StarDifficulty(10.11, 0)) { Anchor = Anchor.Centre, Origin = Anchor.Centre },
|
||||||
changingStarRating = new StarRatingDisplay(),
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
AddRepeatStep("change bottom rating", () =>
|
[Test]
|
||||||
|
public void TestChangingStarRatingDisplay()
|
||||||
|
{
|
||||||
|
StarRatingDisplay starRating = null;
|
||||||
|
|
||||||
|
AddStep("load display", () => Child = starRating = new StarRatingDisplay(new StarDifficulty(5.55, 1))
|
||||||
{
|
{
|
||||||
changingStarRating.Current.Value = new StarDifficulty(RNG.NextDouble(0, 10), RNG.Next());
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Scale = new Vector2(3f),
|
||||||
|
});
|
||||||
|
|
||||||
|
AddRepeatStep("set random value", () =>
|
||||||
|
{
|
||||||
|
starRating.Current.Value = new StarDifficulty(RNG.NextDouble(0.0, 11.0), 1);
|
||||||
}, 10);
|
}, 10);
|
||||||
|
|
||||||
|
AddSliderStep("set exact stars", 0.0, 11.0, 5.55, d =>
|
||||||
|
{
|
||||||
|
if (starRating != null)
|
||||||
|
starRating.Current.Value = new StarDifficulty(d, 1);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ namespace osu.Game.Screens.Ranking.Expanded
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A pill that displays the star rating of a <see cref="BeatmapInfo"/>.
|
/// A pill that displays the star rating of a <see cref="BeatmapInfo"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class StarRatingDisplay : CompositeDrawable, IHasCurrentValue<StarDifficulty?>
|
public class StarRatingDisplay : CompositeDrawable, IHasCurrentValue<StarDifficulty>
|
||||||
{
|
{
|
||||||
private Box background;
|
private Box background;
|
||||||
private OsuTextFlowContainer textFlow;
|
private OsuTextFlowContainer textFlow;
|
||||||
@ -30,21 +30,14 @@ namespace osu.Game.Screens.Ranking.Expanded
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private OsuColour colours { get; set; }
|
private OsuColour colours { get; set; }
|
||||||
|
|
||||||
private readonly BindableWithCurrent<StarDifficulty?> current = new BindableWithCurrent<StarDifficulty?>();
|
private readonly BindableWithCurrent<StarDifficulty> current = new BindableWithCurrent<StarDifficulty>();
|
||||||
|
|
||||||
public Bindable<StarDifficulty?> Current
|
public Bindable<StarDifficulty> Current
|
||||||
{
|
{
|
||||||
get => current.Current;
|
get => current.Current;
|
||||||
set => current.Current = value;
|
set => current.Current = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a new <see cref="StarRatingDisplay"/> without any <see cref="StarDifficulty"/> set, displaying a placeholder until <see cref="Current"/> is changed.
|
|
||||||
/// </summary>
|
|
||||||
public StarRatingDisplay()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -112,26 +105,16 @@ namespace osu.Game.Screens.Ranking.Expanded
|
|||||||
|
|
||||||
private void updateDisplay()
|
private void updateDisplay()
|
||||||
{
|
{
|
||||||
const double duration = 400;
|
var starRatingParts = Current.Value.Stars.ToString("0.00", CultureInfo.InvariantCulture).Split('.');
|
||||||
const Easing easing = Easing.OutQuint;
|
|
||||||
|
|
||||||
double stars = Current.Value?.Stars ?? 0.00f;
|
|
||||||
|
|
||||||
var starRatingParts = stars.ToString("0.00", CultureInfo.InvariantCulture).Split('.');
|
|
||||||
string wholePart = starRatingParts[0];
|
string wholePart = starRatingParts[0];
|
||||||
string fractionPart = starRatingParts[1];
|
string fractionPart = starRatingParts[1];
|
||||||
string separator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
|
string separator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
|
||||||
|
|
||||||
if (Current.Value == null)
|
var rating = Current.Value.DifficultyRating;
|
||||||
background.FadeColour(Color4.SlateGray.Opacity(0.3f));
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var rating = Current.Value.Value.DifficultyRating;
|
|
||||||
|
|
||||||
background.FadeColour(rating == DifficultyRating.ExpertPlus
|
background.Colour = rating == DifficultyRating.ExpertPlus
|
||||||
? ColourInfo.GradientVertical(Color4Extensions.FromHex("#C1C1C1"), Color4Extensions.FromHex("#595959"))
|
? ColourInfo.GradientVertical(Color4Extensions.FromHex("#C1C1C1"), Color4Extensions.FromHex("#595959"))
|
||||||
: (ColourInfo)colours.ForDifficultyRating(rating), duration, easing);
|
: (ColourInfo)colours.ForDifficultyRating(rating);
|
||||||
}
|
|
||||||
|
|
||||||
textFlow.Clear();
|
textFlow.Clear();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user