mirror of
https://github.com/ppy/osu
synced 2025-01-18 20:10:49 +00:00
Make GameplayLeaderboardScore a model class
This commit is contained in:
parent
0faf3fdfd3
commit
a8abefcd66
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a player to the leaderboard.
|
||||
/// </summary>
|
||||
/// <param name="totalScore">A bindable of the player's total score.</param>
|
||||
/// <param name="accuracy">A bindable of the player's accuracy.</param>
|
||||
/// <param name="combo">A bindable of the player's current combo.</param>
|
||||
/// <param name="user">The player.</param>
|
||||
public void AddPlayer([NotNull] IBindableNumber<double> totalScore,
|
||||
[NotNull] IBindableNumber<double> accuracy,
|
||||
[NotNull] IBindableNumber<int> combo,
|
||||
[NotNull] User user)
|
||||
public override void Add(GameplayLeaderboardScore drawable)
|
||||
{
|
||||
AddPlayer(totalScore, accuracy, combo, user, false);
|
||||
base.Add(drawable);
|
||||
drawable?.TotalScore.BindValueChanged(_ => updateScores(), true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a player to the leaderboard.
|
||||
/// </summary>
|
||||
/// <param name="totalScore">A bindable of the player's total score.</param>
|
||||
/// <param name="accuracy">A bindable of the player's accuracy.</param>
|
||||
/// <param name="combo">A bindable of the player's current combo.</param>
|
||||
/// <param name="user">The player.</param>
|
||||
/// <param name="localUser">Whether the provided <paramref name="user"/> is the local user.</param>
|
||||
protected void AddPlayer([NotNull] IBindableNumber<double> totalScore,
|
||||
[NotNull] IBindableNumber<double> accuracy,
|
||||
[NotNull] IBindableNumber<int> 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();
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user