mirror of
https://github.com/ppy/osu
synced 2024-12-29 02:12:43 +00:00
Re-sort the leaderboard order a maximum of once a second
This commit is contained in:
parent
21a4e6a3f9
commit
f991448a3e
@ -3,6 +3,7 @@
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using osu.Framework.Caching;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Users;
|
||||
@ -12,6 +13,8 @@ namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
public class GameplayLeaderboard : FillFlowContainer<GameplayLeaderboardScore>
|
||||
{
|
||||
private readonly Cached sorting = new Cached();
|
||||
|
||||
public GameplayLeaderboard()
|
||||
{
|
||||
Width = GameplayLeaderboardScore.EXTENDED_WIDTH + GameplayLeaderboardScore.SHEAR_WIDTH;
|
||||
@ -24,6 +27,13 @@ namespace osu.Game.Screens.Play.HUD
|
||||
LayoutEasing = Easing.OutQuint;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
Scheduler.AddDelayed(sort, 1000, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a player to the leaderboard.
|
||||
/// </summary>
|
||||
@ -41,7 +51,7 @@ namespace osu.Game.Screens.Play.HUD
|
||||
};
|
||||
|
||||
base.Add(drawable);
|
||||
drawable.TotalScore.BindValueChanged(_ => Scheduler.AddOnce(sort), true);
|
||||
drawable.TotalScore.BindValueChanged(_ => sorting.Invalidate(), true);
|
||||
|
||||
Height = Count * (GameplayLeaderboardScore.PANEL_HEIGHT + Spacing.Y);
|
||||
|
||||
@ -55,6 +65,9 @@ namespace osu.Game.Screens.Play.HUD
|
||||
|
||||
private void sort()
|
||||
{
|
||||
if (sorting.IsValid)
|
||||
return;
|
||||
|
||||
var orderedByScore = this.OrderByDescending(i => i.TotalScore.Value).ToList();
|
||||
|
||||
for (int i = 0; i < Count; i++)
|
||||
@ -62,6 +75,8 @@ namespace osu.Game.Screens.Play.HUD
|
||||
SetLayoutPosition(orderedByScore[i], i);
|
||||
orderedByScore[i].ScorePosition = i + 1;
|
||||
}
|
||||
|
||||
sorting.Validate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user