2020-02-14 19:27:37 +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-02-14 19:27:37 +08:00
|
|
|
using osu.Framework.Allocation;
|
2020-03-11 09:18:41 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2020-02-14 19:27:37 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2020-02-27 18:24:13 +08:00
|
|
|
using osu.Framework.Threading;
|
2021-11-04 17:02:44 +08:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2020-02-14 19:27:37 +08:00
|
|
|
using osu.Game.Users.Drawables;
|
|
|
|
using osuTK;
|
|
|
|
|
2020-12-25 23:50:00 +08:00
|
|
|
namespace osu.Game.Screens.OnlinePlay.Components
|
2020-02-14 19:27:37 +08:00
|
|
|
{
|
2020-12-26 00:12:33 +08:00
|
|
|
public class ParticipantsList : OnlinePlayComposite
|
2020-02-14 19:27:37 +08:00
|
|
|
{
|
2020-02-19 18:54:07 +08:00
|
|
|
public const float TILE_SIZE = 35;
|
2020-02-19 16:37:01 +08:00
|
|
|
|
|
|
|
public override Axes RelativeSizeAxes
|
|
|
|
{
|
|
|
|
get => base.RelativeSizeAxes;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
base.RelativeSizeAxes = value;
|
2020-02-27 18:37:04 +08:00
|
|
|
|
|
|
|
if (tiles != null)
|
|
|
|
tiles.RelativeSizeAxes = value;
|
2020-02-19 16:37:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public new Axes AutoSizeAxes
|
|
|
|
{
|
|
|
|
get => base.AutoSizeAxes;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
base.AutoSizeAxes = value;
|
2020-02-27 18:37:04 +08:00
|
|
|
|
|
|
|
if (tiles != null)
|
|
|
|
tiles.AutoSizeAxes = value;
|
2020-02-19 16:37:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-27 18:37:04 +08:00
|
|
|
private FillDirection direction = FillDirection.Full;
|
|
|
|
|
2020-02-19 16:37:01 +08:00
|
|
|
public FillDirection Direction
|
|
|
|
{
|
2020-02-27 18:37:04 +08:00
|
|
|
get => direction;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
direction = value;
|
2020-02-14 19:27:37 +08:00
|
|
|
|
2020-02-27 18:37:04 +08:00
|
|
|
if (tiles != null)
|
|
|
|
tiles.Direction = value;
|
|
|
|
}
|
2020-02-14 19:27:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2022-06-24 20:25:23 +08:00
|
|
|
RecentParticipants.CollectionChanged += (_, _) => updateParticipants();
|
2020-02-27 18:24:13 +08:00
|
|
|
updateParticipants();
|
2020-02-14 19:27:37 +08:00
|
|
|
}
|
|
|
|
|
2020-02-27 18:24:13 +08:00
|
|
|
private ScheduledDelegate scheduledUpdate;
|
2020-02-27 18:37:04 +08:00
|
|
|
private FillFlowContainer<UserTile> tiles;
|
2020-02-14 19:27:37 +08:00
|
|
|
|
|
|
|
private void updateParticipants()
|
|
|
|
{
|
2020-02-27 18:24:13 +08:00
|
|
|
scheduledUpdate?.Cancel();
|
|
|
|
scheduledUpdate = Schedule(() =>
|
2020-02-14 19:27:37 +08:00
|
|
|
{
|
2020-02-27 18:37:04 +08:00
|
|
|
tiles?.FadeOut(250, Easing.Out).Expire();
|
2020-02-14 19:27:37 +08:00
|
|
|
|
2020-02-27 18:37:04 +08:00
|
|
|
tiles = new FillFlowContainer<UserTile>
|
2020-02-27 18:24:13 +08:00
|
|
|
{
|
2020-02-27 18:37:04 +08:00
|
|
|
Alpha = 0,
|
|
|
|
Direction = Direction,
|
|
|
|
AutoSizeAxes = AutoSizeAxes,
|
|
|
|
RelativeSizeAxes = RelativeSizeAxes,
|
2020-06-25 20:59:36 +08:00
|
|
|
Spacing = Vector2.One
|
2020-02-27 18:37:04 +08:00
|
|
|
};
|
2020-02-14 19:27:37 +08:00
|
|
|
|
2020-02-27 18:42:28 +08:00
|
|
|
for (int i = 0; i < RecentParticipants.Count; i++)
|
|
|
|
tiles.Add(new UserTile { User = RecentParticipants[i] });
|
2020-02-14 19:27:37 +08:00
|
|
|
|
2020-02-27 18:37:04 +08:00
|
|
|
AddInternal(tiles);
|
2020-02-14 19:27:37 +08:00
|
|
|
|
2020-02-27 18:37:04 +08:00
|
|
|
tiles.Delay(250).FadeIn(250, Easing.OutQuint);
|
2020-02-27 18:24:13 +08:00
|
|
|
});
|
2020-02-14 19:27:37 +08:00
|
|
|
}
|
|
|
|
|
2021-06-17 15:26:07 +08:00
|
|
|
private class UserTile : CompositeDrawable
|
2020-02-14 19:27:37 +08:00
|
|
|
{
|
2021-11-04 17:02:44 +08:00
|
|
|
public APIUser User
|
2020-02-27 18:24:13 +08:00
|
|
|
{
|
|
|
|
get => avatar.User;
|
|
|
|
set => avatar.User = value;
|
|
|
|
}
|
2020-02-14 19:27:37 +08:00
|
|
|
|
2020-02-27 18:24:13 +08:00
|
|
|
private readonly UpdateableAvatar avatar;
|
|
|
|
|
|
|
|
public UserTile()
|
2020-02-14 19:27:37 +08:00
|
|
|
{
|
2020-02-19 18:54:07 +08:00
|
|
|
Size = new Vector2(TILE_SIZE);
|
2020-02-14 19:27:37 +08:00
|
|
|
CornerRadius = 5f;
|
|
|
|
Masking = true;
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-03-11 09:18:41 +08:00
|
|
|
Colour = Color4Extensions.FromHex(@"27252d"),
|
2020-02-14 19:27:37 +08:00
|
|
|
},
|
2021-06-17 15:26:07 +08:00
|
|
|
avatar = new UpdateableAvatar(showUsernameTooltip: true) { RelativeSizeAxes = Axes.Both },
|
2020-02-14 19:27:37 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|