2020-12-19 01:37:47 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2020-12-19 01:37:47 +08:00
|
|
|
using System.Linq;
|
2022-03-18 12:25:03 +08:00
|
|
|
using JetBrains.Annotations;
|
2020-12-19 01:37:47 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osuTK;
|
|
|
|
|
2020-12-25 23:50:00 +08:00
|
|
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
|
2020-12-19 01:37:47 +08:00
|
|
|
{
|
2020-12-25 12:38:11 +08:00
|
|
|
public class ParticipantsList : MultiplayerRoomComposite
|
2020-12-19 01:37:47 +08:00
|
|
|
{
|
|
|
|
private FillFlowContainer<ParticipantPanel> panels;
|
|
|
|
|
2022-03-18 12:25:03 +08:00
|
|
|
[CanBeNull]
|
|
|
|
private ParticipantPanel currentHostPanel;
|
|
|
|
|
2020-12-19 01:37:47 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2022-01-19 13:08:21 +08:00
|
|
|
private void load()
|
2020-12-19 01:37:47 +08:00
|
|
|
{
|
2022-07-08 06:42:55 +08:00
|
|
|
InternalChild = new OsuScrollContainer
|
2020-12-19 01:37:47 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-07-08 06:42:55 +08:00
|
|
|
ScrollbarVisible = false,
|
|
|
|
Child = panels = new FillFlowContainer<ParticipantPanel>
|
2020-12-19 01:37:47 +08:00
|
|
|
{
|
2022-07-08 06:42:55 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(0, 2)
|
2020-12-19 01:37:47 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-12-26 09:48:55 +08:00
|
|
|
protected override void OnRoomUpdated()
|
2020-12-19 01:37:47 +08:00
|
|
|
{
|
2020-12-26 09:48:55 +08:00
|
|
|
base.OnRoomUpdated();
|
2020-12-19 01:37:47 +08:00
|
|
|
|
|
|
|
if (Room == null)
|
|
|
|
panels.Clear();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Remove panels for users no longer in the room.
|
2021-12-07 16:24:03 +08:00
|
|
|
foreach (var p in panels)
|
|
|
|
{
|
|
|
|
// Note that we *must* use reference equality here, as this call is scheduled and a user may have left and joined since it was last run.
|
|
|
|
if (Room.Users.All(u => !ReferenceEquals(p.User, u)))
|
|
|
|
p.Expire();
|
|
|
|
}
|
2020-12-19 01:37:47 +08:00
|
|
|
|
|
|
|
// Add panels for all users new to the room.
|
|
|
|
foreach (var user in Room.Users.Except(panels.Select(p => p.User)))
|
|
|
|
panels.Add(new ParticipantPanel(user));
|
2022-03-18 12:25:03 +08:00
|
|
|
|
|
|
|
if (currentHostPanel == null || !currentHostPanel.User.Equals(Room.Host))
|
|
|
|
{
|
|
|
|
// Reset position of previous host back to normal, if one existing.
|
|
|
|
if (currentHostPanel != null && panels.Contains(currentHostPanel))
|
|
|
|
panels.SetLayoutPosition(currentHostPanel, 0);
|
|
|
|
|
2022-03-19 09:01:35 +08:00
|
|
|
currentHostPanel = null;
|
|
|
|
|
2022-03-18 12:25:03 +08:00
|
|
|
// Change position of new host to display above all participants.
|
2022-03-19 09:01:35 +08:00
|
|
|
if (Room.Host != null)
|
2022-03-19 19:54:58 +08:00
|
|
|
{
|
|
|
|
currentHostPanel = panels.SingleOrDefault(u => u.User.Equals(Room.Host));
|
|
|
|
|
|
|
|
if (currentHostPanel != null)
|
|
|
|
panels.SetLayoutPosition(currentHostPanel, -1);
|
|
|
|
}
|
2022-03-18 12:25:03 +08:00
|
|
|
}
|
2020-12-19 01:37:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|