1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-19 05:22:57 +08:00
osu-lazer/osu.Game/Online/Leaderboards/DrawableRank.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

106 lines
3.6 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
2022-06-17 15:37:17 +08:00
#nullable disable
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
{
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;
2020-03-17 15:25:41 +08:00
var rankColour = OsuColour.ForRank(rank);
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(),
2020-03-04 10:21:37 +08:00
Font = OsuFont.Numeric.With(size: 25),
2020-03-17 15:25:51 +08:00
Text = GetRankName(rank),
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
}
2020-03-17 15:25:51 +08:00
public static string GetRankName(ScoreRank rank) => rank.GetDescription().TrimEnd('+');
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, Color4Extensions.FromHex("afdff0"));
2019-06-30 09:20:42 +08:00
case ScoreRank.X:
case ScoreRank.S:
return ColourInfo.GradientVertical(Color4Extensions.FromHex(@"ffe7a8"), Color4Extensions.FromHex(@"ffb800"));
case ScoreRank.A:
return Color4Extensions.FromHex(@"275227");
case ScoreRank.B:
return Color4Extensions.FromHex(@"553a2b");
case ScoreRank.C:
return Color4Extensions.FromHex(@"473625");
2019-06-30 09:20:42 +08:00
default:
return Color4Extensions.FromHex(@"512525");
2019-04-22 08:57:33 +08:00
}
2017-11-11 11:54:52 +08:00
}
}
}