1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-20 01:33:12 +08:00

Merge pull request #7815 from smoogipoo/participants-bindable

Make room participants into a bindable list
This commit is contained in:
Dean Herbert 2020-02-13 20:35:38 +09:00 committed by GitHub
commit 1e58670930
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 20 deletions

View File

@ -16,7 +16,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
Add(new Participants { RelativeSizeAxes = Axes.Both }); Add(new Participants { RelativeSizeAxes = Axes.Both });
AddStep(@"set max to null", () => Room.MaxParticipants.Value = null); AddStep(@"set max to null", () => Room.MaxParticipants.Value = null);
AddStep(@"set users", () => Room.Participants.Value = new[] AddStep(@"set users", () => Room.Participants.AddRange(new[]
{ {
new User new User
{ {
@ -42,10 +42,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
CoverUrl = @"https://assets.ppy.sh/user-profile-covers/5287410/5cfeaa9dd41cbce038ecdc9d781396ed4b0108089170bf7f50492ef8eadeb368.jpeg", CoverUrl = @"https://assets.ppy.sh/user-profile-covers/5287410/5cfeaa9dd41cbce038ecdc9d781396ed4b0108089170bf7f50492ef8eadeb368.jpeg",
IsSupporter = true, IsSupporter = true,
}, },
}); }));
AddStep(@"set max", () => Room.MaxParticipants.Value = 10); AddStep(@"set max", () => Room.MaxParticipants.Value = 10);
AddStep(@"clear users", () => Room.Participants.Value = System.Array.Empty<User>()); AddStep(@"clear users", () => Room.Participants.Clear());
AddStep(@"set max to null", () => Room.MaxParticipants.Value = null); AddStep(@"set max to null", () => Room.MaxParticipants.Value = null);
} }
} }

View File

@ -65,7 +65,7 @@ namespace osu.Game.Online.Multiplayer
[Cached] [Cached]
[JsonIgnore] [JsonIgnore]
public Bindable<IEnumerable<User>> Participants { get; private set; } = new Bindable<IEnumerable<User>>(Enumerable.Empty<User>()); public BindableList<User> Participants { get; private set; } = new BindableList<User>();
[Cached] [Cached]
public Bindable<int> ParticipantCount { get; private set; } = new Bindable<int>(); public Bindable<int> ParticipantCount { get; private set; } = new Bindable<int>();
@ -130,7 +130,6 @@ namespace osu.Game.Online.Multiplayer
Type.Value = other.Type.Value; Type.Value = other.Type.Value;
MaxParticipants.Value = other.MaxParticipants.Value; MaxParticipants.Value = other.MaxParticipants.Value;
ParticipantCount.Value = other.ParticipantCount.Value; ParticipantCount.Value = other.ParticipantCount.Value;
Participants.Value = other.Participants.Value.ToArray();
EndDate.Value = other.EndDate.Value; EndDate.Value = other.EndDate.Value;
if (DateTimeOffset.Now >= EndDate.Value) if (DateTimeOffset.Now >= EndDate.Value)
@ -142,6 +141,10 @@ namespace osu.Game.Online.Multiplayer
else if (other.Playlist.Count > 0) else if (other.Playlist.Count > 0)
Playlist.First().ID = other.Playlist.First().ID; Playlist.First().ID = other.Playlist.First().ID;
foreach (var removedItem in Participants.Except(other.Participants).ToArray())
Participants.Remove(removedItem);
Participants.AddRange(other.Participants.Except(Participants).ToArray());
Position = other.Position; Position = other.Position;
} }

View File

