2023-01-16 23:57:18 +08: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.
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2023-01-17 00:35:27 +08:00
|
|
|
using osu.Framework.Graphics.Cursor;
|
2023-01-16 23:57:18 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2023-01-17 00:15:37 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2023-01-17 00:35:27 +08:00
|
|
|
using osu.Framework.Localisation;
|
|
|
|
using osu.Game.Graphics;
|
2023-01-16 23:57:18 +08:00
|
|
|
using osu.Game.Graphics.Containers;
|
2023-01-17 00:35:27 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2023-01-17 00:15:37 +08:00
|
|
|
using osu.Game.Overlays;
|
2023-01-17 00:35:27 +08:00
|
|
|
using osu.Game.Scoring;
|
|
|
|
using osu.Game.Utils;
|
2023-01-16 23:57:18 +08:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Online.Leaderboards
|
|
|
|
{
|
|
|
|
public partial class LeaderBoardScoreV2 : OsuClickableContainer
|
|
|
|
{
|
2023-01-17 00:35:27 +08:00
|
|
|
private readonly ScoreInfo score;
|
|
|
|
|
2023-01-16 23:57:18 +08:00
|
|
|
private const int HEIGHT = 60;
|
|
|
|
private const int corner_radius = 10;
|
2023-01-17 00:15:37 +08:00
|
|
|
private const int transition_duration = 200;
|
|
|
|
|
2023-01-17 00:35:27 +08:00
|
|
|
private readonly int? rank;
|
|
|
|
|
|
|
|
private readonly bool isPersonalBest;
|
|
|
|
|
2023-01-17 00:15:37 +08:00
|
|
|
private Colour4 foregroundColour;
|
|
|
|
private Colour4 backgroundColour;
|
2023-01-16 23:57:18 +08:00
|
|
|
|
|
|
|
private static readonly Vector2 shear = new Vector2(0.15f, 0);
|
|
|
|
|
2023-01-17 00:15:37 +08:00
|
|
|
[Cached]
|
|
|
|
private OverlayColourProvider colourProvider { get; set; } = new OverlayColourProvider(OverlayColourScheme.Aquamarine);
|
|
|
|
|
2023-01-16 23:57:18 +08:00
|
|
|
private Container content = null!;
|
2023-01-17 00:15:37 +08:00
|
|
|
private Box background = null!;
|
|
|
|
private Box foreground = null!;
|
|
|
|
|
2023-01-17 00:35:27 +08:00
|
|
|
public LeaderBoardScoreV2(ScoreInfo score, int? rank, bool isPersonalBest = false)
|
2023-01-17 00:15:37 +08:00
|
|
|
{
|
2023-01-17 00:35:27 +08:00
|
|
|
this.score = score;
|
|
|
|
this.rank = rank;
|
2023-01-17 00:15:37 +08:00
|
|
|
this.isPersonalBest = isPersonalBest;
|
|
|
|
}
|
2023-01-16 23:57:18 +08:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2023-01-17 00:15:37 +08:00
|
|
|
foregroundColour = isPersonalBest ? colourProvider.Background1 : colourProvider.Background5;
|
|
|
|
backgroundColour = isPersonalBest ? colourProvider.Background2 : colourProvider.Background4;
|
|
|
|
|
2023-01-16 23:57:18 +08:00
|
|
|
Shear = shear;
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
Height = HEIGHT;
|
|
|
|
Child = content = new Container
|
|
|
|
{
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = corner_radius,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2023-01-17 00:15:37 +08:00
|
|
|
background = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = backgroundColour
|
|
|
|
},
|
|
|
|
new GridContainer
|
2023-01-16 23:57:18 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2023-01-17 00:15:37 +08:00
|
|
|
ColumnDimensions = new[]
|
|
|
|
{
|
|
|
|
new Dimension(GridSizeMode.Absolute, 65),
|
|
|
|
new Dimension(),
|
|
|
|
new Dimension(GridSizeMode.Absolute, 176)
|
|
|
|
},
|
|
|
|
Content = new[]
|
|
|
|
{
|
|
|
|
new[]
|
|
|
|
{
|
2023-01-17 00:35:27 +08:00
|
|
|
new RankLabel(rank)
|
|
|
|
{
|
|
|
|
Shear = -shear,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
Width = 35
|
|
|
|
},
|
2023-01-17 00:15:37 +08:00
|
|
|
createCentreContent(),
|
|
|
|
Empty(),
|
|
|
|
}
|
|
|
|
}
|
2023-01-16 23:57:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2023-01-17 00:15:37 +08:00
|
|
|
|
|
|
|
private Container createCentreContent() =>
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = corner_radius,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
foreground = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = foregroundColour
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
updateState();
|
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
updateState();
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateState()
|
|
|
|
{
|
|
|
|
foreground.FadeColour(IsHovered ? foregroundColour.Lighten(0.2f) : foregroundColour, transition_duration, Easing.OutQuint);
|
|
|
|
background.FadeColour(IsHovered ? backgroundColour.Lighten(0.2f) : backgroundColour, transition_duration, Easing.OutQuint);
|
|
|
|
}
|
2023-01-17 00:35:27 +08:00
|
|
|
|
|
|
|
private partial class RankLabel : Container, IHasTooltip
|
|
|
|
{
|
|
|
|
public RankLabel(int? rank)
|
|
|
|
{
|
|
|
|
if (rank >= 1000)
|
|
|
|
TooltipText = $"#{rank:N0}";
|
|
|
|
|
|
|
|
Child = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Font = OsuFont.GetFont(size: 20, weight: FontWeight.SemiBold, italics: true),
|
|
|
|
Text = rank == null ? "-" : rank.Value.FormatRank().Insert(0, "#")
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public LocalisableString TooltipText { get; }
|
|
|
|
}
|
2023-01-16 23:57:18 +08:00
|
|
|
}
|
|
|
|
}
|