2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-09-18 21:32:49 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2017-12-25 17:31:19 +08:00
|
|
|
|
using System;
|
2017-09-18 21:32:49 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2018-03-02 14:34:31 +08:00
|
|
|
|
using NUnit.Framework;
|
2017-09-18 21:32:49 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2017-12-27 18:42:44 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-12-26 00:50:05 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2017-09-18 21:32:49 +08:00
|
|
|
|
using osu.Framework.MathUtils;
|
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
|
using osu.Game.Overlays.Notifications;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
|
{
|
2018-03-02 14:34:31 +08:00
|
|
|
|
[TestFixture]
|
2017-12-20 20:47:45 +08:00
|
|
|
|
public class TestCaseNotificationOverlay : OsuTestCase
|
2017-09-18 21:32:49 +08:00
|
|
|
|
{
|
|
|
|
|
private readonly NotificationOverlay manager;
|
2017-12-23 21:33:43 +08:00
|
|
|
|
private readonly List<ProgressNotification> progressingNotifications = new List<ProgressNotification>();
|
2017-09-18 21:32:49 +08:00
|
|
|
|
|
2017-12-25 17:31:19 +08:00
|
|
|
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
|
|
|
|
{
|
2017-12-27 18:42:44 +08:00
|
|
|
|
typeof(NotificationSection),
|
|
|
|
|
typeof(SimpleNotification),
|
2017-12-25 17:31:19 +08:00
|
|
|
|
typeof(ProgressNotification),
|
|
|
|
|
typeof(ProgressCompletionNotification),
|
|
|
|
|
typeof(IHasCompletionTarget),
|
2017-12-27 18:42:44 +08:00
|
|
|
|
typeof(Notification)
|
2017-12-25 17:31:19 +08:00
|
|
|
|
};
|
|
|
|
|
|
2017-09-18 21:32:49 +08:00
|
|
|
|
public TestCaseNotificationOverlay()
|
|
|
|
|
{
|
|
|
|
|
progressingNotifications.Clear();
|
|
|
|
|
|
|
|
|
|
Content.Add(manager = new NotificationOverlay
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopRight,
|
2017-12-23 21:33:43 +08:00
|
|
|
|
Origin = Anchor.TopRight
|
2017-09-18 21:32:49 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-12-26 00:50:05 +08:00
|
|
|
|
SpriteText displayedCount = new SpriteText();
|
|
|
|
|
|
|
|
|
|
Content.Add(displayedCount);
|
|
|
|
|
|
2017-12-27 18:42:44 +08:00
|
|
|
|
void setState(Visibility state) => AddStep(state.ToString(), () => manager.State = state);
|
|
|
|
|
void checkProgressingCount(int expected) => AddAssert($"progressing count is {expected}", () => progressingNotifications.Count == expected);
|
|
|
|
|
|
2017-12-26 00:50:05 +08:00
|
|
|
|
manager.UnreadCount.ValueChanged += count => { displayedCount.Text = $"displayed count: {count}"; };
|
|
|
|
|
|
2017-12-27 18:42:44 +08:00
|
|
|
|
|
|
|
|
|
setState(Visibility.Visible);
|
2017-12-23 21:33:43 +08:00
|
|
|
|
AddStep(@"simple #1", sendHelloNotification);
|
|
|
|
|
AddStep(@"simple #2", sendAmazingNotification);
|
|
|
|
|
AddStep(@"progress #1", sendUploadProgress);
|
|
|
|
|
AddStep(@"progress #2", sendDownloadProgress);
|
2017-12-27 18:42:44 +08:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2017-12-27 19:26:14 +08:00
|
|
|
|
AddWaitStep(10);
|
2017-12-27 18:42:44 +08:00
|
|
|
|
|
|
|
|
|
checkProgressingCount(0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setState(Visibility.Visible);
|
|
|
|
|
|
|
|
|
|
//AddStep(@"barrage", () => sendBarrage());
|
2017-09-18 21:32:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-27 18:42:44 +08:00
|
|
|
|
private void sendBarrage(int remaining = 10)
|
2017-09-18 21:32:49 +08:00
|
|
|
|
{
|
|
|
|
|
switch (RNG.Next(0, 4))
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
2017-12-23 21:33:43 +08:00
|
|
|
|
sendHelloNotification();
|
2017-09-18 21:32:49 +08:00
|
|
|
|
break;
|
|
|
|
|
case 1:
|
2017-12-23 21:33:43 +08:00
|
|
|
|
sendAmazingNotification();
|
2017-09-18 21:32:49 +08:00
|
|
|
|
break;
|
|
|
|
|
case 2:
|
2017-12-23 21:33:43 +08:00
|
|
|
|
sendUploadProgress();
|
2017-09-18 21:32:49 +08:00
|
|
|
|
break;
|
|
|
|
|
case 3:
|
2017-12-23 21:33:43 +08:00
|
|
|
|
sendDownloadProgress();
|
2017-09-18 21:32:49 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (remaining > 0)
|
|
|
|
|
Scheduler.AddDelayed(() => sendBarrage(remaining - 1), 80);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
progressingNotifications.RemoveAll(n => n.State == ProgressNotificationState.Completed);
|
|
|
|
|
|
2017-10-20 11:21:18 +08:00
|
|
|
|
if (progressingNotifications.Count(n => n.State == ProgressNotificationState.Active) < 3)
|
2017-09-18 21:32:49 +08:00
|
|
|
|
{
|
2017-12-27 18:42:44 +08:00
|
|
|
|
var p = progressingNotifications.FirstOrDefault(n => n.State == ProgressNotificationState.Queued);
|
2017-10-20 11:21:18 +08:00
|
|
|
|
if (p != null)
|
|
|
|
|
p.State = ProgressNotificationState.Active;
|
2017-09-18 21:32:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var n in progressingNotifications.FindAll(n => n.State == ProgressNotificationState.Active))
|
|
|
|
|
{
|
|
|
|
|
if (n.Progress < 1)
|
2017-12-27 19:26:14 +08:00
|
|
|
|
n.Progress += (float)(Time.Elapsed / 400) * RNG.NextSingle();
|
2017-09-18 21:32:49 +08:00
|
|
|
|
else
|
|
|
|
|
n.State = ProgressNotificationState.Completed;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-23 21:33:43 +08:00
|
|
|
|
private void sendDownloadProgress()
|
2017-09-18 21:32:49 +08:00
|
|
|
|
{
|
2017-12-18 18:14:07 +08:00
|
|
|
|
var n = new ProgressNotification
|
|
|
|
|
{
|
|
|
|
|
Text = @"Downloading Haitai...",
|
|
|
|
|
CompletionText = "Downloaded Haitai!",
|
|
|
|
|
};
|
2017-09-18 21:32:49 +08:00
|
|
|
|
manager.Post(n);
|
|
|
|
|
progressingNotifications.Add(n);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-23 21:33:43 +08:00
|
|
|
|
private void sendUploadProgress()
|
2017-09-18 21:32:49 +08:00
|
|
|
|
{
|
2017-12-18 18:14:07 +08:00
|
|
|
|
var n = new ProgressNotification
|
|
|
|
|
{
|
|
|
|
|
Text = @"Uploading to BSS...",
|
|
|
|
|
CompletionText = "Uploaded to BSS!",
|
|
|
|
|
};
|
2017-09-18 21:32:49 +08:00
|
|
|
|
manager.Post(n);
|
|
|
|
|
progressingNotifications.Add(n);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-23 21:33:43 +08:00
|
|
|
|
private void sendAmazingNotification()
|
2017-09-18 21:32:49 +08:00
|
|
|
|
{
|
|
|
|
|
manager.Post(new SimpleNotification { Text = @"You are amazing" });
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-23 21:33:43 +08:00
|
|
|
|
private void sendHelloNotification()
|
2017-09-18 21:32:49 +08:00
|
|
|
|
{
|
|
|
|
|
manager.Post(new SimpleNotification { Text = @"Welcome to osu!. Enjoy your stay!" });
|
|
|
|
|
}
|
2017-12-27 18:42:44 +08:00
|
|
|
|
|
|
|
|
|
private void sendManyNotifications()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
|
manager.Post(new SimpleNotification { Text = @"Spam incoming!!" });
|
|
|
|
|
}
|
2017-09-18 21:32:49 +08:00
|
|
|
|
}
|
|
|
|
|
}
|