1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 03:25:11 +08:00

Support more than two teams

This commit is contained in:
Dean Herbert 2021-08-09 17:23:02 +09:00
parent cdc173e867
commit ebbf6467e8
2 changed files with 19 additions and 18 deletions

View File

@ -4,11 +4,9 @@
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Configuration;
using osu.Game.Online.API;
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
using osu.Game.Online.Rooms;
@ -82,13 +80,16 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}, Add);
LoadComponentAsync(new MatchScoreDisplay
}, gameplayLeaderboard =>
{
Team1Score = { BindTarget = leaderboard.Team1Score },
Team2Score = { BindTarget = leaderboard.Team2Score }
}, Add);
LoadComponentAsync(new MatchScoreDisplay
{
Team1Score = { BindTarget = leaderboard.TeamScores[0] },
Team2Score = { BindTarget = leaderboard.TeamScores[1] }
}, Add);
Add(gameplayLeaderboard);
});
});
AddUntilStep("wait for load", () => leaderboard.IsLoaded);

View File

@ -26,8 +26,7 @@ namespace osu.Game.Screens.Play.HUD
{
protected readonly Dictionary<int, TrackedUserData> UserScores = new Dictionary<int, TrackedUserData>();
public readonly BindableInt Team1Score = new BindableInt();
public readonly BindableInt Team2Score = new BindableInt();
public readonly Dictionary<int, BindableInt> TeamScores = new Dictionary<int, BindableInt>();
[Resolved]
private OsuColour colours { get; set; }
@ -45,7 +44,7 @@ namespace osu.Game.Screens.Play.HUD
private readonly BindableList<int> playingUsers;
private Bindable<ScoringMode> scoringMode;
private bool hasTeams;
private bool hasTeams => TeamScores.Count > 0;
/// <summary>
/// Construct a new leaderboard.
@ -74,7 +73,8 @@ namespace osu.Game.Screens.Play.HUD
trackedUser.ScoringMode.BindTo(scoringMode);
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(() =>
@ -177,15 +177,15 @@ namespace osu.Game.Screens.Play.HUD
if (!hasTeams)
return;
Team1Score.Value = 0;
Team2Score.Value = 0;
foreach (var scores in TeamScores.Values) scores.Value = 0;
foreach (var u in UserScores.Values)
{
if (u.Team == 0)
Team1Score.Value += (int)u.Score.Value;
else
Team2Score.Value += (int)u.Score.Value;
if (u.Team == null)
continue;
if (TeamScores.TryGetValue(u.Team.Value, out var team))
team.Value += (int)u.Score.Value;
}
}