mirror of
https://github.com/ppy/osu
synced 2025-02-02 19:32:19 +00:00
Pass users in via constructor and correctly unbind on disposal
This commit is contained in:
parent
6e2131c164
commit
6bce587b59
@ -3,6 +3,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
@ -43,7 +44,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
streamingClient,
|
||||
lookupCache,
|
||||
scoreProcessor = new OsuScoreProcessor(),
|
||||
new MultiplayerGameplayLeaderboard(scoreProcessor)
|
||||
new MultiplayerGameplayLeaderboard(scoreProcessor, streamingClient.PlayingUsers.ToArray())
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
|
@ -16,13 +16,22 @@ namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
private readonly ScoreProcessor scoreProcessor;
|
||||
|
||||
private readonly int[] userIds;
|
||||
|
||||
private readonly Dictionary<int, TrackedUserData> userScores = new Dictionary<int, TrackedUserData>();
|
||||
|
||||
/// <summary>
|
||||
/// Construct a new leaderboard.
|
||||
/// </summary>
|
||||
/// <param name="scoreProcessor">A score processor instance to handle score calculation for scores of users in the match.</param>
|
||||
public MultiplayerGameplayLeaderboard(ScoreProcessor scoreProcessor)
|
||||
/// <param name="userIds">IDs of all users in this match.</param>
|
||||
public MultiplayerGameplayLeaderboard(ScoreProcessor scoreProcessor, int[] userIds)
|
||||
{
|
||||
// todo: this will eventually need to be created per user to support different mod combinations.
|
||||
this.scoreProcessor = scoreProcessor;
|
||||
|
||||
// todo: this will likely be passed in as User instances.
|
||||
this.userIds = userIds;
|
||||
}
|
||||
|
||||
[Resolved]
|
||||
@ -31,8 +40,6 @@ namespace osu.Game.Screens.Play.HUD
|
||||
[Resolved]
|
||||
private UserLookupCache userLookupCache { get; set; }
|
||||
|
||||
private readonly Dictionary<int, TrackedUserData> userScores = new Dictionary<int, TrackedUserData>();
|
||||
|
||||
private Bindable<ScoringMode> scoringMode;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
@ -40,9 +47,11 @@ namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
streamingClient.OnNewFrames += handleIncomingFrames;
|
||||
|
||||
foreach (var user in streamingClient.PlayingUsers)
|
||||
foreach (var user in userIds)
|
||||
{
|
||||
streamingClient.WatchUser(user);
|
||||
|
||||
// probably won't be required in the final implementation.
|
||||
var resolvedUser = userLookupCache.GetUserAsync(user).Result;
|
||||
|
||||
var trackedUser = new TrackedUserData();
|
||||
@ -70,6 +79,21 @@ namespace osu.Game.Screens.Play.HUD
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
if (streamingClient != null)
|
||||
{
|
||||
foreach (var user in userIds)
|
||||
{
|
||||
streamingClient.StopWatchingUser(user);
|
||||
}
|
||||
|
||||
streamingClient.OnNewFrames -= handleIncomingFrames;
|
||||
}
|
||||
}
|
||||
|
||||
private class TrackedUserData
|
||||
{
|
||||
public readonly BindableDouble Score = new BindableDouble();
|
||||
|
Loading…
Reference in New Issue
Block a user