mirror of
https://github.com/ppy/osu
synced 2024-12-18 21:06:38 +00:00
Merge pull request #15338 from peppy/add-progress-notification-icons
Add icons to various progress notification states
This commit is contained in:
commit
e5107ae0f7
@ -41,6 +41,44 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
notificationOverlay.UnreadCount.ValueChanged += count => { displayedCount.Text = $"displayed count: {count.NewValue}"; };
|
||||
});
|
||||
|
||||
[Test]
|
||||
public void TestCompleteProgress()
|
||||
{
|
||||
ProgressNotification notification = null;
|
||||
AddStep("add progress notification", () =>
|
||||
{
|
||||
notification = new ProgressNotification
|
||||
{
|
||||
Text = @"Uploading to BSS...",
|
||||
CompletionText = "Uploaded to BSS!",
|
||||
};
|
||||
notificationOverlay.Post(notification);
|
||||
progressingNotifications.Add(notification);
|
||||
});
|
||||
|
||||
AddUntilStep("wait completion", () => notification.State == ProgressNotificationState.Completed);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCancelProgress()
|
||||
{
|
||||
ProgressNotification notification = null;
|
||||
AddStep("add progress notification", () =>
|
||||
{
|
||||
notification = new ProgressNotification
|
||||
{
|
||||
Text = @"Uploading to BSS...",
|
||||
CompletionText = "Uploaded to BSS!",
|
||||
};
|
||||
notificationOverlay.Post(notification);
|
||||
progressingNotifications.Add(notification);
|
||||
});
|
||||
|
||||
AddWaitStep("wait 3", 3);
|
||||
|
||||
AddStep("cancel notification", () => notification.State = ProgressNotificationState.Cancelled);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBasicFlow()
|
||||
{
|
||||
@ -138,7 +176,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
foreach (var n in progressingNotifications.FindAll(n => n.State == ProgressNotificationState.Active))
|
||||
{
|
||||
if (n.Progress < 1)
|
||||
n.Progress += (float)(Time.Elapsed / 400) * RNG.NextSingle();
|
||||
n.Progress += (float)(Time.Elapsed / 2000);
|
||||
else
|
||||
n.State = ProgressNotificationState.Completed;
|
||||
}
|
||||
|
@ -4,11 +4,15 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Colour;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
@ -16,6 +20,8 @@ namespace osu.Game.Overlays.Notifications
|
||||
{
|
||||
public class ProgressNotification : Notification, IHasCompletionTarget
|
||||
{
|
||||
private const float loading_spinner_size = 22;
|
||||
|
||||
public string Text
|
||||
{
|
||||
set => Schedule(() => textDrawable.Text = value);
|
||||
@ -65,29 +71,53 @@ namespace osu.Game.Overlays.Notifications
|
||||
|
||||
private void updateState()
|
||||
{
|
||||
const double colour_fade_duration = 200;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case ProgressNotificationState.Queued:
|
||||
Light.Colour = colourQueued;
|
||||
Light.Pulsate = false;
|
||||
progressBar.Active = false;
|
||||
|
||||
iconBackground.FadeColour(ColourInfo.GradientVertical(colourQueued, colourQueued.Lighten(0.5f)), colour_fade_duration);
|
||||
loadingSpinner.Show();
|
||||
break;
|
||||
|
||||
case ProgressNotificationState.Active:
|
||||
Light.Colour = colourActive;
|
||||
Light.Pulsate = true;
|
||||
progressBar.Active = true;
|
||||
|
||||
iconBackground.FadeColour(ColourInfo.GradientVertical(colourActive, colourActive.Lighten(0.5f)), colour_fade_duration);
|
||||
loadingSpinner.Show();
|
||||
break;
|
||||
|
||||
case ProgressNotificationState.Cancelled:
|
||||
cancellationTokenSource.Cancel();
|
||||
|
||||
iconBackground.FadeColour(ColourInfo.GradientVertical(Color4.Gray, Color4.Gray.Lighten(0.5f)), colour_fade_duration);
|
||||
loadingSpinner.Hide();
|
||||
|
||||
var icon = new SpriteIcon
|
||||
{
|
||||
Icon = FontAwesome.Solid.Ban,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(loading_spinner_size),
|
||||
};
|
||||
|
||||
IconContent.Add(icon);
|
||||
|
||||
icon.FadeInFromZero(200, Easing.OutQuint);
|
||||
|
||||
Light.Colour = colourCancelled;
|
||||
Light.Pulsate = false;
|
||||
progressBar.Active = false;
|
||||
break;
|
||||
|
||||
case ProgressNotificationState.Completed:
|
||||
loadingSpinner.Hide();
|
||||
NotificationContent.MoveToY(-DrawSize.Y / 2, 200, Easing.OutQuint);
|
||||
this.FadeOut(200).Finally(d => Completed());
|
||||
break;
|
||||
@ -115,15 +145,13 @@ namespace osu.Game.Overlays.Notifications
|
||||
private Color4 colourActive;
|
||||
private Color4 colourCancelled;
|
||||
|
||||
private Box iconBackground;
|
||||
private LoadingSpinner loadingSpinner;
|
||||
|
||||
private readonly TextFlowContainer textDrawable;
|
||||
|
||||
public ProgressNotification()
|
||||
{
|
||||
IconContent.Add(new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
});
|
||||
|
||||
Content.Add(textDrawable = new OsuTextFlowContainer
|
||||
{
|
||||
Colour = OsuColour.Gray(128),
|
||||
@ -138,6 +166,9 @@ namespace osu.Game.Overlays.Notifications
|
||||
RelativeSizeAxes = Axes.X,
|
||||
});
|
||||
|
||||
// make some extra space for the progress bar.
|
||||
IconContent.Margin = new MarginPadding { Bottom = 5 };
|
||||
|
||||
State = ProgressNotificationState.Queued;
|
||||
|
||||
// don't close on click by default.
|
||||
@ -150,6 +181,19 @@ namespace osu.Game.Overlays.Notifications
|
||||
colourQueued = colours.YellowDark;
|
||||
colourActive = colours.Blue;
|
||||
colourCancelled = colours.Red;
|
||||
|
||||
IconContent.AddRange(new Drawable[]
|
||||
{
|
||||
iconBackground = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4.White,
|
||||
},
|
||||
loadingSpinner = new LoadingSpinner
|
||||
{
|
||||
Size = new Vector2(loading_spinner_size),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
|
Loading…
Reference in New Issue
Block a user