2020-10-28 08:19:14 +00: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;
|
2020-11-06 07:38:57 +00:00
|
|
|
using osu.Game.Database;
|
2020-10-28 08:19:14 +00:00
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Online.Spectator;
|
2020-12-25 15:50:00 +00:00
|
|
|
using osu.Game.Screens.OnlinePlay.Match.Components;
|
2020-10-28 08:19:14 +00:00
|
|
|
using osu.Game.Screens.Play;
|
|
|
|
using osu.Game.Users;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Dashboard
|
|
|
|
{
|
|
|
|
internal class CurrentlyPlayingDisplay : CompositeDrawable
|
|
|
|
{
|
2020-11-04 06:29:14 +00:00
|
|
|
private readonly IBindableList<int> playingUsers = new BindableList<int>();
|
2020-10-28 08:19:14 +00:00
|
|
|
|
2020-11-02 12:09:47 +00:00
|
|
|
private FillFlowContainer<PlayingUserPanel> userFlow;
|
2020-10-28 08:19:14 +00:00
|
|
|
|
|
|
|
[Resolved]
|
2021-05-20 06:55:07 +00:00
|
|
|
private SpectatorClient spectatorClient { get; set; }
|
2020-10-28 08:19:14 +00:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
2020-11-02 12:09:47 +00:00
|
|
|
InternalChild = userFlow = new FillFlowContainer<PlayingUserPanel>
|
2020-10-28 08:19:14 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2020-11-06 04:08:07 +00:00
|
|
|
Padding = new MarginPadding(10),
|
2020-10-28 08:19:14 +00:00
|
|
|
Spacing = new Vector2(10),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private IAPIProvider api { get; set; }
|
|
|
|
|
2020-11-06 07:38:57 +00:00
|
|
|
[Resolved]
|
|
|
|
private UserLookupCache users { get; set; }
|
|
|
|
|
2020-10-28 08:19:14 +00:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2021-05-20 06:55:07 +00:00
|
|
|
playingUsers.BindTo(spectatorClient.PlayingUsers);
|
2020-11-09 03:22:54 +00:00
|
|
|
playingUsers.BindCollectionChanged(onUsersChanged, true);
|
|
|
|
}
|
2020-11-06 03:54:08 +00:00
|
|
|
|
2020-11-09 03:22:54 +00:00
|
|
|
private void onUsersChanged(object sender, NotifyCollectionChangedEventArgs e) => Schedule(() =>
|
|
|
|
{
|
|
|
|
switch (e.Action)
|
|
|
|
{
|
|
|
|
case NotifyCollectionChangedAction.Add:
|
2021-10-27 04:04:41 +00:00
|
|
|
foreach (int id in e.NewItems.OfType<int>().ToArray())
|
2020-11-09 03:22:54 +00:00
|
|
|
{
|
|
|
|
users.GetUserAsync(id).ContinueWith(u =>
|
2020-10-28 08:19:14 +00:00
|
|
|
{
|
2020-11-09 03:22:54 +00:00
|
|
|
if (u.Result == null) return;
|
|
|
|
|
|
|
|
Schedule(() =>
|
2020-10-28 08:19:14 +00:00
|
|
|
{
|
2020-11-09 03:22:54 +00:00
|
|
|
// user may no longer be playing.
|
|
|
|
if (!playingUsers.Contains(u.Result.Id))
|
2020-11-06 08:55:29 +00:00
|
|
|
return;
|
|
|
|
|
2020-11-09 03:22:54 +00:00
|
|
|
userFlow.Add(createUserPanel(u.Result));
|
2020-11-06 07:38:57 +00:00
|
|
|
});
|
2020-11-09 03:22:54 +00:00
|
|
|
});
|
|
|
|
}
|
2020-10-28 08:19:14 +00:00
|
|
|
|
2020-11-09 03:22:54 +00:00
|
|
|
break;
|
2020-10-28 08:19:14 +00:00
|
|
|
|
2020-11-09 03:22:54 +00:00
|
|
|
case NotifyCollectionChangedAction.Remove:
|
2021-10-27 04:04:41 +00:00
|
|
|
foreach (int u in e.OldItems.OfType<int>())
|
2020-11-09 03:22:54 +00:00
|
|
|
userFlow.FirstOrDefault(card => card.User.Id == u)?.Expire();
|
|
|
|
break;
|
2020-10-28 08:19:14 +00:00
|
|
|
|
2020-11-09 03:22:54 +00:00
|
|
|
case NotifyCollectionChangedAction.Reset:
|
|
|
|
userFlow.Clear();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2020-10-28 08:19:14 +00:00
|
|
|
|
2020-11-02 12:09:47 +00:00
|
|
|
private PlayingUserPanel createUserPanel(User user) =>
|
|
|
|
new PlayingUserPanel(user).With(panel =>
|
2020-10-28 08:19:14 +00:00
|
|
|
{
|
|
|
|
panel.Anchor = Anchor.TopCentre;
|
|
|
|
panel.Origin = Anchor.TopCentre;
|
|
|
|
});
|
2020-11-02 12:09:47 +00: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;
|
2020-11-10 03:33:07 +00:00
|
|
|
}
|
2020-11-02 12:09:47 +00:00
|
|
|
|
2020-11-10 03:33:07 +00:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(IAPIProvider api)
|
|
|
|
{
|
2020-11-02 12:09:47 +00:00
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
2020-11-03 18:03:48 +00:00
|
|
|
AutoSizeAxes = Axes.Y,
|
2020-11-02 12:09:47 +00:00
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(2),
|
2020-11-03 18:03:48 +00:00
|
|
|
Width = 290,
|
2020-11-02 12:09:47 +00:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2020-11-10 03:33:07 +00:00
|
|
|
new UserGridPanel(User)
|
2020-11-02 12:09:47 +00:00
|
|
|
{
|
2020-11-03 18:03:48 +00:00
|
|
|
RelativeSizeAxes = Axes.X,
|
2020-11-03 18:12:03 +00:00
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
2020-11-02 12:09:47 +00:00
|
|
|
},
|
2020-11-10 03:33:07 +00:00
|
|
|
new PurpleTriangleButton
|
2020-11-02 12:09:47 +00:00
|
|
|
{
|
2020-11-03 18:03:48 +00:00
|
|
|
RelativeSizeAxes = Axes.X,
|
2020-11-02 12:09:47 +00:00
|
|
|
Text = "Watch",
|
2020-11-03 18:12:03 +00:00
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
2021-04-01 13:08:52 +00:00
|
|
|
Action = () => game?.PerformFromScreen(s => s.Push(new SoloSpectator(User))),
|
2020-11-10 03:33:07 +00:00
|
|
|
Enabled = { Value = User.Id != api.LocalUser.Value.Id }
|
2020-11-02 12:09:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2020-10-28 08:19:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|