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

Merge pull request #11323 from bdach/fix-gameplay-leaderboard-clickable-avatars

Fix gameplay leaderboard avatars being clickable
This commit is contained in:
Dean Herbert 2020-12-27 20:40:47 +09:00 committed by GitHub
commit 7dd572fe9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 98 additions and 69 deletions

View File

@ -78,7 +78,7 @@ namespace osu.Game.Online.Leaderboards
statisticsLabels = GetStatistics(score).Select(s => new ScoreComponentLabel(s)).ToList();
DrawableAvatar innerAvatar;
ClickableAvatar innerAvatar;
Children = new Drawable[]
{
@ -115,7 +115,7 @@ namespace osu.Game.Online.Leaderboards
Children = new[]
{
avatar = new DelayedLoadWrapper(
innerAvatar = new DrawableAvatar(user)
innerAvatar = new ClickableAvatar(user)
{
RelativeSizeAxes = Axes.Both,
CornerRadius = corner_radius,

View File

@ -25,7 +25,7 @@ namespace osu.Game.Overlays.Chat.Tabs
if (value.Type != ChannelType.PM)
throw new ArgumentException("Argument value needs to have the targettype user!");
DrawableAvatar avatar;
ClickableAvatar avatar;
AddRange(new Drawable[]
{
@ -48,7 +48,7 @@ namespace osu.Game.Overlays.Chat.Tabs
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Masking = true,
Child = new DelayedLoadWrapper(avatar = new DrawableAvatar(value.Users.First())
Child = new DelayedLoadWrapper(avatar = new ClickableAvatar(value.Users.First())
{
RelativeSizeAxes = Axes.Both,
OpenOnClick = { Value = false },

View File

@ -78,6 +78,8 @@ namespace osu.Game.Screens.Play.HUD
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Container avatarContainer;
InternalChildren = new Drawable[]
{
mainFillContainer = new Container
@ -152,7 +154,7 @@ namespace osu.Game.Screens.Play.HUD
Spacing = new Vector2(4f, 0f),
Children = new Drawable[]
{
new CircularContainer
avatarContainer = new CircularContainer
{
Masking = true,
Anchor = Anchor.CentreLeft,
@ -166,11 +168,7 @@ namespace osu.Game.Screens.Play.HUD
Alpha = 0.3f,
RelativeSizeAxes = Axes.Both,
Colour = colours.Gray4,
},
new UpdateableAvatar(User)
{
RelativeSizeAxes = Axes.Both,
},
}
}
},
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);
Accuracy.BindValueChanged(v => accuracyText.Text = v.NewValue.FormatAccuracy(), true);
Combo.BindValueChanged(v => comboText.Text = $"{v.NewValue}x", true);

View 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);
}
}
}
}

View File

@ -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.
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers;
namespace osu.Game.Users.Drawables
{
[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;
[Resolved(CanBeNull = true)]
private OsuGame game { get; set; }
/// <summary>
/// An avatar for specified user.
/// A simple, non-interactable avatar sprite for the specified user.
/// </summary>
/// <param name="user">The user. A null value will get a placeholder avatar.</param>
public DrawableAvatar(User user = null)
{
this.user = user;
RelativeSizeAxes = Axes.Both;
FillMode = FillMode.Fit;
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
}
[BackgroundDependencyLoader]
private void load(LargeTextureStore textures)
{
if (textures == null)
throw new ArgumentNullException(nameof(textures));
if (user != null && user.Id > 1)
Texture = textures.Get($@"https://a.ppy.sh/{user.Id}");
Texture texture = null;
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);
Texture ??= textures.Get(@"Online/avatar-guest");
}
private void openProfile()
protected override void LoadComplete()
{
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);
}
base.LoadComplete();
this.FadeInFromZero(300, Easing.OutQuint);
}
}
}

View File

@ -65,12 +65,11 @@ namespace osu.Game.Users.Drawables
if (user == null && !ShowGuestOnNull)
return null;
var avatar = new DrawableAvatar(user)
var avatar = new ClickableAvatar(user)
{
RelativeSizeAxes = Axes.Both,
};
avatar.OnLoadComplete += d => d.FadeInFromZero(300, Easing.OutQuint);
avatar.OpenOnClick.BindTo(OpenOnClick);
return avatar;