mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 15:43:22 +08:00
Simplify logic and test/fix edge case
This commit is contained in:
parent
8a67304b9f
commit
7b66616dc4
@ -31,7 +31,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
NumberOfCircles = 3
|
||||
NumberOfCircles = 4
|
||||
};
|
||||
});
|
||||
|
||||
@ -43,6 +43,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
for (int i = 0; i < 8; i++)
|
||||
addUser(i);
|
||||
});
|
||||
|
||||
AddStep("set 8 circles", () => list.NumberOfCircles = 8);
|
||||
AddAssert("0 hidden users", () => list.ChildrenOfType<RecentParticipantsList.HiddenUserCount>().Single().Count == 0);
|
||||
|
||||
@ -59,6 +60,27 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
AddAssert("0 hidden users", () => list.ChildrenOfType<RecentParticipantsList.HiddenUserCount>().Single().Count == 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestHiddenUsersBecomeDisplayed()
|
||||
{
|
||||
AddStep("add 8 users", () =>
|
||||
{
|
||||
for (int i = 0; i < 8; i++)
|
||||
addUser(i);
|
||||
});
|
||||
|
||||
AddStep("set 3 circles", () => list.NumberOfCircles = 3);
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
AddStep("remove user", () => removeUserAt(0));
|
||||
int remainingUsers = 7 - i;
|
||||
|
||||
int displayedUsers = remainingUsers > 3 ? 2 : remainingUsers;
|
||||
AddAssert($"{displayedUsers} avatars displayed", () => list.ChildrenOfType<UpdateableAvatar>().Count() == displayedUsers);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCircleCount()
|
||||
{
|
||||
@ -69,12 +91,12 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
});
|
||||
|
||||
AddStep("set 3 circles", () => list.NumberOfCircles = 3);
|
||||
AddAssert("3 circles displayed", () => list.ChildrenOfType<UpdateableAvatar>().Count() == 3);
|
||||
AddAssert("47 hidden users", () => list.ChildrenOfType<RecentParticipantsList.HiddenUserCount>().Single().Count == 47);
|
||||
AddAssert("2 users displayed", () => list.ChildrenOfType<UpdateableAvatar>().Count() == 2);
|
||||
AddAssert("48 hidden users", () => list.ChildrenOfType<RecentParticipantsList.HiddenUserCount>().Single().Count == 48);
|
||||
|
||||
AddStep("set 10 circles", () => list.NumberOfCircles = 10);
|
||||
AddAssert("10 circles displayed", () => list.ChildrenOfType<UpdateableAvatar>().Count() == 10);
|
||||
AddAssert("40 hidden users", () => list.ChildrenOfType<RecentParticipantsList.HiddenUserCount>().Single().Count == 40);
|
||||
AddAssert("9 users displayed", () => list.ChildrenOfType<UpdateableAvatar>().Count() == 9);
|
||||
AddAssert("41 hidden users", () => list.ChildrenOfType<RecentParticipantsList.HiddenUserCount>().Single().Count == 41);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -109,18 +131,18 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
private void addUser(int id)
|
||||
{
|
||||
SelectedRoom.Value.ParticipantCount.Value++;
|
||||
SelectedRoom.Value.RecentParticipants.Add(new User
|
||||
{
|
||||
Id = id,
|
||||
Username = $"User {id}"
|
||||
});
|
||||
SelectedRoom.Value.ParticipantCount.Value++;
|
||||
}
|
||||
|
||||
private void removeUserAt(int index)
|
||||
{
|
||||
SelectedRoom.Value.ParticipantCount.Value--;
|
||||
SelectedRoom.Value.RecentParticipants.RemoveAt(index);
|
||||
SelectedRoom.Value.ParticipantCount.Value--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,8 +22,6 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
{
|
||||
private const float avatar_size = 36;
|
||||
|
||||
private bool canDisplayMoreUsers = true;
|
||||
|
||||
private FillFlowContainer<CircularAvatar> avatarFlow;
|
||||
private HiddenUserCount hiddenUsers;
|
||||
|
||||
@ -91,10 +89,10 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
base.LoadComplete();
|
||||
|
||||
RecentParticipants.BindCollectionChanged(onParticipantsChanged, true);
|
||||
ParticipantCount.BindValueChanged(_ => updateHiddenUserCount(), true);
|
||||
ParticipantCount.BindValueChanged(_ => updateHiddenUsers(), true);
|
||||
}
|
||||
|
||||
private int numberOfCircles = 3;
|
||||
private int numberOfCircles = 4;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum number of circles visible (including the "hidden count" circle in the overflow case).
|
||||
@ -114,7 +112,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
foreach (var u in RecentParticipants)
|
||||
addUser(u);
|
||||
|
||||
updateHiddenUserCount();
|
||||
updateHiddenUsers();
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,44 +143,43 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
break;
|
||||
}
|
||||
|
||||
updateHiddenUserCount();
|
||||
updateHiddenUsers();
|
||||
}
|
||||
|
||||
private int displayedCircles => avatarFlow.Count + (hiddenUsers.Count > 0 ? 1 : 0);
|
||||
|
||||
private void addUser(User user)
|
||||
{
|
||||
if (!canDisplayMoreUsers)
|
||||
return;
|
||||
|
||||
if (avatarFlow.Count < NumberOfCircles)
|
||||
if (displayedCircles < NumberOfCircles)
|
||||
avatarFlow.Add(new CircularAvatar { User = user });
|
||||
else if (avatarFlow.Count == NumberOfCircles)
|
||||
avatarFlow.Remove(avatarFlow.Last());
|
||||
}
|
||||
|
||||
private void removeUser(User user)
|
||||
{
|
||||
var nextUser = RecentParticipants.FirstOrDefault(u => avatarFlow.All(a => a.User != u));
|
||||
if (nextUser == null)
|
||||
return;
|
||||
|
||||
if (canDisplayMoreUsers || NumberOfCircles == RecentParticipants.Count)
|
||||
avatarFlow.Add(new CircularAvatar { User = nextUser });
|
||||
avatarFlow.RemoveAll(a => a.User == user);
|
||||
}
|
||||
|
||||
private void clearUsers()
|
||||
{
|
||||
canDisplayMoreUsers = true;
|
||||
avatarFlow.Clear();
|
||||
updateHiddenUserCount();
|
||||
updateHiddenUsers();
|
||||
}
|
||||
|
||||
private void updateHiddenUserCount()
|
||||
private void updateHiddenUsers()
|
||||
{
|
||||
int count = ParticipantCount.Value - avatarFlow.Count;
|
||||
int hiddenCount = 0;
|
||||
if (RecentParticipants.Count > NumberOfCircles)
|
||||
hiddenCount = ParticipantCount.Value - NumberOfCircles + 1;
|
||||
|
||||
Debug.Assert(count != 1);
|
||||
hiddenUsers.Count = hiddenCount;
|
||||
|
||||
hiddenUsers.Count = count;
|
||||
if (displayedCircles > NumberOfCircles)
|
||||
avatarFlow.Remove(avatarFlow.Last());
|
||||
else if (displayedCircles < NumberOfCircles)
|
||||
{
|
||||
var nextUser = RecentParticipants.FirstOrDefault(u => avatarFlow.All(a => a.User != u));
|
||||
if (nextUser != null) addUser(nextUser);
|
||||
}
|
||||
}
|
||||
|
||||
private class CircularAvatar : CompositeDrawable
|
||||
@ -193,9 +190,10 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
set => avatar.User = value;
|
||||
}
|
||||
|
||||
private readonly UpdateableAvatar avatar;
|
||||
private readonly UpdateableAvatar avatar = new UpdateableAvatar(showUsernameTooltip: true) { RelativeSizeAxes = Axes.Both };
|
||||
|
||||
public CircularAvatar()
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OverlayColourProvider colours)
|
||||
{
|
||||
Size = new Vector2(avatar_size);
|
||||
|
||||
@ -203,7 +201,15 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Masking = true,
|
||||
Child = avatar = new UpdateableAvatar(showUsernameTooltip: true) { RelativeSizeAxes = Axes.Both }
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
Colour = colours.Background5,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
avatar
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user