mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 12:57:36 +08:00
Merge branch 'master' into argon-skin-coverage
This commit is contained in:
commit
0c0093e641
86
osu.Game.Tests/Visual/Online/TestSceneUserClickableAvatar.cs
Normal file
86
osu.Game.Tests/Visual/Online/TestSceneUserClickableAvatar.cs
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
// 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.Linq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Effects;
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Game.Graphics.Cursor;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
using osu.Game.Users;
|
||||||
|
using osu.Game.Users.Drawables;
|
||||||
|
using osuTK;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Online
|
||||||
|
{
|
||||||
|
public partial class TestSceneUserClickableAvatar : OsuManualInputManagerTestScene
|
||||||
|
{
|
||||||
|
[SetUp]
|
||||||
|
public void SetUp() => Schedule(() =>
|
||||||
|
{
|
||||||
|
Child = new FillFlowContainer
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Spacing = new Vector2(10f),
|
||||||
|
Children = new[]
|
||||||
|
{
|
||||||
|
generateUser(@"peppy", 2, CountryCode.AU, @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg", false, "99EB47"),
|
||||||
|
generateUser(@"flyte", 3103765, CountryCode.JP, @"https://osu.ppy.sh/images/headers/profile-covers/c6.jpg", true),
|
||||||
|
generateUser(@"joshika39", 17032217, CountryCode.RS, @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg", false),
|
||||||
|
new UpdateableAvatar(),
|
||||||
|
new UpdateableAvatar()
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestClickableAvatarHover()
|
||||||
|
{
|
||||||
|
AddStep("hover avatar with user panel", () => InputManager.MoveMouseTo(this.ChildrenOfType<ClickableAvatar>().ElementAt(1)));
|
||||||
|
AddUntilStep("wait for tooltip to show", () => this.ChildrenOfType<ClickableAvatar.UserCardTooltip>().FirstOrDefault()?.State.Value == Visibility.Visible);
|
||||||
|
AddStep("hover out", () => InputManager.MoveMouseTo(new Vector2(0)));
|
||||||
|
AddUntilStep("wait for tooltip to hide", () => this.ChildrenOfType<ClickableAvatar.UserCardTooltip>().FirstOrDefault()?.State.Value == Visibility.Hidden);
|
||||||
|
|
||||||
|
AddStep("hover avatar without user panel", () => InputManager.MoveMouseTo(this.ChildrenOfType<ClickableAvatar>().ElementAt(0)));
|
||||||
|
AddUntilStep("wait for tooltip to show", () => this.ChildrenOfType<OsuTooltipContainer.OsuTooltip>().FirstOrDefault()?.State.Value == Visibility.Visible);
|
||||||
|
AddStep("hover out", () => InputManager.MoveMouseTo(new Vector2(0)));
|
||||||
|
AddUntilStep("wait for tooltip to hide", () => this.ChildrenOfType<OsuTooltipContainer.OsuTooltip>().FirstOrDefault()?.State.Value == Visibility.Hidden);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Drawable generateUser(string username, int id, CountryCode countryCode, string cover, bool showPanel, string? color = null)
|
||||||
|
{
|
||||||
|
var user = new APIUser
|
||||||
|
{
|
||||||
|
Username = username,
|
||||||
|
Id = id,
|
||||||
|
CountryCode = countryCode,
|
||||||
|
CoverUrl = cover,
|
||||||
|
Colour = color ?? "000000",
|
||||||
|
Status =
|
||||||
|
{
|
||||||
|
Value = new UserStatusOnline()
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return new ClickableAvatar(user, showPanel)
|
||||||
|
{
|
||||||
|
Width = 50,
|
||||||
|
Height = 50,
|
||||||
|
CornerRadius = 10,
|
||||||
|
Masking = true,
|
||||||
|
EdgeEffect = new EdgeEffectParameters
|
||||||
|
{
|
||||||
|
Type = EdgeEffectType.Shadow,
|
||||||
|
Radius = 1,
|
||||||
|
Colour = Color4.Black.Opacity(0.2f),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -74,7 +74,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Statistics
|
|||||||
|
|
||||||
#region Tooltip implementation
|
#region Tooltip implementation
|
||||||
|
|
||||||
public virtual ITooltip GetCustomTooltip() => null;
|
public virtual ITooltip GetCustomTooltip() => null!;
|
||||||
public virtual object TooltipContent => null;
|
public virtual object TooltipContent => null;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -55,7 +55,7 @@ namespace osu.Game.Overlays.BeatmapSet
|
|||||||
AutoSizeAxes = Axes.Both,
|
AutoSizeAxes = Axes.Both,
|
||||||
CornerRadius = 4,
|
CornerRadius = 4,
|
||||||
Masking = true,
|
Masking = true,
|
||||||
Child = avatar = new UpdateableAvatar(showGuestOnNull: false)
|
Child = avatar = new UpdateableAvatar(showUserPanelOnHover: true, showGuestOnNull: false)
|
||||||
{
|
{
|
||||||
Size = new Vector2(height),
|
Size = new Vector2(height),
|
||||||
},
|
},
|
||||||
|
@ -102,7 +102,7 @@ namespace osu.Game.Overlays.Comments
|
|||||||
Padding = new MarginPadding { Horizontal = WaveOverlayContainer.HORIZONTAL_PADDING, Vertical = 20 },
|
Padding = new MarginPadding { Horizontal = WaveOverlayContainer.HORIZONTAL_PADDING, Vertical = 20 },
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
avatar = new UpdateableAvatar(api.LocalUser.Value)
|
avatar = new UpdateableAvatar(api.LocalUser.Value, isInteractive: false)
|
||||||
{
|
{
|
||||||
Size = new Vector2(50),
|
Size = new Vector2(50),
|
||||||
CornerExponent = 2,
|
CornerExponent = 2,
|
||||||
|
@ -144,7 +144,7 @@ namespace osu.Game.Overlays.Comments
|
|||||||
Size = new Vector2(avatar_size),
|
Size = new Vector2(avatar_size),
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new UpdateableAvatar(Comment.User)
|
new UpdateableAvatar(Comment.User, showUserPanelOnHover: true)
|
||||||
{
|
{
|
||||||
Size = new Vector2(avatar_size),
|
Size = new Vector2(avatar_size),
|
||||||
Masking = true,
|
Masking = true,
|
||||||
|
@ -115,7 +115,7 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
|||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Colour = Color4Extensions.FromHex(@"27252d"),
|
Colour = Color4Extensions.FromHex(@"27252d"),
|
||||||
},
|
},
|
||||||
avatar = new UpdateableAvatar(showUsernameTooltip: true) { RelativeSizeAxes = Axes.Both },
|
avatar = new UpdateableAvatar(showUserPanelOnHover: true) { RelativeSizeAxes = Axes.Both },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -289,7 +289,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
|||||||
set => avatar.User = value;
|
set => avatar.User = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly UpdateableAvatar avatar = new UpdateableAvatar(showUsernameTooltip: true) { RelativeSizeAxes = Axes.Both };
|
private readonly UpdateableAvatar avatar = new UpdateableAvatar(showUserPanelOnHover: true) { RelativeSizeAxes = Axes.Both };
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OverlayColourProvider colours)
|
private void load(OverlayColourProvider colours)
|
||||||
|
@ -1,38 +1,31 @@
|
|||||||
// 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;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Cursor;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Framework.Localisation;
|
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
|
using osu.Game.Graphics.Cursor;
|
||||||
using osu.Game.Localisation;
|
using osu.Game.Localisation;
|
||||||
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Users.Drawables
|
namespace osu.Game.Users.Drawables
|
||||||
{
|
{
|
||||||
public partial class ClickableAvatar : OsuClickableContainer
|
public partial class ClickableAvatar : OsuClickableContainer, IHasCustomTooltip<APIUser?>
|
||||||
{
|
{
|
||||||
public override LocalisableString TooltipText
|
public ITooltip<APIUser?> GetCustomTooltip() => showCardOnHover ? new UserCardTooltip() : new NoCardTooltip();
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (!Enabled.Value)
|
|
||||||
return string.Empty;
|
|
||||||
|
|
||||||
return ShowUsernameTooltip ? (user?.Username ?? string.Empty) : ContextMenuStrings.ViewProfile;
|
public APIUser? TooltipContent { get; }
|
||||||
}
|
|
||||||
set => throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// By default, the tooltip will show "view profile" as avatars are usually displayed next to a username.
|
|
||||||
/// Setting this to <c>true</c> exposes the username via tooltip for special cases where this is not true.
|
|
||||||
/// </summary>
|
|
||||||
public bool ShowUsernameTooltip { get; set; }
|
|
||||||
|
|
||||||
private readonly APIUser? user;
|
private readonly APIUser? user;
|
||||||
|
|
||||||
|
private readonly bool showCardOnHover;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private OsuGame? game { get; set; }
|
private OsuGame? game { get; set; }
|
||||||
|
|
||||||
@ -40,12 +33,15 @@ namespace osu.Game.Users.Drawables
|
|||||||
/// A clickable avatar for the specified user, with UI sounds included.
|
/// A clickable avatar for the specified user, with UI sounds included.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="user">The user. A null value will get a placeholder avatar.</param>
|
/// <param name="user">The user. A null value will get a placeholder avatar.</param>
|
||||||
public ClickableAvatar(APIUser? user = null)
|
/// <param name="showCardOnHover">If set to true, the <see cref="UserGridPanel"/> will be shown for the tooltip</param>
|
||||||
|
public ClickableAvatar(APIUser? user = null, bool showCardOnHover = false)
|
||||||
{
|
{
|
||||||
this.user = user;
|
|
||||||
|
|
||||||
if (user?.Id != APIUser.SYSTEM_USER_ID)
|
if (user?.Id != APIUser.SYSTEM_USER_ID)
|
||||||
Action = openProfile;
|
Action = openProfile;
|
||||||
|
|
||||||
|
this.showCardOnHover = showCardOnHover;
|
||||||
|
|
||||||
|
TooltipContent = this.user = user ?? new GuestUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -67,5 +63,65 @@ namespace osu.Game.Users.Drawables
|
|||||||
|
|
||||||
return base.OnClick(e);
|
return base.OnClick(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public partial class UserCardTooltip : VisibilityContainer, ITooltip<APIUser?>
|
||||||
|
{
|
||||||
|
public UserCardTooltip()
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void PopIn() => this.FadeIn(150, Easing.OutQuint);
|
||||||
|
protected override void PopOut() => this.Delay(150).FadeOut(500, Easing.OutQuint);
|
||||||
|
|
||||||
|
public void Move(Vector2 pos) => Position = pos;
|
||||||
|
|
||||||
|
private APIUser? user;
|
||||||
|
|
||||||
|
public void SetContent(APIUser? content)
|
||||||
|
{
|
||||||
|
if (content == user && Children.Any())
|
||||||
|
return;
|
||||||
|
|
||||||
|
user = content;
|
||||||
|
|
||||||
|
if (user != null)
|
||||||
|
{
|
||||||
|
LoadComponentAsync(new UserGridPanel(user)
|
||||||
|
{
|
||||||
|
Width = 300,
|
||||||
|
}, panel => Child = panel);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var tooltip = new OsuTooltipContainer.OsuTooltip();
|
||||||
|
tooltip.SetContent(ContextMenuStrings.ViewProfile);
|
||||||
|
tooltip.Show();
|
||||||
|
|
||||||
|
Child = tooltip;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial class NoCardTooltip : VisibilityContainer, ITooltip<APIUser?>
|
||||||
|
{
|
||||||
|
private readonly OsuTooltipContainer.OsuTooltip tooltip;
|
||||||
|
|
||||||
|
public NoCardTooltip()
|
||||||
|
{
|
||||||
|
tooltip = new OsuTooltipContainer.OsuTooltip();
|
||||||
|
tooltip.SetContent(ContextMenuStrings.ViewProfile);
|
||||||
|
Child = tooltip;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void PopIn() => tooltip.Show();
|
||||||
|
protected override void PopOut() => tooltip.Hide();
|
||||||
|
|
||||||
|
public void Move(Vector2 pos) => Position = pos;
|
||||||
|
|
||||||
|
public void SetContent(APIUser? content)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,21 +46,24 @@ namespace osu.Game.Users.Drawables
|
|||||||
protected override double LoadDelay => 200;
|
protected override double LoadDelay => 200;
|
||||||
|
|
||||||
private readonly bool isInteractive;
|
private readonly bool isInteractive;
|
||||||
private readonly bool showUsernameTooltip;
|
|
||||||
private readonly bool showGuestOnNull;
|
private readonly bool showGuestOnNull;
|
||||||
|
private readonly bool showUserPanelOnHover;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Construct a new UpdateableAvatar.
|
/// Construct a new UpdateableAvatar.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="user">The initial user to display.</param>
|
/// <param name="user">The initial user to display.</param>
|
||||||
/// <param name="isInteractive">If set to true, hover/click sounds will play and clicking the avatar will open the user's profile.</param>
|
/// <param name="isInteractive">If set to true, hover/click sounds will play and clicking the avatar will open the user's profile.</param>
|
||||||
/// <param name="showUsernameTooltip">Whether to show the username rather than "view profile" on the tooltip. (note: this only applies if <paramref name="isInteractive"/> is also true)</param>
|
/// <param name="showUserPanelOnHover">
|
||||||
|
/// If set to true, the user status panel will be displayed in the tooltip.
|
||||||
|
/// Only has an effect if <see cref="isInteractive"/> is true.
|
||||||
|
/// </param>
|
||||||
/// <param name="showGuestOnNull">Whether to show a default guest representation on null user (as opposed to nothing).</param>
|
/// <param name="showGuestOnNull">Whether to show a default guest representation on null user (as opposed to nothing).</param>
|
||||||
public UpdateableAvatar(APIUser? user = null, bool isInteractive = true, bool showUsernameTooltip = false, bool showGuestOnNull = true)
|
public UpdateableAvatar(APIUser? user = null, bool isInteractive = true, bool showUserPanelOnHover = false, bool showGuestOnNull = true)
|
||||||
{
|
{
|
||||||
this.isInteractive = isInteractive;
|
this.isInteractive = isInteractive;
|
||||||
this.showUsernameTooltip = showUsernameTooltip;
|
|
||||||
this.showGuestOnNull = showGuestOnNull;
|
this.showGuestOnNull = showGuestOnNull;
|
||||||
|
this.showUserPanelOnHover = showUserPanelOnHover;
|
||||||
|
|
||||||
User = user;
|
User = user;
|
||||||
}
|
}
|
||||||
@ -72,19 +75,16 @@ namespace osu.Game.Users.Drawables
|
|||||||
|
|
||||||
if (isInteractive)
|
if (isInteractive)
|
||||||
{
|
{
|
||||||
return new ClickableAvatar(user)
|
return new ClickableAvatar(user, showUserPanelOnHover)
|
||||||
{
|
{
|
||||||
ShowUsernameTooltip = showUsernameTooltip,
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
return new DrawableAvatar(user)
|
||||||
{
|
{
|
||||||
return new DrawableAvatar(user)
|
RelativeSizeAxes = Axes.Both,
|
||||||
{
|
};
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,10 @@ using osuTK;
|
|||||||
|
|
||||||
namespace osu.Game.Users
|
namespace osu.Game.Users
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A user "card", commonly used in a grid layout or in popovers.
|
||||||
|
/// Comes with a preset height, but width must be specified.
|
||||||
|
/// </summary>
|
||||||
public partial class UserGridPanel : ExtendedUserPanel
|
public partial class UserGridPanel : ExtendedUserPanel
|
||||||
{
|
{
|
||||||
private const int margin = 10;
|
private const int margin = 10;
|
||||||
|
Loading…
Reference in New Issue
Block a user