From b45d8c785cd662796c6098f72aadf589b99161e4 Mon Sep 17 00:00:00 2001 From: Joshua Hegedus Date: Mon, 6 Nov 2023 08:38:34 +0100 Subject: [PATCH] fixed review findings --- .../Online/TestSceneUserClickableAvatar.cs | 26 +++++++++++++++++++ osu.Game/Users/Drawables/ClickableAvatar.cs | 21 +++++++++++++++ osu.Game/Users/Drawables/UpdateableAvatar.cs | 1 + 3 files changed, 48 insertions(+) diff --git a/osu.Game.Tests/Visual/Online/TestSceneUserClickableAvatar.cs b/osu.Game.Tests/Visual/Online/TestSceneUserClickableAvatar.cs index 13f559ac09..a24581f7ed 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneUserClickableAvatar.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneUserClickableAvatar.cs @@ -78,6 +78,8 @@ namespace osu.Game.Tests.Visual.Online Type = EdgeEffectType.Shadow, Radius = 1, Colour = Color4.Black.Opacity(0.2f), }, }, + new ClickableAvatar(), + new ClickableAvatar(), }, }; }); @@ -120,6 +122,30 @@ namespace osu.Game.Tests.Visual.Online AddWaitStep("wait for tooltip to show", 5); AddStep("Hover out", () => InputManager.MoveMouseTo(new Vector2(0))); AddWaitStep("wait for tooltip to hide", 3); + + AddStep($"click null user {4}. {nameof(ClickableAvatar)}", () => + { + var targets = this.ChildrenOfType().ToList(); + if (targets.Count < 4) + return; + + InputManager.MoveMouseTo(targets[3]); + }); + AddWaitStep("wait for tooltip to show", 5); + AddStep("Hover out", () => InputManager.MoveMouseTo(new Vector2(0))); + AddWaitStep("wait for tooltip to hide", 3); + + AddStep($"click null user {5}. {nameof(ClickableAvatar)}", () => + { + var targets = this.ChildrenOfType().ToList(); + if (targets.Count < 5) + return; + + InputManager.MoveMouseTo(targets[4]); + }); + AddWaitStep("wait for tooltip to show", 5); + AddStep("Hover out", () => InputManager.MoveMouseTo(new Vector2(0))); + AddWaitStep("wait for tooltip to hide", 3); } } } diff --git a/osu.Game/Users/Drawables/ClickableAvatar.cs b/osu.Game/Users/Drawables/ClickableAvatar.cs index d6c6afba0b..0ed9f56cc7 100644 --- a/osu.Game/Users/Drawables/ClickableAvatar.cs +++ b/osu.Game/Users/Drawables/ClickableAvatar.cs @@ -1,12 +1,15 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; 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.Localisation; using osu.Game.Graphics.Containers; +using osu.Game.Localisation; using osu.Game.Online.API.Requests.Responses; using osuTK; @@ -21,6 +24,24 @@ namespace osu.Game.Users.Drawables Width = 300 }; + public override LocalisableString TooltipText + { + get + { + if (!Enabled.Value) + return string.Empty; + + return ShowUsernameTooltip ? (user?.Username ?? string.Empty) : ContextMenuStrings.ViewProfile; + } + set => throw new NotSupportedException(); + } + + /// + /// By default, the tooltip will show "view profile" as avatars are usually displayed next to a username. + /// Setting this to true exposes the username via tooltip for special cases where this is not true. + /// + public bool ShowUsernameTooltip { get; set; } + private readonly APIUser? user; [Resolved] diff --git a/osu.Game/Users/Drawables/UpdateableAvatar.cs b/osu.Game/Users/Drawables/UpdateableAvatar.cs index 58b3646995..711e7ab799 100644 --- a/osu.Game/Users/Drawables/UpdateableAvatar.cs +++ b/osu.Game/Users/Drawables/UpdateableAvatar.cs @@ -75,6 +75,7 @@ namespace osu.Game.Users.Drawables return new ClickableAvatar(user) { RelativeSizeAxes = Axes.Both, + ShowUsernameTooltip = showUsernameTooltip, }; } else