osu/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 09:19:50 +00:00
2019-02-21 10:04:31 +00:00
using osu.Framework.Bindables;
2018-04-13 09:19:50 +00: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 09:19:50 +00:00
public User User
{
get => user;
2018-04-13 09:19:50 +00:00
set
{
if (user?.Id == value?.Id)
return;
user = value;
if (IsLoaded)
updateAvatar();
}
}
2018-12-20 11:08:22 +00:00
/// <summary>
/// Whether to open the user's profile when clicked.
/// </summary>
public readonly BindableBool OpenOnClick = new BindableBool(true);
2018-04-13 09:19:50 +00:00
protected override void LoadComplete()
{
base.LoadComplete();
updateAvatar();
}
private void updateAvatar()
{
displayedAvatar?.FadeOut(300);
displayedAvatar?.Expire();
2018-12-20 11:08:22 +00:00
if (user != null || ShowGuestOnNull)
{
2018-12-20 11:08:22 +00:00
var avatar = new Avatar(user)
{
RelativeSizeAxes = Axes.Both,
};
2019-03-17 04:43:23 +00:00
avatar.OnLoadComplete += d => d.FadeInFromZero(300, Easing.OutQuint);
2018-12-20 11:08:22 +00:00
avatar.OpenOnClick.BindTo(OpenOnClick);
Add(displayedAvatar = new DelayedLoadWrapper(avatar));
}
2018-04-13 09:19:50 +00:00
}
}
}