Move click action out of user panel

This commit is contained in:
Dean Herbert 2020-11-02 21:09:47 +09:00
parent ed30756c19
commit c1d9a0c92c
3 changed files with 52 additions and 16 deletions

View File

@ -229,7 +229,7 @@ namespace osu.Game.Tests.Visual.Gameplay
AddUntilStep("wait for screen load", () => spectatorScreen.LoadState == LoadState.Loaded); AddUntilStep("wait for screen load", () => spectatorScreen.LoadState == LoadState.Loaded);
} }
internal class TestSpectatorStreamingClient : SpectatorStreamingClient public class TestSpectatorStreamingClient : SpectatorStreamingClient
{ {
public readonly User StreamingUser = new User { Id = 1234, Username = "Test user" }; public readonly User StreamingUser = new User { Id = 1234, Username = "Test user" };

View File

@ -11,6 +11,7 @@ using osu.Framework.Screens;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests;
using osu.Game.Online.Spectator; using osu.Game.Online.Spectator;
using osu.Game.Screens.Multi.Match.Components;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osu.Game.Users; using osu.Game.Users;
using osuTK; using osuTK;
@ -21,7 +22,7 @@ namespace osu.Game.Overlays.Dashboard
{ {
private IBindableList<int> playingUsers; private IBindableList<int> playingUsers;
private FillFlowContainer<UserPanel> userFlow; private FillFlowContainer<PlayingUserPanel> userFlow;
[Resolved] [Resolved]
private SpectatorStreamingClient spectatorStreaming { get; set; } private SpectatorStreamingClient spectatorStreaming { get; set; }
@ -32,7 +33,7 @@ namespace osu.Game.Overlays.Dashboard
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
InternalChild = userFlow = new FillFlowContainer<UserPanel> InternalChild = userFlow = new FillFlowContainer<PlayingUserPanel>
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
@ -78,19 +79,53 @@ namespace osu.Game.Overlays.Dashboard
}), true); }), true);
} }
[Resolved(canBeNull: true)] private PlayingUserPanel createUserPanel(User user) =>
private OsuGame game { get; set; } new PlayingUserPanel(user).With(panel =>
private UserPanel createUserPanel(User user)
{
return new UserGridPanel(user).With(panel =>
{ {
panel.Anchor = Anchor.TopCentre; panel.Anchor = Anchor.TopCentre;
panel.Origin = Anchor.TopCentre; panel.Origin = Anchor.TopCentre;
panel.Width = 290;
panel.ShowProfileOnClick = false;
panel.Action = () => game?.PerformFromScreen(s => s.Push(new Spectator(user)));
}); });
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
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(2),
Children = new Drawable[]
{
new UserGridPanel(user)
{
Width = 290,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
new PurpleTriangleButton
{
Width = 290,
Text = "Watch",
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Action = () => game?.PerformFromScreen(s => s.Push(new Spectator(user)))
}
}
},
};
}
} }
} }
} }

View File

@ -20,10 +20,12 @@ namespace osu.Game.Users
{ {
public readonly User User; public readonly User User;
/// <summary>
/// Perform an action in addition to showing the user's profile.
/// This should be used to perform auxiliary tasks and not as a primary action for clicking a user panel (to maintain a consistent UX).
/// </summary>
public new Action Action; public new Action Action;
public bool ShowProfileOnClick = true;
protected Action ViewProfile { get; private set; } protected Action ViewProfile { get; private set; }
protected Drawable Background { get; private set; } protected Drawable Background { get; private set; }
@ -70,8 +72,7 @@ namespace osu.Game.Users
base.Action = ViewProfile = () => base.Action = ViewProfile = () =>
{ {
Action?.Invoke(); Action?.Invoke();
if (ShowProfileOnClick) profileOverlay?.ShowUser(User);
profileOverlay?.ShowUser(User);
}; };
} }