From 68752f95e516459ea1ab814812919b381d78c45d Mon Sep 17 00:00:00 2001 From: cdwcgt Date: Wed, 6 Sep 2023 22:49:13 +0900 Subject: [PATCH 1/3] color friend score to pink --- .../Gameplay/TestSceneGameplayLeaderboard.cs | 31 +++++++++++++++++++ .../Play/HUD/GameplayLeaderboardScore.cs | 15 ++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs index d4000c07e7..418e0ad981 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs @@ -6,11 +6,14 @@ using System.Linq; using NUnit.Framework; using osu.Framework.Bindables; +using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.PolygonExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; using osu.Framework.Testing; using osu.Framework.Utils; +using osu.Game.Online.API; using osu.Game.Online.API.Requests.Responses; using osu.Game.Screens.Play.HUD; using osuTK; @@ -139,6 +142,29 @@ namespace osu.Game.Tests.Visual.Gameplay => AddAssert($"leaderboard height is {panelCount} panels high", () => leaderboard.DrawHeight == (GameplayLeaderboardScore.PANEL_HEIGHT + leaderboard.Spacing) * panelCount); } + [Test] + public void TestFriendScore() + { + APIUser friend = new APIUser { Username = "my friend", Id = 10000 }; + + createLeaderboard(); + addLocalPlayer(); + + AddStep("initialize api", () => + { + var api = (DummyAPIAccess)API; + + api.Friends.Add(friend); + }); + + int playerNumber = 1; + AddRepeatStep("add 3 other players", () => createRandomScore(new APIUser { Username = $"Player {playerNumber++}" }), 3); + AddUntilStep("there are no pink color score", () => leaderboard.ChildrenOfType().All(b => b.Colour != Color4Extensions.FromHex("ff549a"))); + + AddRepeatStep("add 3 friend score", () => createRandomScore(friend), 3); + AddUntilStep("there are pink color for friend score", () => leaderboard.GetScoreByUsername("my friend").ChildrenOfType().Any(b => b.Colour == Color4Extensions.FromHex("ff549a"))); + } + private void addLocalPlayer() { AddStep("add local player", () => @@ -179,6 +205,11 @@ namespace osu.Game.Tests.Visual.Gameplay return scoreItem != null && scoreItem.ScorePosition == expectedPosition; } + + public GameplayLeaderboardScore GetScoreByUsername(string username) + { + return Flow.FirstOrDefault(i => i.User?.Username == username); + } } } } diff --git a/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs b/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs index dcb2c1071e..502303e80c 100644 --- a/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs +++ b/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Extensions.Color4Extensions; @@ -11,6 +12,8 @@ using osu.Framework.Graphics.Shapes; using osu.Game.Configuration; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; +using osu.Game.Online.API; +using osu.Game.Online.API.Requests.Responses; using osu.Game.Rulesets.Scoring; using osu.Game.Users; using osu.Game.Users.Drawables; @@ -107,6 +110,8 @@ namespace osu.Game.Screens.Play.HUD private IBindable scoreDisplayMode = null!; + private readonly IBindableList apiFriends = new BindableList(); + /// /// Creates a new . /// @@ -124,7 +129,7 @@ namespace osu.Game.Screens.Play.HUD } [BackgroundDependencyLoader] - private void load(OsuColour colours, OsuConfigManager osuConfigManager) + private void load(OsuColour colours, OsuConfigManager osuConfigManager, IAPIProvider api) { Container avatarContainer; @@ -311,6 +316,9 @@ namespace osu.Game.Screens.Play.HUD }, true); HasQuit.BindValueChanged(_ => updateState()); + + apiFriends.BindTo(api.Friends); + apiFriends.BindCollectionChanged((_, _) => updateState()); } protected override void LoadComplete() @@ -389,6 +397,11 @@ namespace osu.Game.Screens.Play.HUD panelColour = BackgroundColour ?? Color4Extensions.FromHex("ffd966"); textColour = TextColour ?? Color4Extensions.FromHex("2e576b"); } + else if (apiFriends.Any(f => User?.Equals(f) == true)) + { + panelColour = BackgroundColour ?? Color4Extensions.FromHex("ff549a"); + textColour = TextColour ?? Color4.White; + } else { panelColour = BackgroundColour ?? Color4Extensions.FromHex("3399cc"); From 87ec33bb66bd35e15b67ce86ddced6d62adfe80b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 7 Sep 2023 14:50:22 +0900 Subject: [PATCH 2/3] Tidy up test --- .../Visual/Gameplay/TestSceneGameplayLeaderboard.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs index 418e0ad981..65f943d36b 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs @@ -150,14 +150,16 @@ namespace osu.Game.Tests.Visual.Gameplay createLeaderboard(); addLocalPlayer(); - AddStep("initialize api", () => + AddStep("Add friend to API", () => { var api = (DummyAPIAccess)API; + api.Friends.Clear(); api.Friends.Add(friend); }); int playerNumber = 1; + AddRepeatStep("add 3 other players", () => createRandomScore(new APIUser { Username = $"Player {playerNumber++}" }), 3); AddUntilStep("there are no pink color score", () => leaderboard.ChildrenOfType().All(b => b.Colour != Color4Extensions.FromHex("ff549a"))); From 71ac5cfc792a2aec35720e08f6d02d87e69995be Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 20 Sep 2023 14:14:37 +0900 Subject: [PATCH 3/3] Don't bother binding to friends changes for score display purposes --- osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs b/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs index 502303e80c..7471955493 100644 --- a/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs +++ b/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs @@ -13,7 +13,6 @@ using osu.Game.Configuration; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Online.API; -using osu.Game.Online.API.Requests.Responses; using osu.Game.Rulesets.Scoring; using osu.Game.Users; using osu.Game.Users.Drawables; @@ -110,7 +109,7 @@ namespace osu.Game.Screens.Play.HUD private IBindable scoreDisplayMode = null!; - private readonly IBindableList apiFriends = new BindableList(); + private bool isFriend; /// /// Creates a new . @@ -317,8 +316,7 @@ namespace osu.Game.Screens.Play.HUD HasQuit.BindValueChanged(_ => updateState()); - apiFriends.BindTo(api.Friends); - apiFriends.BindCollectionChanged((_, _) => updateState()); + isFriend = User != null && api.Friends.Any(u => User.OnlineID == u.Id); } protected override void LoadComplete() @@ -397,7 +395,7 @@ namespace osu.Game.Screens.Play.HUD panelColour = BackgroundColour ?? Color4Extensions.FromHex("ffd966"); textColour = TextColour ?? Color4Extensions.FromHex("2e576b"); } - else if (apiFriends.Any(f => User?.Equals(f) == true)) + else if (isFriend) { panelColour = BackgroundColour ?? Color4Extensions.FromHex("ff549a"); textColour = TextColour ?? Color4.White;