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.
|
|
|
|
|
2022-05-27 04:57:24 +08:00
|
|
|
using System.Collections.Generic;
|
2022-02-02 22:19:43 +08:00
|
|
|
using System.Collections.Specialized;
|
2022-01-25 23:21:54 +08:00
|
|
|
using System.Diagnostics;
|
2020-10-28 16:19:14 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2022-01-03 16:31:12 +08:00
|
|
|
using osu.Framework.Extensions;
|
2020-10-28 16:19:14 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-05-27 06:40:23 +08:00
|
|
|
using osu.Framework.Localisation;
|
2020-10-28 16:19:14 +08:00
|
|
|
using osu.Framework.Screens;
|
2020-11-06 15:38:57 +08:00
|
|
|
using osu.Game.Database;
|
2022-05-27 04:57:24 +08:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2020-10-28 16:19:14 +08:00
|
|
|
using osu.Game.Online.API;
|
2021-11-04 17:02:44 +08:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2020-10-28 16:19:14 +08:00
|
|
|
using osu.Game.Online.Spectator;
|
2022-04-18 16:49:28 +08:00
|
|
|
using osu.Game.Screens;
|
2020-12-25 23:50:00 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.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
|
|
|
|
{
|
2022-05-27 04:57:24 +08:00
|
|
|
private const float search_bar_height = 40;
|
|
|
|
private const float search_bar_width = 250;
|
|
|
|
|
2022-02-02 22:19:43 +08:00
|
|
|
private readonly IBindableList<int> playingUsers = new BindableList<int>();
|
2020-10-28 16:19:14 +08:00
|
|
|
|
2022-05-27 06:40:23 +08:00
|
|
|
private SearchContainer<PlayingUserPanel> userFlow;
|
2020-10-28 16:19:14 +08:00
|
|
|
|
2022-05-27 04:57:24 +08:00
|
|
|
private FocusedTextBox searchBar;
|
|
|
|
private Container<FocusedTextBox> searchBarContainer;
|
|
|
|
|
2020-10-28 16:19:14 +08:00
|
|
|
[Resolved]
|
2021-05-20 14:55:07 +08:00
|
|
|
private SpectatorClient spectatorClient { get; set; }
|
2020-10-28 16:19:14 +08:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
2022-05-27 04:57:24 +08:00
|
|
|
searchBarContainer = new Container<FocusedTextBox>
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Padding = new MarginPadding(10),
|
|
|
|
Child = searchBar = new FocusedTextBox
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Height = search_bar_height,
|
|
|
|
Width = search_bar_width,
|
|
|
|
|
|
|
|
Colour = OsuColour.Gray(0.8f),
|
|
|
|
|
|
|
|
PlaceholderText = "Search for User...",
|
|
|
|
HoldFocus = true,
|
|
|
|
ReleaseFocusOnCommit = true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-05-27 06:40:23 +08:00
|
|
|
userFlow = new SearchContainer<PlayingUserPanel>
|
2020-10-28 16:19:14 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2022-05-27 04:57:24 +08:00
|
|
|
Padding = new MarginPadding {
|
|
|
|
Top = 10 + 10 + search_bar_height,
|
|
|
|
Bottom = 10,
|
|
|
|
Right = 10,
|
|
|
|
Left = 10,
|
|
|
|
},
|
2020-10-28 16:19:14 +08:00
|
|
|
Spacing = new Vector2(10),
|
|
|
|
};
|
2022-05-27 04:57:24 +08:00
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
searchBarContainer,
|
|
|
|
userFlow,
|
|
|
|
};
|
|
|
|
|
|
|
|
searchBar.Current.ValueChanged += onSearchBarValueChanged;
|
2020-10-28 16:19:14 +08:00
|
|
|
}
|
|
|
|
|
2020-11-06 15:38:57 +08:00
|
|
|
[Resolved]
|
|
|
|
private UserLookupCache users { get; set; }
|
|
|
|
|
2020-10-28 16:19:14 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2022-02-02 22:19:43 +08:00
|
|
|
playingUsers.BindTo(spectatorClient.PlayingUsers);
|
|
|
|
playingUsers.BindCollectionChanged(onPlayingUsersChanged, true);
|
2020-11-09 11:22:54 +08:00
|
|
|
}
|
2020-11-06 11:54:08 +08:00
|
|
|
|
2022-05-27 04:57:24 +08:00
|
|
|
private void addCard(int userId)
|
|
|
|
{
|
|
|
|
users.GetUserAsync(userId).ContinueWith(task =>
|
|
|
|
{
|
|
|
|
var user = task.GetResultSafely();
|
|
|
|
|
|
|
|
if (user == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!user.Username.ToLower().Contains(searchBar.Text.ToLower()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
Schedule(() =>
|
|
|
|
{
|
|
|
|
// user may no longer be playing.
|
|
|
|
if (!playingUsers.Contains(user.Id))
|
|
|
|
return;
|
|
|
|
|
|
|
|
userFlow.Add(createUserPanel(user));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-05-27 06:40:23 +08:00
|
|
|
private void onSearchBarValueChanged(ValueChangedEvent<string> change) => userFlow.SearchTerm = searchBar.Text;
|
2022-05-27 04:57:24 +08:00
|
|
|
|
2022-02-02 22:19:43 +08:00
|
|
|
private void onPlayingUsersChanged(object sender, NotifyCollectionChangedEventArgs e) => Schedule(() =>
|
2020-11-09 11:22:54 +08:00
|
|
|
{
|
|
|
|
switch (e.Action)
|
|
|
|
{
|
2022-02-02 22:19:43 +08:00
|
|
|
case NotifyCollectionChangedAction.Add:
|
2022-01-25 23:21:54 +08:00
|
|
|
Debug.Assert(e.NewItems != null);
|
|
|
|
|
2022-02-02 22:19:43 +08:00
|
|
|
foreach (int userId in e.NewItems)
|
2022-05-27 04:57:24 +08:00
|
|
|
addCard(userId);
|
2020-10-28 16:19:14 +08:00
|
|
|
|
2020-11-09 11:22:54 +08:00
|
|
|
break;
|
2020-10-28 16:19:14 +08:00
|
|
|
|
2022-02-02 22:19:43 +08:00
|
|
|
case NotifyCollectionChangedAction.Remove:
|
2022-01-25 23:21:54 +08:00
|
|
|
Debug.Assert(e.OldItems != null);
|
2020-10-28 16:19:14 +08:00
|
|
|
|
2022-02-02 22:19:43 +08:00
|
|
|
foreach (int userId in e.OldItems)
|
2022-05-27 06:40:23 +08:00
|
|
|
userFlow.FirstOrDefault(card => card.User.Id == userId)?.Expire();
|
2020-11-09 11:22:54 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2020-10-28 16:19:14 +08:00
|
|
|
|
2021-11-04 17:02:44 +08:00
|
|
|
private PlayingUserPanel createUserPanel(APIUser user) =>
|
2020-11-02 20:09:47 +08:00
|
|
|
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
|
|
|
|
2022-05-27 06:40:23 +08:00
|
|
|
private class PlayingUserPanel : CompositeDrawable, IFilterable
|
2020-11-02 20:09:47 +08:00
|
|
|
{
|
2021-11-04 17:02:44 +08:00
|
|
|
public readonly APIUser User;
|
2022-05-27 06:40:23 +08:00
|
|
|
public IEnumerable<LocalisableString> FilterTerms => filterTerm;
|
2020-11-02 20:09:47 +08:00
|
|
|
|
|
|
|
[Resolved(canBeNull: true)]
|
2022-04-18 16:49:28 +08:00
|
|
|
private IPerformFromScreenRunner performer { get; set; }
|
2022-05-27 06:40:23 +08:00
|
|
|
private IEnumerable<LocalisableString> filterTerm;
|
|
|
|
|
|
|
|
public bool MatchingFilter
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value)
|
|
|
|
Show();
|
|
|
|
else
|
|
|
|
Hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool FilteringActive
|
|
|
|
{
|
|
|
|
set { }
|
|
|
|
}
|
2020-11-02 20:09:47 +08:00
|
|
|
|
2021-11-04 17:02:44 +08:00
|
|
|
public PlayingUserPanel(APIUser user)
|
2020-11-02 20:09:47 +08:00
|
|
|
{
|
|
|
|
User = user;
|
2022-05-27 06:40:23 +08:00
|
|
|
filterTerm = new LocalisableString[] { User.Username };
|
2020-11-02 20:09:47 +08:00
|
|
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
2020-11-10 11:33:07 +08:00
|
|
|
}
|
2020-11-02 20:09:47 +08:00
|
|
|
|
2020-11-10 11:33:07 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(IAPIProvider api)
|
|
|
|
{
|
2020-11-02 20:09:47 +08:00
|
|
|
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[]
|
|
|
|
{
|
2020-11-10 11:33:07 +08:00
|
|
|
new UserGridPanel(User)
|
2020-11-02 20:09:47 +08:00
|
|
|
{
|
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
|
|
|
},
|
2020-11-10 11:33:07 +08:00
|
|
|
new PurpleTriangleButton
|
2020-11-02 20:09:47 +08:00
|
|
|
{
|
2020-11-04 02:03:48 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
2022-04-21 13:09:51 +08:00
|
|
|
Text = "Spectate",
|
2020-11-04 02:12:03 +08:00
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
2022-04-18 16:49:28 +08:00
|
|
|
Action = () => performer?.PerformFromScreen(s => s.Push(new SoloSpectator(User))),
|
2020-11-10 11:33:07 +08:00
|
|
|
Enabled = { Value = User.Id != api.LocalUser.Value.Id }
|
2020-11-02 20:09:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2020-10-28 16:19:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|