mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Allow UpdateableAvatar to handle displaying username as tooltip
This commit is contained in:
@ -51,7 +51,7 @@ namespace osu.Game.Overlays.Chat.Tabs
|
|||||||
Child = new DelayedLoadWrapper(avatar = new ClickableAvatar(value.Users.First())
|
Child = new DelayedLoadWrapper(avatar = new ClickableAvatar(value.Users.First())
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
OpenOnClick = { Value = false },
|
OpenOnClick = false,
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
@ -58,12 +58,11 @@ namespace osu.Game.Overlays.Profile.Header
|
|||||||
Origin = Anchor.CentreLeft,
|
Origin = Anchor.CentreLeft,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
avatar = new UpdateableAvatar
|
avatar = new UpdateableAvatar(openOnClick: false)
|
||||||
{
|
{
|
||||||
Size = new Vector2(avatar_size),
|
Size = new Vector2(avatar_size),
|
||||||
Masking = true,
|
Masking = true,
|
||||||
CornerRadius = avatar_size * 0.25f,
|
CornerRadius = avatar_size * 0.25f,
|
||||||
OpenOnClick = { Value = false },
|
|
||||||
ShowGuestOnNull = false,
|
ShowGuestOnNull = false,
|
||||||
},
|
},
|
||||||
new Container
|
new Container
|
||||||
|
@ -32,14 +32,13 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
|
|
||||||
Add(new OpaqueBackground { Depth = 1 });
|
Add(new OpaqueBackground { Depth = 1 });
|
||||||
|
|
||||||
Flow.Add(avatar = new UpdateableAvatar
|
Flow.Add(avatar = new UpdateableAvatar(openOnClick: false)
|
||||||
{
|
{
|
||||||
Masking = true,
|
Masking = true,
|
||||||
Size = new Vector2(32),
|
Size = new Vector2(32),
|
||||||
Anchor = Anchor.CentreLeft,
|
Anchor = Anchor.CentreLeft,
|
||||||
Origin = Anchor.CentreLeft,
|
Origin = Anchor.CentreLeft,
|
||||||
CornerRadius = 4,
|
CornerRadius = 4,
|
||||||
OpenOnClick = { Value = false },
|
|
||||||
EdgeEffect = new EdgeEffectParameters
|
EdgeEffect = new EdgeEffectParameters
|
||||||
{
|
{
|
||||||
Type = EdgeEffectType.Shadow,
|
Type = EdgeEffectType.Shadow,
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// 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 osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
@ -13,16 +12,32 @@ namespace osu.Game.Users.Drawables
|
|||||||
{
|
{
|
||||||
public class ClickableAvatar : Container
|
public class ClickableAvatar : Container
|
||||||
{
|
{
|
||||||
|
private const string default_tooltip_text = "view profile";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether to open the user's profile when clicked.
|
/// Whether to open the user's profile when clicked.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly BindableBool OpenOnClick = new BindableBool(true);
|
public bool OpenOnClick
|
||||||
|
{
|
||||||
|
set => clickableArea.Enabled.Value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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
|
||||||
|
{
|
||||||
|
set => clickableArea.TooltipText = value ? (user?.Username ?? string.Empty) : default_tooltip_text;
|
||||||
|
}
|
||||||
|
|
||||||
private readonly User user;
|
private readonly User user;
|
||||||
|
|
||||||
[Resolved(CanBeNull = true)]
|
[Resolved(CanBeNull = true)]
|
||||||
private OsuGame game { get; set; }
|
private OsuGame game { get; set; }
|
||||||
|
|
||||||
|
private readonly ClickableArea clickableArea;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A clickable avatar for the specified user, with UI sounds included.
|
/// A clickable avatar for the specified user, with UI sounds included.
|
||||||
/// If <see cref="OpenOnClick"/> is <c>true</c>, clicking will open the user's profile.
|
/// If <see cref="OpenOnClick"/> is <c>true</c>, clicking will open the user's profile.
|
||||||
@ -31,35 +46,35 @@ namespace osu.Game.Users.Drawables
|
|||||||
public ClickableAvatar(User user = null)
|
public ClickableAvatar(User user = null)
|
||||||
{
|
{
|
||||||
this.user = user;
|
this.user = user;
|
||||||
}
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load(LargeTextureStore textures)
|
|
||||||
{
|
|
||||||
ClickableArea clickableArea;
|
|
||||||
Add(clickableArea = new ClickableArea
|
Add(clickableArea = new ClickableArea
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Action = openProfile
|
Action = openProfile
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(LargeTextureStore textures)
|
||||||
|
{
|
||||||
LoadComponentAsync(new DrawableAvatar(user), clickableArea.Add);
|
LoadComponentAsync(new DrawableAvatar(user), clickableArea.Add);
|
||||||
|
|
||||||
clickableArea.Enabled.BindTo(OpenOnClick);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openProfile()
|
private void openProfile()
|
||||||
{
|
{
|
||||||
if (!OpenOnClick.Value)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (user?.Id > 1)
|
if (user?.Id > 1)
|
||||||
game?.ShowUser(user.Id);
|
game?.ShowUser(user.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ClickableArea : OsuClickableContainer
|
private class ClickableArea : OsuClickableContainer
|
||||||
{
|
{
|
||||||
public override string TooltipText => Enabled.Value ? @"view profile" : null;
|
private string tooltip = default_tooltip_text;
|
||||||
|
|
||||||
|
public override string TooltipText
|
||||||
|
{
|
||||||
|
get => Enabled.Value ? tooltip : null;
|
||||||
|
set => tooltip = value;
|
||||||
|
}
|
||||||
|
|
||||||
protected override bool OnClick(ClickEvent e)
|
protected override bool OnClick(ClickEvent e)
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
// 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 osu.Framework.Bindables;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Effects;
|
using osu.Framework.Graphics.Effects;
|
||||||
@ -45,33 +44,38 @@ namespace osu.Game.Users.Drawables
|
|||||||
|
|
||||||
protected override double LoadDelay => 200;
|
protected override double LoadDelay => 200;
|
||||||
|
|
||||||
/// <summary>
|
private readonly bool openOnClick;
|
||||||
/// Whether to show a default guest representation on null user (as opposed to nothing).
|
private readonly bool showUsernameTooltip;
|
||||||
/// </summary>
|
private readonly bool showGuestOnNull;
|
||||||
public bool ShowGuestOnNull = true;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether to open the user's profile when clicked.
|
/// Construct a new UpdateableAvatar.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly BindableBool OpenOnClick = new BindableBool(true);
|
/// <param name="user">The initial user to display.</param>
|
||||||
|
/// <param name="openOnClick">Whether to open the user's profile when clicked.</param>
|
||||||
public UpdateableAvatar(User user = null)
|
/// <param name="showUsernameTooltip">Whether to show the username rather than "view profile" on the tooltip.</param>
|
||||||
|
/// <param name="showGuestOnNull">Whether to show a default guest representation on null user (as opposed to nothing).</param>
|
||||||
|
public UpdateableAvatar(User user = null, bool openOnClick = true, bool showUsernameTooltip = false, bool showGuestOnNull = true)
|
||||||
{
|
{
|
||||||
|
this.openOnClick = openOnClick;
|
||||||
|
this.showUsernameTooltip = showUsernameTooltip;
|
||||||
|
this.showGuestOnNull = showGuestOnNull;
|
||||||
|
|
||||||
User = user;
|
User = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Drawable CreateDrawable(User user)
|
protected override Drawable CreateDrawable(User user)
|
||||||
{
|
{
|
||||||
if (user == null && !ShowGuestOnNull)
|
if (user == null && !showGuestOnNull)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var avatar = new ClickableAvatar(user)
|
var avatar = new ClickableAvatar(user)
|
||||||
{
|
{
|
||||||
|
OpenOnClick = openOnClick,
|
||||||
|
ShowUsernameTooltip = showUsernameTooltip,
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
};
|
};
|
||||||
|
|
||||||
avatar.OpenOnClick.BindTo(OpenOnClick);
|
|
||||||
|
|
||||||
return avatar;
|
return avatar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,11 +48,7 @@ namespace osu.Game.Users
|
|||||||
statusIcon.FinishTransforms();
|
statusIcon.FinishTransforms();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected UpdateableAvatar CreateAvatar() => new UpdateableAvatar
|
protected UpdateableAvatar CreateAvatar() => new UpdateableAvatar(User, false);
|
||||||
{
|
|
||||||
User = User,
|
|
||||||
OpenOnClick = { Value = false }
|
|
||||||
};
|
|
||||||
|
|
||||||
protected UpdateableFlag CreateFlag() => new UpdateableFlag(User.Country)
|
protected UpdateableFlag CreateFlag() => new UpdateableFlag(User.Country)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user