1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-18 11:20:24 +08:00

Apply minor refactor to notification classes to be more flexible in usages

This commit is contained in:
Salman Alshamrani
2025-07-03 11:18:16 +03:00
committed by Dean Herbert
Unverified
parent 2a1cb46163
commit c2ace36348
3 changed files with 71 additions and 92 deletions
@@ -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<Room?> 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))
{
}
}
}
}
@@ -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;
}
}
}
@@ -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);
}
}
}
}