2019-01-24 08:43:03 +00:00
|
|
|
|
// 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 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2018-12-14 10:51:27 +00:00
|
|
|
|
using osu.Framework.Extensions;
|
2019-06-30 01:20:42 +00: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 07:12:57 +00:00
|
|
|
|
using osu.Game.Scoring;
|
2019-06-30 01:20:42 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-12-14 10:51:27 +00:00
|
|
|
|
namespace osu.Game.Online.Leaderboards
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-06-30 01:20:42 +00:00
|
|
|
|
public class DrawableRank : CompositeDrawable
|
2019-06-17 17:04:09 +00:00
|
|
|
|
{
|
2019-06-17 19:33:27 +00:00
|
|
|
|
private readonly ScoreRank rank;
|
2019-06-17 17:04:09 +00:00
|
|
|
|
|
2019-06-30 01:20:42 +00:00
|
|
|
|
private readonly Box background;
|
|
|
|
|
private readonly Triangles triangles;
|
|
|
|
|
private readonly OsuSpriteText name;
|
|
|
|
|
|
2019-06-17 19:33:27 +00:00
|
|
|
|
public DrawableRank(ScoreRank rank)
|
|
|
|
|
{
|
|
|
|
|
this.rank = rank;
|
2019-06-30 01:20:42 +00:00
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
FillMode = FillMode.Fit;
|
|
|
|
|
FillAspectRatio = 2;
|
|
|
|
|
|
|
|
|
|
InternalChild = new DrawSizePreservingFillContainer
|
|
|
|
|
{
|
|
|
|
|
TargetDrawSize = new Vector2(64, 32),
|
|
|
|
|
Strategy = DrawSizePreservationStrategy.Minimum,
|
|
|
|
|
Child = new CircularContainer
|
|
|
|
|
{
|
|
|
|
|
Masking = true,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
background = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
|
|
|
|
triangles = new Triangles
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2019-06-30 01:59:33 +00:00
|
|
|
|
TriangleScale = 1,
|
2019-06-30 01:20:42 +00:00
|
|
|
|
Velocity = 0.5f,
|
|
|
|
|
},
|
|
|
|
|
name = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Padding = new MarginPadding { Top = 5 },
|
|
|
|
|
Font = OsuFont.GetFont(Typeface.Venera, 25),
|
|
|
|
|
Text = getRankName(),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2019-06-17 19:33:27 +00:00
|
|
|
|
}
|
2019-06-17 17:04:09 +00:00
|
|
|
|
|
2019-06-30 01:20:42 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-06-30 01:20:42 +00:00
|
|
|
|
var rankColour = getRankColour(colours);
|
|
|
|
|
background.Colour = rankColour;
|
|
|
|
|
triangles.ColourDark = rankColour.Darken(0.3f);
|
|
|
|
|
triangles.ColourLight = rankColour.Lighten(0.1f);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-06-30 01:20:42 +00:00
|
|
|
|
name.Colour = getRankNameColour(colours);
|
2019-06-17 04:34:35 +00:00
|
|
|
|
}
|
2019-05-07 06:09:03 +00:00
|
|
|
|
|
2019-06-30 01:20:42 +00:00
|
|
|
|
private string getRankName() => rank.GetDescription().TrimEnd('+');
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retrieves the grade background colour.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Color4 getRankColour(OsuColour colours)
|
2019-06-17 04:34:35 +00:00
|
|
|
|
{
|
2019-06-17 17:04:09 +00:00
|
|
|
|
switch (rank)
|
2019-04-22 00:57:33 +00:00
|
|
|
|
{
|
2019-06-30 01:20:42 +00:00
|
|
|
|
case ScoreRank.XH:
|
|
|
|
|
case ScoreRank.X:
|
|
|
|
|
return colours.PinkDarker;
|
2019-05-07 06:09:03 +00:00
|
|
|
|
|
2019-04-22 00:57:33 +00:00
|
|
|
|
case ScoreRank.SH:
|
2019-06-30 01:20:42 +00:00
|
|
|
|
case ScoreRank.S:
|
|
|
|
|
return Color4.DarkCyan;
|
|
|
|
|
|
|
|
|
|
case ScoreRank.A:
|
|
|
|
|
return colours.Green;
|
|
|
|
|
|
|
|
|
|
case ScoreRank.B:
|
|
|
|
|
return Color4.Orange;
|
2019-05-07 06:09:03 +00:00
|
|
|
|
|
2019-06-30 01:20:42 +00:00
|
|
|
|
case ScoreRank.C:
|
|
|
|
|
return Color4.OrangeRed;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return colours.Red;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retrieves the grade text colour.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private ColourInfo getRankNameColour(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
switch (rank)
|
|
|
|
|
{
|
2019-04-22 00:57:33 +00:00
|
|
|
|
case ScoreRank.XH:
|
2019-06-30 01:20:42 +00:00
|
|
|
|
case ScoreRank.SH:
|
|
|
|
|
return ColourInfo.GradientVertical(Color4.White, Color4.LightGray);
|
|
|
|
|
|
|
|
|
|
case ScoreRank.X:
|
|
|
|
|
case ScoreRank.S:
|
|
|
|
|
return ColourInfo.GradientVertical(Color4.Yellow, Color4.Orange);
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return getRankColour(colours).Darken(2);
|
2019-04-22 00:57:33 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|