1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 13:32:54 +08:00

Update gameplay leaderboard scores with the new design

This commit is contained in:
Salman Ahmed 2020-12-17 15:12:32 +03:00
parent 5d180753fa
commit 0faf3fdfd3
3 changed files with 215 additions and 111 deletions

View File

@ -24,9 +24,8 @@ namespace osu.Game.Tests.Visual.Gameplay
Add(leaderboard = new TestGameplayLeaderboard
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Origin = Anchor.TopCentre,
Scale = new Vector2(2),
RelativeSizeAxes = Axes.X,
});
}
@ -39,7 +38,7 @@ namespace osu.Game.Tests.Visual.Gameplay
playerScore.Value = 1222333;
});
AddStep("add player user", () => leaderboard.AddPlayer(playerScore, new User { Username = "You" }));
AddStep("add player user", () => leaderboard.AddLocalUser(playerScore, new User { Username = "You" }));
AddSliderStep("set player score", 50, 5000000, 1222333, v => playerScore.Value = v);
}
@ -75,6 +74,12 @@ namespace osu.Game.Tests.Visual.Gameplay
return scoreItem != null && scoreItem.ScorePosition == expectedPosition;
}
public void AddPlayer(BindableDouble totalScore, User user) =>
base.AddPlayer(totalScore, new BindableDouble(1f), new BindableInt(1), user, false);
public void AddLocalUser(BindableDouble totalScore, User user) =>
base.AddPlayer(totalScore, new BindableDouble(1f), new BindableInt(1), user, true);
}
}
}

View File

