From e8f96b24013827b5c173159b960a0443d18ee87c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sat, 26 Dec 2020 14:02:53 +0100 Subject: [PATCH] Bring back DrawableAvatar as a simple sprite --- osu.Game/Users/Drawables/ClickableAvatar.cs | 22 ++---------- osu.Game/Users/Drawables/DrawableAvatar.cs | 39 +++++++++++++++++++++ 2 files changed, 42 insertions(+), 19 deletions(-) create mode 100644 osu.Game/Users/Drawables/DrawableAvatar.cs diff --git a/osu.Game/Users/Drawables/ClickableAvatar.cs b/osu.Game/Users/Drawables/ClickableAvatar.cs index 61af2d8e27..0fca9c7c9b 100644 --- a/osu.Game/Users/Drawables/ClickableAvatar.cs +++ b/osu.Game/Users/Drawables/ClickableAvatar.cs @@ -1,19 +1,16 @@ // Copyright (c) ppy Pty Ltd . 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 ClickableAvatar : Container { /// @@ -27,7 +24,7 @@ namespace osu.Game.Users.Drawables private OsuGame game { get; set; } /// - /// A clickable avatar for specified user, with UI sounds included. + /// A clickable avatar for the specified user, with UI sounds included. /// If is true, clicking will open the user's profile. /// /// The user. A null value will get a placeholder avatar. @@ -39,28 +36,15 @@ namespace osu.Game.Users.Drawables [BackgroundDependencyLoader] private void load(LargeTextureStore textures) { - if (textures == null) - throw new ArgumentNullException(nameof(textures)); - - 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 }); + LoadComponentAsync(new DrawableAvatar(user), clickableArea.Add); + clickableArea.Enabled.BindTo(OpenOnClick); } diff --git a/osu.Game/Users/Drawables/DrawableAvatar.cs b/osu.Game/Users/Drawables/DrawableAvatar.cs new file mode 100644 index 0000000000..81f6ad52d9 --- /dev/null +++ b/osu.Game/Users/Drawables/DrawableAvatar.cs @@ -0,0 +1,39 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Textures; + +namespace osu.Game.Users.Drawables +{ + [LongRunningLoad] + public class DrawableAvatar : Sprite + { + private readonly User user; + + /// + /// A simple, non-interactable avatar sprite for the specified user. + /// + /// The user. A null value will get a placeholder avatar. + 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 (user != null && user.Id > 1) + Texture = textures.Get($@"https://a.ppy.sh/{user.Id}"); + + Texture ??= textures.Get(@"Online/avatar-guest"); + } + } +}