mirror of
https://github.com/osukey/osukey.git
synced 2025-08-08 00:53:56 +09:00
Merge pull request #11323 from bdach/fix-gameplay-leaderboard-clickable-avatars
Fix gameplay leaderboard avatars being clickable
This commit is contained in:
@ -78,7 +78,7 @@ namespace osu.Game.Online.Leaderboards
|
|||||||
|
|
||||||
statisticsLabels = GetStatistics(score).Select(s => new ScoreComponentLabel(s)).ToList();
|
statisticsLabels = GetStatistics(score).Select(s => new ScoreComponentLabel(s)).ToList();
|
||||||
|
|
||||||
DrawableAvatar innerAvatar;
|
ClickableAvatar innerAvatar;
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
@ -115,7 +115,7 @@ namespace osu.Game.Online.Leaderboards
|
|||||||
Children = new[]
|
Children = new[]
|
||||||
{
|
{
|
||||||
avatar = new DelayedLoadWrapper(
|
avatar = new DelayedLoadWrapper(
|
||||||
innerAvatar = new DrawableAvatar(user)
|
innerAvatar = new ClickableAvatar(user)
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
CornerRadius = corner_radius,
|
CornerRadius = corner_radius,
|
||||||
|
@ -25,7 +25,7 @@ namespace osu.Game.Overlays.Chat.Tabs
|
|||||||
if (value.Type != ChannelType.PM)
|
if (value.Type != ChannelType.PM)
|
||||||
throw new ArgumentException("Argument value needs to have the targettype user!");
|
throw new ArgumentException("Argument value needs to have the targettype user!");
|
||||||
|
|
||||||
DrawableAvatar avatar;
|
ClickableAvatar avatar;
|
||||||
|
|
||||||
AddRange(new Drawable[]
|
AddRange(new Drawable[]
|
||||||
{
|
{
|
||||||
@ -48,7 +48,7 @@ namespace osu.Game.Overlays.Chat.Tabs
|
|||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Masking = true,
|
Masking = true,
|
||||||
Child = new DelayedLoadWrapper(avatar = new DrawableAvatar(value.Users.First())
|
Child = new DelayedLoadWrapper(avatar = new ClickableAvatar(value.Users.First())
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
OpenOnClick = { Value = false },
|
OpenOnClick = { Value = false },
|
||||||
|
@ -78,6 +78,8 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours)
|
private void load(OsuColour colours)
|
||||||
{
|
{
|
||||||
|
Container avatarContainer;
|
||||||
|
|
||||||
InternalChildren = new Drawable[]
|
InternalChildren = new Drawable[]
|
||||||
{
|
{
|
||||||
mainFillContainer = new Container
|
mainFillContainer = new Container
|
||||||
@ -152,7 +154,7 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
Spacing = new Vector2(4f, 0f),
|
Spacing = new Vector2(4f, 0f),
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new CircularContainer
|
avatarContainer = new CircularContainer
|
||||||
{
|
{
|
||||||
Masking = true,
|
Masking = true,
|
||||||
Anchor = Anchor.CentreLeft,
|
Anchor = Anchor.CentreLeft,
|
||||||
@ -166,11 +168,7 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
Alpha = 0.3f,
|
Alpha = 0.3f,
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Colour = colours.Gray4,
|
Colour = colours.Gray4,
|
||||||
},
|
}
|
||||||
new UpdateableAvatar(User)
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
usernameText = new OsuSpriteText
|
usernameText = new OsuSpriteText
|
||||||
@ -227,6 +225,8 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
LoadComponentAsync(new DrawableAvatar(User), avatarContainer.Add);
|
||||||
|
|
||||||
TotalScore.BindValueChanged(v => scoreText.Text = v.NewValue.ToString("N0"), true);
|
TotalScore.BindValueChanged(v => scoreText.Text = v.NewValue.ToString("N0"), true);
|
||||||
Accuracy.BindValueChanged(v => accuracyText.Text = v.NewValue.FormatAccuracy(), true);
|
Accuracy.BindValueChanged(v => accuracyText.Text = v.NewValue.FormatAccuracy(), true);
|
||||||
Combo.BindValueChanged(v => comboText.Text = $"{v.NewValue}x", true);
|
Combo.BindValueChanged(v => comboText.Text = $"{v.NewValue}x", true);
|
||||||
|
73
osu.Game/Users/Drawables/ClickableAvatar.cs
Normal file
73
osu.Game/Users/Drawables/ClickableAvatar.cs
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
// 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 osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Textures;
|
||||||
|
using osu.Framework.Input.Events;
|
||||||
|
using osu.Game.Graphics.Containers;
|
||||||
|
|
||||||
|
namespace osu.Game.Users.Drawables
|
||||||
|
{
|
||||||
|
public class ClickableAvatar : Container
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Whether to open the user's profile when clicked.
|
||||||
|
/// </summary>
|
||||||
|
public readonly BindableBool OpenOnClick = new BindableBool(true);
|
||||||
|
|
||||||
|
private readonly User user;
|
||||||
|
|
||||||
|
[Resolved(CanBeNull = true)]
|
||||||
|
private OsuGame game { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user">The user. A null value will get a placeholder avatar.</param>
|
||||||
|
public ClickableAvatar(User user = null)
|
||||||
|
{
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(LargeTextureStore textures)
|
||||||
|
{
|
||||||
|
ClickableArea clickableArea;
|
||||||
|
Add(clickableArea = new ClickableArea
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Action = openProfile
|
||||||
|
});
|
||||||
|
|
||||||
|
LoadComponentAsync(new DrawableAvatar(user), clickableArea.Add);
|
||||||
|
|
||||||
|
clickableArea.Enabled.BindTo(OpenOnClick);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openProfile()
|
||||||
|
{
|
||||||
|
if (!OpenOnClick.Value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (user?.Id > 1)
|
||||||
|
game?.ShowUser(user.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ClickableArea : OsuClickableContainer
|
||||||
|
{
|
||||||
|
public override string TooltipText => Enabled.Value ? @"view profile" : null;
|
||||||
|
|
||||||
|
protected override bool OnClick(ClickEvent e)
|
||||||
|
{
|
||||||
|
if (!Enabled.Value)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return base.OnClick(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,88 +1,45 @@
|
|||||||
// 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 System;
|
|
||||||
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.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
using osu.Framework.Input.Events;
|
|
||||||
using osu.Game.Graphics.Containers;
|
|
||||||
|
|
||||||
namespace osu.Game.Users.Drawables
|
namespace osu.Game.Users.Drawables
|
||||||
{
|
{
|
||||||
[LongRunningLoad]
|
[LongRunningLoad]
|
||||||
public class DrawableAvatar : Container
|
public class DrawableAvatar : Sprite
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Whether to open the user's profile when clicked.
|
|
||||||
/// </summary>
|
|
||||||
public readonly BindableBool OpenOnClick = new BindableBool(true);
|
|
||||||
|
|
||||||
private readonly User user;
|
private readonly User user;
|
||||||
|
|
||||||
[Resolved(CanBeNull = true)]
|
|
||||||
private OsuGame game { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An avatar for specified user.
|
/// A simple, non-interactable avatar sprite for the specified user.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="user">The user. A null value will get a placeholder avatar.</param>
|
/// <param name="user">The user. A null value will get a placeholder avatar.</param>
|
||||||
public DrawableAvatar(User user = null)
|
public DrawableAvatar(User user = null)
|
||||||
{
|
{
|
||||||
this.user = user;
|
this.user = user;
|
||||||
|
|
||||||
|
RelativeSizeAxes = Axes.Both;
|
||||||
|
FillMode = FillMode.Fit;
|
||||||
|
Anchor = Anchor.Centre;
|
||||||
|
Origin = Anchor.Centre;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(LargeTextureStore textures)
|
private void load(LargeTextureStore textures)
|
||||||
{
|
{
|
||||||
if (textures == null)
|
if (user != null && user.Id > 1)
|
||||||
throw new ArgumentNullException(nameof(textures));
|
Texture = textures.Get($@"https://a.ppy.sh/{user.Id}");
|
||||||
|
|
||||||
Texture texture = null;
|
Texture ??= textures.Get(@"Online/avatar-guest");
|
||||||
if (user != null && user.Id > 1) texture = textures.Get($@"https://a.ppy.sh/{user.Id}");
|
|
||||||
texture ??= textures.Get(@"Online/avatar-guest");
|
|
||||||
|
|
||||||
ClickableArea clickableArea;
|
|
||||||
Add(clickableArea = new ClickableArea
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Child = new Sprite
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Texture = texture,
|
|
||||||
FillMode = FillMode.Fit,
|
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre
|
|
||||||
},
|
|
||||||
Action = openProfile
|
|
||||||
});
|
|
||||||
|
|
||||||
clickableArea.Enabled.BindTo(OpenOnClick);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openProfile()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
if (!OpenOnClick.Value)
|
base.LoadComplete();
|
||||||
return;
|
this.FadeInFromZero(300, Easing.OutQuint);
|
||||||
|
|
||||||
if (user?.Id > 1)
|
|
||||||
game?.ShowUser(user.Id);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ClickableArea : OsuClickableContainer
|
|
||||||
{
|
|
||||||
public override string TooltipText => Enabled.Value ? @"view profile" : null;
|
|
||||||
|
|
||||||
protected override bool OnClick(ClickEvent e)
|
|
||||||
{
|
|
||||||
if (!Enabled.Value)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return base.OnClick(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,12 +65,11 @@ namespace osu.Game.Users.Drawables
|
|||||||
if (user == null && !ShowGuestOnNull)
|
if (user == null && !ShowGuestOnNull)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var avatar = new DrawableAvatar(user)
|
var avatar = new ClickableAvatar(user)
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
};
|
};
|
||||||
|
|
||||||
avatar.OnLoadComplete += d => d.FadeInFromZero(300, Easing.OutQuint);
|
|
||||||
avatar.OpenOnClick.BindTo(OpenOnClick);
|
avatar.OpenOnClick.BindTo(OpenOnClick);
|
||||||
|
|
||||||
return avatar;
|
return avatar;
|
||||||
|
Reference in New Issue
Block a user