@ -15,8 +15,7 @@ namespace osu.Game.Screens.Play.HUD
{
public GameplayLeaderboard()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
AutoSizeAxes = Axes.Both;
Direction = FillDirection.Vertical;
@ -29,32 +28,44 @@ namespace osu.Game.Screens.Play.HUD
/// <summary>
/// Adds a player to the leaderboard.
/// </summary>
/// <param name="currentScore">The bindable current score of the player.</param>
/// <param name="totalScore">A bindable of the player's total score.</param>
/// <param name="accuracy">A bindable of the player's accuracy.</param>
/// <param name="combo">A bindable of the player's current combo.</param>
/// <param name="user">The player.</param>
public void AddPlayer([NotNull] BindableDouble currentScore, [NotNull] User user)
public void AddPlayer([NotNull] IBindableNumber<double> totalScore,
[NotNull] IBindableNumber<double> accuracy,
[NotNull] IBindableNumber<int> combo,
[NotNull] User user)
{
var scoreItem = addScore(currentScore.Value, user);
currentScore.ValueChanged += s => scoreItem.TotalScore = s.NewValue;
AddPlayer(totalScore, accuracy, combo, user, false);
}
private GameplayLeaderboardScore addScore(double totalScore, User user)
/// <summary>
/// Adds a player to the leaderboard.
/// </summary>
/// <param name="totalScore">A bindable of the player's total score.</param>
/// <param name="accuracy">A bindable of the player's accuracy.</param>
/// <param name="combo">A bindable of the player's current combo.</param>
/// <param name="user">The player.</param>
/// <param name="localUser">Whether the provided <paramref name="user"/> is the local user.</param>
protected void AddPlayer([NotNull] IBindableNumber<double> totalScore,
[NotNull] IBindableNumber<double> accuracy,
[NotNull] IBindableNumber<int> combo,
[NotNull] User user, bool localUser) => Schedule(() =>
{
var scoreItem = new GameplayLeaderboardScore
Add(new GameplayLeaderboardScore(user, localUser)
{
User = user,
TotalScore = totalScore,
OnScoreChange = updateScores,
};
TotalScore = { BindTarget = totalScore },
Accuracy = { BindTarget = accuracy },
Combo = { BindTarget = combo },
});
Add(scoreItem);
updateScores();
return scoreItem;
}
totalScore.BindValueChanged(_ => updateScores(), true);
});
private void updateScores()
{
var orderedByScore = this.OrderByDescending(i => i.TotalScore).ToList();
var orderedByScore = this.OrderByDescending(i => i.TotalScore.Value).ToList();
for (int i = 0; i < Count; i++)
{

View File

@ -1,25 +1,35 @@
// 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 System;
using System.Linq;
using Humanizer;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API;
using osu.Game.Users;
using osu.Game.Utils;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Play.HUD
{
public class GameplayLeaderboardScore : CompositeDrawable
{
private readonly OsuSpriteText positionText, positionSymbol, userString;
private readonly GlowingSpriteText scoreText;
private const float regular_width = 215f;
private const float extended_width = 235f;
public Action OnScoreChange;
private const float panel_height = 35f;
private OsuSpriteText positionText, scoreText, accuracyText, comboText;
public readonly BindableDouble TotalScore = new BindableDouble();
public readonly BindableDouble Accuracy = new BindableDouble();
public readonly BindableInt Combo = new BindableInt();
private int? scorePosition;
@ -34,103 +44,181 @@ namespace osu.Game.Screens.Play.HUD
positionText.Text = $"#{scorePosition.Value.ToMetric(decimals: scorePosition < 100000 ? 1 : 0)}";
positionText.FadeTo(scorePosition.HasValue ? 1 : 0);
positionSymbol.FadeTo(scorePosition.HasValue ? 1 : 0);
}
}
private double totalScore;
public User User { get; }
public double TotalScore
private readonly bool localUser;
public GameplayLeaderboardScore(User user, bool localUser)
{
get => totalScore;
set
{
totalScore = value;
scoreText.Text = totalScore.ToString("N0");
User = user;
this.localUser = localUser;
OnScoreChange?.Invoke();
}
}
AutoSizeAxes = Axes.Both;
private User user;
public User User
{
get => user;
set
{
user = value;
userString.Text = user?.Username;
}
}
public GameplayLeaderboardScore()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
InternalChild = new Container
{
Masking = true,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new FillFlowContainer
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopRight,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Margin = new MarginPadding { Right = 2.5f },
Spacing = new Vector2(2.5f),
Children = new[]
{
positionText = new OsuSpriteText
{
Alpha = 0,
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold),
},
positionSymbol = new OsuSpriteText
{
Alpha = 0,
Font = OsuFont.GetFont(size: 14, weight: FontWeight.SemiBold),
Text = ">",
},
}
},
new FillFlowContainer
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopLeft,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Margin = new MarginPadding { Left = 2.5f },
Spacing = new Vector2(2.5f),
Children = new Drawable[]
{
userString = new OsuSpriteText
{
Size = new Vector2(80, 16),
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true),
},
scoreText = new GlowingSpriteText
{
GlowColour = Color4Extensions.FromHex(@"83ccfa"),
Font = OsuFont.Numeric.With(size: 14),
}
}
},
},
};
Anchor = Anchor.TopRight;
Origin = Anchor.TopRight;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
private void load(IAPIProvider api)
{
positionText.Colour = colours.YellowLight;
positionSymbol.Colour = colours.Yellow;
const float panel_shear = 0.15f;
const float shear_width = panel_height * panel_shear;
Color4 panelColour, textColour;
float panelWidth;
if (localUser)
{
panelWidth = extended_width;
panelColour = Color4Extensions.FromHex("7fcc33");
textColour = Color4.White;
}
else if (api.Friends.Any(f => User.Equals(f)))
{
panelWidth = extended_width;
panelColour = Color4Extensions.FromHex("ffd966");
textColour = Color4Extensions.FromHex("2e576b");
}
else
{
panelWidth = regular_width;
panelColour = Color4Extensions.FromHex("3399cc");
textColour = Color4.White;
}
InternalChildren = new Drawable[]
{
new Container
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Masking = true,
CornerRadius = 5f,
Shear = new Vector2(panel_shear, 0f),
Size = new Vector2(panelWidth, panel_height),
Child = new Box
{
Alpha = 0.5f,
RelativeSizeAxes = Axes.Both,
Colour = panelColour,
}
},
new GridContainer
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Size = new Vector2(regular_width, panel_height),
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.Absolute, 35f),
new Dimension(),
new Dimension(GridSizeMode.Absolute, 85f),
},
Content = new[]
{
new Drawable[]
{
positionText = new OsuSpriteText
{
Padding = new MarginPadding { Right = shear_width / 2 },
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = textColour,
Font = OsuFont.Torus.With(size: 14, weight: FontWeight.Bold),
Shadow = false,
},
new Container
{
Padding = new MarginPadding { Horizontal = shear_width / 3 },
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Container
{
Masking = true,
CornerRadius = 5f,
Shear = new Vector2(panel_shear, 0f),
RelativeSizeAxes = Axes.Both,
Children = new[]
{
new Box
{
Alpha = 0.5f,
RelativeSizeAxes = Axes.Both,
Colour = panelColour,
},
}
},
new OsuSpriteText
{
Padding = new MarginPadding { Left = shear_width },
RelativeSizeAxes = Axes.X,
Width = 0.8f,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Colour = textColour,
Font = OsuFont.Torus.With(size: 14, weight: FontWeight.SemiBold),
Text = User.Username,
Truncate = true,
Shadow = false,
}
}
},
new Container
{
Padding = new MarginPadding { Top = 2f, Right = 17.5f, Bottom = 5f },
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Colour = textColour,
Children = new Drawable[]
{
scoreText = new OsuSpriteText
{
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
Spacing = new Vector2(0.5f, 0f),
Font = OsuFont.Torus.With(size: 16, weight: FontWeight.SemiBold),
Shadow = false,
},
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Children = new Drawable[]
{
accuracyText = new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.Torus.With(size: 12, weight: FontWeight.SemiBold),
Shadow = false,
},
comboText = new OsuSpriteText
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Font = OsuFont.Torus.With(size: 12, weight: FontWeight.SemiBold),
Shadow = false,
},
}
}
},
}
}
}
}
};
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);
}
}
}