diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs index d4000c07e7..65f943d36b 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,31 @@ void checkHeight(int panelCount) => 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("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"))); + + 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 +207,11 @@ public bool CheckPositionByUsername(string username, int? expectedPosition) 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..7471955493 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,7 @@ using osu.Game.Configuration; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; +using osu.Game.Online.API; using osu.Game.Rulesets.Scoring; using osu.Game.Users; using osu.Game.Users.Drawables; @@ -107,6 +109,8 @@ public int? ScorePosition private IBindable scoreDisplayMode = null!; + private bool isFriend; + /// /// Creates a new . /// @@ -124,7 +128,7 @@ public GameplayLeaderboardScore(IUser? user, bool tracked) } [BackgroundDependencyLoader] - private void load(OsuColour colours, OsuConfigManager osuConfigManager) + private void load(OsuColour colours, OsuConfigManager osuConfigManager, IAPIProvider api) { Container avatarContainer; @@ -311,6 +315,8 @@ private void load(OsuColour colours, OsuConfigManager osuConfigManager) }, true); HasQuit.BindValueChanged(_ => updateState()); + + isFriend = User != null && api.Friends.Any(u => User.OnlineID == u.Id); } protected override void LoadComplete() @@ -389,6 +395,11 @@ private void updateState() panelColour = BackgroundColour ?? Color4Extensions.FromHex("ffd966"); textColour = TextColour ?? Color4Extensions.FromHex("2e576b"); } + else if (isFriend) + { + panelColour = BackgroundColour ?? Color4Extensions.FromHex("ff549a"); + textColour = TextColour ?? Color4.White; + } else { panelColour = BackgroundColour ?? Color4Extensions.FromHex("3399cc");