1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 23:27:25 +08:00

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);
}
internal class TestSpectatorStreamingClient : SpectatorStreamingClient
public class TestSpectatorStreamingClient : SpectatorStreamingClient
{
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.Requests;
using osu.Game.Online.Spectator;
using osu.Game.Screens.Multi.Match.Components;
using osu.Game.Screens.Play;
using osu.Game.Users;
using osuTK;
@ -21,7 +22,7 @@ namespace osu.Game.Overlays.Dashboard
{
private IBindableList<int> playingUsers;
private FillFlowContainer<UserPanel> userFlow;
private FillFlowContainer<PlayingUserPanel> userFlow;
[Resolved]
private SpectatorStreamingClient spectatorStreaming { get; set; }
@ -32,7 +33,7 @@ namespace osu.Game.Overlays.Dashboard
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
InternalChild = userFlow = new FillFlowContainer<UserPanel>
InternalChild = userFlow = new FillFlowContainer<PlayingUserPanel>
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
@ -78,19 +79,53 @@ namespace osu.Game.Overlays.Dashboard
}), true);
}
[Resolved(canBeNull: true)]
private OsuGame game { get; set; }
private UserPanel createUserPanel(User user)
{
return new UserGridPanel(user).With(panel =>
private PlayingUserPanel createUserPanel(User user) =>
new PlayingUserPanel(user).With(panel =>
{
panel.Anchor = 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;
/// <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 bool ShowProfileOnClick = true;
protected Action ViewProfile { get; private set; }
protected Drawable Background { get; private set; }
@ -70,7 +72,6 @@ namespace osu.Game.Users
base.Action = ViewProfile = () =>
{
Action?.Invoke();
if (ShowProfileOnClick)
profileOverlay?.ShowUser(User);
};
}