From 0faf3fdfd3fc4f96d137d1e8824398383e441ace Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Thu, 17 Dec 2020 15:12:32 +0300 Subject: [PATCH 1/6] Update gameplay leaderboard scores with the new design --- .../Gameplay/TestSceneGameplayLeaderboard.cs | 11 +- .../Screens/Play/HUD/GameplayLeaderboard.cs | 47 +-- .../Play/HUD/GameplayLeaderboardScore.cs | 268 ++++++++++++------ 3 files changed, 215 insertions(+), 111 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs index df970c1c46..d0fdb3dd9c 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs @@ -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); } } } diff --git a/osu.Game/Screens/Play/HUD/GameplayLeaderboard.cs b/osu.Game/Screens/Play/HUD/GameplayLeaderboard.cs index e53c56b390..a2673e3097 100644 --- a/osu.Game/Screens/Play/HUD/GameplayLeaderboard.cs +++ b/osu.Game/Screens/Play/HUD/GameplayLeaderboard.cs @@ -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 /// /// Adds a player to the leaderboard. /// - /// The bindable current score of the player. + /// A bindable of the player's total score. + /// A bindable of the player's accuracy. + /// A bindable of the player's current combo. /// The player. - public void AddPlayer([NotNull] BindableDouble currentScore, [NotNull] User user) + public void AddPlayer([NotNull] IBindableNumber totalScore, + [NotNull] IBindableNumber accuracy, + [NotNull] IBindableNumber 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) + /// + /// Adds a player to the leaderboard. + /// + /// A bindable of the player's total score. + /// A bindable of the player's accuracy. + /// A bindable of the player's current combo. + /// The player. + /// Whether the provided is the local user. + protected void AddPlayer([NotNull] IBindableNumber totalScore, + [NotNull] IBindableNumber accuracy, + [NotNull] IBindableNumber 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++) { diff --git a/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs b/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs index 4c75f422c9..62ea5782e8 100644 --- a/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs +++ b/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs @@ -1,25 +1,35 @@ // Copyright (c) ppy Pty Ltd . 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); } } } From a8abefcd665adf869b97e45d89c0d85a6d979a7b Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 18 Dec 2020 03:34:33 +0300 Subject: [PATCH 2/6] Make GameplayLeaderboardScore a model class --- .../Gameplay/TestSceneGameplayLeaderboard.cs | 20 +++++---- .../Screens/Play/HUD/GameplayLeaderboard.cs | 41 ++----------------- .../Play/HUD/GameplayLeaderboardScore.cs | 5 ++- 3 files changed, 17 insertions(+), 49 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs index d0fdb3dd9c..12bc918d45 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs @@ -38,7 +38,7 @@ namespace osu.Game.Tests.Visual.Gameplay playerScore.Value = 1222333; }); - AddStep("add player user", () => leaderboard.AddLocalUser(playerScore, new User { Username = "You" })); + AddStep("add local player", () => leaderboard.Add(createLeaderboardScore(playerScore, "You", true))); AddSliderStep("set player score", 50, 5000000, 1222333, v => playerScore.Value = v); } @@ -48,8 +48,8 @@ namespace osu.Game.Tests.Visual.Gameplay var player2Score = new BindableDouble(1234567); var player3Score = new BindableDouble(1111111); - AddStep("add player 2", () => leaderboard.AddPlayer(player2Score, new User { Username = "Player 2" })); - AddStep("add player 3", () => leaderboard.AddPlayer(player3Score, new User { Username = "Player 3" })); + AddStep("add player 2", () => leaderboard.Add(createLeaderboardScore(player2Score, "Player 2"))); + AddStep("add player 3", () => leaderboard.Add(createLeaderboardScore(player3Score, "Player 3"))); AddAssert("is player 2 position #1", () => leaderboard.CheckPositionByUsername("Player 2", 1)); AddAssert("is player position #2", () => leaderboard.CheckPositionByUsername("You", 2)); @@ -66,6 +66,14 @@ namespace osu.Game.Tests.Visual.Gameplay AddAssert("is player 2 position #3", () => leaderboard.CheckPositionByUsername("Player 2", 3)); } + private static GameplayLeaderboardScore createLeaderboardScore(BindableDouble score, string username, bool localOrReplayPlayer = false) + { + return new GameplayLeaderboardScore(new User { Username = username }, localOrReplayPlayer) + { + TotalScore = { BindTarget = score }, + }; + } + private class TestGameplayLeaderboard : GameplayLeaderboard { public bool CheckPositionByUsername(string username, int? expectedPosition) @@ -74,12 +82,6 @@ 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); } } } diff --git a/osu.Game/Screens/Play/HUD/GameplayLeaderboard.cs b/osu.Game/Screens/Play/HUD/GameplayLeaderboard.cs index a2673e3097..573bf54b14 100644 --- a/osu.Game/Screens/Play/HUD/GameplayLeaderboard.cs +++ b/osu.Game/Screens/Play/HUD/GameplayLeaderboard.cs @@ -2,11 +2,8 @@ // See the LICENCE file in the repository root for full licence text. using System.Linq; -using JetBrains.Annotations; -using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Game.Users; using osuTK; namespace osu.Game.Screens.Play.HUD @@ -25,44 +22,12 @@ namespace osu.Game.Screens.Play.HUD LayoutEasing = Easing.OutQuint; } - /// - /// Adds a player to the leaderboard. - /// - /// A bindable of the player's total score. - /// A bindable of the player's accuracy. - /// A bindable of the player's current combo. - /// The player. - public void AddPlayer([NotNull] IBindableNumber totalScore, - [NotNull] IBindableNumber accuracy, - [NotNull] IBindableNumber combo, - [NotNull] User user) + public override void Add(GameplayLeaderboardScore drawable) { - AddPlayer(totalScore, accuracy, combo, user, false); + base.Add(drawable); + drawable?.TotalScore.BindValueChanged(_ => updateScores(), true); } - /// - /// Adds a player to the leaderboard. - /// - /// A bindable of the player's total score. - /// A bindable of the player's accuracy. - /// A bindable of the player's current combo. - /// The player. - /// Whether the provided is the local user. - protected void AddPlayer([NotNull] IBindableNumber totalScore, - [NotNull] IBindableNumber accuracy, - [NotNull] IBindableNumber combo, - [NotNull] User user, bool localUser) => Schedule(() => - { - Add(new GameplayLeaderboardScore(user, localUser) - { - TotalScore = { BindTarget = totalScore }, - Accuracy = { BindTarget = accuracy }, - Combo = { BindTarget = combo }, - }); - - totalScore.BindValueChanged(_ => updateScores(), true); - }); - private void updateScores() { var orderedByScore = this.OrderByDescending(i => i.TotalScore.Value).ToList(); diff --git a/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs b/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs index 62ea5782e8..f94d6bd01f 100644 --- a/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs +++ b/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs @@ -27,8 +27,9 @@ namespace osu.Game.Screens.Play.HUD 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 BindableDouble TotalScore = new BindableDouble(1000000); + public readonly BindableDouble Accuracy = new BindableDouble(1); public readonly BindableInt Combo = new BindableInt(); private int? scorePosition; From 92bf74ba29b3bc6c8ec645fe54d9c218d76ff6cf Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 18 Dec 2020 03:37:24 +0300 Subject: [PATCH 3/6] localUser -> localOrReplayPlayer --- .../Screens/Play/HUD/GameplayLeaderboardScore.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs b/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs index f94d6bd01f..285ed93341 100644 --- a/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs +++ b/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs @@ -50,12 +50,17 @@ namespace osu.Game.Screens.Play.HUD public User User { get; } - private readonly bool localUser; + private readonly bool localOrReplayPlayer; - public GameplayLeaderboardScore(User user, bool localUser) + /// + /// Creates a new . + /// + /// The score's player. + /// Whether the player is the local user or a replay player. + public GameplayLeaderboardScore(User user, bool localOrReplayPlayer) { User = user; - this.localUser = localUser; + this.localOrReplayPlayer = localOrReplayPlayer; AutoSizeAxes = Axes.Both; @@ -72,7 +77,7 @@ namespace osu.Game.Screens.Play.HUD Color4 panelColour, textColour; float panelWidth; - if (localUser) + if (localOrReplayPlayer) { panelWidth = extended_width; panelColour = Color4Extensions.FromHex("7fcc33"); From 4af508235ee855cd0ac9be9d5aed56d416651f95 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 18 Dec 2020 15:35:18 +0900 Subject: [PATCH 4/6] Rename long variable --- osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs b/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs index 285ed93341..1d548e8809 100644 --- a/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs +++ b/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs @@ -50,17 +50,17 @@ namespace osu.Game.Screens.Play.HUD public User User { get; } - private readonly bool localOrReplayPlayer; + private readonly bool trackedPlayer; /// /// Creates a new . /// /// The score's player. - /// Whether the player is the local user or a replay player. - public GameplayLeaderboardScore(User user, bool localOrReplayPlayer) + /// Whether the player is the local user or a replay player. + public GameplayLeaderboardScore(User user, bool trackedPlayer) { User = user; - this.localOrReplayPlayer = localOrReplayPlayer; + this.trackedPlayer = trackedPlayer; AutoSizeAxes = Axes.Both; @@ -77,7 +77,7 @@ namespace osu.Game.Screens.Play.HUD Color4 panelColour, textColour; float panelWidth; - if (localOrReplayPlayer) + if (trackedPlayer) { panelWidth = extended_width; panelColour = Color4Extensions.FromHex("7fcc33"); From ceb2e4762d7c63efc3f9e044ae326447543c8528 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 18 Dec 2020 16:20:42 +0900 Subject: [PATCH 5/6] Add test covering a more consistent spread of player scores --- .../Visual/Gameplay/TestSceneGameplayLeaderboard.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs index 12bc918d45..d596def98a 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs @@ -6,6 +6,7 @@ using NUnit.Framework; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Testing; +using osu.Framework.Utils; using osu.Game.Screens.Play.HUD; using osu.Game.Users; using osuTK; @@ -66,6 +67,13 @@ namespace osu.Game.Tests.Visual.Gameplay AddAssert("is player 2 position #3", () => leaderboard.CheckPositionByUsername("Player 2", 3)); } + [Test] + public void TestRandomScores() + { + int playerNumber = 1; + AddRepeatStep("add player with random score", () => leaderboard.Add(createLeaderboardScore(new BindableDouble(RNG.Next(0, 5_000_000)), $"Player {playerNumber++}")), 10); + } + private static GameplayLeaderboardScore createLeaderboardScore(BindableDouble score, string username, bool localOrReplayPlayer = false) { return new GameplayLeaderboardScore(new User { Username = username }, localOrReplayPlayer) From c84807ed5c0f09e47993666920d5374d561c5f9b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 18 Dec 2020 16:20:54 +0900 Subject: [PATCH 6/6] Refactor implementation --- .../Play/HUD/GameplayLeaderboardScore.cs | 123 +++++++++++------- 1 file changed, 73 insertions(+), 50 deletions(-) diff --git a/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs b/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs index 1d548e8809..439210c944 100644 --- a/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs +++ b/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Linq; using Humanizer; using osu.Framework.Allocation; using osu.Framework.Bindables; @@ -11,7 +10,6 @@ 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; @@ -26,7 +24,7 @@ namespace osu.Game.Screens.Play.HUD private const float panel_height = 35f; - private OsuSpriteText positionText, scoreText, accuracyText, comboText; + private OsuSpriteText positionText, scoreText, accuracyText, comboText, usernameText; public readonly BindableDouble TotalScore = new BindableDouble(1000000); public readonly BindableDouble Accuracy = new BindableDouble(1); @@ -45,6 +43,7 @@ namespace osu.Game.Screens.Play.HUD positionText.Text = $"#{scorePosition.Value.ToMetric(decimals: scorePosition < 100000 ? 1 : 0)}"; positionText.FadeTo(scorePosition.HasValue ? 1 : 0); + updateColour(); } } @@ -52,6 +51,9 @@ namespace osu.Game.Screens.Play.HUD private readonly bool trackedPlayer; + private Container mainFillContainer; + private Box centralFill; + /// /// Creates a new . /// @@ -62,62 +64,93 @@ namespace osu.Game.Screens.Play.HUD User = user; this.trackedPlayer = trackedPlayer; - AutoSizeAxes = Axes.Both; + AutoSizeAxes = Axes.X; + Height = panel_height; Anchor = Anchor.TopRight; Origin = Anchor.TopRight; } - [BackgroundDependencyLoader] - private void load(IAPIProvider api) + protected override void LoadComplete() { - const float panel_shear = 0.15f; - const float shear_width = panel_height * panel_shear; + base.LoadComplete(); - Color4 panelColour, textColour; - float panelWidth; + updateColour(); + FinishTransforms(true); + } - if (trackedPlayer) + private void updateColour() + { + if (scorePosition == 1) { - panelWidth = extended_width; + mainFillContainer.ResizeWidthTo(extended_width, 200, Easing.OutQuint); panelColour = Color4Extensions.FromHex("7fcc33"); textColour = Color4.White; } - else if (api.Friends.Any(f => User.Equals(f))) + else if (trackedPlayer) { - panelWidth = extended_width; + mainFillContainer.ResizeWidthTo(extended_width, 200, Easing.OutQuint); panelColour = Color4Extensions.FromHex("ffd966"); textColour = Color4Extensions.FromHex("2e576b"); } else { - panelWidth = regular_width; + mainFillContainer.ResizeWidthTo(regular_width, 200, Easing.OutQuint); panelColour = Color4Extensions.FromHex("3399cc"); textColour = Color4.White; } + } + + private Color4 panelColour + { + set + { + mainFillContainer.FadeColour(value, 200, Easing.OutQuint); + centralFill.FadeColour(value, 200, Easing.OutQuint); + } + } + + private Color4 textColour + { + set + { + scoreText.FadeColour(value, 200, Easing.OutQuint); + accuracyText.FadeColour(value, 200, Easing.OutQuint); + comboText.FadeColour(value, 200, Easing.OutQuint); + usernameText.FadeColour(value, 200, Easing.OutQuint); + positionText.FadeColour(value, 200, Easing.OutQuint); + } + } + + [BackgroundDependencyLoader] + private void load() + { + const float panel_shear = 0.15f; + const float shear_width = panel_height * panel_shear; InternalChildren = new Drawable[] { - new Container + mainFillContainer = new Container { + Width = regular_width, + RelativeSizeAxes = Axes.Y, 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 { + Width = regular_width, + RelativeSizeAxes = Axes.Y, Anchor = Anchor.TopRight, Origin = Anchor.TopRight, - Size = new Vector2(regular_width, panel_height), ColumnDimensions = new[] { new Dimension(GridSizeMode.Absolute, 35f), @@ -133,7 +166,7 @@ namespace osu.Game.Screens.Play.HUD Padding = new MarginPadding { Right = shear_width / 2 }, Anchor = Anchor.Centre, Origin = Anchor.Centre, - Colour = textColour, + Colour = Color4.White, Font = OsuFont.Torus.With(size: 14, weight: FontWeight.Bold), Shadow = false, }, @@ -151,22 +184,22 @@ namespace osu.Game.Screens.Play.HUD RelativeSizeAxes = Axes.Both, Children = new[] { - new Box + centralFill = new Box { Alpha = 0.5f, RelativeSizeAxes = Axes.Both, - Colour = panelColour, + Colour = Color4Extensions.FromHex("3399cc"), }, } }, - new OsuSpriteText + usernameText = new OsuSpriteText { Padding = new MarginPadding { Left = shear_width }, RelativeSizeAxes = Axes.X, Width = 0.8f, Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, - Colour = textColour, + Colour = Color4.White, Font = OsuFont.Torus.With(size: 14, weight: FontWeight.SemiBold), Text = User.Username, Truncate = true, @@ -180,41 +213,31 @@ namespace osu.Game.Screens.Play.HUD RelativeSizeAxes = Axes.Both, Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, - Colour = textColour, + Colour = Color4.White, 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), + Spacing = new Vector2(-1f, 0f), + Font = OsuFont.Torus.With(size: 16, weight: FontWeight.SemiBold, fixedWidth: true), Shadow = false, }, - new Container + accuracyText = new OsuSpriteText { - 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, - }, - } - } + 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, + }, }, } }