2020-10-28 16:19:14 +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.
|
|
|
|
|
|
|
|
using System.Collections.Specialized;
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Screens;
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Online.API.Requests;
|
|
|
|
using osu.Game.Online.Spectator;
|
2020-11-02 20:09:47 +08:00
|
|
|
using osu.Game.Screens.Multi.Match.Components;
|
2020-10-28 16:19:14 +08:00
|
|
|
using osu.Game.Screens.Play;
|
|
|
|
using osu.Game.Users;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Dashboard
|
|
|
|
{
|
|
|
|
internal class CurrentlyPlayingDisplay : CompositeDrawable
|
|
|
|
{
|
2020-11-04 14:29:14 +08:00
|
|
|
private readonly IBindableList<int> playingUsers = new BindableList<int>();
|
2020-10-28 16:19:14 +08:00
|
|
|
|
2020-11-02 20:09:47 +08:00
|
|
|
private FillFlowContainer<PlayingUserPanel> userFlow;
|
2020-10-28 16:19:14 +08:00
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private SpectatorStreamingClient spectatorStreaming { get; set; }
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
2020-11-02 20:09:47 +08:00
|
|
|
InternalChild = userFlow = new FillFlowContainer<PlayingUserPanel>
|
2020-10-28 16:19:14 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Spacing = new Vector2(10),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private IAPIProvider api { get; set; }
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2020-11-04 14:29:14 +08:00
|
|
|
playingUsers.BindTo(spectatorStreaming.PlayingUsers);
|
2020-10-28 16:19:14 +08:00
|
|
|
playingUsers.BindCollectionChanged((sender, e) => Schedule(() =>
|
|
|
|
{
|
|
|
|
switch (e.Action)
|
|
|
|
{
|
|
|
|
case NotifyCollectionChangedAction.Add:
|
2020-11-06 11:54:08 +08:00
|
|
|
var request = new GetUsersRequest(e.NewItems.OfType<int>().ToArray());
|
|
|
|
|
|
|
|
request.Success += users => Schedule(() =>
|
2020-10-28 16:19:14 +08:00
|
|
|
{
|
2020-11-06 11:54:08 +08:00
|
|
|
foreach (var user in users.Users)
|
2020-10-28 16:19:14 +08:00
|
|
|
{
|
2020-11-06 12:29:47 +08:00
|
|
|
if (playingUsers.Contains(user.Id))
|
2020-11-02 19:19:38 +08:00
|
|
|
userFlow.Add(createUserPanel(user));
|
2020-11-06 11:54:08 +08:00
|
|
|
}
|
|
|
|
});
|
2020-10-28 16:19:14 +08:00
|
|
|
|
2020-11-06 11:54:08 +08:00
|
|
|
api.Queue(request);
|
2020-10-28 16:19:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NotifyCollectionChangedAction.Remove:
|
|
|
|
foreach (var u in e.OldItems.OfType<int>())
|
|
|
|
userFlow.FirstOrDefault(card => card.User.Id == u)?.Expire();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NotifyCollectionChangedAction.Reset:
|
|
|
|
userFlow.Clear();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}), true);
|
|
|
|
}
|
|
|
|
|
2020-11-02 20:09:47 +08:00
|
|
|
private PlayingUserPanel createUserPanel(User user) =>
|
|
|
|
new PlayingUserPanel(user).With(panel =>
|
2020-10-28 16:19:14 +08:00
|
|
|
{
|
|
|
|
panel.Anchor = Anchor.TopCentre;
|
|
|
|
panel.Origin = Anchor.TopCentre;
|
|
|
|
});
|
2020-11-02 20:09:47 +08:00
|
|
|
|
|
|
|
private class PlayingUserPanel : CompositeDrawable
|
|
|
|
{
|
|
|
|
public readonly User User;
|
|
|
|
|
|
|
|
[Resolved(canBeNull: true)]
|
|
|
|
private OsuGame game { get; set; }
|
|
|
|
|
|
|
|
public PlayingUserPanel(User user)
|
|
|
|
{
|
|
|
|
User = user;
|
|
|
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
2020-11-04 02:03:48 +08:00
|
|
|
AutoSizeAxes = Axes.Y,
|
2020-11-02 20:09:47 +08:00
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(2),
|
2020-11-04 02:03:48 +08:00
|
|
|
Width = 290,
|
2020-11-02 20:09:47 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new UserGridPanel(user)
|
|
|
|
{
|
2020-11-04 02:03:48 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
2020-11-04 02:12:03 +08:00
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
2020-11-02 20:09:47 +08:00
|
|
|
},
|
|
|
|
new PurpleTriangleButton
|
|
|
|
{
|
2020-11-04 02:03:48 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
2020-11-02 20:09:47 +08:00
|
|
|
Text = "Watch",
|
2020-11-04 02:12:03 +08:00
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
2020-11-02 20:09:47 +08:00
|
|
|
Action = () => game?.PerformFromScreen(s => s.Push(new Spectator(user)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2020-10-28 16:19:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|