1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 23:07:26 +08:00
osu-lazer/osu.Game/Screens/Play/HUD/GameplayLeaderboard.cs

53 lines
1.5 KiB
C#
Raw Normal View History

// 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
{
public class GameplayLeaderboard : FillFlowContainer<GameplayLeaderboardScore>
{
public GameplayLeaderboard()
{
AutoSizeAxes = Axes.Both;
2020-12-15 14:44:56 +08:00
Direction = FillDirection.Vertical;
2020-12-15 14:44:56 +08:00
Spacing = new Vector2(2.5f);
2020-12-15 14:44:56 +08:00
LayoutDuration = 250;
LayoutEasing = Easing.OutQuint;
}
public ILeaderboardScore AddPlayer(User user, bool isTracked)
{
var drawable = new GameplayLeaderboardScore(user, isTracked);
base.Add(drawable);
drawable.TotalScore.BindValueChanged(_ => Scheduler.AddOnce(sort), true);
return drawable;
}
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();
for (int i = 0; i < Count; i++)
{
2020-12-15 14:44:56 +08:00
SetLayoutPosition(orderedByScore[i], i);
orderedByScore[i].ScorePosition = i + 1;
}
}
}
}