diff --git a/osu.Desktop.VisualTests/Tests/TestCaseNotificationManager.cs b/osu.Desktop.VisualTests/Tests/TestCaseNotificationManager.cs index cc9201c1fd..77b313f4ad 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseNotificationManager.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseNotificationManager.cs @@ -88,13 +88,13 @@ namespace osu.Desktop.VisualTests.Tests if (n.Progress < 1) n.Progress += (float)(Time.Elapsed / 2000) * RNG.NextSingle(); else - n.Complete(); + n.State = ProgressNotificationState.Completed; } } private void sendProgress2() { - var n = new ProgressNotification(@"Downloading Haitai..."); + var n = new ProgressNotification { Text = @"Downloading Haitai..." }; manager.Post(n); progressingNotifications.Add(n); } @@ -103,19 +103,19 @@ namespace osu.Desktop.VisualTests.Tests private void sendProgress1() { - var n = new ProgressNotification(@"Uploading to BSS..."); + var n = new ProgressNotification { Text = @"Uploading to BSS..." }; manager.Post(n); progressingNotifications.Add(n); } private void sendNotification2() { - manager.Post(new SimpleNotification(@"You are amazing")); + manager.Post(new SimpleNotification { Text = @"You are amazing" }); } private void sendNotification1() { - manager.Post(new SimpleNotification(@"Welcome to osu!. Enjoy your stay!")); + manager.Post(new SimpleNotification { Text = @"Welcome to osu!. Enjoy your stay!" }); } } } diff --git a/osu.Game/Overlays/Notifications/ProgressCompletionNotification.cs b/osu.Game/Overlays/Notifications/ProgressCompletionNotification.cs index 1861e410d2..a5ec9a3545 100644 --- a/osu.Game/Overlays/Notifications/ProgressCompletionNotification.cs +++ b/osu.Game/Overlays/Notifications/ProgressCompletionNotification.cs @@ -1,6 +1,8 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Game.Graphics; + namespace osu.Game.Overlays.Notifications { public class ProgressCompletionNotification : SimpleNotification @@ -8,9 +10,9 @@ namespace osu.Game.Overlays.Notifications private ProgressNotification progressNotification; public ProgressCompletionNotification(ProgressNotification progressNotification) - : base(@"Task has completed!") { this.progressNotification = progressNotification; + Icon = FontAwesome.fa_check; } } } \ No newline at end of file diff --git a/osu.Game/Overlays/Notifications/ProgressNotification.cs b/osu.Game/Overlays/Notifications/ProgressNotification.cs index 4cb1557c32..b00204e166 100644 --- a/osu.Game/Overlays/Notifications/ProgressNotification.cs +++ b/osu.Game/Overlays/Notifications/ProgressNotification.cs @@ -17,6 +17,16 @@ namespace osu.Game.Overlays.Notifications public class ProgressNotification : Notification, IHasCompletionTarget { private string text; + public string Text + { + get { return text; } + set + { + text = value; + if (IsLoaded) + textDrawable.Text = text; + } + } private float progress; public float Progress @@ -24,42 +34,79 @@ namespace osu.Game.Overlays.Notifications get { return progress; } set { - Debug.Assert(state == ProgressNotificationState.Active); progress = value; - progressBar.Progress = progress; + if (IsLoaded) + progressBar.Progress = progress; } } - public ProgressNotificationState State + protected override void LoadComplete() + { + base.LoadComplete(); + + //we may have received changes before we were displayed. + State = state; + Progress = progress; + } + + public virtual ProgressNotificationState State { get { return state; } set { + bool stateChanged = state != value; state = value; - switch (state) + + if (IsLoaded) { - case ProgressNotificationState.Queued: - Light.Colour = colourQueued; - Light.Pulsate = false; - progressBar.Active = false; - break; - case ProgressNotificationState.Active: - Light.Colour = colourActive; - Light.Pulsate = true; - progressBar.Active = true; - break; - case ProgressNotificationState.Cancelled: - Light.Colour = colourCancelled; - Light.Pulsate = false; - progressBar.Active = false; - break; + switch (state) + { + case ProgressNotificationState.Queued: + Light.Colour = colourQueued; + Light.Pulsate = false; + progressBar.Active = false; + break; + case ProgressNotificationState.Active: + Light.Colour = colourActive; + Light.Pulsate = true; + progressBar.Active = true; + break; + case ProgressNotificationState.Cancelled: + Light.Colour = colourCancelled; + Light.Pulsate = false; + progressBar.Active = false; + break; + } + } + + if (stateChanged) + { + switch (state) + { + case ProgressNotificationState.Completed: + NotificationContent.MoveToY(-DrawSize.Y / 2, 200, EasingTypes.OutQuint); + FadeTo(0.01f, 200); //don't completely fade out or our scheduled task won't run. + + Delay(100); + Schedule(Completed); + break; + } } } } private ProgressNotificationState state; - public Action Completed; + protected virtual Notification CreateCompletionNotification() => new ProgressCompletionNotification(this) + { + Activated = CompletionClickAction, + Text = $"Task \"{Text}\" has completed!" + }; + + protected virtual void Completed() + { + CompletionTarget?.Invoke(CreateCompletionNotification()); + } public override bool DisplayOnTop => false; @@ -68,10 +115,7 @@ namespace osu.Game.Overlays.Notifications private Color4 colourActive; private Color4 colourCancelled; - public ProgressNotification(string text) - { - this.text = text; - } + private SpriteText textDrawable; [BackgroundDependencyLoader] private void load(OsuColour colours) @@ -85,7 +129,7 @@ namespace osu.Game.Overlays.Notifications RelativeSizeAxes = Axes.Both, }); - Content.Add(new SpriteText + Content.Add(textDrawable = new SpriteText { TextSize = 16, Colour = OsuColour.Gray(128), @@ -104,23 +148,6 @@ namespace osu.Game.Overlays.Notifications State = ProgressNotificationState.Queued; } - public void Complete() - { - Debug.Assert(state != ProgressNotificationState.Completed); - - state = ProgressNotificationState.Completed; - - NotificationContent.MoveToY(-DrawSize.Y / 2, 200, EasingTypes.OutQuint); - FadeTo(0.01f, 200); //don't completely fade out or our scheduled task won't run. - - Delay(100); - Schedule(() => - { - CompletionTarget?.Invoke(new ProgressCompletionNotification(this)); - base.Close(); - }); - } - public override void Close() { switch (State) @@ -135,8 +162,16 @@ namespace osu.Game.Overlays.Notifications } } + /// + /// The function to post completion notifications back to. + /// public Action CompletionTarget { get; set; } + /// + /// An action to complete when the completion notification is clicked. + /// + public Func CompletionClickAction; + class ProgressBar : Container { private Box box; @@ -175,7 +210,7 @@ namespace osu.Game.Overlays.Notifications { colourActive = colours.Blue; Colour = colourInactive = OsuColour.Gray(0.5f); - + Height = 5; Children = new[] diff --git a/osu.Game/Overlays/Notifications/SimpleNotification.cs b/osu.Game/Overlays/Notifications/SimpleNotification.cs index 7c6666082e..52bd271252 100644 --- a/osu.Game/Overlays/Notifications/SimpleNotification.cs +++ b/osu.Game/Overlays/Notifications/SimpleNotification.cs @@ -12,12 +12,33 @@ namespace osu.Game.Overlays.Notifications public class SimpleNotification : Notification { private string text; - - public SimpleNotification(string text) + public string Text { - this.text = text; + get { return text; } + set + { + text = value; + if (IsLoaded) + textDrawable.Text = text; + } } + private FontAwesome icon = FontAwesome.fa_info_circle; + public FontAwesome Icon + { + get { return icon; } + set + { + icon = value; + if (IsLoaded) + iconDrawable.Icon = icon; + } + } + + + private SpriteText textDrawable; + private TextAwesome iconDrawable; + [BackgroundDependencyLoader] private void load(OsuColour colours) { @@ -28,14 +49,14 @@ namespace osu.Game.Overlays.Notifications RelativeSizeAxes = Axes.Both, ColourInfo = ColourInfo.GradientVertical(OsuColour.Gray(0.2f), OsuColour.Gray(0.5f)) }, - new TextAwesome + iconDrawable = new TextAwesome { Anchor = Anchor.Centre, - Icon = FontAwesome.fa_info_circle, + Icon = icon , } }); - Content.Add(new SpriteText + Content.Add(textDrawable = new SpriteText { TextSize = 16, Colour = OsuColour.Gray(128),