mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 17:02:55 +08:00
Add simple listing of currently playing users
This commit is contained in:
parent
ce9dd0c920
commit
32becb6882
95
osu.Game/Overlays/Dashboard/CurrentlyPlayingDisplay.cs
Normal file
95
osu.Game/Overlays/Dashboard/CurrentlyPlayingDisplay.cs
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
// 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;
|
||||||
|
using osu.Game.Screens.Play;
|
||||||
|
using osu.Game.Users;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Dashboard
|
||||||
|
{
|
||||||
|
internal class CurrentlyPlayingDisplay : CompositeDrawable
|
||||||
|
{
|
||||||
|
private IBindableList<int> playingUsers;
|
||||||
|
|
||||||
|
private FillFlowContainer<UserPanel> userFlow;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private SpectatorStreamingClient spectatorStreaming { get; set; }
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X;
|
||||||
|
AutoSizeAxes = Axes.Y;
|
||||||
|
|
||||||
|
InternalChild = userFlow = new FillFlowContainer<UserPanel>
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
AutoSizeAxes = Axes.Y,
|
||||||
|
Spacing = new Vector2(10),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private IAPIProvider api { get; set; }
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
playingUsers = spectatorStreaming.PlayingUsers.GetBoundCopy();
|
||||||
|
playingUsers.BindCollectionChanged((sender, e) => Schedule(() =>
|
||||||
|
{
|
||||||
|
switch (e.Action)
|
||||||
|
{
|
||||||
|
case NotifyCollectionChangedAction.Add:
|
||||||
|
foreach (var u in e.NewItems.OfType<int>())
|
||||||
|
{
|
||||||
|
var request = new GetUserRequest(u);
|
||||||
|
request.Success += user => Schedule(() =>
|
||||||
|
{
|
||||||
|
if (playingUsers.Contains((int)user.Id))
|
||||||
|
userFlow.Add(createUserPanel(user));
|
||||||
|
});
|
||||||
|
api.Queue(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private OsuGame game { get; set; }
|
||||||
|
|
||||||
|
private UserPanel createUserPanel(User user)
|
||||||
|
{
|
||||||
|
return new UserGridPanel(user).With(panel =>
|
||||||
|
{
|
||||||
|
panel.Anchor = Anchor.TopCentre;
|
||||||
|
panel.Origin = Anchor.TopCentre;
|
||||||
|
panel.Width = 290;
|
||||||
|
panel.Action = () => game.PerformFromScreen(s => s.Push(new Spectator(user)));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Dashboard
|
namespace osu.Game.Overlays.Dashboard
|
||||||
{
|
{
|
||||||
public class DashboardOverlayHeader : TabControlOverlayHeader<DashboardOverlayTabs>
|
public class DashboardOverlayHeader : TabControlOverlayHeader<DashboardOverlayTabs>
|
||||||
@ -20,6 +22,9 @@ namespace osu.Game.Overlays.Dashboard
|
|||||||
|
|
||||||
public enum DashboardOverlayTabs
|
public enum DashboardOverlayTabs
|
||||||
{
|
{
|
||||||
Friends
|
Friends,
|
||||||
|
|
||||||
|
[Description("Currently Playing")]
|
||||||
|
CurrentlyPlaying
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,6 +130,10 @@ namespace osu.Game.Overlays
|
|||||||
loadDisplay(new FriendDisplay());
|
loadDisplay(new FriendDisplay());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case DashboardOverlayTabs.CurrentlyPlaying:
|
||||||
|
loadDisplay(new CurrentlyPlayingDisplay());
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new NotImplementedException($"Display for {tab.NewValue} tab is not implemented");
|
throw new NotImplementedException($"Display for {tab.NewValue} tab is not implemented");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user