mirror of
https://github.com/ppy/osu
synced 2025-01-19 12:30:50 +00: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,
|
Anchor = Anchor.Centre,
|
||||||
Origin = 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++)
|
for (int i = 0; i < 8; i++)
|
||||||
addUser(i);
|
addUser(i);
|
||||||
});
|
});
|
||||||
|
|
||||||
AddStep("set 8 circles", () => list.NumberOfCircles = 8);
|
AddStep("set 8 circles", () => list.NumberOfCircles = 8);
|
||||||
AddAssert("0 hidden users", () => list.ChildrenOfType<RecentParticipantsList.HiddenUserCount>().Single().Count == 0);
|
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);
|
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]
|
[Test]
|
||||||
public void TestCircleCount()
|
public void TestCircleCount()
|
||||||
{
|
{
|
||||||
@ -69,12 +91,12 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
});
|
});
|
||||||
|
|
||||||
AddStep("set 3 circles", () => list.NumberOfCircles = 3);
|
AddStep("set 3 circles", () => list.NumberOfCircles = 3);
|
||||||
AddAssert("3 circles displayed", () => list.ChildrenOfType<UpdateableAvatar>().Count() == 3);
|
AddAssert("2 users displayed", () => list.ChildrenOfType<UpdateableAvatar>().Count() == 2);
|
||||||
AddAssert("47 hidden users", () => list.ChildrenOfType<RecentParticipantsList.HiddenUserCount>().Single().Count == 47);
|
AddAssert("48 hidden users", () => list.ChildrenOfType<RecentParticipantsList.HiddenUserCount>().Single().Count == 48);
|
||||||
|
|
||||||
AddStep("set 10 circles", () => list.NumberOfCircles = 10);
|
AddStep("set 10 circles", () => list.NumberOfCircles = 10);
|
||||||
AddAssert("10 circles displayed", () => list.ChildrenOfType<UpdateableAvatar>().Count() == 10);
|
AddAssert("9 users displayed", () => list.ChildrenOfType<UpdateableAvatar>().Count() == 9);
|
||||||
AddAssert("40 hidden users", () => list.ChildrenOfType<RecentParticipantsList.HiddenUserCount>().Single().Count == 40);
|
AddAssert("41 hidden users", () => list.ChildrenOfType<RecentParticipantsList.HiddenUserCount>().Single().Count == 41);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -109,18 +131,18 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
|
|
||||||
private void addUser(int id)
|
private void addUser(int id)
|
||||||
{
|
{
|
||||||
SelectedRoom.Value.ParticipantCount.Value++;
|
|
||||||
SelectedRoom.Value.RecentParticipants.Add(new User
|
SelectedRoom.Value.RecentParticipants.Add(new User
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
Username = $"User {id}"
|
Username = $"User {id}"
|
||||||
});
|
});
|
||||||
|
SelectedRoom.Value.ParticipantCount.Value++;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeUserAt(int index)
|
private void removeUserAt(int index)
|
||||||
{
|
{
|
||||||
SelectedRoom.Value.ParticipantCount.Value--;
|
|
||||||
SelectedRoom.Value.RecentParticipants.RemoveAt(index);
|
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 const float avatar_size = 36;
|
||||||
|
|
||||||
private bool canDisplayMoreUsers = true;
|
|
||||||
|
|
||||||
private FillFlowContainer<CircularAvatar> avatarFlow;
|
private FillFlowContainer<CircularAvatar> avatarFlow;
|
||||||
private HiddenUserCount hiddenUsers;
|
private HiddenUserCount hiddenUsers;
|
||||||
|
|
||||||
@ -91,10 +89,10 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
|||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
RecentParticipants.BindCollectionChanged(onParticipantsChanged, true);
|
RecentParticipants.BindCollectionChanged(onParticipantsChanged, true);
|
||||||
ParticipantCount.BindValueChanged(_ => updateHiddenUserCount(), true);
|
ParticipantCount.BindValueChanged(_ => updateHiddenUsers(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int numberOfCircles = 3;
|
private int numberOfCircles = 4;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The maximum number of circles visible (including the "hidden count" circle in the overflow case).
|
/// 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)
|
foreach (var u in RecentParticipants)
|
||||||
addUser(u);
|
addUser(u);
|
||||||
|
|
||||||
updateHiddenUserCount();
|
updateHiddenUsers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,44 +143,43 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateHiddenUserCount();
|
updateHiddenUsers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int displayedCircles => avatarFlow.Count + (hiddenUsers.Count > 0 ? 1 : 0);
|
||||||
|
|
||||||
private void addUser(User user)
|
private void addUser(User user)
|
||||||
{
|
{
|
||||||
if (!canDisplayMoreUsers)
|
if (displayedCircles < NumberOfCircles)
|
||||||
return;
|
|
||||||
|
|
||||||
if (avatarFlow.Count < NumberOfCircles)
|
|
||||||
avatarFlow.Add(new CircularAvatar { User = user });
|
avatarFlow.Add(new CircularAvatar { User = user });
|
||||||
else if (avatarFlow.Count == NumberOfCircles)
|
|
||||||
avatarFlow.Remove(avatarFlow.Last());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeUser(User user)
|
private void removeUser(User user)
|
||||||
{
|
{
|
||||||
var nextUser = RecentParticipants.FirstOrDefault(u => avatarFlow.All(a => a.User != u));
|
avatarFlow.RemoveAll(a => a.User == user);
|
||||||
if (nextUser == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (canDisplayMoreUsers || NumberOfCircles == RecentParticipants.Count)
|
|
||||||
avatarFlow.Add(new CircularAvatar { User = nextUser });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearUsers()
|
private void clearUsers()
|
||||||
{
|
{
|
||||||
canDisplayMoreUsers = true;
|
|
||||||
avatarFlow.Clear();
|
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
|
private class CircularAvatar : CompositeDrawable
|
||||||
@ -193,9 +190,10 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
|||||||
set => avatar.User = value;
|
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);
|
Size = new Vector2(avatar_size);
|
||||||
|
|
||||||
@ -203,7 +201,15 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
|||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Masking = true,
|
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