2019-01-24 16:43:03 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-12-06 15:29:41 +08:00
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Input.Events;
|
2020-02-20 18:47:50 +08:00
|
|
|
using osuTK;
|
2018-12-06 15:29:41 +08:00
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
{
|
|
|
|
/// <summary>
|
2020-02-20 18:47:50 +08:00
|
|
|
/// An overlay that will show a loading overlay and completely block input to an area.
|
|
|
|
/// Also optionally dims target elements.
|
2018-12-06 15:29:41 +08:00
|
|
|
/// Useful for disabling all elements in a form and showing we are waiting on a response, for instance.
|
|
|
|
/// </summary>
|
|
|
|
public class ProcessingOverlay : VisibilityContainer
|
|
|
|
{
|
2020-02-20 18:47:50 +08:00
|
|
|
private readonly Drawable dimTarget;
|
2018-12-06 15:29:41 +08:00
|
|
|
|
2020-02-20 18:47:50 +08:00
|
|
|
private Container loadingBox;
|
|
|
|
|
|
|
|
private const float transition_duration = 600;
|
|
|
|
|
|
|
|
public ProcessingOverlay(Drawable dimTarget = null)
|
2018-12-06 15:29:41 +08:00
|
|
|
{
|
2020-02-20 18:47:50 +08:00
|
|
|
this.dimTarget = dimTarget;
|
2018-12-06 15:29:41 +08:00
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
2020-02-20 18:47:50 +08:00
|
|
|
loadingBox = new Container
|
2018-12-06 15:29:41 +08:00
|
|
|
{
|
2020-02-20 18:47:50 +08:00
|
|
|
Size = new Vector2(80),
|
|
|
|
Scale = new Vector2(0.8f),
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = 15,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Colour = Color4.Black,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
new LoadingAnimation { State = { Value = Visibility.Visible } }
|
|
|
|
}
|
2018-12-06 15:29:41 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-02-20 18:47:50 +08:00
|
|
|
protected override bool Handle(UIEvent e) => true;
|
2018-12-06 15:29:41 +08:00
|
|
|
|
|
|
|
protected override void PopIn()
|
|
|
|
{
|
2020-02-20 18:47:50 +08:00
|
|
|
this.FadeIn(transition_duration, Easing.OutQuint);
|
|
|
|
loadingBox.ScaleTo(1, transition_duration, Easing.OutElastic);
|
|
|
|
|
|
|
|
dimTarget?.FadeColour(OsuColour.Gray(0.5f), transition_duration, Easing.OutQuint);
|
2018-12-06 15:29:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
{
|
|
|
|
this.FadeOut(transition_duration, Easing.OutQuint);
|
2020-02-20 18:47:50 +08:00
|
|
|
loadingBox.ScaleTo(0.8f, transition_duration / 2, Easing.In);
|
|
|
|
|
|
|
|
dimTarget?.FadeColour(Color4.White, transition_duration, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
|
|
if (State.Value == Visibility.Visible)
|
|
|
|
{
|
2020-02-21 07:34:51 +08:00
|
|
|
// ensure we don't leave the target in a bad state.
|
2020-02-21 07:55:12 +08:00
|
|
|
dimTarget?.FadeColour(Color4.White, transition_duration, Easing.OutQuint);
|
2020-02-20 18:47:50 +08:00
|
|
|
}
|
2018-12-06 15:29:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|