osu/osu.Desktop.VisualTests/Tests/TestCaseNotificationManager.cs

113 lines
3.7 KiB
C#
Raw Normal View History

2017-02-10 07:26:43 +00:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using osu.Framework.Graphics;
2017-03-28 12:03:34 +00:00
using osu.Framework.Testing;
2017-02-10 07:26:43 +00:00
using osu.Framework.MathUtils;
using osu.Game.Overlays;
using System.Linq;
using osu.Game.Overlays.Notifications;
2017-02-26 20:31:40 +00:00
using osu.Framework.Graphics.Containers;
2017-02-10 07:26:43 +00:00
namespace osu.Desktop.VisualTests.Tests
{
2017-03-07 01:59:19 +00:00
internal class TestCaseNotificationManager : TestCase
2017-02-10 07:26:43 +00:00
{
public override string Description => @"I handle notifications";
2017-07-08 09:17:47 +00:00
private readonly NotificationManager manager;
2017-02-10 07:26:43 +00:00
public TestCaseNotificationManager()
2017-02-10 07:26:43 +00:00
{
progressingNotifications.Clear();
Content.Add(manager = new NotificationManager
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
});
2017-03-31 08:55:07 +00:00
AddToggleStep(@"show", state => manager.State = state ? Visibility.Visible : Visibility.Hidden);
2017-02-10 07:26:43 +00:00
2017-03-31 08:55:07 +00:00
AddStep(@"simple #1", sendNotification1);
AddStep(@"simple #2", sendNotification2);
AddStep(@"progress #1", sendProgress1);
AddStep(@"progress #2", sendProgress2);
AddStep(@"barrage", () => sendBarrage());
2017-02-10 07:26:43 +00:00
}
private void sendBarrage(int remaining = 100)
{
switch (RNG.Next(0, 4))
{
case 0:
sendNotification1();
break;
case 1:
sendNotification2();
break;
case 2:
sendProgress1();
break;
case 3:
sendProgress2();
break;
}
if (remaining > 0)
Scheduler.AddDelayed(() => sendBarrage(remaining - 1), 80);
2017-02-10 07:26:43 +00:00
}
protected override void Update()
{
base.Update();
progressingNotifications.RemoveAll(n => n.State == ProgressNotificationState.Completed);
while (progressingNotifications.Count(n => n.State == ProgressNotificationState.Active) < 3)
{
var p = progressingNotifications.FirstOrDefault(n => n.IsLoaded && n.State == ProgressNotificationState.Queued);
if (p == null)
break;
p.State = ProgressNotificationState.Active;
}
foreach (var n in progressingNotifications.FindAll(n => n.State == ProgressNotificationState.Active))
{
if (n.Progress < 1)
n.Progress += (float)(Time.Elapsed / 2000) * RNG.NextSingle();
else
n.State = ProgressNotificationState.Completed;
2017-02-10 07:26:43 +00:00
}
}
private void sendProgress2()
{
var n = new ProgressNotification { Text = @"Downloading Haitai..." };
2017-02-10 07:26:43 +00:00
manager.Post(n);
progressingNotifications.Add(n);
}
private readonly List<ProgressNotification> progressingNotifications = new List<ProgressNotification>();
2017-02-10 07:26:43 +00:00
private void sendProgress1()
{
var n = new ProgressNotification { Text = @"Uploading to BSS..." };
2017-02-10 07:26:43 +00:00
manager.Post(n);
progressingNotifications.Add(n);
}
private void sendNotification2()
{
manager.Post(new SimpleNotification { Text = @"You are amazing" });
2017-02-10 07:26:43 +00:00
}
private void sendNotification1()
{
manager.Post(new SimpleNotification { Text = @"Welcome to osu!. Enjoy your stay!" });
2017-02-10 07:26:43 +00:00
}
}
}