1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 23:12:56 +08:00

Use ModelBackedDrawable in UpdateableAvatar

This commit is contained in:
iiSaLMaN 2019-06-17 07:16:38 +03:00 committed by GitHub
parent 98f8b1d59a
commit 4cb9563af2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,12 +10,8 @@ namespace osu.Game.Users
/// <summary> /// <summary>
/// An avatar which can update to a new user when needed. /// An avatar which can update to a new user when needed.
/// </summary> /// </summary>
public class UpdateableAvatar : Container public class UpdateableAvatar : ModelBackedDrawable<User>
{ {
private Drawable displayedAvatar;
private User user;
/// <summary> /// <summary>
/// Whether to show a default guest representation on null user (as opposed to nothing). /// Whether to show a default guest representation on null user (as opposed to nothing).
/// </summary> /// </summary>
@ -23,17 +19,8 @@ namespace osu.Game.Users
public User User public User User
{ {
get => user; get => Model;
set set => Model = value;
{
if (user?.Id == value?.Id)
return;
user = value;
if (IsLoaded)
updateAvatar();
}
} }
/// <summary> /// <summary>
@ -41,17 +28,8 @@ namespace osu.Game.Users
/// </summary> /// </summary>
public readonly BindableBool OpenOnClick = new BindableBool(true); public readonly BindableBool OpenOnClick = new BindableBool(true);
protected override void LoadComplete() protected override Drawable CreateDrawable(User user)
{ {
base.LoadComplete();
updateAvatar();
}
private void updateAvatar()
{
displayedAvatar?.FadeOut(300);
displayedAvatar?.Expire();
if (user != null || ShowGuestOnNull) if (user != null || ShowGuestOnNull)
{ {
var avatar = new Avatar(user) var avatar = new Avatar(user)
@ -62,8 +40,10 @@ namespace osu.Game.Users
avatar.OnLoadComplete += d => d.FadeInFromZero(300, Easing.OutQuint); avatar.OnLoadComplete += d => d.FadeInFromZero(300, Easing.OutQuint);
avatar.OpenOnClick.BindTo(OpenOnClick); avatar.OpenOnClick.BindTo(OpenOnClick);
Add(displayedAvatar = new DelayedLoadWrapper(avatar)); return avatar;
} }
return null;
} }
} }
} }