1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:28:00 +08:00

Merge pull request #24730 from cdwcgt/leaderboard-friend-highlight

Highlight friend score in gameplay leaderboards
This commit is contained in:
Dean Herbert 2023-09-20 14:54:12 +09:00 committed by GitHub
commit 2c38bed944
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 1 deletions

View File

@ -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 @@ 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("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<Box>().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<Box>().Any(b => b.Colour == Color4Extensions.FromHex("ff549a")));
}
private void addLocalPlayer()
{
AddStep("add local player", () =>
@ -179,6 +207,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);
}
}
}
}

View File

@ -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.Framework.Graphics.Shapes;
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 @@ namespace osu.Game.Screens.Play.HUD
private IBindable<ScoringMode> scoreDisplayMode = null!;
private bool isFriend;
/// <summary>
/// Creates a new <see cref="GameplayLeaderboardScore"/>.
/// </summary>
@ -124,7 +128,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 +315,8 @@ namespace osu.Game.Screens.Play.HUD
}, true);
HasQuit.BindValueChanged(_ => updateState());
isFriend = User != null && api.Friends.Any(u => User.OnlineID == u.Id);
}
protected override void LoadComplete()
@ -389,6 +395,11 @@ namespace osu.Game.Screens.Play.HUD
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");