2019-07-29 11:51:44 +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.
|
|
|
|
|
2020-12-28 19:16:53 +08:00
|
|
|
using JetBrains.Annotations;
|
2019-07-29 11:51:44 +08:00
|
|
|
using osu.Framework.Allocation;
|
2020-12-17 20:12:32 +08:00
|
|
|
using osu.Framework.Bindables;
|
2020-12-15 14:22:14 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2019-07-29 11:51:44 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-12-17 20:12:32 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2019-07-29 11:51:44 +08:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Users;
|
2020-12-18 18:09:05 +08:00
|
|
|
using osu.Game.Users.Drawables;
|
2020-12-17 20:12:32 +08:00
|
|
|
using osu.Game.Utils;
|
2019-07-29 11:51:44 +08:00
|
|
|
using osuTK;
|
2020-12-17 20:12:32 +08:00
|
|
|
using osuTK.Graphics;
|
2019-07-29 11:51:44 +08:00
|
|
|
|
2020-12-15 14:27:26 +08:00
|
|
|
namespace osu.Game.Screens.Play.HUD
|
2019-07-29 11:51:44 +08:00
|
|
|
{
|
2020-12-18 16:07:38 +08:00
|
|
|
public class GameplayLeaderboardScore : CompositeDrawable, ILeaderboardScore
|
2019-07-29 11:51:44 +08:00
|
|
|
{
|
2020-12-18 18:09:50 +08:00
|
|
|
public const float EXTENDED_WIDTH = 255f;
|
2020-12-18 16:25:48 +08:00
|
|
|
|
2020-12-18 18:09:50 +08:00
|
|
|
private const float regular_width = 235f;
|
2019-07-29 11:51:44 +08:00
|
|
|
|
2020-12-18 16:25:48 +08:00
|
|
|
public const float PANEL_HEIGHT = 35f;
|
2020-12-17 20:12:32 +08:00
|
|
|
|
2020-12-18 16:30:11 +08:00
|
|
|
public const float SHEAR_WIDTH = PANEL_HEIGHT * panel_shear;
|
|
|
|
|
|
|
|
private const float panel_shear = 0.15f;
|
|
|
|
|
2020-12-18 15:20:54 +08:00
|
|
|
private OsuSpriteText positionText, scoreText, accuracyText, comboText, usernameText;
|
2020-12-18 08:34:33 +08:00
|
|
|
|
2020-12-18 16:07:38 +08:00
|
|
|
public BindableDouble TotalScore { get; } = new BindableDouble();
|
|
|
|
public BindableDouble Accuracy { get; } = new BindableDouble(1);
|
|
|
|
public BindableInt Combo { get; } = new BindableInt();
|
2020-12-26 10:43:10 +08:00
|
|
|
public BindableBool HasQuit { get; } = new BindableBool();
|
2019-07-29 11:51:44 +08:00
|
|
|
|
|
|
|
private int? scorePosition;
|
|
|
|
|
|
|
|
public int? ScorePosition
|
|
|
|
{
|
|
|
|
get => scorePosition;
|
|
|
|
set
|
|
|
|
{
|
2020-12-18 16:19:00 +08:00
|
|
|
if (value == scorePosition)
|
|
|
|
return;
|
|
|
|
|
2019-07-29 11:51:44 +08:00
|
|
|
scorePosition = value;
|
|
|
|
|
|
|
|
if (scorePosition.HasValue)
|
2020-12-19 22:02:56 +08:00
|
|
|
positionText.Text = $"#{scorePosition.Value.FormatRank()}";
|
2019-07-29 11:51:44 +08:00
|
|
|
|
2019-08-04 23:35:53 +08:00
|
|
|
positionText.FadeTo(scorePosition.HasValue ? 1 : 0);
|
2020-12-27 19:58:37 +08:00
|
|
|
updateState();
|
2019-07-29 11:51:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-28 19:16:53 +08:00
|
|
|
[CanBeNull]
|
2020-12-17 20:12:32 +08:00
|
|
|
public User User { get; }
|
|
|
|
|
2020-12-18 14:35:18 +08:00
|
|
|
private readonly bool trackedPlayer;
|
2020-12-18 08:37:24 +08:00
|
|
|
|
2020-12-18 15:20:54 +08:00
|
|
|
private Container mainFillContainer;
|
|
|
|
private Box centralFill;
|
|
|
|
|
2020-12-18 08:37:24 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Creates a new <see cref="GameplayLeaderboardScore"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="user">The score's player.</param>
|
2020-12-18 14:35:18 +08:00
|
|
|
/// <param name="trackedPlayer">Whether the player is the local user or a replay player.</param>
|
2020-12-28 19:16:53 +08:00
|
|
|
public GameplayLeaderboardScore([CanBeNull] User user, bool trackedPlayer)
|
2019-07-29 11:51:44 +08:00
|
|
|
{
|
2020-12-17 20:12:32 +08:00
|
|
|
User = user;
|
2020-12-18 14:35:18 +08:00
|
|
|
this.trackedPlayer = trackedPlayer;
|
2019-07-29 11:51:44 +08:00
|
|
|
|
2020-12-18 16:25:48 +08:00
|
|
|
Size = new Vector2(EXTENDED_WIDTH, PANEL_HEIGHT);
|
2020-12-17 20:12:32 +08:00
|
|
|
}
|
2019-07-29 11:51:44 +08:00
|
|
|
|
2020-12-18 15:20:54 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2020-12-18 18:09:05 +08:00
|
|
|
private void load(OsuColour colours)
|
2020-12-18 15:20:54 +08:00
|
|
|
{
|
2020-12-26 21:06:23 +08:00
|
|
|
Container avatarContainer;
|
|
|
|
|
2020-12-17 20:12:32 +08:00
|
|
|
InternalChildren = new Drawable[]
|
2019-07-29 11:51:44 +08:00
|
|
|
{
|
2020-12-18 15:20:54 +08:00
|
|
|
mainFillContainer = new Container
|
2019-07-29 11:51:44 +08:00
|
|
|
{
|
2020-12-18 15:20:54 +08:00
|
|
|
Width = regular_width,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2020-12-17 20:12:32 +08:00
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = 5f,
|
|
|
|
Shear = new Vector2(panel_shear, 0f),
|
|
|
|
Child = new Box
|
2019-07-29 11:51:44 +08:00
|
|
|
{
|
2020-12-17 20:12:32 +08:00
|
|
|
Alpha = 0.5f,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new GridContainer
|
|
|
|
{
|
2020-12-18 15:20:54 +08:00
|
|
|
Width = regular_width,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2020-12-17 20:12:32 +08:00
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
ColumnDimensions = new[]
|
|
|
|
{
|
|
|
|
new Dimension(GridSizeMode.Absolute, 35f),
|
|
|
|
new Dimension(),
|
|
|
|
new Dimension(GridSizeMode.Absolute, 85f),
|
|
|
|
},
|
|
|
|
Content = new[]
|
|
|
|
{
|
|
|
|
new Drawable[]
|
2019-07-29 11:51:44 +08:00
|
|
|
{
|
|
|
|
positionText = new OsuSpriteText
|
|
|
|
{
|
2020-12-18 16:30:11 +08:00
|
|
|
Padding = new MarginPadding { Right = SHEAR_WIDTH / 2 },
|
2020-12-17 20:12:32 +08:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2020-12-18 15:20:54 +08:00
|
|
|
Colour = Color4.White,
|
2020-12-17 20:12:32 +08:00
|
|
|
Font = OsuFont.Torus.With(size: 14, weight: FontWeight.Bold),
|
|
|
|
Shadow = false,
|
2019-07-29 11:51:44 +08:00
|
|
|
},
|
2020-12-17 20:12:32 +08:00
|
|
|
new Container
|
2019-07-29 11:51:44 +08:00
|
|
|
{
|
2020-12-18 16:30:11 +08:00
|
|
|
Padding = new MarginPadding { Horizontal = SHEAR_WIDTH / 3 },
|
2020-12-17 20:12:32 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = 5f,
|
|
|
|
Shear = new Vector2(panel_shear, 0f),
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new[]
|
|
|
|
{
|
2020-12-18 15:20:54 +08:00
|
|
|
centralFill = new Box
|
2020-12-17 20:12:32 +08:00
|
|
|
{
|
|
|
|
Alpha = 0.5f,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-12-18 15:20:54 +08:00
|
|
|
Colour = Color4Extensions.FromHex("3399cc"),
|
2020-12-17 20:12:32 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
2020-12-18 18:09:05 +08:00
|
|
|
new FillFlowContainer
|
2020-12-17 20:12:32 +08:00
|
|
|
{
|
2020-12-18 16:30:11 +08:00
|
|
|
Padding = new MarginPadding { Left = SHEAR_WIDTH },
|
2020-12-17 20:12:32 +08:00
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
2020-12-18 18:09:05 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Spacing = new Vector2(4f, 0f),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2020-12-26 21:06:23 +08:00
|
|
|
avatarContainer = new CircularContainer
|
2020-12-18 18:09:05 +08:00
|
|
|
{
|
|
|
|
Masking = true,
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Size = new Vector2(25f),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Name = "Placeholder while avatar loads",
|
|
|
|
Alpha = 0.3f,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = colours.Gray4,
|
2020-12-26 21:06:23 +08:00
|
|
|
}
|
2020-12-18 18:09:05 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
usernameText = new OsuSpriteText
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2020-12-20 01:48:17 +08:00
|
|
|
Width = 0.6f,
|
2020-12-18 18:09:05 +08:00
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Colour = Color4.White,
|
|
|
|
Font = OsuFont.Torus.With(size: 14, weight: FontWeight.SemiBold),
|
2020-12-28 19:16:53 +08:00
|
|
|
Text = User?.Username,
|
2020-12-18 18:09:05 +08:00
|
|
|
Truncate = true,
|
|
|
|
Shadow = false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2020-12-17 20:12:32 +08:00
|
|
|
}
|
2019-07-29 11:51:44 +08:00
|
|
|
},
|
2020-12-17 20:12:32 +08:00
|
|
|
new Container
|
2019-07-29 11:51:44 +08:00
|
|
|
{
|
2020-12-17 20:12:32 +08:00
|
|
|
Padding = new MarginPadding { Top = 2f, Right = 17.5f, Bottom = 5f },
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
2020-12-18 15:20:54 +08:00
|
|
|
Colour = Color4.White,
|
2020-12-17 20:12:32 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
scoreText = new OsuSpriteText
|
|
|
|
{
|
2020-12-18 15:20:54 +08:00
|
|
|
Spacing = new Vector2(-1f, 0f),
|
|
|
|
Font = OsuFont.Torus.With(size: 16, weight: FontWeight.SemiBold, fixedWidth: true),
|
2020-12-17 20:12:32 +08:00
|
|
|
Shadow = false,
|
|
|
|
},
|
2020-12-18 15:20:54 +08:00
|
|
|
accuracyText = new OsuSpriteText
|
2020-12-17 20:12:32 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
2020-12-18 15:20:54 +08:00
|
|
|
Font = OsuFont.Torus.With(size: 12, weight: FontWeight.SemiBold, fixedWidth: true),
|
|
|
|
Spacing = new Vector2(-1f, 0f),
|
|
|
|
Shadow = false,
|
|
|
|
},
|
|
|
|
comboText = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomRight,
|
|
|
|
Origin = Anchor.BottomRight,
|
|
|
|
Spacing = new Vector2(-1f, 0f),
|
|
|
|
Font = OsuFont.Torus.With(size: 12, weight: FontWeight.SemiBold, fixedWidth: true),
|
|
|
|
Shadow = false,
|
|
|
|
},
|
2020-12-17 20:12:32 +08:00
|
|
|
},
|
2019-07-29 11:51:44 +08:00
|
|
|
}
|
|
|
|
}
|
2020-12-17 20:12:32 +08:00
|
|
|
}
|
|
|
|
}
|
2019-07-29 11:51:44 +08:00
|
|
|
};
|
|
|
|
|
2020-12-26 21:06:23 +08:00
|
|
|
LoadComponentAsync(new DrawableAvatar(User), avatarContainer.Add);
|
|
|
|
|
2020-12-17 20:12:32 +08:00
|
|
|
TotalScore.BindValueChanged(v => scoreText.Text = v.NewValue.ToString("N0"), true);
|
|
|
|
Accuracy.BindValueChanged(v => accuracyText.Text = v.NewValue.FormatAccuracy(), true);
|
|
|
|
Combo.BindValueChanged(v => comboText.Text = $"{v.NewValue}x", true);
|
2020-12-27 20:00:27 +08:00
|
|
|
HasQuit.BindValueChanged(_ => updateState());
|
2019-07-29 11:51:44 +08:00
|
|
|
}
|
2020-12-19 22:05:59 +08:00
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2020-12-27 19:58:37 +08:00
|
|
|
updateState();
|
2020-12-19 22:05:59 +08:00
|
|
|
FinishTransforms(true);
|
|
|
|
}
|
|
|
|
|
2020-12-19 22:18:05 +08:00
|
|
|
private const double panel_transition_duration = 500;
|
2020-12-19 22:05:59 +08:00
|
|
|
|
2020-12-27 19:58:37 +08:00
|
|
|
private void updateState()
|
2020-12-19 22:05:59 +08:00
|
|
|
{
|
2020-12-26 10:43:10 +08:00
|
|
|
if (HasQuit.Value)
|
2020-12-27 12:40:02 +08:00
|
|
|
{
|
|
|
|
// we will probably want to display this in a better way once we have a design.
|
|
|
|
// and also show states other than quit.
|
|
|
|
mainFillContainer.ResizeWidthTo(regular_width, panel_transition_duration, Easing.OutElastic);
|
|
|
|
panelColour = Color4.Gray;
|
|
|
|
textColour = Color4.White;
|
2020-12-26 10:43:10 +08:00
|
|
|
return;
|
2020-12-27 12:40:02 +08:00
|
|
|
}
|
2020-12-26 10:43:10 +08:00
|
|
|
|
2020-12-19 22:05:59 +08:00
|
|
|
if (scorePosition == 1)
|
|
|
|
{
|
2020-12-19 22:18:05 +08:00
|
|
|
mainFillContainer.ResizeWidthTo(EXTENDED_WIDTH, panel_transition_duration, Easing.OutElastic);
|
2020-12-19 22:05:59 +08:00
|
|
|
panelColour = Color4Extensions.FromHex("7fcc33");
|
|
|
|
textColour = Color4.White;
|
|
|
|
}
|
|
|
|
else if (trackedPlayer)
|
|
|
|
{
|
2020-12-19 22:18:05 +08:00
|
|
|
mainFillContainer.ResizeWidthTo(EXTENDED_WIDTH, panel_transition_duration, Easing.OutElastic);
|
2020-12-19 22:05:59 +08:00
|
|
|
panelColour = Color4Extensions.FromHex("ffd966");
|
|
|
|
textColour = Color4Extensions.FromHex("2e576b");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-19 22:18:05 +08:00
|
|
|
mainFillContainer.ResizeWidthTo(regular_width, panel_transition_duration, Easing.OutElastic);
|
2020-12-19 22:05:59 +08:00
|
|
|
panelColour = Color4Extensions.FromHex("3399cc");
|
|
|
|
textColour = Color4.White;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Color4 panelColour
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
2020-12-19 22:18:05 +08:00
|
|
|
mainFillContainer.FadeColour(value, panel_transition_duration, Easing.OutQuint);
|
|
|
|
centralFill.FadeColour(value, panel_transition_duration, Easing.OutQuint);
|
2020-12-19 22:05:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-19 22:17:31 +08:00
|
|
|
private const double text_transition_duration = 200;
|
|
|
|
|
2020-12-19 22:05:59 +08:00
|
|
|
private Color4 textColour
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
2020-12-19 22:17:31 +08:00
|
|
|
scoreText.FadeColour(value, text_transition_duration, Easing.OutQuint);
|
|
|
|
accuracyText.FadeColour(value, text_transition_duration, Easing.OutQuint);
|
|
|
|
comboText.FadeColour(value, text_transition_duration, Easing.OutQuint);
|
|
|
|
usernameText.FadeColour(value, text_transition_duration, Easing.OutQuint);
|
|
|
|
positionText.FadeColour(value, text_transition_duration, Easing.OutQuint);
|
2020-12-19 22:05:59 +08:00
|
|
|
}
|
|
|
|
}
|
2019-07-29 11:51:44 +08:00
|
|
|
}
|
|
|
|
}
|