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:
parent
98f8b1d59a
commit
4cb9563af2
@ -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 @@ namespace osu.Game.Users
|
||||
|
||||
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 @@ namespace osu.Game.Users
|
||||
/// </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 @@ namespace osu.Game.Users
|
||||
avatar.OnLoadComplete += d => d.FadeInFromZero(300, Easing.OutQuint);
|
||||
avatar.OpenOnClick.BindTo(OpenOnClick);
|
||||
|
||||
Add(displayedAvatar = new DelayedLoadWrapper(avatar));
|
||||
return avatar;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user