From e37089af5e188e7dbb769ba4d891a25b48420412 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 15 Dec 2020 15:44:56 +0900 Subject: [PATCH] Further code cleanup --- .../Screens/Play/HUD/GameplayLeaderboard.cs | 65 ++++--------------- .../Play/HUD/GameplayLeaderboardScore.cs | 5 +- 2 files changed, 15 insertions(+), 55 deletions(-) diff --git a/osu.Game/Screens/Play/HUD/GameplayLeaderboard.cs b/osu.Game/Screens/Play/HUD/GameplayLeaderboard.cs index 9e1b9a3958..6ee654fb9e 100644 --- a/osu.Game/Screens/Play/HUD/GameplayLeaderboard.cs +++ b/osu.Game/Screens/Play/HUD/GameplayLeaderboard.cs @@ -1,11 +1,12 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Linq; +using JetBrains.Annotations; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Game.Scoring; using osu.Game.Users; using osuTK; @@ -13,52 +14,33 @@ namespace osu.Game.Screens.Play.HUD { public class GameplayLeaderboard : FillFlowContainer { - /// - /// Whether to declare a new position for un-positioned players. - /// Must be disabled for online leaderboards with top 50 scores only. - /// - public bool DeclareNewPosition = true; - public GameplayLeaderboard() { RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; + Direction = FillDirection.Vertical; + Spacing = new Vector2(2.5f); - LayoutDuration = 500; + + LayoutDuration = 250; LayoutEasing = Easing.OutQuint; } /// - /// Adds a real-time player score item whose score is updated via a . + /// Adds a player to the leaderboard. /// /// The bindable current score of the player. - /// The player user. - /// Returns the drawable score item of that player. - public GameplayLeaderboardScore AddRealTimePlayer(BindableDouble currentScore, User user = null) + /// The player. + public void AddPlayer([NotNull] BindableDouble currentScore, [NotNull] User user) { - if (currentScore == null) - return null; - var scoreItem = addScore(currentScore.Value, user); currentScore.ValueChanged += s => scoreItem.TotalScore = s.NewValue; - - return scoreItem; } - /// - /// Adds a score item based off a with an initial position. - /// - /// The score info to use for this item. - /// The initial position of this item. - /// Returns the drawable score item of that player. - public GameplayLeaderboardScore AddScore(ScoreInfo score, int? initialPosition = null) => score != null ? addScore(score.TotalScore, score.User, initialPosition) : null; - - private int maxPosition => this.Max(i => this.Any(item => item.InitialPosition.HasValue) ? i.InitialPosition : i.ScorePosition) ?? 0; - - private GameplayLeaderboardScore addScore(double totalScore, User user = null, int? position = null) + private GameplayLeaderboardScore addScore(double totalScore, User user) { - var scoreItem = new GameplayLeaderboardScore(position) + var scoreItem = new GameplayLeaderboardScore { User = user, TotalScore = totalScore, @@ -66,38 +48,19 @@ namespace osu.Game.Screens.Play.HUD }; Add(scoreItem); - SetLayoutPosition(scoreItem, position ?? maxPosition + 1); - - reorderPositions(); + updateScores(); return scoreItem; } - private void reorderPositions() - { - var orderedByScore = this.OrderByDescending(i => i.TotalScore).ToList(); - var orderedPositions = this.Select(i => this.Any(item => item.InitialPosition.HasValue) ? i.InitialPosition : i.ScorePosition).OrderByDescending(p => p.HasValue).ThenBy(p => p).ToList(); - - for (int i = 0; i < Count; i++) - { - int newPosition = orderedPositions[i] ?? maxPosition + 1; - - SetLayoutPosition(orderedByScore[i], newPosition); - orderedByScore[i].ScorePosition = DeclareNewPosition ? newPosition : orderedPositions[i]; - } - } - private void updateScores() { var orderedByScore = this.OrderByDescending(i => i.TotalScore).ToList(); - var orderedPositions = this.Select(i => this.Any(item => item.InitialPosition.HasValue) ? i.InitialPosition : i.ScorePosition).OrderByDescending(p => p.HasValue).ThenBy(p => p).ToList(); for (int i = 0; i < Count; i++) { - int newPosition = orderedPositions[i] ?? maxPosition + 1; - - SetLayoutPosition(orderedByScore[i], newPosition); - orderedByScore[i].ScorePosition = DeclareNewPosition ? newPosition : orderedPositions[i]; + SetLayoutPosition(orderedByScore[i], i); + orderedByScore[i].ScorePosition = i + 1; } } } diff --git a/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs b/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs index 3af7345ae1..4c75f422c9 100644 --- a/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs +++ b/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs @@ -22,7 +22,6 @@ namespace osu.Game.Screens.Play.HUD public Action OnScoreChange; private int? scorePosition; - public int? InitialPosition; public int? ScorePosition { @@ -65,7 +64,7 @@ namespace osu.Game.Screens.Play.HUD } } - public GameplayLeaderboardScore(int? initialPosition) + public GameplayLeaderboardScore() { RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; @@ -125,8 +124,6 @@ namespace osu.Game.Screens.Play.HUD }, }, }; - - InitialPosition = ScorePosition = initialPosition; } [BackgroundDependencyLoader]