mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 10:02:59 +08:00
Merge pull request #11285 from peppy/resort-leaderboard-less
Re-sort the leaderboard order a maximum of once a second
This commit is contained in:
commit
fa14438671
@ -52,19 +52,19 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
AddStep("add player 2", () => createLeaderboardScore(player2Score, new User { Username = "Player 2" }));
|
AddStep("add player 2", () => createLeaderboardScore(player2Score, new User { Username = "Player 2" }));
|
||||||
AddStep("add player 3", () => createLeaderboardScore(player3Score, new User { Username = "Player 3" }));
|
AddStep("add player 3", () => createLeaderboardScore(player3Score, new User { Username = "Player 3" }));
|
||||||
|
|
||||||
AddAssert("is player 2 position #1", () => leaderboard.CheckPositionByUsername("Player 2", 1));
|
AddUntilStep("is player 2 position #1", () => leaderboard.CheckPositionByUsername("Player 2", 1));
|
||||||
AddAssert("is player position #2", () => leaderboard.CheckPositionByUsername("You", 2));
|
AddUntilStep("is player position #2", () => leaderboard.CheckPositionByUsername("You", 2));
|
||||||
AddAssert("is player 3 position #3", () => leaderboard.CheckPositionByUsername("Player 3", 3));
|
AddUntilStep("is player 3 position #3", () => leaderboard.CheckPositionByUsername("Player 3", 3));
|
||||||
|
|
||||||
AddStep("set score above player 3", () => player2Score.Value = playerScore.Value - 500);
|
AddStep("set score above player 3", () => player2Score.Value = playerScore.Value - 500);
|
||||||
AddAssert("is player position #1", () => leaderboard.CheckPositionByUsername("You", 1));
|
AddUntilStep("is player position #1", () => leaderboard.CheckPositionByUsername("You", 1));
|
||||||
AddAssert("is player 2 position #2", () => leaderboard.CheckPositionByUsername("Player 2", 2));
|
AddUntilStep("is player 2 position #2", () => leaderboard.CheckPositionByUsername("Player 2", 2));
|
||||||
AddAssert("is player 3 position #3", () => leaderboard.CheckPositionByUsername("Player 3", 3));
|
AddUntilStep("is player 3 position #3", () => leaderboard.CheckPositionByUsername("Player 3", 3));
|
||||||
|
|
||||||
AddStep("set score below players", () => player2Score.Value = playerScore.Value - 123456);
|
AddStep("set score below players", () => player2Score.Value = playerScore.Value - 123456);
|
||||||
AddAssert("is player position #1", () => leaderboard.CheckPositionByUsername("You", 1));
|
AddUntilStep("is player position #1", () => leaderboard.CheckPositionByUsername("You", 1));
|
||||||
AddAssert("is player 3 position #2", () => leaderboard.CheckPositionByUsername("Player 3", 2));
|
AddUntilStep("is player 3 position #2", () => leaderboard.CheckPositionByUsername("Player 3", 2));
|
||||||
AddAssert("is player 2 position #3", () => leaderboard.CheckPositionByUsername("Player 2", 3));
|
AddUntilStep("is player 2 position #3", () => leaderboard.CheckPositionByUsername("Player 2", 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using osu.Framework.Caching;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
@ -12,6 +13,8 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
{
|
{
|
||||||
public class GameplayLeaderboard : FillFlowContainer<GameplayLeaderboardScore>
|
public class GameplayLeaderboard : FillFlowContainer<GameplayLeaderboardScore>
|
||||||
{
|
{
|
||||||
|
private readonly Cached sorting = new Cached();
|
||||||
|
|
||||||
public GameplayLeaderboard()
|
public GameplayLeaderboard()
|
||||||
{
|
{
|
||||||
Width = GameplayLeaderboardScore.EXTENDED_WIDTH + GameplayLeaderboardScore.SHEAR_WIDTH;
|
Width = GameplayLeaderboardScore.EXTENDED_WIDTH + GameplayLeaderboardScore.SHEAR_WIDTH;
|
||||||
@ -24,6 +27,13 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
LayoutEasing = Easing.OutQuint;
|
LayoutEasing = Easing.OutQuint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
Scheduler.AddDelayed(sort, 1000, true);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a player to the leaderboard.
|
/// Adds a player to the leaderboard.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -41,7 +51,7 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
};
|
};
|
||||||
|
|
||||||
base.Add(drawable);
|
base.Add(drawable);
|
||||||
drawable.TotalScore.BindValueChanged(_ => Scheduler.AddOnce(sort), true);
|
drawable.TotalScore.BindValueChanged(_ => sorting.Invalidate(), true);
|
||||||
|
|
||||||
Height = Count * (GameplayLeaderboardScore.PANEL_HEIGHT + Spacing.Y);
|
Height = Count * (GameplayLeaderboardScore.PANEL_HEIGHT + Spacing.Y);
|
||||||
|
|
||||||
@ -55,6 +65,9 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
|
|
||||||
private void sort()
|
private void sort()
|
||||||
{
|
{
|
||||||
|
if (sorting.IsValid)
|
||||||
|
return;
|
||||||
|
|
||||||
var orderedByScore = this.OrderByDescending(i => i.TotalScore.Value).ToList();
|
var orderedByScore = this.OrderByDescending(i => i.TotalScore.Value).ToList();
|
||||||
|
|
||||||
for (int i = 0; i < Count; i++)
|
for (int i = 0; i < Count; i++)
|
||||||
@ -62,6 +75,8 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
SetLayoutPosition(orderedByScore[i], i);
|
SetLayoutPosition(orderedByScore[i], i);
|
||||||
orderedByScore[i].ScorePosition = i + 1;
|
orderedByScore[i].ScorePosition = i + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sorting.Validate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user