mirror of
https://github.com/ppy/osu
synced 2024-12-11 17:42:28 +00:00
Fix notification overlay layout and scheduled tasks being delayed
Closes #1295
This commit is contained in:
parent
9841fd6cd6
commit
7d0c94fd01
@ -5,6 +5,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.MathUtils;
|
using osu.Framework.MathUtils;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
@ -19,11 +20,12 @@ namespace osu.Game.Tests.Visual
|
|||||||
|
|
||||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
{
|
{
|
||||||
typeof(Notification),
|
typeof(NotificationSection),
|
||||||
|
typeof(SimpleNotification),
|
||||||
typeof(ProgressNotification),
|
typeof(ProgressNotification),
|
||||||
typeof(ProgressCompletionNotification),
|
typeof(ProgressCompletionNotification),
|
||||||
typeof(SimpleNotification),
|
|
||||||
typeof(IHasCompletionTarget),
|
typeof(IHasCompletionTarget),
|
||||||
|
typeof(Notification)
|
||||||
};
|
};
|
||||||
|
|
||||||
public TestCaseNotificationOverlay()
|
public TestCaseNotificationOverlay()
|
||||||
@ -40,17 +42,44 @@ namespace osu.Game.Tests.Visual
|
|||||||
|
|
||||||
Content.Add(displayedCount);
|
Content.Add(displayedCount);
|
||||||
|
|
||||||
|
void setState(Visibility state) => AddStep(state.ToString(), () => manager.State = state);
|
||||||
|
void checkProgressingCount(int expected) => AddAssert($"progressing count is {expected}", () => progressingNotifications.Count == expected);
|
||||||
|
|
||||||
manager.UnreadCount.ValueChanged += count => { displayedCount.Text = $"displayed count: {count}"; };
|
manager.UnreadCount.ValueChanged += count => { displayedCount.Text = $"displayed count: {count}"; };
|
||||||
|
|
||||||
AddStep(@"toggle", manager.ToggleVisibility);
|
|
||||||
|
setState(Visibility.Visible);
|
||||||
AddStep(@"simple #1", sendHelloNotification);
|
AddStep(@"simple #1", sendHelloNotification);
|
||||||
AddStep(@"simple #2", sendAmazingNotification);
|
AddStep(@"simple #2", sendAmazingNotification);
|
||||||
AddStep(@"progress #1", sendUploadProgress);
|
AddStep(@"progress #1", sendUploadProgress);
|
||||||
AddStep(@"progress #2", sendDownloadProgress);
|
AddStep(@"progress #2", sendDownloadProgress);
|
||||||
AddStep(@"barrage", () => sendBarrage());
|
|
||||||
|
checkProgressingCount(2);
|
||||||
|
|
||||||
|
setState(Visibility.Hidden);
|
||||||
|
|
||||||
|
AddRepeatStep(@"add many simple", sendManyNotifications, 3);
|
||||||
|
AddWaitStep(5);
|
||||||
|
|
||||||
|
checkProgressingCount(0);
|
||||||
|
|
||||||
|
AddStep(@"progress #3", sendUploadProgress);
|
||||||
|
|
||||||
|
checkProgressingCount(1);
|
||||||
|
|
||||||
|
AddAssert("Displayed count is 33", () => manager.UnreadCount.Value == 33);
|
||||||
|
|
||||||
|
AddWaitStep(5);
|
||||||
|
|
||||||
|
checkProgressingCount(0);
|
||||||
|
|
||||||
|
|
||||||
|
setState(Visibility.Visible);
|
||||||
|
|
||||||
|
//AddStep(@"barrage", () => sendBarrage());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendBarrage(int remaining = 100)
|
private void sendBarrage(int remaining = 10)
|
||||||
{
|
{
|
||||||
switch (RNG.Next(0, 4))
|
switch (RNG.Next(0, 4))
|
||||||
{
|
{
|
||||||
@ -80,7 +109,7 @@ namespace osu.Game.Tests.Visual
|
|||||||
|
|
||||||
if (progressingNotifications.Count(n => n.State == ProgressNotificationState.Active) < 3)
|
if (progressingNotifications.Count(n => n.State == ProgressNotificationState.Active) < 3)
|
||||||
{
|
{
|
||||||
var p = progressingNotifications.FirstOrDefault(n => n.IsAlive && n.State == ProgressNotificationState.Queued);
|
var p = progressingNotifications.FirstOrDefault(n => n.State == ProgressNotificationState.Queued);
|
||||||
if (p != null)
|
if (p != null)
|
||||||
p.State = ProgressNotificationState.Active;
|
p.State = ProgressNotificationState.Active;
|
||||||
}
|
}
|
||||||
@ -88,7 +117,7 @@ namespace osu.Game.Tests.Visual
|
|||||||
foreach (var n in progressingNotifications.FindAll(n => n.State == ProgressNotificationState.Active))
|
foreach (var n in progressingNotifications.FindAll(n => n.State == ProgressNotificationState.Active))
|
||||||
{
|
{
|
||||||
if (n.Progress < 1)
|
if (n.Progress < 1)
|
||||||
n.Progress += (float)(Time.Elapsed / 2000) * RNG.NextSingle();
|
n.Progress += (float)(Time.Elapsed / 200) * RNG.NextSingle();
|
||||||
else
|
else
|
||||||
n.State = ProgressNotificationState.Completed;
|
n.State = ProgressNotificationState.Completed;
|
||||||
}
|
}
|
||||||
@ -125,5 +154,11 @@ namespace osu.Game.Tests.Visual
|
|||||||
{
|
{
|
||||||
manager.Post(new SimpleNotification { Text = @"Welcome to osu!. Enjoy your stay!" });
|
manager.Post(new SimpleNotification { Text = @"Welcome to osu!. Enjoy your stay!" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendManyNotifications()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
manager.Post(new SimpleNotification { Text = @"Spam incoming!!" });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,10 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
private OsuSpriteText titleText;
|
private OsuSpriteText titleText;
|
||||||
private OsuSpriteText countText;
|
private OsuSpriteText countText;
|
||||||
|
|
||||||
|
// this is required to ensure correct layout and scheduling on children.
|
||||||
|
// the layout portion of this is being tracked as a framework issue (TODO).
|
||||||
|
protected override bool RequiresChildrenUpdate => true;
|
||||||
|
|
||||||
private ClearAllButton clearButton;
|
private ClearAllButton clearButton;
|
||||||
|
|
||||||
private FlowContainer<Notification> notifications;
|
private FlowContainer<Notification> notifications;
|
||||||
|
Loading…
Reference in New Issue
Block a user