// Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; namespace osu.Game.Users { /// /// An avatar which can update to a new user when needed. /// public class UpdateableAvatar : Container { private Drawable displayedAvatar; private User user; /// /// Whether to show a default guest representation on null user (as opposed to nothing). /// public bool ShowGuestOnNull = true; public User User { get { return user; } set { if (user?.Id == value?.Id) return; user = value; if (IsLoaded) updateAvatar(); } } /// /// Whether to open the user's profile when clicked. /// public readonly BindableBool OpenOnClick = new BindableBool(true); protected override void LoadComplete() { base.LoadComplete(); updateAvatar(); } private void updateAvatar() { displayedAvatar?.FadeOut(300); displayedAvatar?.Expire(); if (user != null || ShowGuestOnNull) { var avatar = new Avatar(user) { RelativeSizeAxes = Axes.Both, OnLoadComplete = d => d.FadeInFromZero(300, Easing.OutQuint), }; avatar.OpenOnClick.BindTo(OpenOnClick); Add(displayedAvatar = new DelayedLoadWrapper(avatar)); } } } }