mirror of
https://github.com/ppy/osu.git
synced 2025-01-07 20:42:54 +08:00
Revert previous player add flow via interface
This commit is contained in:
parent
99f2032fdf
commit
bca4d83af7
@ -39,7 +39,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
playerScore.Value = 1222333;
|
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);
|
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 player2Score = new BindableDouble(1234567);
|
||||||
var player3Score = new BindableDouble(1111111);
|
var player3Score = new BindableDouble(1111111);
|
||||||
|
|
||||||
AddStep("add player 2", () => leaderboard.Add(createLeaderboardScore(player2Score, "Player 2")));
|
AddStep("add player 2", () => createLeaderboardScore(player2Score, "Player 2"));
|
||||||
AddStep("add player 3", () => leaderboard.Add(createLeaderboardScore(player3Score, "Player 3")));
|
AddStep("add player 3", () => createLeaderboardScore(player3Score, "Player 3"));
|
||||||
|
|
||||||
AddAssert("is player 2 position #1", () => leaderboard.CheckPositionByUsername("Player 2", 1));
|
AddAssert("is player 2 position #1", () => leaderboard.CheckPositionByUsername("Player 2", 1));
|
||||||
AddAssert("is player position #2", () => leaderboard.CheckPositionByUsername("You", 2));
|
AddAssert("is player position #2", () => leaderboard.CheckPositionByUsername("You", 2));
|
||||||
@ -71,15 +71,13 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
public void TestRandomScores()
|
public void TestRandomScores()
|
||||||
{
|
{
|
||||||
int playerNumber = 1;
|
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)
|
var leaderboardScore = leaderboard.AddPlayer(new User { Username = username }, isTracked);
|
||||||
{
|
leaderboardScore.TotalScore.BindTo(score);
|
||||||
TotalScore = { BindTarget = score },
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestGameplayLeaderboard : GameplayLeaderboard
|
private class TestGameplayLeaderboard : GameplayLeaderboard
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Game.Users;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Play.HUD
|
namespace osu.Game.Screens.Play.HUD
|
||||||
@ -22,13 +24,21 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
LayoutEasing = Easing.OutQuint;
|
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);
|
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();
|
var orderedByScore = this.OrderByDescending(i => i.TotalScore.Value).ToList();
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ using osuTK.Graphics;
|
|||||||
|
|
||||||
namespace osu.Game.Screens.Play.HUD
|
namespace osu.Game.Screens.Play.HUD
|
||||||
{
|
{
|
||||||
public class GameplayLeaderboardScore : CompositeDrawable
|
public class GameplayLeaderboardScore : CompositeDrawable, ILeaderboardScore
|
||||||
{
|
{
|
||||||
private const float regular_width = 215f;
|
private const float regular_width = 215f;
|
||||||
private const float extended_width = 235f;
|
private const float extended_width = 235f;
|
||||||
@ -26,9 +26,9 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
|
|
||||||
private OsuSpriteText positionText, scoreText, accuracyText, comboText, usernameText;
|
private OsuSpriteText positionText, scoreText, accuracyText, comboText, usernameText;
|
||||||
|
|
||||||
public readonly BindableDouble TotalScore = new BindableDouble(1000000);
|
public BindableDouble TotalScore { get; } = new BindableDouble();
|
||||||
public readonly BindableDouble Accuracy = new BindableDouble(1);
|
public BindableDouble Accuracy { get; } = new BindableDouble(1);
|
||||||
public readonly BindableInt Combo = new BindableInt();
|
public BindableInt Combo { get; } = new BindableInt();
|
||||||
|
|
||||||
private int? scorePosition;
|
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