Add leaderboard display to realtime player

This commit is contained in:
Dean Herbert 2020-12-22 19:09:59 +09:00
parent 3c33ea7f1c
commit 6517acc510
2 changed files with 29 additions and 1 deletions

View File

@ -3,6 +3,7 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using osu.Framework.Allocation;
@ -12,7 +13,9 @@
using osu.Game.Online.RealtimeMultiplayer;
using osu.Game.Scoring;
using osu.Game.Screens.Multi.Play;
using osu.Game.Screens.Play.HUD;
using osu.Game.Screens.Ranking;
using osuTK;
namespace osu.Game.Screens.Multi.RealtimeMultiplayer
{
@ -30,6 +33,8 @@ public class RealtimePlayer : TimeshiftPlayer
private readonly TaskCompletionSource<bool> resultsReady = new TaskCompletionSource<bool>();
private readonly ManualResetEventSlim startedEvent = new ManualResetEventSlim();
private MultiplayerGameplayLeaderboard leaderboard;
public RealtimePlayer(PlaylistItem playlistItem)
: base(playlistItem, false)
{
@ -55,6 +60,24 @@ private void load()
this.Exit();
});
}
Debug.Assert(client.Room != null);
int[] userIds = client.Room.Users.Where(u => u.State >= MultiplayerUserState.WaitingForLoad).Select(u => u.UserID).ToArray();
// todo: this should be implemented via a custom HUD implementation, and correctly masked to the main content area.
LoadComponentAsync(leaderboard = new MultiplayerGameplayLeaderboard(ScoreProcessor, userIds), HUDOverlay.Add);
}
protected override void Update()
{
base.Update();
const float padding = 44; // enough margin to avoid the hit error display.
leaderboard.Position = new Vector2(
padding,
padding + HUDOverlay.TopScoringElementsHeight);
}
private void onMatchStarted() => startedEvent.Set();

View File

@ -28,6 +28,11 @@ public class HUDOverlay : Container, IKeyBindingHandler<GlobalAction>
public const Easing FADE_EASING = Easing.Out;
/// <summary>
/// The total height of all the top of screen scoring elements.
/// </summary>
public float TopScoringElementsHeight { get; private set; }
public readonly KeyCounterDisplay KeyCounter;
public readonly SkinnableComboCounter ComboCounter;
public readonly SkinnableScoreCounter ScoreCounter;
@ -209,7 +214,7 @@ protected override void Update()
// HACK: for now align with the accuracy counter.
// this is done for the sake of hacky legacy skins which extend the health bar to take up the full screen area.
// it only works with the default skin due to padding offsetting it *just enough* to coexist.
topRightElements.Y = ToLocalSpace(AccuracyCounter.Drawable.ScreenSpaceDrawQuad.BottomRight).Y;
topRightElements.Y = TopScoringElementsHeight = ToLocalSpace(AccuracyCounter.Drawable.ScreenSpaceDrawQuad.BottomRight).Y;
bottomRightElements.Y = -Progress.Height;
}