Add display queueing when multiple medals are granted in quick succession

This commit is contained in:
Bartłomiej Dach 2024-02-20 13:08:02 +01:00
parent 2e5b61302a
commit e4971ae121
No known key found for this signature in database
2 changed files with 48 additions and 15 deletions

View File

@ -29,23 +29,48 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test]
public void TestBasicAward()
{
AddStep("award medal", () => dummyAPI.NotificationsClient.Receive(new SocketMessage
awardMedal(new UserAchievementUnlock
{
Event = @"new",
Data = JObject.FromObject(new NewPrivateNotificationEvent
{
Name = @"user_achievement_unlock",
Details = JObject.FromObject(new UserAchievementUnlock
{
Title = "Time And A Half",
Description = "Having a right ol' time. One and a half of them, almost.",
Slug = @"all-intro-doubletime"
})
})
}));
Title = "Time And A Half",
Description = "Having a right ol' time. One and a half of them, almost.",
Slug = @"all-intro-doubletime"
});
AddUntilStep("overlay shown", () => overlay.State.Value, () => Is.EqualTo(Visibility.Visible));
AddRepeatStep("dismiss", () => InputManager.Key(Key.Escape), 2);
AddUntilStep("overlay hidden", () => overlay.State.Value, () => Is.EqualTo(Visibility.Hidden));
}
[Test]
public void TestMultipleMedalsInQuickSuccession()
{
awardMedal(new UserAchievementUnlock
{
Title = "Time And A Half",
Description = "Having a right ol' time. One and a half of them, almost.",
Slug = @"all-intro-doubletime"
});
awardMedal(new UserAchievementUnlock
{
Title = "S-Ranker",
Description = "Accuracy is really underrated.",
Slug = @"all-secret-rank-s"
});
awardMedal(new UserAchievementUnlock
{
Title = "500 Combo",
Description = "500 big ones! You're moving up in the world!",
Slug = @"osu-combo-500"
});
}
private void awardMedal(UserAchievementUnlock unlock) => AddStep("award medal", () => dummyAPI.NotificationsClient.Receive(new SocketMessage
{
Event = @"new",
Data = JObject.FromObject(new NewPrivateNotificationEvent
{
Name = @"user_achievement_unlock",
Details = JObject.FromObject(unlock)
})
}));
}
}

View File

@ -1,6 +1,7 @@
// 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 System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.ObjectExtensions;
@ -29,6 +30,8 @@ namespace osu.Game.Overlays
this.FadeOut();
}
private readonly Queue<MedalAnimation> queuedMedals = new Queue<MedalAnimation>();
[Resolved]
private IAPIProvider api { get; set; } = null!;
@ -71,7 +74,7 @@ namespace osu.Game.Overlays
Show();
LoadComponentAsync(new MedalAnimation(medal), animation =>
{
medalContainer.Add(animation);
queuedMedals.Enqueue(animation);
showingMedals = true;
});
}
@ -80,7 +83,12 @@ namespace osu.Game.Overlays
{
base.Update();
if (showingMedals && !medalContainer.Any())
if (!showingMedals || medalContainer.Any())
return;
if (queuedMedals.TryDequeue(out var nextMedal))
medalContainer.Add(nextMedal);
else
Hide();
}