2020-12-15 14:27:26 +08:00
|
|
|
// 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.
|
|
|
|
|
2020-12-18 16:07:38 +08:00
|
|
|
using System;
|
2020-12-15 14:27:26 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-12-18 16:07:38 +08:00
|
|
|
using osu.Game.Users;
|
2020-12-15 14:27:26 +08:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play.HUD
|
|
|
|
{
|
|
|
|
public class GameplayLeaderboard : FillFlowContainer<GameplayLeaderboardScore>
|
|
|
|
{
|
|
|
|
public GameplayLeaderboard()
|
|
|
|
{
|
2020-12-17 20:12:32 +08:00
|
|
|
AutoSizeAxes = Axes.Both;
|
2020-12-15 14:44:56 +08:00
|
|
|
|
2020-12-15 14:27:26 +08:00
|
|
|
Direction = FillDirection.Vertical;
|
2020-12-15 14:44:56 +08:00
|
|
|
|
2020-12-15 14:27:26 +08:00
|
|
|
Spacing = new Vector2(2.5f);
|
2020-12-15 14:44:56 +08:00
|
|
|
|
|
|
|
LayoutDuration = 250;
|
2020-12-15 14:27:26 +08:00
|
|
|
LayoutEasing = Easing.OutQuint;
|
|
|
|
}
|
|
|
|
|
2020-12-18 16:07:38 +08:00
|
|
|
public ILeaderboardScore AddPlayer(User user, bool isTracked)
|
2020-12-15 14:27:26 +08:00
|
|
|
{
|
2020-12-18 16:07:38 +08:00
|
|
|
var drawable = new GameplayLeaderboardScore(user, isTracked);
|
2020-12-18 08:34:33 +08:00
|
|
|
base.Add(drawable);
|
2020-12-18 16:07:38 +08:00
|
|
|
drawable.TotalScore.BindValueChanged(_ => Scheduler.AddOnce(sort), true);
|
|
|
|
|
|
|
|
return drawable;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Add(GameplayLeaderboardScore drawable)
|
|
|
|
{
|
|
|
|
throw new InvalidOperationException($"Use {nameof(AddPlayer)} instead.");
|
2020-12-15 14:27:26 +08:00
|
|
|
}
|
|
|
|
|
2020-12-18 16:07:38 +08:00
|
|
|
private void sort()
|
2020-12-15 14:27:26 +08:00
|
|
|
{
|
2020-12-17 20:12:32 +08:00
|
|
|
var orderedByScore = this.OrderByDescending(i => i.TotalScore.Value).ToList();
|
2020-12-15 14:27:26 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < Count; i++)
|
|
|
|
{
|
2020-12-15 14:44:56 +08:00
|
|
|
SetLayoutPosition(orderedByScore[i], i);
|
|
|
|
orderedByScore[i].ScorePosition = i + 1;
|
2020-12-15 14:27:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|