2021-04-09 16:31:14 +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.
|
|
|
|
|
|
|
|
using System;
|
2021-04-12 21:00:27 +08:00
|
|
|
using JetBrains.Annotations;
|
2021-04-09 16:31:14 +08:00
|
|
|
using osu.Framework.Timing;
|
2021-08-06 19:06:57 +08:00
|
|
|
using osu.Game.Online.Multiplayer;
|
2021-04-09 16:31:14 +08:00
|
|
|
using osu.Game.Rulesets.Scoring;
|
|
|
|
using osu.Game.Screens.Play.HUD;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
|
|
|
{
|
2021-04-22 22:39:02 +08:00
|
|
|
public class MultiSpectatorLeaderboard : MultiplayerGameplayLeaderboard
|
2021-04-09 16:31:14 +08:00
|
|
|
{
|
2021-04-22 22:52:22 +08:00
|
|
|
public MultiSpectatorLeaderboard([NotNull] ScoreProcessor scoreProcessor, int[] userIds)
|
2021-04-09 16:31:14 +08:00
|
|
|
: base(scoreProcessor, userIds)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-04-12 21:00:27 +08:00
|
|
|
public void AddClock(int userId, IClock clock)
|
|
|
|
{
|
|
|
|
if (!UserScores.TryGetValue(userId, out var data))
|
2021-07-06 13:56:00 +08:00
|
|
|
throw new ArgumentException(@"Provided user is not tracked by this leaderboard", nameof(userId));
|
2021-04-09 16:31:14 +08:00
|
|
|
|
2021-04-12 21:00:27 +08:00
|
|
|
((SpectatingTrackedUserData)data).Clock = clock;
|
|
|
|
}
|
2021-04-09 16:31:14 +08:00
|
|
|
|
2021-04-12 21:00:27 +08:00
|
|
|
public void RemoveClock(int userId)
|
2021-04-09 16:31:14 +08:00
|
|
|
{
|
2021-04-12 21:00:27 +08:00
|
|
|
if (!UserScores.TryGetValue(userId, out var data))
|
2021-07-06 13:56:00 +08:00
|
|
|
throw new ArgumentException(@"Provided user is not tracked by this leaderboard", nameof(userId));
|
2021-04-09 16:31:14 +08:00
|
|
|
|
2021-04-12 21:00:27 +08:00
|
|
|
((SpectatingTrackedUserData)data).Clock = null;
|
2021-04-09 16:31:14 +08:00
|
|
|
}
|
|
|
|
|
2021-08-06 19:06:57 +08:00
|
|
|
protected override TrackedUserData CreateUserData(MultiplayerRoomUser user, ScoreProcessor scoreProcessor) => new SpectatingTrackedUserData(user, scoreProcessor);
|
2021-04-12 21:00:27 +08:00
|
|
|
|
2021-04-09 16:31:14 +08:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2021-04-12 21:00:27 +08:00
|
|
|
foreach (var (_, data) in UserScores)
|
|
|
|
data.UpdateScore();
|
2021-04-09 16:31:14 +08:00
|
|
|
}
|
|
|
|
|
2021-04-12 21:00:27 +08:00
|
|
|
private class SpectatingTrackedUserData : TrackedUserData
|
2021-04-09 16:31:14 +08:00
|
|
|
{
|
2021-04-12 21:00:27 +08:00
|
|
|
[CanBeNull]
|
|
|
|
public IClock Clock;
|
2021-04-09 16:31:14 +08:00
|
|
|
|
2021-08-06 19:06:57 +08:00
|
|
|
public SpectatingTrackedUserData(MultiplayerRoomUser user, ScoreProcessor scoreProcessor)
|
|
|
|
: base(user, scoreProcessor)
|
2021-04-09 16:31:14 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-04-12 21:00:27 +08:00
|
|
|
public override void UpdateScore()
|
2021-04-09 16:31:14 +08:00
|
|
|
{
|
2021-04-12 21:00:27 +08:00
|
|
|
if (Frames.Count == 0)
|
|
|
|
return;
|
2021-04-09 16:31:14 +08:00
|
|
|
|
2021-04-12 21:00:27 +08:00
|
|
|
if (Clock == null)
|
|
|
|
return;
|
2021-04-09 16:31:14 +08:00
|
|
|
|
2021-04-12 21:00:27 +08:00
|
|
|
int frameIndex = Frames.BinarySearch(new TimedFrame(Clock.CurrentTime));
|
|
|
|
if (frameIndex < 0)
|
|
|
|
frameIndex = ~frameIndex;
|
|
|
|
frameIndex = Math.Clamp(frameIndex - 1, 0, Frames.Count - 1);
|
|
|
|
|
|
|
|
SetFrame(Frames[frameIndex]);
|
|
|
|
}
|
2021-04-09 16:31:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|