1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 17:32:55 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Components/ParticipantsList.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

124 lines
3.4 KiB
C#
Raw Normal View History

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