Rename variables and mak seconary tooltip type work again

This commit is contained in:
Dean Herbert 2023-11-10 11:52:34 +09:00
parent 615d8384ab
commit 7fc2050f72
No known key found for this signature in database
5 changed files with 69 additions and 29 deletions

View File

@ -102,9 +102,9 @@ public void TestClickableAvatarHover()
AddWaitStep("wait for tooltip to hide", 3);
}
private Drawable generateUser(string username, int id, CountryCode countryCode, string cover, bool onlyUsername, string? color = null)
private Drawable generateUser(string username, int id, CountryCode countryCode, string cover, bool showPanel, string? color = null)
{
return new ClickableAvatar(new APIUser
var user = new APIUser
{
Username = username,
Id = id,
@ -115,7 +115,9 @@ private Drawable generateUser(string username, int id, CountryCode countryCode,
{
Value = new UserStatusOnline()
},
})
};
return new ClickableAvatar(user, showPanel)
{
Width = 50,
Height = 50,
@ -125,7 +127,6 @@ private Drawable generateUser(string username, int id, CountryCode countryCode,
{
Type = EdgeEffectType.Shadow, Radius = 1, Colour = Color4.Black.Opacity(0.2f),
},
ShowUsernameOnly = onlyUsername,
};
}
}

View File

@ -115,7 +115,7 @@ public UserTile()
RelativeSizeAxes = Axes.Both,
Colour = Color4Extensions.FromHex(@"27252d"),
},
avatar = new UpdateableAvatar(showUsernameOnly: true) { RelativeSizeAxes = Axes.Both },
avatar = new UpdateableAvatar(showUserPanelOnHover: true) { RelativeSizeAxes = Axes.Both },
};
}
}

View File

@ -289,7 +289,7 @@ public APIUser User
set => avatar.User = value;
}
private readonly UpdateableAvatar avatar = new UpdateableAvatar(showUsernameOnly: true) { RelativeSizeAxes = Axes.Both };
private readonly UpdateableAvatar avatar = new UpdateableAvatar(showUserPanelOnHover: true) { RelativeSizeAxes = Axes.Both };
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colours)

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.Linq;
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.Game.Graphics.Containers;
using osu.Game.Graphics.Cursor;
using osu.Game.Localisation;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osuTK;
@ -15,15 +18,13 @@ namespace osu.Game.Users.Drawables
{
public partial class ClickableAvatar : OsuClickableContainer, IHasCustomTooltip<APIUser?>
{
// public ITooltip<APIUser> GetCustomTooltip() => new APIUserTooltip(user!) { ShowTooltip = TooltipEnabled };
public ITooltip<APIUser?> GetCustomTooltip() => new UserCardTooltip();
public ITooltip<APIUser?> GetCustomTooltip() => showCardOnHover ? new UserCardTooltip() : new NoCardTooltip();
public APIUser? TooltipContent { get; }
private readonly APIUser? user;
// TODO: reimplement.
public bool ShowUsernameOnly { get; set; }
private readonly bool showCardOnHover;
[Resolved]
private OsuGame? game { get; set; }
@ -32,12 +33,15 @@ public partial class ClickableAvatar : OsuClickableContainer, IHasCustomTooltip<
/// A clickable avatar for the specified user, with UI sounds included.
/// </summary>
/// <param name="user">The user. A null value will get a placeholder avatar.</param>
public ClickableAvatar(APIUser? user = null)
/// <param name="showCardOnHover"></param>
public ClickableAvatar(APIUser? user = null, bool showCardOnHover = false)
{
if (user?.Id != APIUser.SYSTEM_USER_ID)
Action = openProfile;
TooltipContent = this.user = user;
this.showCardOnHover = showCardOnHover;
TooltipContent = this.user = user ?? new GuestUser();
}
[BackgroundDependencyLoader]
@ -65,23 +69,59 @@ public partial class UserCardTooltip : VisibilityContainer, ITooltip<APIUser?>
public UserCardTooltip()
{
AutoSizeAxes = Axes.Both;
Masking = true;
CornerRadius = 5;
}
protected override void PopIn()
{
this.FadeIn(20, Easing.OutQuint);
}
protected override void PopOut() => this.FadeOut(80, Easing.OutQuint);
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;
public void SetContent(APIUser? content) => LoadComponentAsync(new UserGridPanel(content ?? new GuestUser())
private APIUser? user;
public void SetContent(APIUser? content)
{
Width = 300,
}, panel => Child = panel);
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?>
{
public NoCardTooltip()
{
var tooltip = new OsuTooltipContainer.OsuTooltip();
tooltip.SetContent(ContextMenuStrings.ViewProfile);
tooltip.Show();
Child = tooltip;
}
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;
public void SetContent(APIUser? content)
{
}
}
}
}

View File

@ -47,20 +47,20 @@ public APIUser? User
private readonly bool isInteractive;
private readonly bool showGuestOnNull;
private readonly bool showUsernameOnly;
private readonly bool showUserPanelOnHover;
/// <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="showUsernameOnly">If set to true, the user status panel will be displayed in the tooltip.</param>
/// <param name="showUserPanelOnHover">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 showUsernameOnly = false, bool showGuestOnNull = true)
public UpdateableAvatar(APIUser? user = null, bool isInteractive = true, bool showUserPanelOnHover = false, bool showGuestOnNull = true)
{
this.isInteractive = isInteractive;
this.showGuestOnNull = showGuestOnNull;
this.showUsernameOnly = showUsernameOnly;
this.showUserPanelOnHover = showUserPanelOnHover;
User = user;
}
@ -72,10 +72,9 @@ public UpdateableAvatar(APIUser? user = null, bool isInteractive = true, bool sh
if (isInteractive)
{
return new ClickableAvatar(user)
return new ClickableAvatar(user, showUserPanelOnHover)
{
RelativeSizeAxes = Axes.Both,
ShowUsernameOnly = showUsernameOnly
};
}