1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 04:27:34 +08:00
osu-lazer/osu.Game/Users/UpdateableAvatar.cs

70 lines
1.8 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
namespace osu.Game.Users
{
/// <summary>
/// An avatar which can update to a new user when needed.
/// </summary>
public class UpdateableAvatar : Container
{
private Drawable displayedAvatar;
private User user;
/// <summary>
/// Whether to show a default guest representation on null user (as opposed to nothing).
/// </summary>
public bool ShowGuestOnNull = true;
2018-04-13 17:19:50 +08:00
public User User
{
get => user;
2018-04-13 17:19:50 +08:00
set
{
if (user?.Id == value?.Id)
return;
user = value;
if (IsLoaded)
updateAvatar();
}
}
2018-12-20 19:08:22 +08:00
/// <summary>
/// Whether to open the user's profile when clicked.
/// </summary>
public readonly BindableBool OpenOnClick = new BindableBool(true);
2018-04-13 17:19:50 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
updateAvatar();
}
private void updateAvatar()
{
displayedAvatar?.FadeOut(300);
displayedAvatar?.Expire();
2018-12-20 19:08:22 +08:00
if (user != null || ShowGuestOnNull)
{
2018-12-20 19:08:22 +08:00
var avatar = new Avatar(user)
{
RelativeSizeAxes = Axes.Both,
};
2019-03-17 12:43:23 +08:00
avatar.OnLoadComplete += d => d.FadeInFromZero(300, Easing.OutQuint);
2018-12-20 19:08:22 +08:00
avatar.OpenOnClick.BindTo(OpenOnClick);
Add(displayedAvatar = new DelayedLoadWrapper(avatar));
}
2018-04-13 17:19:50 +08:00
}
}
}