mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 20:13:22 +08:00
Support more than two teams
This commit is contained in:
parent
cdc173e867
commit
ebbf6467e8
@ -4,11 +4,9 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Configuration;
|
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
|
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
@ -82,13 +80,16 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
}, Add);
|
}, gameplayLeaderboard =>
|
||||||
|
|
||||||
LoadComponentAsync(new MatchScoreDisplay
|
|
||||||
{
|
{
|
||||||
Team1Score = { BindTarget = leaderboard.Team1Score },
|
LoadComponentAsync(new MatchScoreDisplay
|
||||||
Team2Score = { BindTarget = leaderboard.Team2Score }
|
{
|
||||||
}, Add);
|
Team1Score = { BindTarget = leaderboard.TeamScores[0] },
|
||||||
|
Team2Score = { BindTarget = leaderboard.TeamScores[1] }
|
||||||
|
}, Add);
|
||||||
|
|
||||||
|
Add(gameplayLeaderboard);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
AddUntilStep("wait for load", () => leaderboard.IsLoaded);
|
AddUntilStep("wait for load", () => leaderboard.IsLoaded);
|
||||||
|
@ -26,8 +26,7 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
{
|
{
|
||||||
protected readonly Dictionary<int, TrackedUserData> UserScores = new Dictionary<int, TrackedUserData>();
|
protected readonly Dictionary<int, TrackedUserData> UserScores = new Dictionary<int, TrackedUserData>();
|
||||||
|
|
||||||
public readonly BindableInt Team1Score = new BindableInt();
|
public readonly Dictionary<int, BindableInt> TeamScores = new Dictionary<int, BindableInt>();
|
||||||
public readonly BindableInt Team2Score = new BindableInt();
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private OsuColour colours { get; set; }
|
private OsuColour colours { get; set; }
|
||||||
@ -45,7 +44,7 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
private readonly BindableList<int> playingUsers;
|
private readonly BindableList<int> playingUsers;
|
||||||
private Bindable<ScoringMode> scoringMode;
|
private Bindable<ScoringMode> scoringMode;
|
||||||
|
|
||||||
private bool hasTeams;
|
private bool hasTeams => TeamScores.Count > 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Construct a new leaderboard.
|
/// Construct a new leaderboard.
|
||||||
@ -74,7 +73,8 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
trackedUser.ScoringMode.BindTo(scoringMode);
|
trackedUser.ScoringMode.BindTo(scoringMode);
|
||||||
UserScores[userId] = trackedUser;
|
UserScores[userId] = trackedUser;
|
||||||
|
|
||||||
hasTeams |= trackedUser.Team != null;
|
if (trackedUser.Team is int team && !TeamScores.ContainsKey(team))
|
||||||
|
TeamScores.Add(team, new BindableInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
userLookupCache.GetUsersAsync(playingUsers.ToArray()).ContinueWith(users => Schedule(() =>
|
userLookupCache.GetUsersAsync(playingUsers.ToArray()).ContinueWith(users => Schedule(() =>
|
||||||
@ -177,15 +177,15 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
if (!hasTeams)
|
if (!hasTeams)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Team1Score.Value = 0;
|
foreach (var scores in TeamScores.Values) scores.Value = 0;
|
||||||
Team2Score.Value = 0;
|
|
||||||
|
|
||||||
foreach (var u in UserScores.Values)
|
foreach (var u in UserScores.Values)
|
||||||
{
|
{
|
||||||
if (u.Team == 0)
|
if (u.Team == null)
|
||||||
Team1Score.Value += (int)u.Score.Value;
|
continue;
|
||||||
else
|
|
||||||
Team2Score.Value += (int)u.Score.Value;
|
if (TeamScores.TryGetValue(u.Team.Value, out var team))
|
||||||
|
team.Value += (int)u.Score.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user