1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-28 03:07:19 +08:00

Added transition in StarRatingDisplay

This commit is contained in:
Denrage 2021-04-24 13:25:29 +02:00
parent 713344ebad
commit 59ae5ab913

View File

@ -12,7 +12,6 @@ using osu.Framework.Graphics.Sprites;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -27,9 +26,8 @@ namespace osu.Game.Screens.Ranking.Expanded
private OsuColour colours { get; set; } private OsuColour colours { get; set; }
private CircularContainer colorContainer; private CircularContainer colorContainer;
private OsuSpriteText wholePartText;
private OsuSpriteText fractionPartText;
private StarDifficulty starDifficulty; private StarDifficulty starDifficulty;
private FillFlowContainer foregroundContainer;
public StarDifficulty StarDifficulty public StarDifficulty StarDifficulty
{ {
@ -52,23 +50,15 @@ namespace osu.Game.Screens.Ranking.Expanded
private void setDifficulty(StarDifficulty difficulty) private void setDifficulty(StarDifficulty difficulty)
{ {
var starRatingParts = difficulty.Stars.ToString("0.00", CultureInfo.InvariantCulture).Split('.'); colorContainer.FadeColour(getDifficultyColour(difficulty), 250);
string wholePart = starRatingParts[0];
string fractionPart = starRatingParts[1];
string separator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
ColourInfo backgroundColour = difficulty.DifficultyRating == DifficultyRating.ExpertPlus foregroundContainer.Expire();
? ColourInfo.GradientVertical(Color4Extensions.FromHex("#C1C1C1"), Color4Extensions.FromHex("#595959")) foregroundContainer = null;
: (ColourInfo)colours.ForDifficultyRating(difficulty.DifficultyRating); AddInternal(foregroundContainer = createForegroundContainer(difficulty));
colorContainer.Colour = backgroundColour;
wholePartText.Text = $"{wholePart}";
fractionPartText.Text = $"{separator}{fractionPart}";
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(BeatmapDifficultyCache difficultyCache) private void load()
{ {
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
@ -78,6 +68,7 @@ namespace osu.Game.Screens.Ranking.Expanded
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Masking = true, Masking = true,
Colour = getDifficultyColour(starDifficulty),
Children = new Drawable[] Children = new Drawable[]
{ {
new Box new Box
@ -86,49 +77,64 @@ namespace osu.Game.Screens.Ranking.Expanded
}, },
} }
}, },
new FillFlowContainer foregroundContainer = createForegroundContainer(starDifficulty),
};
}
private ColourInfo getDifficultyColour(StarDifficulty difficulty)
{
return difficulty.DifficultyRating == DifficultyRating.ExpertPlus
? ColourInfo.GradientVertical(Color4Extensions.FromHex("#C1C1C1"), Color4Extensions.FromHex("#595959"))
: (ColourInfo)colours.ForDifficultyRating(difficulty.DifficultyRating);
}
private FillFlowContainer createForegroundContainer(StarDifficulty difficulty)
{
var starRatingParts = difficulty.Stars.ToString("0.00", CultureInfo.InvariantCulture).Split('.');
string wholePart = starRatingParts[0];
string fractionPart = starRatingParts[1];
string separator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
return new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Padding = new MarginPadding { Horizontal = 8, Vertical = 4 },
Direction = FillDirection.Horizontal,
Spacing = new Vector2(2, 0),
Children = new Drawable[]
{ {
AutoSizeAxes = Axes.Both, new SpriteIcon
Padding = new MarginPadding { Horizontal = 8, Vertical = 4 },
Direction = FillDirection.Horizontal,
Spacing = new Vector2(2, 0),
Children = new Drawable[]
{ {
new SpriteIcon Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Size = new Vector2(7),
Icon = FontAwesome.Solid.Star,
Colour = Color4.Black
},
new OsuTextFlowContainer(s => s.Font = OsuFont.Numeric.With(weight: FontWeight.Black))
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
TextAnchor = Anchor.BottomLeft,
}.With(t =>
{
t.AddText($"{wholePart}", s =>
{ {
Anchor = Anchor.CentreLeft, s.Colour = Color4.Black;
Origin = Anchor.CentreLeft, s.Font = s.Font.With(size: 14);
Size = new Vector2(7), s.UseFullGlyphHeight = false;
Icon = FontAwesome.Solid.Star, });
Colour = Color4.Black t.AddText($"{separator}{fractionPart}", s =>
},
new OsuTextFlowContainer(s => s.Font = OsuFont.Numeric.With(weight: FontWeight.Black))
{ {
Anchor = Anchor.CentreLeft, s.Colour = Color4.Black;
Origin = Anchor.CentreLeft, s.Font = s.Font.With(size: 7);
AutoSizeAxes = Axes.Both, s.UseFullGlyphHeight = false;
Direction = FillDirection.Horizontal, });
TextAnchor = Anchor.BottomLeft, }),
}.With(t =>
{
t.AddText(wholePartText = new OsuSpriteText(), s =>
{
s.Colour = Color4.Black;
s.Font = s.Font.With(size: 14);
s.UseFullGlyphHeight = false;
});
t.AddText(fractionPartText = new OsuSpriteText(), s =>
{
s.Colour = Color4.Black;
s.Font = s.Font.With(size: 7);
s.UseFullGlyphHeight = false;
});
}),
}
} }
}; };
setDifficulty(starDifficulty);
} }
} }
} }