@ -51,9 +51,9 @@ namespace osu.Game.Screens.Multi.Match.Components
}, },
}; };
Participants.BindValueChanged(participants => Participants.ItemsAdded += users =>
{ {
usersFlow.Children = participants.NewValue.Select(u => usersFlow.AddRange(users.Select(u =>
{ {
var panel = new UserPanel(u) var panel = new UserPanel(u)
{ {
@ -65,8 +65,13 @@ namespace osu.Game.Screens.Multi.Match.Components
panel.OnLoadComplete += d => d.FadeInFromZero(60); panel.OnLoadComplete += d => d.FadeInFromZero(60);
return panel; return panel;
}).ToList(); }).ToList());
}, true); };
Participants.ItemsRemoved += users =>
{
usersFlow.RemoveAll(p => users.Contains(p.User));
};
} }
} }
} }

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Collections.Generic;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -35,7 +34,7 @@ namespace osu.Game.Screens.Multi
protected Bindable<PlaylistItem> CurrentItem { get; private set; } protected Bindable<PlaylistItem> CurrentItem { get; private set; }
[Resolved(typeof(Room))] [Resolved(typeof(Room))]
protected Bindable<IEnumerable<User>> Participants { get; private set; } protected BindableList<User> Participants { get; private set; }
[Resolved(typeof(Room))] [Resolved(typeof(Room))]
protected Bindable<int> ParticipantCount { get; private set; } protected Bindable<int> ParticipantCount { get; private set; }

View File

@ -26,11 +26,12 @@ namespace osu.Game.Users
{ {
public class UserPanel : OsuClickableContainer, IHasContextMenu public class UserPanel : OsuClickableContainer, IHasContextMenu
{ {
private readonly User user;
private const float height = 100; private const float height = 100;
private const float content_padding = 10; private const float content_padding = 10;
private const float status_height = 30; private const float status_height = 30;
public readonly User User;
[Resolved(canBeNull: true)] [Resolved(canBeNull: true)]
private OsuColour colours { get; set; } private OsuColour colours { get; set; }
@ -54,7 +55,7 @@ namespace osu.Game.Users
if (user == null) if (user == null)
throw new ArgumentNullException(nameof(user)); throw new ArgumentNullException(nameof(user));
this.user = user; User = user;
Height = height - status_height; Height = height - status_height;
} }
@ -86,7 +87,7 @@ namespace osu.Game.Users
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
User = user, User = User,
}, 300, 5000) }, 300, 5000)
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
@ -106,7 +107,7 @@ namespace osu.Game.Users
new UpdateableAvatar new UpdateableAvatar
{ {
Size = new Vector2(height - status_height - content_padding * 2), Size = new Vector2(height - status_height - content_padding * 2),
User = user, User = User,
Masking = true, Masking = true,
CornerRadius = 5, CornerRadius = 5,
OpenOnClick = { Value = false }, OpenOnClick = { Value = false },
@ -125,7 +126,7 @@ namespace osu.Game.Users
{ {
new OsuSpriteText new OsuSpriteText
{ {
Text = user.Username, Text = User.Username,
Font = OsuFont.GetFont(weight: FontWeight.SemiBold, size: 18, italics: true), Font = OsuFont.GetFont(weight: FontWeight.SemiBold, size: 18, italics: true),
}, },
infoContainer = new FillFlowContainer infoContainer = new FillFlowContainer
@ -138,7 +139,7 @@ namespace osu.Game.Users
Spacing = new Vector2(5f, 0f), Spacing = new Vector2(5f, 0f),
Children = new Drawable[] Children = new Drawable[]
{ {
new UpdateableFlag(user.Country) new UpdateableFlag(User.Country)
{ {
Width = 30f, Width = 30f,
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
@ -191,12 +192,12 @@ namespace osu.Game.Users
} }
}); });
if (user.IsSupporter) if (User.IsSupporter)
{ {
infoContainer.Add(new SupporterIcon infoContainer.Add(new SupporterIcon
{ {
Height = 20f, Height = 20f,
SupportLevel = user.SupportLevel SupportLevel = User.SupportLevel
}); });
} }
@ -206,7 +207,7 @@ namespace osu.Game.Users
base.Action = ViewProfile = () => base.Action = ViewProfile = () =>
{ {
Action?.Invoke(); Action?.Invoke();
profile?.ShowUser(user); profile?.ShowUser(User);
}; };
} }