1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 09:02:55 +08:00
osu-lazer/osu.Game/Online/Leaderboards/DrawableRank.cs

133 lines
4.3 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2018-04-13 17:19:50 +08:00
using osu.Framework.Extensions;
2019-06-30 09:20:42 +08:00
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.Sprites;
2018-11-28 15:12:57 +08:00
using osu.Game.Scoring;
2019-06-30 09:20:42 +08:00
using osuTK;
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Online.Leaderboards
2018-04-13 17:19:50 +08:00
{
2019-06-30 09:20:42 +08:00
public class DrawableRank : CompositeDrawable
{
2019-06-18 03:33:27 +08:00
private readonly ScoreRank rank;
2019-06-18 03:33:27 +08:00
public DrawableRank(ScoreRank rank)
{
this.rank = rank;
2019-06-30 09:20:42 +08:00
RelativeSizeAxes = Axes.Both;
FillMode = FillMode.Fit;
FillAspectRatio = 2;
var rankColour = getRankColour();
2019-06-30 09:20:42 +08:00
InternalChild = new DrawSizePreservingFillContainer
{
TargetDrawSize = new Vector2(64, 32),
Strategy = DrawSizePreservationStrategy.Minimum,
Child = new CircularContainer
{
Masking = true,
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Box
2019-06-30 09:20:42 +08:00
{
RelativeSizeAxes = Axes.Both,
Colour = rankColour,
2019-06-30 09:20:42 +08:00
},
new Triangles
2019-06-30 09:20:42 +08:00
{
RelativeSizeAxes = Axes.Both,
ColourDark = rankColour.Darken(0.1f),
ColourLight = rankColour.Lighten(0.1f),
Velocity = 0.25f,
2019-06-30 09:20:42 +08:00
},
new OsuSpriteText
2019-06-30 09:20:42 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2019-06-30 13:05:45 +08:00
Spacing = new Vector2(-3, 0),
2019-06-30 09:20:42 +08:00
Padding = new MarginPadding { Top = 5 },
Colour = getRankNameColour(),
2019-06-30 09:20:42 +08:00
Font = OsuFont.GetFont(Typeface.Venera, 25),
Text = getRankName(),
2019-06-30 13:05:45 +08:00
ShadowColour = Color4.Black.Opacity(0.3f),
ShadowOffset = new Vector2(0, 0.08f),
Shadow = true,
2019-06-30 09:20:42 +08:00
},
}
}
};
2019-06-18 03:33:27 +08:00
}
2019-06-30 09:20:42 +08:00
private string getRankName() => rank.GetDescription().TrimEnd('+');
/// <summary>
/// Retrieves the grade background colour.
/// </summary>
private Color4 getRankColour()
{
switch (rank)
2019-04-22 08:57:33 +08:00
{
2019-06-30 09:20:42 +08:00
case ScoreRank.XH:
case ScoreRank.X:
return OsuColour.FromHex(@"ce1c9d");
2019-05-07 14:09:03 +08:00
2019-04-22 08:57:33 +08:00
case ScoreRank.SH:
2019-06-30 09:20:42 +08:00
case ScoreRank.S:
return OsuColour.FromHex(@"00a8b5");
2019-06-30 09:20:42 +08:00
case ScoreRank.A:
return OsuColour.FromHex(@"7cce14");
2019-06-30 09:20:42 +08:00
case ScoreRank.B:
return OsuColour.FromHex(@"e3b130");
2019-05-07 14:09:03 +08:00
2019-06-30 09:20:42 +08:00
case ScoreRank.C:
return OsuColour.FromHex(@"f18252");
2019-06-30 09:20:42 +08:00
default:
return OsuColour.FromHex(@"e95353");
2019-06-30 09:20:42 +08:00
}
}
/// <summary>
/// Retrieves the grade text colour.
/// </summary>
private ColourInfo getRankNameColour()
2019-06-30 09:20:42 +08:00
{
switch (rank)
{
2019-04-22 08:57:33 +08:00
case ScoreRank.XH:
2019-06-30 09:20:42 +08:00
case ScoreRank.SH:
return ColourInfo.GradientVertical(Color4.White, OsuColour.FromHex("afdff0"));
2019-06-30 09:20:42 +08:00
case ScoreRank.X:
case ScoreRank.S:
return ColourInfo.GradientVertical(OsuColour.FromHex(@"ffe7a8"), OsuColour.FromHex(@"ffb800"));
case ScoreRank.A:
return OsuColour.FromHex(@"275227");
case ScoreRank.B:
return OsuColour.FromHex(@"553a2b");
case ScoreRank.C:
return OsuColour.FromHex(@"473625");
2019-06-30 09:20:42 +08:00
default:
return OsuColour.FromHex(@"512525");
2019-04-22 08:57:33 +08:00
}
2018-04-13 17:19:50 +08:00
}
}
}