mirror of
https://github.com/osukey/osukey.git
synced 2025-08-07 00:23:59 +09:00
Make ParticipantsList use the new participants property
This commit is contained in:
@ -59,7 +59,7 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
public Bindable<int?> MaxParticipants { get; private set; } = new Bindable<int?>();
|
public Bindable<int?> MaxParticipants { get; private set; } = new Bindable<int?>();
|
||||||
|
|
||||||
[Cached]
|
[Cached]
|
||||||
[JsonIgnore]
|
[JsonProperty("recent_participants")]
|
||||||
public BindableList<User> Participants { get; private set; } = new BindableList<User>();
|
public BindableList<User> Participants { get; private set; } = new BindableList<User>();
|
||||||
|
|
||||||
[Cached]
|
[Cached]
|
||||||
|
@ -7,9 +7,8 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Cursor;
|
using osu.Framework.Graphics.Cursor;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Framework.Threading;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Online.API;
|
|
||||||
using osu.Game.Online.API.Requests;
|
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
using osu.Game.Users.Drawables;
|
using osu.Game.Users.Drawables;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
@ -46,73 +45,69 @@ namespace osu.Game.Screens.Multi.Components
|
|||||||
set => fill.Direction = value;
|
set => fill.Direction = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly FillFlowContainer fill;
|
private readonly FillFlowContainer<UserTile> fill;
|
||||||
|
|
||||||
public ParticipantsList()
|
public ParticipantsList()
|
||||||
{
|
{
|
||||||
InternalChild = fill = new FillFlowContainer { Spacing = new Vector2(10) };
|
InternalChild = fill = new FillFlowContainer<UserTile> { Spacing = new Vector2(10) };
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
RoomID.BindValueChanged(_ => updateParticipants(), true);
|
Participants.CollectionChanged += (_, __) => updateParticipants();
|
||||||
|
updateParticipants();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Resolved]
|
private ScheduledDelegate scheduledUpdate;
|
||||||
private IAPIProvider api { get; set; }
|
|
||||||
|
|
||||||
private GetRoomScoresRequest request;
|
|
||||||
|
|
||||||
private void updateParticipants()
|
private void updateParticipants()
|
||||||
{
|
{
|
||||||
var roomId = RoomID.Value ?? 0;
|
scheduledUpdate?.Cancel();
|
||||||
|
scheduledUpdate = Schedule(() =>
|
||||||
request?.Cancel();
|
|
||||||
|
|
||||||
// nice little progressive fade
|
|
||||||
int time = 500;
|
|
||||||
|
|
||||||
foreach (var c in fill.Children)
|
|
||||||
{
|
{
|
||||||
c.Delay(500 - time).FadeOut(time, Easing.Out);
|
// Remove all extra tiles with a nice, progressive fade
|
||||||
time = Math.Max(20, time - 20);
|
int time = 500;
|
||||||
c.Expire();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (roomId == 0) return;
|
for (int i = Participants.Count; i < fill.Count; i++)
|
||||||
|
{
|
||||||
|
var tile = fill[i];
|
||||||
|
|
||||||
request = new GetRoomScoresRequest(roomId);
|
tile.Delay(500 - time).FadeOut(time, Easing.Out);
|
||||||
request.Success += scores => Schedule(() =>
|
time = Math.Max(20, time - 20);
|
||||||
{
|
tile.Expire();
|
||||||
if (roomId != RoomID.Value)
|
}
|
||||||
return;
|
|
||||||
|
|
||||||
fill.Clear();
|
// Add new tiles for all new players
|
||||||
foreach (var s in scores)
|
for (int i = fill.Count; i < Participants.Count; i++)
|
||||||
fill.Add(new UserTile(s.User));
|
{
|
||||||
|
var tile = new UserTile();
|
||||||
|
fill.Add(tile);
|
||||||
|
|
||||||
fill.FadeInFromZero(1000, Easing.OutQuint);
|
tile.ClearTransforms();
|
||||||
|
tile.LifetimeEnd = double.MaxValue;
|
||||||
|
tile.FadeInFromZero(250, Easing.OutQuint);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < Participants.Count; i++)
|
||||||
|
fill[i].User = Participants[i];
|
||||||
});
|
});
|
||||||
|
|
||||||
api.Queue(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
|
||||||
{
|
|
||||||
request?.Cancel();
|
|
||||||
base.Dispose(isDisposing);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class UserTile : CompositeDrawable, IHasTooltip
|
private class UserTile : CompositeDrawable, IHasTooltip
|
||||||
{
|
{
|
||||||
private readonly User user;
|
public User User
|
||||||
|
{
|
||||||
public string TooltipText => user.Username;
|
get => avatar.User;
|
||||||
|
set => avatar.User = value;
|
||||||
public UserTile(User user)
|
}
|
||||||
|
|
||||||
|
public string TooltipText => User?.Username ?? string.Empty;
|
||||||
|
|
||||||
|
private readonly UpdateableAvatar avatar;
|
||||||
|
|
||||||
|
public UserTile()
|
||||||
{
|
{
|
||||||
this.user = user;
|
|
||||||
Size = new Vector2(TILE_SIZE);
|
Size = new Vector2(TILE_SIZE);
|
||||||
CornerRadius = 5f;
|
CornerRadius = 5f;
|
||||||
Masking = true;
|
Masking = true;
|
||||||
@ -124,11 +119,7 @@ namespace osu.Game.Screens.Multi.Components
|
|||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Colour = OsuColour.FromHex(@"27252d"),
|
Colour = OsuColour.FromHex(@"27252d"),
|
||||||
},
|
},
|
||||||
new UpdateableAvatar
|
avatar = new UpdateableAvatar { RelativeSizeAxes = Axes.Both },
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
User = user,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user