2017-02-10 15:26:43 +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;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-02-10 15:26:43 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics;
|
2017-02-15 20:37:43 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-02-10 15:26:43 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Notifications
|
|
|
|
|
{
|
|
|
|
|
public class ProgressNotification : Notification, IHasCompletionTarget
|
|
|
|
|
{
|
2017-02-12 13:50:42 +08:00
|
|
|
|
public string Text
|
|
|
|
|
{
|
2017-02-12 18:39:54 +08:00
|
|
|
|
get { return textDrawable.Text; }
|
2017-02-12 13:50:42 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2017-02-12 18:39:54 +08:00
|
|
|
|
textDrawable.Text = value;
|
2017-02-12 13:50:42 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-10 15:26:43 +08:00
|
|
|
|
|
|
|
|
|
public float Progress
|
|
|
|
|
{
|
2017-02-12 18:39:54 +08:00
|
|
|
|
get { return progressBar.Progress; }
|
2017-02-10 15:26:43 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2017-02-12 18:39:54 +08:00
|
|
|
|
progressBar.Progress = value;
|
2017-02-10 15:26:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-12 13:50:42 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
//we may have received changes before we were displayed.
|
|
|
|
|
State = state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual ProgressNotificationState State
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
|
|
|
|
get { return state; }
|
|
|
|
|
set
|
|
|
|
|
{
|
2017-02-12 13:50:42 +08:00
|
|
|
|
bool stateChanged = state != value;
|
2017-02-10 15:26:43 +08:00
|
|
|
|
state = value;
|
2017-02-12 13:50:42 +08:00
|
|
|
|
|
|
|
|
|
if (IsLoaded)
|
|
|
|
|
{
|
|
|
|
|
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)
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
2017-02-12 13:50:42 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
2017-02-10 15:26:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ProgressNotificationState state;
|
|
|
|
|
|
2017-07-13 14:02:45 +08:00
|
|
|
|
protected virtual Notification CreateCompletionNotification() => new ProgressCompletionNotification
|
2017-02-12 13:50:42 +08:00
|
|
|
|
{
|
|
|
|
|
Activated = CompletionClickAction,
|
|
|
|
|
Text = $"Task \"{Text}\" has completed!"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
protected virtual void Completed()
|
|
|
|
|
{
|
2017-02-12 18:39:54 +08:00
|
|
|
|
Expire();
|
2017-02-12 13:50:42 +08:00
|
|
|
|
CompletionTarget?.Invoke(CreateCompletionNotification());
|
|
|
|
|
}
|
2017-02-10 15:26:43 +08:00
|
|
|
|
|
|
|
|
|
public override bool DisplayOnTop => false;
|
|
|
|
|
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly ProgressBar progressBar;
|
2017-02-10 15:26:43 +08:00
|
|
|
|
private Color4 colourQueued;
|
|
|
|
|
private Color4 colourActive;
|
|
|
|
|
private Color4 colourCancelled;
|
|
|
|
|
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly SpriteText textDrawable;
|
2017-02-10 15:26:43 +08:00
|
|
|
|
|
2017-02-12 18:39:54 +08:00
|
|
|
|
public ProgressNotification()
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
|
|
|
|
IconContent.Add(new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
});
|
|
|
|
|
|
2017-02-15 20:37:43 +08:00
|
|
|
|
Content.Add(textDrawable = new OsuSpriteText
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
|
|
|
|
TextSize = 16,
|
|
|
|
|
Colour = OsuColour.Gray(128),
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
NotificationContent.Add(progressBar = new ProgressBar
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
State = ProgressNotificationState.Queued;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-12 18:39:54 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
colourQueued = colours.YellowDark;
|
|
|
|
|
colourActive = colours.Blue;
|
|
|
|
|
colourCancelled = colours.Red;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
public override void Close()
|
|
|
|
|
{
|
|
|
|
|
switch (State)
|
|
|
|
|
{
|
|
|
|
|
case ProgressNotificationState.Cancelled:
|
|
|
|
|
base.Close();
|
|
|
|
|
break;
|
|
|
|
|
case ProgressNotificationState.Active:
|
|
|
|
|
case ProgressNotificationState.Queued:
|
|
|
|
|
State = ProgressNotificationState.Cancelled;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-12 13:50:42 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The function to post completion notifications back to.
|
|
|
|
|
/// </summary>
|
2017-02-10 15:26:43 +08:00
|
|
|
|
public Action<Notification> CompletionTarget { get; set; }
|
|
|
|
|
|
2017-02-12 13:50:42 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// An action to complete when the completion notification is clicked.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Func<bool> CompletionClickAction;
|
|
|
|
|
|
2017-03-07 09:59:19 +08:00
|
|
|
|
private class ProgressBar : Container
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
|
|
|
|
private Box box;
|
|
|
|
|
|
|
|
|
|
private Color4 colourActive;
|
|
|
|
|
private Color4 colourInactive;
|
|
|
|
|
|
|
|
|
|
private float progress;
|
|
|
|
|
public float Progress
|
|
|
|
|
{
|
|
|
|
|
get { return progress; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (progress == value) return;
|
|
|
|
|
|
|
|
|
|
progress = value;
|
|
|
|
|
box.ResizeTo(new Vector2(progress, 1), 100, EasingTypes.OutQuad);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool active;
|
|
|
|
|
|
|
|
|
|
public bool Active
|
|
|
|
|
{
|
|
|
|
|
get { return active; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
active = value;
|
|
|
|
|
FadeColour(active ? colourActive : colourInactive, 100);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
colourActive = colours.Blue;
|
|
|
|
|
Colour = colourInactive = OsuColour.Gray(0.5f);
|
2017-02-12 13:50:42 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
Height = 5;
|
|
|
|
|
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
box = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Width = 0,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum ProgressNotificationState
|
|
|
|
|
{
|
|
|
|
|
Queued,
|
|
|
|
|
Active,
|
|
|
|
|
Completed,
|
|
|
|
|
Cancelled
|
|
|
|
|
}
|
|
|
|
|
}
|