1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-19 06:42:54 +08:00
osu-lazer/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs

344 lines
15 KiB
C#
Raw Normal View History

2017-03-04 15:37:34 +08:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Linq;
2017-03-04 15:37:34 +08:00
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Allocation;
2017-08-14 01:54:07 +08:00
using osu.Framework.Extensions.Color4Extensions;
2017-03-04 15:37:34 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
2017-08-14 06:27:54 +08:00
using osu.Framework.Input;
2017-03-04 15:37:34 +08:00
using osu.Game.Graphics;
2017-08-14 01:54:07 +08:00
using osu.Game.Graphics.Containers;
2017-03-04 15:37:34 +08:00
using osu.Game.Graphics.Sprites;
2017-04-18 15:05:58 +08:00
using osu.Game.Rulesets.Scoring;
2017-08-14 01:54:07 +08:00
using osu.Game.Rulesets.UI;
using osu.Game.Users;
2017-03-04 15:37:34 +08:00
namespace osu.Game.Screens.Select.Leaderboards
{
public class LeaderboardScore : OsuClickableContainer
2017-03-04 15:37:34 +08:00
{
2017-03-19 15:34:29 +08:00
public static readonly float HEIGHT = 60;
2017-03-22 08:04:33 +08:00
public readonly int RankPosition;
public readonly Score Score;
2017-03-04 15:37:34 +08:00
private const float corner_radius = 5;
2017-03-19 15:34:29 +08:00
private const float edge_margin = 5;
private const float background_alpha = 0.25f;
2017-03-18 05:29:55 +08:00
private const float rank_width = 30;
2017-03-04 15:37:34 +08:00
private Box background;
private Container content;
2017-11-23 19:23:47 +08:00
private Drawable avatar;
private DrawableRank scoreRank;
private OsuSpriteText nameLabel;
private GlowingSpriteText scoreLabel;
private ScoreComponentLabel maxCombo;
private ScoreComponentLabel accuracy;
private Container flagBadgeContainer;
private FillFlowContainer<ModIcon> modsContainer;
2017-03-16 12:15:06 +08:00
public LeaderboardScore(Score score, int rank)
2017-03-04 15:37:34 +08:00
{
Score = score;
2017-03-22 08:04:33 +08:00
RankPosition = rank;
2017-03-04 15:37:34 +08:00
RelativeSizeAxes = Axes.X;
2017-03-18 06:07:45 +08:00
Height = HEIGHT;
}
2017-03-04 15:37:34 +08:00
[BackgroundDependencyLoader]
private void load()
{
2017-03-04 15:37:34 +08:00
Children = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Y,
2017-03-18 05:29:55 +08:00
Width = rank_width,
2017-03-04 15:37:34 +08:00
Children = new[]
{
new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = @"Exo2.0-MediumItalic",
TextSize = 22,
2017-03-22 08:04:33 +08:00
Text = RankPosition.ToString(),
2017-03-04 15:37:34 +08:00
},
},
},
content = new Container
2017-03-04 15:37:34 +08:00
{
RelativeSizeAxes = Axes.Both,
2017-03-18 05:29:55 +08:00
Padding = new MarginPadding { Left = rank_width, },
2017-03-04 15:37:34 +08:00
Children = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
CornerRadius = corner_radius,
Masking = true,
Children = new[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
Alpha = background_alpha,
2017-03-04 15:37:34 +08:00
},
},
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(edge_margin),
2017-11-23 19:23:47 +08:00
Children = new[]
2017-03-04 15:37:34 +08:00
{
avatar = new DelayedLoadWrapper(
new Avatar(Score.User)
2017-03-19 16:29:10 +08:00
{
2017-04-02 14:56:12 +08:00
RelativeSizeAxes = Axes.Both,
CornerRadius = corner_radius,
Masking = true,
OnLoadComplete = d => d.FadeInFromZero(200),
2017-06-12 11:48:47 +08:00
EdgeEffect = new EdgeEffectParameters
2017-03-28 13:24:21 +08:00
{
2017-04-02 14:56:12 +08:00
Type = EdgeEffectType.Shadow,
Radius = 1,
Colour = Color4.Black.Opacity(0.2f),
2017-03-28 13:24:21 +08:00
},
2017-11-23 19:23:47 +08:00
})
2017-04-02 14:56:12 +08:00
{
2017-04-04 08:47:52 +08:00
RelativeSizeAxes = Axes.None,
2017-04-02 14:56:12 +08:00
Size = new Vector2(HEIGHT - edge_margin * 2, HEIGHT - edge_margin * 2),
2017-03-04 15:37:34 +08:00
},
new Container
{
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
2017-03-18 06:07:45 +08:00
Position = new Vector2(HEIGHT - edge_margin, 0f),
2017-03-04 15:37:34 +08:00
Children = new Drawable[]
{
nameLabel = new OsuSpriteText
2017-03-04 15:37:34 +08:00
{
Text = Score.User.Username,
2017-03-04 15:37:34 +08:00
Font = @"Exo2.0-BoldItalic",
TextSize = 23,
},
new FillFlowContainer
{
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
AutoSizeAxes = Axes.Both,
2017-03-05 10:38:01 +08:00
Direction = FillDirection.Horizontal,
2017-03-04 15:37:34 +08:00
Spacing = new Vector2(10f, 0f),
Children = new Drawable[]
{
flagBadgeContainer = new Container
2017-03-04 15:37:34 +08:00
{
Size = new Vector2(87f, 20f),
Masking = true,
Children = new Drawable[]
{
2017-07-24 15:25:49 +08:00
new DrawableFlag(Score.User?.Country?.FlagName)
{
Width = 30,
RelativeSizeAxes = Axes.Y,
},
2017-03-04 15:37:34 +08:00
},
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
2017-03-05 10:38:01 +08:00
Direction = FillDirection.Horizontal,
2017-03-04 15:37:34 +08:00
Spacing = new Vector2(10f, 0f),
2017-03-18 05:16:59 +08:00
Margin = new MarginPadding { Left = edge_margin, },
2017-03-04 15:37:34 +08:00
Children = new Drawable[]
{
2017-03-14 23:58:22 +08:00
maxCombo = new ScoreComponentLabel(FontAwesome.fa_link, Score.MaxCombo.ToString()),
accuracy = new ScoreComponentLabel(FontAwesome.fa_crosshairs, string.Format(Score.Accuracy % 1 == 0 ? @"{0:P0}" : @"{0:P2}", Score.Accuracy)),
2017-03-04 15:37:34 +08:00
},
},
},
},
},
},
2017-03-18 05:16:59 +08:00
new FillFlowContainer
2017-03-04 15:37:34 +08:00
{
2017-03-18 05:16:59 +08:00
AutoSizeAxes = Axes.Both,
2017-03-04 15:37:34 +08:00
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
2017-03-18 05:16:59 +08:00
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5f, 0f),
Children = new Drawable[]
{
2017-03-18 05:29:55 +08:00
scoreLabel = new GlowingSpriteText(Score.TotalScore.ToString(@"N0"), @"Venera", 23, Color4.White, OsuColour.FromHex(@"83ccfa")),
2017-03-18 05:16:59 +08:00
new Container
{
Size = new Vector2(40f, 20f),
Children = new[]
{
scoreRank = new DrawableRank(Score.Rank)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(40f),
},
},
},
},
2017-03-04 15:37:34 +08:00
},
2017-08-14 01:54:07 +08:00
modsContainer = new FillFlowContainer<ModIcon>
2017-03-04 15:37:34 +08:00
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
AutoSizeAxes = Axes.Both,
2017-03-05 10:38:01 +08:00
Direction = FillDirection.Horizontal,
ChildrenEnumerable = Score.Mods.Select(mod => new ModIcon(mod) { Scale = new Vector2(0.375f) })
2017-03-04 15:37:34 +08:00
},
},
},
},
},
};
}
public override void Show()
{
2017-11-23 19:23:47 +08:00
foreach (var d in new[] { avatar, nameLabel, scoreLabel, scoreRank, flagBadgeContainer, maxCombo, accuracy, modsContainer })
d.FadeOut();
Alpha = 0;
content.MoveToY(75);
avatar.MoveToX(75);
nameLabel.MoveToX(150);
this.FadeIn(200);
content.MoveToY(0, 800, Easing.OutQuint);
using (BeginDelayedSequence(100, true))
{
avatar.FadeIn(300, Easing.OutQuint);
nameLabel.FadeIn(350, Easing.OutQuint);
2017-03-04 15:37:34 +08:00
avatar.MoveToX(0, 300, Easing.OutQuint);
nameLabel.MoveToX(0, 350, Easing.OutQuint);
using (BeginDelayedSequence(250, true))
{
scoreLabel.FadeIn(200);
scoreRank.FadeIn(200);
2017-03-18 06:45:51 +08:00
using (BeginDelayedSequence(50, true))
{
var drawables = new Drawable[] { flagBadgeContainer, maxCombo, accuracy, modsContainer, };
for (int i = 0; i < drawables.Length; i++)
drawables[i].FadeIn(100 + i * 50);
}
}
}
}
2017-03-18 06:45:51 +08:00
2017-08-14 06:27:54 +08:00
protected override bool OnHover(InputState state)
2017-03-18 06:45:51 +08:00
{
2017-07-23 02:50:25 +08:00
background.FadeTo(0.5f, 300, Easing.OutQuint);
2017-03-18 06:45:51 +08:00
return base.OnHover(state);
}
2017-08-14 06:27:54 +08:00
protected override void OnHoverLost(InputState state)
2017-03-18 06:45:51 +08:00
{
2017-07-23 02:50:25 +08:00
background.FadeTo(background_alpha, 200, Easing.OutQuint);
2017-03-18 06:45:51 +08:00
base.OnHoverLost(state);
}
2017-03-14 22:55:19 +08:00
private class GlowingSpriteText : Container
{
public GlowingSpriteText(string text, string font, int textSize, Color4 textColour, Color4 glowColour)
{
AutoSizeAxes = Axes.Both;
Children = new Drawable[]
{
new BufferedContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
BlurSigma = new Vector2(4),
CacheDrawnFrameBuffer = true,
RelativeSizeAxes = Axes.Both,
2017-09-07 21:46:21 +08:00
Blending = BlendingMode.Additive,
Size = new Vector2(3f),
Children = new[]
{
new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = font,
2017-03-15 14:21:07 +08:00
FixedWidth = true,
2017-08-14 06:27:54 +08:00
TextSize = textSize,
Text = text,
Colour = glowColour,
Shadow = false,
},
},
},
new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = font,
2017-03-15 14:21:07 +08:00
FixedWidth = true,
TextSize = textSize,
Text = text,
Colour = textColour,
Shadow = false,
},
};
}
}
2017-03-14 22:55:19 +08:00
private class ScoreComponentLabel : Container
2017-03-04 15:37:34 +08:00
{
public ScoreComponentLabel(FontAwesome icon, string value)
{
Anchor = Anchor.CentreLeft;
Origin = Anchor.CentreLeft;
Size = new Vector2(60f, 20f);
Padding = new MarginPadding { Top = 10f, };
Children = new Drawable[]
{
new SpriteIcon
2017-03-04 15:37:34 +08:00
{
Origin = Anchor.Centre,
2017-03-04 15:37:34 +08:00
Icon = FontAwesome.fa_square,
Colour = OsuColour.FromHex(@"3087ac"),
Rotation = 45,
Size = new Vector2(20),
2017-03-04 15:37:34 +08:00
Shadow = true,
},
new SpriteIcon
2017-03-04 15:37:34 +08:00
{
Origin = Anchor.Centre,
2017-03-04 15:37:34 +08:00
Icon = icon,
Colour = OsuColour.FromHex(@"a4edff"),
Size = new Vector2(14),
2017-03-04 15:37:34 +08:00
},
new GlowingSpriteText(value, @"Exo2.0-Bold", 17, Color4.White, OsuColour.FromHex(@"83ccfa"))
2017-03-04 15:37:34 +08:00
{
Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Left = 15, },
},
};
}
}
}
}