Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ppy
GitHub Repository: ppy/osu
Path: blob/master/osu.Game/Overlays/Notifications/UserAvatarNotification.cs
2264 views
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Users.Drawables;

namespace osu.Game.Overlays.Notifications
{
    public abstract partial class UserAvatarNotification : SimpleNotification
    {
        private readonly APIUser? user;

        protected DrawableAvatar Avatar { get; private set; } = null!;

        protected UserAvatarNotification(APIUser? user, LocalisableString text = default)
        {
            this.user = user;

            Icon = default;
            Text = text;
        }

        [BackgroundDependencyLoader]
        private void load()
        {
            IconContent.Masking = true;
            IconContent.CornerRadius = CORNER_RADIUS;
            IconContent.ChangeChildDepth(IconDrawable, float.MinValue);

            LoadComponentAsync(Avatar = new DrawableAvatar(user)
            {
                FillMode = FillMode.Fill,
            }, IconContent.Add);
        }

        protected override void Update()
        {
            base.Update();
            IconContent.Width = IconContent.DrawHeight;
        }
    }
}