Display avatar in invitation notification

This commit is contained in:
Marvin Schürz 2023-10-02 23:10:51 +02:00
parent 251e4d4de9
commit e81695bcac
4 changed files with 99 additions and 5 deletions

View File

@ -4,13 +4,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Database;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API;
using osu.Game.Online.Multiplayer;
using osu.Game.Overlays;
using osu.Game.Overlays.Notifications;
@ -31,6 +35,8 @@ public partial class TestSceneNotificationOverlay : OsuManualInputManagerTestSce
public double TimeToCompleteProgress { get; set; } = 2000;
private readonly UserLookupCache userLookupCache = new TestUserLookupCache();
[SetUp]
public void SetUp() => Schedule(() =>
{
@ -60,6 +66,7 @@ public void TestBasicFlow()
AddStep(@"simple #2", sendAmazingNotification);
AddStep(@"progress #1", sendUploadProgress);
AddStep(@"progress #2", sendDownloadProgress);
AddStep(@"User notification", sendUserNotification);
checkProgressingCount(2);
@ -537,6 +544,16 @@ private void sendDownloadProgress()
progressingNotifications.Add(n);
}
private async void sendUserNotification()
{
var user = await userLookupCache.GetUserAsync(0).ConfigureAwait(true);
if (user == null) return;
var n = new UserAvatarNotification(user, $"{user.Username} is telling you to NOT download Haitai!");
notificationOverlay.Post(n);
}
private void sendUploadProgress()
{
var n = new ProgressNotification

View File

@ -450,10 +450,9 @@ async Task IMultiplayerClient.Invited(int invitedBy, MultiplayerRoom room)
Scheduler.Add(() =>
{
PostNotification?.Invoke(new SimpleNotification
{
Text = "You got invited into a multiplayer match by " + user.Username + "!",
});
PostNotification?.Invoke(
new UserAvatarNotification(user, $"{user.Username} invited you to a multiplayer match!")
);
});
}

View File

@ -113,7 +113,7 @@ private void load()
RelativeSizeAxes = Axes.X,
Children = new[]
{
new NotificationSection(AccountsStrings.NotificationsTitle, new[] { typeof(SimpleNotification) }),
new NotificationSection(AccountsStrings.NotificationsTitle, new[] { typeof(SimpleNotification), typeof(UserAvatarNotification) }),
new NotificationSection(NotificationsStrings.RunningTasks, new[] { typeof(ProgressNotification) }),
}
}

View File

@ -0,0 +1,78 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Extensions;
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
{
private LocalisableString text;
public override LocalisableString Text
{
get => text;
set
{
text = value;
if (textDrawable != null)
textDrawable.Text = text;
}
}
private TextFlowContainer? textDrawable;
private APIUser user;
public UserAvatarNotification(APIUser user, LocalisableString text)
{
this.user = user;
Text = text;
}
private DrawableAvatar? avatar;
protected override IconUsage CloseButtonIcon => FontAwesome.Solid.Times;
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
IconContent.Masking = true;
// Workaround for the corner radius on parent's mask breaking if we add masking to IconContent
IconContent.CornerRadius = 6;
IconContent.AddRange(new Drawable[]
{
new Box()
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background5,
},
});
avatar = new DrawableAvatar(user)
{
FillMode = FillMode.Fill,
};
LoadComponentAsync(avatar, IconContent.Add);
Content.Add(textDrawable = new OsuTextFlowContainer(t => t.Font = t.Font.With(size: 14, weight: FontWeight.Medium))
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Text = text
});
}
}
}