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
1 changed files with 7 additions and 27 deletions

View File

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