mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 23:59:16 +08:00
Rework notifications to be more flexible.
This commit is contained in:
parent
a14b7eb598
commit
ac548dc9ec
@ -88,13 +88,13 @@ namespace osu.Desktop.VisualTests.Tests
|
|||||||
if (n.Progress < 1)
|
if (n.Progress < 1)
|
||||||
n.Progress += (float)(Time.Elapsed / 2000) * RNG.NextSingle();
|
n.Progress += (float)(Time.Elapsed / 2000) * RNG.NextSingle();
|
||||||
else
|
else
|
||||||
n.Complete();
|
n.State = ProgressNotificationState.Completed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendProgress2()
|
private void sendProgress2()
|
||||||
{
|
{
|
||||||
var n = new ProgressNotification(@"Downloading Haitai...");
|
var n = new ProgressNotification { Text = @"Downloading Haitai..." };
|
||||||
manager.Post(n);
|
manager.Post(n);
|
||||||
progressingNotifications.Add(n);
|
progressingNotifications.Add(n);
|
||||||
}
|
}
|
||||||
@ -103,19 +103,19 @@ namespace osu.Desktop.VisualTests.Tests
|
|||||||
|
|
||||||
private void sendProgress1()
|
private void sendProgress1()
|
||||||
{
|
{
|
||||||
var n = new ProgressNotification(@"Uploading to BSS...");
|
var n = new ProgressNotification { Text = @"Uploading to BSS..." };
|
||||||
manager.Post(n);
|
manager.Post(n);
|
||||||
progressingNotifications.Add(n);
|
progressingNotifications.Add(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendNotification2()
|
private void sendNotification2()
|
||||||
{
|
{
|
||||||
manager.Post(new SimpleNotification(@"You are amazing"));
|
manager.Post(new SimpleNotification { Text = @"You are amazing" });
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendNotification1()
|
private void sendNotification1()
|
||||||
{
|
{
|
||||||
manager.Post(new SimpleNotification(@"Welcome to osu!. Enjoy your stay!"));
|
manager.Post(new SimpleNotification { Text = @"Welcome to osu!. Enjoy your stay!" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Notifications
|
namespace osu.Game.Overlays.Notifications
|
||||||
{
|
{
|
||||||
public class ProgressCompletionNotification : SimpleNotification
|
public class ProgressCompletionNotification : SimpleNotification
|
||||||
@ -8,9 +10,9 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
private ProgressNotification progressNotification;
|
private ProgressNotification progressNotification;
|
||||||
|
|
||||||
public ProgressCompletionNotification(ProgressNotification progressNotification)
|
public ProgressCompletionNotification(ProgressNotification progressNotification)
|
||||||
: base(@"Task has completed!")
|
|
||||||
{
|
{
|
||||||
this.progressNotification = progressNotification;
|
this.progressNotification = progressNotification;
|
||||||
|
Icon = FontAwesome.fa_check;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,6 +17,16 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
public class ProgressNotification : Notification, IHasCompletionTarget
|
public class ProgressNotification : Notification, IHasCompletionTarget
|
||||||
{
|
{
|
||||||
private string text;
|
private string text;
|
||||||
|
public string Text
|
||||||
|
{
|
||||||
|
get { return text; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
text = value;
|
||||||
|
if (IsLoaded)
|
||||||
|
textDrawable.Text = text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private float progress;
|
private float progress;
|
||||||
public float Progress
|
public float Progress
|
||||||
@ -24,42 +34,79 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
get { return progress; }
|
get { return progress; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
Debug.Assert(state == ProgressNotificationState.Active);
|
|
||||||
progress = value;
|
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; }
|
get { return state; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
|
bool stateChanged = state != value;
|
||||||
state = value;
|
state = value;
|
||||||
switch (state)
|
|
||||||
|
if (IsLoaded)
|
||||||
{
|
{
|
||||||
case ProgressNotificationState.Queued:
|
switch (state)
|
||||||
Light.Colour = colourQueued;
|
{
|
||||||
Light.Pulsate = false;
|
case ProgressNotificationState.Queued:
|
||||||
progressBar.Active = false;
|
Light.Colour = colourQueued;
|
||||||
break;
|
Light.Pulsate = false;
|
||||||
case ProgressNotificationState.Active:
|
progressBar.Active = false;
|
||||||
Light.Colour = colourActive;
|
break;
|
||||||
Light.Pulsate = true;
|
case ProgressNotificationState.Active:
|
||||||
progressBar.Active = true;
|
Light.Colour = colourActive;
|
||||||
break;
|
Light.Pulsate = true;
|
||||||
case ProgressNotificationState.Cancelled:
|
progressBar.Active = true;
|
||||||
Light.Colour = colourCancelled;
|
break;
|
||||||
Light.Pulsate = false;
|
case ProgressNotificationState.Cancelled:
|
||||||
progressBar.Active = false;
|
Light.Colour = colourCancelled;
|
||||||
break;
|
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;
|
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;
|
public override bool DisplayOnTop => false;
|
||||||
|
|
||||||
@ -68,10 +115,7 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
private Color4 colourActive;
|
private Color4 colourActive;
|
||||||
private Color4 colourCancelled;
|
private Color4 colourCancelled;
|
||||||
|
|
||||||
public ProgressNotification(string text)
|
private SpriteText textDrawable;
|
||||||
{
|
|
||||||
this.text = text;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours)
|
private void load(OsuColour colours)
|
||||||
@ -85,7 +129,7 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
});
|
});
|
||||||
|
|
||||||
Content.Add(new SpriteText
|
Content.Add(textDrawable = new SpriteText
|
||||||
{
|
{
|
||||||
TextSize = 16,
|
TextSize = 16,
|
||||||
Colour = OsuColour.Gray(128),
|
Colour = OsuColour.Gray(128),
|
||||||
@ -104,23 +148,6 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
State = ProgressNotificationState.Queued;
|
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()
|
public override void Close()
|
||||||
{
|
{
|
||||||
switch (State)
|
switch (State)
|
||||||
@ -135,8 +162,16 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The function to post completion notifications back to.
|
||||||
|
/// </summary>
|
||||||
public Action<Notification> CompletionTarget { get; set; }
|
public Action<Notification> CompletionTarget { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An action to complete when the completion notification is clicked.
|
||||||
|
/// </summary>
|
||||||
|
public Func<bool> CompletionClickAction;
|
||||||
|
|
||||||
class ProgressBar : Container
|
class ProgressBar : Container
|
||||||
{
|
{
|
||||||
private Box box;
|
private Box box;
|
||||||
@ -175,7 +210,7 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
{
|
{
|
||||||
colourActive = colours.Blue;
|
colourActive = colours.Blue;
|
||||||
Colour = colourInactive = OsuColour.Gray(0.5f);
|
Colour = colourInactive = OsuColour.Gray(0.5f);
|
||||||
|
|
||||||
Height = 5;
|
Height = 5;
|
||||||
|
|
||||||
Children = new[]
|
Children = new[]
|
||||||
|
@ -12,12 +12,33 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
public class SimpleNotification : Notification
|
public class SimpleNotification : Notification
|
||||||
{
|
{
|
||||||
private string text;
|
private string text;
|
||||||
|
public string Text
|
||||||
public SimpleNotification(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]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours)
|
private void load(OsuColour colours)
|
||||||
{
|
{
|
||||||
@ -28,14 +49,14 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
ColourInfo = ColourInfo.GradientVertical(OsuColour.Gray(0.2f), OsuColour.Gray(0.5f))
|
ColourInfo = ColourInfo.GradientVertical(OsuColour.Gray(0.2f), OsuColour.Gray(0.5f))
|
||||||
},
|
},
|
||||||
new TextAwesome
|
iconDrawable = new TextAwesome
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Icon = FontAwesome.fa_info_circle,
|
Icon = icon ,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Content.Add(new SpriteText
|
Content.Add(textDrawable = new SpriteText
|
||||||
{
|
{
|
||||||
TextSize = 16,
|
TextSize = 16,
|
||||||
Colour = OsuColour.Gray(128),
|
Colour = OsuColour.Gray(128),
|
||||||
|
Loading…
Reference in New Issue
Block a user