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

fixed tests

This commit is contained in:
Joshua Hegedus 2023-11-09 13:09:59 +01:00
parent 02966bc02f
commit ccb9ff826a
No known key found for this signature in database
GPG Key ID: 331D6A883C797319
5 changed files with 152 additions and 106 deletions

View File

@ -1,11 +1,13 @@
// 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;
@ -28,8 +30,10 @@ namespace osu.Game.Tests.Visual.Online
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", false),
generateUser(@"joshika39", 17032217, CountryCode.RS, @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg", true),
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()
},
};
});
@ -37,68 +41,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 user {1} with UserGridPanel {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 user {2} with username only. {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 user {3} with UserGridPanel {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, bool isTooltipEnabled, string? color = null)
private Drawable generateUser(string username, int id, CountryCode countryCode, string cover, bool onlyUsername, string? color = null)
{
return new ClickableAvatar(new APIUser
{
@ -121,7 +125,7 @@ namespace osu.Game.Tests.Visual.Online
{
Type = EdgeEffectType.Shadow, Radius = 1, Colour = Color4.Black.Opacity(0.2f),
},
IsTooltipEnabled = isTooltipEnabled,
ShowUsernameOnly = onlyUsername,
};
}
}

View File

@ -115,7 +115,7 @@ namespace osu.Game.Screens.OnlinePlay.Components
RelativeSizeAxes = Axes.Both,
Colour = Color4Extensions.FromHex(@"27252d"),
},
avatar = new UpdateableAvatar { RelativeSizeAxes = Axes.Both },
avatar = new UpdateableAvatar(showUsernameOnly: true) { RelativeSizeAxes = Axes.Both },
};
}
}

View File

@ -289,7 +289,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
set => avatar.User = value;
}
private readonly UpdateableAvatar avatar = new UpdateableAvatar { RelativeSizeAxes = Axes.Both };
private readonly UpdateableAvatar avatar = new UpdateableAvatar(showUsernameOnly: true) { RelativeSizeAxes = Axes.Both };
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colours)

View File

@ -1,44 +1,43 @@
// 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.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Graphics.Containers;
using osu.Game.Localisation;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API.Requests.Responses;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Users.Drawables
{
public partial class ClickableAvatar : OsuClickableContainer, IHasCustomTooltip<APIUser>
public partial class ClickableAvatar : OsuClickableContainer, IHasCustomTooltip<ClickableAvatar.APIUserTooltipContent>
{
public ITooltip<APIUser> GetCustomTooltip()
{
return new APIUserTooltip(user);
}
// public ITooltip<APIUser> GetCustomTooltip() => new APIUserTooltip(user!) { ShowTooltip = TooltipEnabled };
public ITooltip<APIUserTooltipContent> GetCustomTooltip() => new APIUserTooltip(new APIUserTooltipContent(user!));
public APIUser? TooltipContent => user;
public override LocalisableString TooltipText
{
get
{
if (!Enabled.Value)
return string.Empty;
return !IsTooltipEnabled ? (user?.Username ?? string.Empty) : ContextMenuStrings.ViewProfile;
}
set => throw new NotSupportedException();
}
public bool IsTooltipEnabled { get; set; }
public APIUserTooltipContent TooltipContent => content;
private readonly APIUserTooltipContent content;
private readonly APIUser? user;
private bool tooltipEnabled;
public override LocalisableString TooltipText => user!.Username;
public bool ShowUsernameOnly
{
get => tooltipEnabled;
set
{
tooltipEnabled = value;
content.ShowUsernameOnly = ShowUsernameOnly;
}
}
[Resolved]
private OsuGame? game { get; set; }
@ -53,11 +52,8 @@ namespace osu.Game.Users.Drawables
if (user?.Id != APIUser.SYSTEM_USER_ID)
Action = openProfile;
}
public void SetValue(out bool value)
{
value = IsTooltipEnabled;
content = new APIUserTooltipContent(user!, ShowUsernameOnly);
}
[BackgroundDependencyLoader]
@ -80,23 +76,57 @@ namespace osu.Game.Users.Drawables
return base.OnClick(e);
}
public partial class APIUserTooltip : VisibilityContainer, ITooltip<APIUser>
public partial class APIUserTooltip : VisibilityContainer, ITooltip<APIUserTooltipContent>
{
private APIUser? user;
public APIUserTooltip(APIUser? user)
private OsuSpriteText text;
private APIUserTooltipContent content;
public APIUserTooltip(APIUserTooltipContent content)
{
this.user = user;
this.content = content;
AutoSizeAxes = Axes.Both;
Masking = true;
CornerRadius = 5;
Child = new UserGridPanel(content.User)
{
Width = 300
};
text = new OsuSpriteText()
{
Text = this.content.User.Username
};
}
protected override void PopIn()
{
if (user is null)
if (content.ShowUsernameOnly)
{
return;
Child = new UserGridPanel(content.User)
{
Width = 300
};
}
else
{
Alpha = 0;
AutoSizeAxes = Axes.Both;
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Gray,
},
text = new OsuSpriteText()
{
Font = FrameworkFont.Regular.With(size: 16),
Padding = new MarginPadding(5),
Text = content.User.Username
}
};
}
Child = new UserGridPanel(user);
this.FadeIn(20, Easing.OutQuint);
}
@ -104,9 +134,22 @@ namespace osu.Game.Users.Drawables
public void Move(Vector2 pos) => Position = pos;
public void SetContent(APIUser user)
public void SetContent(APIUserTooltipContent content)
{
this.user = user;
this.content = content;
text.Text = this.content.User.Username;
}
}
public class APIUserTooltipContent
{
public APIUser User { get; }
public bool ShowUsernameOnly { get; set; }
public APIUserTooltipContent(APIUser user, bool showUsernameOnly = false)
{
User = user;
ShowUsernameOnly = showUsernameOnly;
}
}
}

View File

@ -47,20 +47,20 @@ namespace osu.Game.Users.Drawables
private readonly bool isInteractive;
private readonly bool showGuestOnNull;
private readonly bool showUserPanel;
private readonly bool showUsernameOnly;
/// <summary>
/// Construct a new UpdateableAvatar.
/// </summary>
/// <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="showUserPanel">If set to true, the user status panel will be displayed in the tooltip.</param>
/// <param name="showUsernameOnly">If set to true, the user status panel will be displayed in the tooltip.</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 showUserPanel = true, bool showGuestOnNull = true)
public UpdateableAvatar(APIUser? user = null, bool isInteractive = true, bool showUsernameOnly = false, bool showGuestOnNull = true)
{
this.isInteractive = isInteractive;
this.showGuestOnNull = showGuestOnNull;
this.showUserPanel = showUserPanel;
this.showUsernameOnly = showUsernameOnly;
User = user;
}
@ -75,7 +75,6 @@ namespace osu.Game.Users.Drawables
return new ClickableAvatar(user)
{
RelativeSizeAxes = Axes.Both,
IsTooltipEnabled = showUserPanel
};
}
else