mirror of
https://github.com/ppy/osu
synced 2024-12-14 10:57:41 +00:00
Merge branch 'gameplay-leaderboard-update' into spectator-driven-leaderboard
This commit is contained in:
commit
5e83605026
@ -39,7 +39,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
playerScore.Value = 1222333;
|
||||
});
|
||||
|
||||
AddStep("add local player", () => leaderboard.Add(createLeaderboardScore(playerScore, "You", true)));
|
||||
AddStep("add local player", () => createLeaderboardScore(playerScore, "You", true));
|
||||
AddSliderStep("set player score", 50, 5000000, 1222333, v => playerScore.Value = v);
|
||||
}
|
||||
|
||||
@ -49,8 +49,8 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
var player2Score = new BindableDouble(1234567);
|
||||
var player3Score = new BindableDouble(1111111);
|
||||
|
||||
AddStep("add player 2", () => leaderboard.Add(createLeaderboardScore(player2Score, "Player 2")));
|
||||
AddStep("add player 3", () => leaderboard.Add(createLeaderboardScore(player3Score, "Player 3")));
|
||||
AddStep("add player 2", () => createLeaderboardScore(player2Score, "Player 2"));
|
||||
AddStep("add player 3", () => createLeaderboardScore(player3Score, "Player 3"));
|
||||
|
||||
AddAssert("is player 2 position #1", () => leaderboard.CheckPositionByUsername("Player 2", 1));
|
||||
AddAssert("is player position #2", () => leaderboard.CheckPositionByUsername("You", 2));
|
||||
@ -71,15 +71,13 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
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);
|
||||
AddRepeatStep("add player with random score", () => createLeaderboardScore(new BindableDouble(RNG.Next(0, 5_000_000)), $"Player {playerNumber++}"), 10);
|
||||
}
|
||||
|
||||
private static GameplayLeaderboardScore createLeaderboardScore(BindableDouble score, string username, bool localOrReplayPlayer = false)
|
||||
private void createLeaderboardScore(BindableDouble score, string username, bool isTracked = false)
|
||||
{
|
||||
return new GameplayLeaderboardScore(new User { Username = username }, localOrReplayPlayer)
|
||||
{
|
||||
TotalScore = { BindTarget = score },
|
||||
};
|
||||
var leaderboardScore = leaderboard.AddPlayer(new User { Username = username }, isTracked);
|
||||
leaderboardScore.TotalScore.BindTo(score);
|
||||
}
|
||||
|
||||
private class TestGameplayLeaderboard : GameplayLeaderboard
|
||||
|
@ -1,9 +1,11 @@
|
||||
// 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 osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Users;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.Play.HUD
|
||||
@ -22,13 +24,21 @@ namespace osu.Game.Screens.Play.HUD
|
||||
LayoutEasing = Easing.OutQuint;
|
||||
}
|
||||
|
||||
public override void Add(GameplayLeaderboardScore drawable)
|
||||
public ILeaderboardScore AddPlayer(User user, bool isTracked)
|
||||
{
|
||||
var drawable = new GameplayLeaderboardScore(user, isTracked);
|
||||
base.Add(drawable);
|
||||
drawable?.TotalScore.BindValueChanged(_ => updateScores(), true);
|
||||
drawable.TotalScore.BindValueChanged(_ => Scheduler.AddOnce(sort), true);
|
||||
|
||||
return drawable;
|
||||
}
|
||||
|
||||
private void updateScores()
|
||||
public override void Add(GameplayLeaderboardScore drawable)
|
||||
{
|
||||
throw new InvalidOperationException($"Use {nameof(AddPlayer)} instead.");
|
||||
}
|
||||
|
||||
private void sort()
|
||||
{
|
||||
var orderedByScore = this.OrderByDescending(i => i.TotalScore.Value).ToList();
|
||||
|
||||
|
@ -17,7 +17,7 @@ using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
public class GameplayLeaderboardScore : CompositeDrawable
|
||||
public class GameplayLeaderboardScore : CompositeDrawable, ILeaderboardScore
|
||||
{
|
||||
private const float regular_width = 215f;
|
||||
private const float extended_width = 235f;
|
||||
@ -26,9 +26,9 @@ namespace osu.Game.Screens.Play.HUD
|
||||
|
||||
private OsuSpriteText positionText, scoreText, accuracyText, comboText, usernameText;
|
||||
|
||||
public readonly BindableDouble TotalScore = new BindableDouble(1000000);
|
||||
public readonly BindableDouble Accuracy = new BindableDouble(1);
|
||||
public readonly BindableInt Combo = new BindableInt();
|
||||
public BindableDouble TotalScore { get; } = new BindableDouble();
|
||||
public BindableDouble Accuracy { get; } = new BindableDouble(1);
|
||||
public BindableInt Combo { get; } = new BindableInt();
|
||||
|
||||
private int? scorePosition;
|
||||
|
||||
|
14
osu.Game/Screens/Play/HUD/ILeaderboardScore.cs
Normal file
14
osu.Game/Screens/Play/HUD/ILeaderboardScore.cs
Normal file
@ -0,0 +1,14 @@
|
||||
// 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 osu.Framework.Bindables;
|
||||
|
||||
namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
public interface ILeaderboardScore
|
||||
{
|
||||
BindableDouble TotalScore { get; }
|
||||
BindableDouble Accuracy { get; }
|
||||
BindableInt Combo { get; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user