1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 05:27:40 +08:00
osu-lazer/osu.Game.Tests/Visual/TestCaseNotificationOverlay.cs

123 lines
4.0 KiB
C#
Raw Normal View History

2017-09-18 21:32:49 +08: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;
2017-09-18 21:32:49 +08:00
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.MathUtils;
using osu.Game.Overlays;
using osu.Game.Overlays.Notifications;
namespace osu.Game.Tests.Visual
{
2017-12-20 20:47:45 +08:00
public class TestCaseNotificationOverlay : OsuTestCase
2017-09-18 21:32:49 +08:00
{
private readonly NotificationOverlay manager;
private readonly List<ProgressNotification> progressingNotifications = new List<ProgressNotification>();
2017-09-18 21:32:49 +08:00
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(Notification),
typeof(ProgressNotification),
typeof(ProgressCompletionNotification),
typeof(SimpleNotification),
typeof(IHasCompletionTarget),
};
2017-09-18 21:32:49 +08:00
public TestCaseNotificationOverlay()
{
progressingNotifications.Clear();
Content.Add(manager = new NotificationOverlay
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight
2017-09-18 21:32:49 +08:00
});
AddStep(@"toggle", manager.ToggleVisibility);
AddStep(@"simple #1", sendHelloNotification);
AddStep(@"simple #2", sendAmazingNotification);
AddStep(@"progress #1", sendUploadProgress);
AddStep(@"progress #2", sendDownloadProgress);
2017-09-18 21:32:49 +08:00
AddStep(@"barrage", () => sendBarrage());
}
private void sendBarrage(int remaining = 100)
{
switch (RNG.Next(0, 4))
{
case 0:
sendHelloNotification();
2017-09-18 21:32:49 +08:00
break;
case 1:
sendAmazingNotification();
2017-09-18 21:32:49 +08:00
break;
case 2:
sendUploadProgress();
2017-09-18 21:32:49 +08:00
break;
case 3:
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);
if (progressingNotifications.Count(n => n.State == ProgressNotificationState.Active) < 3)
2017-09-18 21:32:49 +08:00
{
var p = progressingNotifications.FirstOrDefault(n => n.IsAlive && n.State == ProgressNotificationState.Queued);
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)
n.Progress += (float)(Time.Elapsed / 2000) * RNG.NextSingle();
else
n.State = ProgressNotificationState.Completed;
}
}
private void sendDownloadProgress()
2017-09-18 21:32:49 +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);
}
private void sendUploadProgress()
2017-09-18 21:32:49 +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);
}
private void sendAmazingNotification()
2017-09-18 21:32:49 +08:00
{
manager.Post(new SimpleNotification { Text = @"You are amazing" });
}
private void sendHelloNotification()
2017-09-18 21:32:49 +08:00
{
manager.Post(new SimpleNotification { Text = @"Welcome to osu!. Enjoy your stay!" });
}
}
}