2020-02-21 14:31:40 +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.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
{
|
|
|
|
/// <summary>
|
2020-02-21 14:35:40 +08:00
|
|
|
/// A layer that will show a loading spinner and completely block input to an area.
|
2020-02-21 14:31:40 +08:00
|
|
|
/// Also optionally dims target elements.
|
|
|
|
/// Useful for disabling all elements in a form and showing we are waiting on a response, for instance.
|
|
|
|
/// </summary>
|
2020-02-21 14:33:31 +08:00
|
|
|
public class LoadingLayer : LoadingSpinner
|
2020-02-21 14:31:40 +08:00
|
|
|
{
|
|
|
|
private readonly Drawable dimTarget;
|
|
|
|
|
2020-02-21 14:35:40 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Constuct a new loading spinner.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="dimTarget">An optional target to dim when displayed.</param>
|
|
|
|
/// <param name="withBox">Whether the spinner should have a surrounding black box for visibility.</param>
|
2020-02-21 14:31:40 +08:00
|
|
|
public LoadingLayer(Drawable dimTarget = null, bool withBox = true)
|
|
|
|
: base(withBox)
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
Size = new Vector2(1);
|
|
|
|
|
|
|
|
this.dimTarget = dimTarget;
|
|
|
|
|
|
|
|
MainContents.RelativeSizeAxes = Axes.None;
|
|
|
|
}
|
|
|
|
|
2020-02-21 15:31:16 +08:00
|
|
|
public override bool HandleNonPositionalInput => false;
|
|
|
|
|
2020-02-21 14:31:40 +08:00
|
|
|
protected override bool Handle(UIEvent e)
|
|
|
|
{
|
|
|
|
switch (e)
|
|
|
|
{
|
|
|
|
// blocking scroll can cause weird behaviour when this layer is used within a ScrollContainer.
|
|
|
|
case ScrollEvent _:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void PopIn()
|
|
|
|
{
|
|
|
|
dimTarget?.FadeColour(OsuColour.Gray(0.5f), TRANSITION_DURATION, Easing.OutQuint);
|
|
|
|
base.PopIn();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
{
|
|
|
|
dimTarget?.FadeColour(Color4.White, TRANSITION_DURATION, Easing.OutQuint);
|
|
|
|
base.PopOut();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
2020-02-23 03:58:52 +08:00
|
|
|
MainContents.Size = new Vector2(Math.Clamp(Math.Min(DrawWidth, DrawHeight) * 0.25f, 30, 100));
|
2020-02-21 14:31:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
|
|
if (State.Value == Visibility.Visible)
|
|
|
|
{
|
|
|
|
// ensure we don't leave the target in a bad state.
|
|
|
|
dimTarget?.FadeColour(Color4.White, TRANSITION_DURATION, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|