diff --git a/osu.Game/Online/Multiplayer/MultiplayerClient.cs b/osu.Game/Online/Multiplayer/MultiplayerClient.cs index 92fc8a3dcf..986bc26716 100644 --- a/osu.Game/Online/Multiplayer/MultiplayerClient.cs +++ b/osu.Game/Online/Multiplayer/MultiplayerClient.cs @@ -11,6 +11,7 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Development; using osu.Framework.Graphics; +using osu.Framework.Graphics.Sprites; using osu.Game.Database; using osu.Game.Localisation; using osu.Game.Online.API; @@ -549,16 +550,14 @@ namespace osu.Game.Online.Multiplayer if (apiUser == null || apiRoom == null) return; - PostNotification?.Invoke( - new UserAvatarNotification(apiUser, NotificationsStrings.InvitedYouToTheMultiplayer(apiUser.Username, apiRoom.Name)) + PostNotification?.Invoke(new MultiplayerInvitationNotification(apiUser, apiRoom) + { + Activated = () => { - Activated = () => - { - PresentMatch?.Invoke(apiRoom, password); - return true; - } + PresentMatch?.Invoke(apiRoom, password); + return true; } - ); + }); Task getRoomAsync(long id) { @@ -982,5 +981,15 @@ namespace osu.Game.Online.Multiplayer }); return Task.CompletedTask; } + + private partial class MultiplayerInvitationNotification : UserAvatarNotification + { + protected override IconUsage CloseButtonIcon => FontAwesome.Solid.Times; + + public MultiplayerInvitationNotification(APIUser user, Room room) + : base(user, NotificationsStrings.InvitedYouToTheMultiplayer(user.Username, room.Name)) + { + } + } } } diff --git a/osu.Game/Overlays/Notifications/SimpleNotification.cs b/osu.Game/Overlays/Notifications/SimpleNotification.cs index 109b31ff71..517d7ead43 100644 --- a/osu.Game/Overlays/Notifications/SimpleNotification.cs +++ b/osu.Game/Overlays/Notifications/SimpleNotification.cs @@ -24,8 +24,7 @@ namespace osu.Game.Overlays.Notifications set { text = value; - if (textDrawable != null) - textDrawable.Text = text; + TextFlow.Text = text; } } @@ -37,8 +36,7 @@ namespace osu.Game.Overlays.Notifications set { icon = value; - if (iconDrawable != null) - iconDrawable.Icon = icon; + IconDrawable.Icon = icon; } } @@ -48,39 +46,6 @@ namespace osu.Game.Overlays.Notifications set => IconContent.Colour = value; } - private TextFlowContainer? textDrawable; - - private SpriteIcon? iconDrawable; - - [BackgroundDependencyLoader] - private void load(OsuColour colours, OverlayColourProvider colourProvider) - { - Light.Colour = colours.Green; - - IconContent.AddRange(new Drawable[] - { - new Box - { - RelativeSizeAxes = Axes.Both, - Colour = colourProvider.Background5, - }, - iconDrawable = new SpriteIcon - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Icon = icon, - Size = new Vector2(16), - } - }); - - Content.Add(textDrawable = new OsuTextFlowContainer(t => t.Font = t.Font.With(size: 14, weight: FontWeight.Medium)) - { - AutoSizeAxes = Axes.Y, - RelativeSizeAxes = Axes.X, - Text = text - }); - } - public override bool Read { get => base.Read; @@ -92,5 +57,42 @@ namespace osu.Game.Overlays.Notifications Light.FadeTo(value ? 0 : 1, 100); } } + + protected TextFlowContainer TextFlow { get; } + protected SpriteIcon IconDrawable { get; } + + private readonly Box iconBackground; + + public SimpleNotification() + { + IconContent.AddRange(new Drawable[] + { + iconBackground = new Box + { + RelativeSizeAxes = Axes.Both, + }, + IconDrawable = new SpriteIcon + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Icon = icon, + Size = new Vector2(16), + } + }); + + Content.Add(TextFlow = new OsuTextFlowContainer(t => t.Font = t.Font.With(size: 14, weight: FontWeight.Medium)) + { + AutoSizeAxes = Axes.Y, + RelativeSizeAxes = Axes.X, + Text = text + }); + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours, OverlayColourProvider colourProvider) + { + Light.Colour = colours.Green; + iconBackground.Colour = colourProvider.Background5; + } } } diff --git a/osu.Game/Overlays/Notifications/UserAvatarNotification.cs b/osu.Game/Overlays/Notifications/UserAvatarNotification.cs index 5a9241a2a1..fe69c47173 100644 --- a/osu.Game/Overlays/Notifications/UserAvatarNotification.cs +++ b/osu.Game/Overlays/Notifications/UserAvatarNotification.cs @@ -3,72 +3,40 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; -using osu.Framework.Graphics.Sprites; using osu.Framework.Localisation; -using osu.Game.Graphics; -using osu.Game.Graphics.Containers; using osu.Game.Online.API.Requests.Responses; using osu.Game.Users.Drawables; namespace osu.Game.Overlays.Notifications { - public partial class UserAvatarNotification : Notification + public partial class UserAvatarNotification : SimpleNotification { - private LocalisableString text; + private readonly APIUser? user; - public override LocalisableString Text - { - get => text; - set - { - text = value; - if (textDrawable != null) - textDrawable.Text = text; - } - } + protected DrawableAvatar Avatar { get; private set; } = null!; - private TextFlowContainer? textDrawable; - - private readonly APIUser user; - - public UserAvatarNotification(APIUser user, LocalisableString text) + public UserAvatarNotification(APIUser? user, LocalisableString text = default) { this.user = user; + + Icon = default; Text = text; } - protected override IconUsage CloseButtonIcon => FontAwesome.Solid.Times; - [BackgroundDependencyLoader] - private void load(OsuColour colours, OverlayColourProvider colourProvider) + private void load() { - Light.Colour = colours.Orange2; - - Content.Add(textDrawable = new OsuTextFlowContainer(t => t.Font = t.Font.With(size: 14, weight: FontWeight.Medium)) + if (user != null) { - AutoSizeAxes = Axes.Y, - RelativeSizeAxes = Axes.X, - Text = text - }); + IconContent.Masking = true; + IconContent.CornerRadius = CORNER_RADIUS; + IconContent.ChangeChildDepth(IconDrawable, float.MinValue); - IconContent.Masking = true; - IconContent.CornerRadius = CORNER_RADIUS; - - IconContent.AddRange(new Drawable[] - { - new Box + LoadComponentAsync(Avatar = new DrawableAvatar(user) { - RelativeSizeAxes = Axes.Both, - Colour = colourProvider.Background5, - }, - }); - - LoadComponentAsync(new DrawableAvatar(user) - { - FillMode = FillMode.Fill, - }, IconContent.Add); + FillMode = FillMode.Fill, + }, IconContent.Add); + } } } }