mirror of
https://github.com/osukey/osukey.git
synced 2025-08-08 00:53:56 +09:00
Pass users in via constructor and correctly unbind on disposal
This commit is contained in:
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -43,7 +44,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
streamingClient,
|
streamingClient,
|
||||||
lookupCache,
|
lookupCache,
|
||||||
scoreProcessor = new OsuScoreProcessor(),
|
scoreProcessor = new OsuScoreProcessor(),
|
||||||
new MultiplayerGameplayLeaderboard(scoreProcessor)
|
new MultiplayerGameplayLeaderboard(scoreProcessor, streamingClient.PlayingUsers.ToArray())
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
|
@ -16,13 +16,22 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
{
|
{
|
||||||
private readonly ScoreProcessor scoreProcessor;
|
private readonly ScoreProcessor scoreProcessor;
|
||||||
|
|
||||||
|
private readonly int[] userIds;
|
||||||
|
|
||||||
|
private readonly Dictionary<int, TrackedUserData> userScores = new Dictionary<int, TrackedUserData>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Construct a new leaderboard.
|
/// Construct a new leaderboard.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="scoreProcessor">A score processor instance to handle score calculation for scores of users in the match.</param>
|
/// <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;
|
this.scoreProcessor = scoreProcessor;
|
||||||
|
|
||||||
|
// todo: this will likely be passed in as User instances.
|
||||||
|
this.userIds = userIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
@ -31,8 +40,6 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private UserLookupCache userLookupCache { get; set; }
|
private UserLookupCache userLookupCache { get; set; }
|
||||||
|
|
||||||
private readonly Dictionary<int, TrackedUserData> userScores = new Dictionary<int, TrackedUserData>();
|
|
||||||
|
|
||||||
private Bindable<ScoringMode> scoringMode;
|
private Bindable<ScoringMode> scoringMode;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -40,9 +47,11 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
{
|
{
|
||||||
streamingClient.OnNewFrames += handleIncomingFrames;
|
streamingClient.OnNewFrames += handleIncomingFrames;
|
||||||
|
|
||||||
foreach (var user in streamingClient.PlayingUsers)
|
foreach (var user in userIds)
|
||||||
{
|
{
|
||||||
streamingClient.WatchUser(user);
|
streamingClient.WatchUser(user);
|
||||||
|
|
||||||
|
// probably won't be required in the final implementation.
|
||||||
var resolvedUser = userLookupCache.GetUserAsync(user).Result;
|
var resolvedUser = userLookupCache.GetUserAsync(user).Result;
|
||||||
|
|
||||||
var trackedUser = new TrackedUserData();
|
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
|
private class TrackedUserData
|
||||||
{
|
{
|
||||||
public readonly BindableDouble Score = new BindableDouble();
|
public readonly BindableDouble Score = new BindableDouble();
|
||||||
|
Reference in New Issue
Block a user