2020-12-26 21:02:53 +08: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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2020-12-26 21:02:53 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2021-11-04 17:02:44 +08:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2020-12-26 21:02:53 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Users.Drawables
|
|
|
|
{
|
|
|
|
[LongRunningLoad]
|
|
|
|
public partial class DrawableAvatar : Sprite
|
|
|
|
{
|
2022-09-13 15:54:03 +08:00
|
|
|
private readonly IUser user;
|
2020-12-26 21:02:53 +08:00
|
|
|
|
|
|
|
/// <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>
|
2022-09-13 15:54:03 +08:00
|
|
|
public DrawableAvatar(IUser user = null)
|
2020-12-26 21:02:53 +08:00
|
|
|
{
|
|
|
|
this.user = user;
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
FillMode = FillMode.Fit;
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(LargeTextureStore textures)
|
|
|
|
{
|
2022-09-13 15:54:03 +08:00
|
|
|
if (user != null && user.OnlineID > 1)
|
2021-06-10 16:39:36 +08: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.
|
2022-09-13 15:54:03 +08:00
|
|
|
Texture = textures.Get((user as APIUser)?.AvatarUrl ?? $@"https://a.ppy.sh/{user.OnlineID}");
|
2021-03-28 02:59:33 +08:00
|
|
|
|
2020-12-26 21:02:53 +08:00
|
|
|
Texture ??= textures.Get(@"Online/avatar-guest");
|
|
|
|
}
|
2020-12-26 21:06:09 +08:00
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
this.FadeInFromZero(300, Easing.OutQuint);
|
|
|
|
}
|
2020-12-26 21:02:53 +08:00
|
|
|
}
|
|
|
|
}
|