1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 08:32:57 +08:00

testing the tooltip

This commit is contained in:
Joshua Hegedus 2023-11-06 14:52:06 +01:00
parent 034f53da4b
commit a01f6187f4
No known key found for this signature in database
GPG Key ID: 331D6A883C797319
3 changed files with 102 additions and 76 deletions

View File

@ -1,13 +1,11 @@
// 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.Online.API.Requests.Responses;
using osu.Game.Users;
using osu.Game.Users.Drawables;
@ -29,12 +27,9 @@ namespace osu.Game.Tests.Visual.Online
Spacing = new Vector2(10f),
Children = new[]
{
generateUser(@"peppy", 2, CountryCode.AU, @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg", "99EB47"),
generateUser(@"flyte", 3103765, CountryCode.JP, @"https://osu.ppy.sh/images/headers/profile-covers/c6.jpg"),
generateUser(@"flyte", 3103765, CountryCode.JP, @"https://osu.ppy.sh/images/headers/profile-covers/c6.jpg"),
new ClickableAvatar(),
new UpdateableAvatar(),
new UpdateableAvatar(),
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", false),
generateUser(@"joshika39", 17032217, CountryCode.RS, @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg", true),
},
};
});
@ -42,68 +37,68 @@ namespace osu.Game.Tests.Visual.Online
[Test]
public void TestClickableAvatarHover()
{
AddStep($"click {1}. {nameof(ClickableAvatar)}", () =>
{
var targets = this.ChildrenOfType<ClickableAvatar>().ToList();
if (targets.Count < 1)
return;
InputManager.MoveMouseTo(targets[0]);
});
AddWaitStep("wait for tooltip to show", 5);
AddStep("Hover out", () => InputManager.MoveMouseTo(new Vector2(0)));
AddWaitStep("wait for tooltip to hide", 3);
AddStep($"click {2}. {nameof(ClickableAvatar)}", () =>
{
var targets = this.ChildrenOfType<ClickableAvatar>().ToList();
if (targets.Count < 2)
return;
InputManager.MoveMouseTo(targets[1]);
});
AddWaitStep("wait for tooltip to show", 5);
AddStep("Hover out", () => InputManager.MoveMouseTo(new Vector2(0)));
AddWaitStep("wait for tooltip to hide", 3);
AddStep($"click {3}. {nameof(ClickableAvatar)}", () =>
{
var targets = this.ChildrenOfType<ClickableAvatar>().ToList();
if (targets.Count < 3)
return;
InputManager.MoveMouseTo(targets[2]);
});
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<ClickableAvatar>().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<ClickableAvatar>().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);
// AddStep($"click {1}. {nameof(ClickableAvatar)}", () =>
// {
// var targets = this.ChildrenOfType<ClickableAvatar>().ToList();
// if (targets.Count < 1)
// return;
//
// InputManager.MoveMouseTo(targets[0]);
// });
// AddWaitStep("wait for tooltip to show", 5);
// AddStep("Hover out", () => InputManager.MoveMouseTo(new Vector2(0)));
// AddWaitStep("wait for tooltip to hide", 3);
//
// AddStep($"click {2}. {nameof(ClickableAvatar)}", () =>
// {
// var targets = this.ChildrenOfType<ClickableAvatar>().ToList();
// if (targets.Count < 2)
// return;
//
// InputManager.MoveMouseTo(targets[1]);
// });
// AddWaitStep("wait for tooltip to show", 5);
// AddStep("Hover out", () => InputManager.MoveMouseTo(new Vector2(0)));
// AddWaitStep("wait for tooltip to hide", 3);
//
// AddStep($"click {3}. {nameof(ClickableAvatar)}", () =>
// {
// var targets = this.ChildrenOfType<ClickableAvatar>().ToList();
// if (targets.Count < 3)
// return;
//
// InputManager.MoveMouseTo(targets[2]);
// });
// 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<ClickableAvatar>().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<ClickableAvatar>().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);
}
private Drawable generateUser(string username, int id, CountryCode countryCode, string cover, string? color = null)
private Drawable generateUser(string username, int id, CountryCode countryCode, string cover, bool isTooltipEnabled, string? color = null)
{
return new ClickableAvatar(new APIUser
{
@ -115,7 +110,7 @@ namespace osu.Game.Tests.Visual.Online
Status =
{
Value = new UserStatusOnline()
}
},
})
{
Width = 50,
@ -126,6 +121,7 @@ namespace osu.Game.Tests.Visual.Online
{
Type = EdgeEffectType.Shadow, Radius = 1, Colour = Color4.Black.Opacity(0.2f),
},
IsTooltipEnabled = isTooltipEnabled,
};
}
}

View File

@ -1,12 +1,15 @@
// 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;
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;
@ -14,14 +17,32 @@ namespace osu.Game.Users.Drawables
{
public partial class ClickableAvatar : OsuClickableContainer, IHasCustomTooltip<UserGridPanel>
{
public ITooltip<UserGridPanel> GetCustomTooltip() => new UserGridPanelTooltip(IsTooltipEnabled);
public ITooltip<UserGridPanel> GetCustomTooltip() => new UserGridPanelTooltip(this);
public UserGridPanel TooltipContent => new UserGridPanel(user!)
{
Width = 300
};
public bool IsTooltipEnabled;
public override LocalisableString TooltipText
{
get
{
if (!Enabled.Value)
return string.Empty;
return !IsTooltipEnabled ? (user?.Username ?? string.Empty) : ContextMenuStrings.ViewProfile;
}
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; }
public bool IsTooltipEnabled { get; set; }
private readonly APIUser? user;
@ -35,12 +56,16 @@ namespace osu.Game.Users.Drawables
public ClickableAvatar(APIUser? user = null)
{
this.user = user;
IsTooltipEnabled = true;
if (user?.Id != APIUser.SYSTEM_USER_ID)
Action = openProfile;
}
public void SetValue(out bool value)
{
value = IsTooltipEnabled;
}
[BackgroundDependencyLoader]
private void load()
{
@ -61,18 +86,22 @@ namespace osu.Game.Users.Drawables
return base.OnClick(e);
}
private partial class UserGridPanelTooltip : VisibilityContainer, ITooltip<UserGridPanel>
public partial class UserGridPanelTooltip : VisibilityContainer, ITooltip<UserGridPanel>
{
private readonly bool isEnabled;
private readonly ClickableAvatar parent;
private UserGridPanel? displayedUser;
private bool isEnabled;
public UserGridPanelTooltip(bool isEnabled = true)
public UserGridPanelTooltip(ClickableAvatar parent)
{
this.isEnabled = isEnabled;
this.parent = parent ?? throw new ArgumentNullException(nameof(parent));
isEnabled = this.parent.IsTooltipEnabled;
}
protected override void PopIn()
{
parent.SetValue(out isEnabled);
if (displayedUser is null || !isEnabled)
{
return;

View File

@ -75,6 +75,7 @@ namespace osu.Game.Users.Drawables
return new ClickableAvatar(user)
{
RelativeSizeAxes = Axes.Both,
IsTooltipEnabled = showUserPanel
};
}
else