2020-12-26 13:02:53 +00:00
|
|
|
// 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.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;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 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)
|
|
|
|
{
|
2021-03-30 08:03:01 +00:00
|
|
|
if (user != null && user.Id > 1)
|
2021-06-10 08:39:36 +00:00
|
|
|
// TODO: The fallback here should not need to exist. Users should be looked up and populated via UserLookupCache or otherwise
|
|
|
|
// in remaining cases where this is required (chat tabs, local leaderboard), at which point this should be removed.
|
|
|
|
Texture = textures.Get(user.AvatarUrl ?? $@"https://a.ppy.sh/{user.Id}");
|
2021-03-27 18:59:33 +00:00
|
|
|
|
2020-12-26 13:02:53 +00:00
|
|
|
Texture ??= textures.Get(@"Online/avatar-guest");
|
|
|
|
}
|
2020-12-26 13:06:09 +00:00
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
this.FadeInFromZero(300, Easing.OutQuint);
|
|
|
|
}
|
2020-12-26 13:02:53 +00:00
|
|
|
}
|
|
|
|
}
|