mirror of
https://github.com/ppy/osu
synced 2025-01-09 15:49:32 +00:00
54982dcdd7
In theory this seemed like a good idea (and an optimisation in some cases, due to lower fill rate), but in practice this leads to weird edge cases. This aims to do away with the operations on external drawables by applying a dim to the area behind the `LoadingLayer` when required. I went over each usage and ensured they look as good or better than previously. The specific bad usage here was the restoration of the colour on dispose (if the `LoadingLayer` was disposed in a still-visible state). I'm aware that the `BeatmapListingOverlay` will now dim completely during load. I think this is fine for the time being.
98 lines
3.3 KiB
C#
98 lines
3.3 KiB
C#
// 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.Graphics.Shapes;
|
|
using osu.Framework.Input.Events;
|
|
using osuTK;
|
|
using osuTK.Graphics;
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
{
|
|
/// <summary>
|
|
/// A layer that will show a loading spinner and completely block input to an area.
|
|
/// Also optionally dims target elements.
|
|
/// Useful for disabling all elements in a form and showing we are waiting on a response, for instance.
|
|
/// </summary>
|
|
public class LoadingLayer : LoadingSpinner
|
|
{
|
|
private readonly Box backgroundDimLayer;
|
|
|
|
/// <summary>
|
|
/// Construct a new loading spinner.
|
|
/// </summary>
|
|
/// <param name="dimBackground">Whether the full background area should be dimmed while loading.</param>
|
|
/// <param name="withBox">Whether the spinner should have a surrounding black box for visibility.</param>
|
|
public LoadingLayer(bool dimBackground = false, bool withBox = true)
|
|
: base(withBox)
|
|
{
|
|
RelativeSizeAxes = Axes.Both;
|
|
Size = new Vector2(1);
|
|
|
|
MainContents.RelativeSizeAxes = Axes.None;
|
|
|
|
if (dimBackground)
|
|
{
|
|
AddInternal(backgroundDimLayer = new Box
|
|
{
|
|
Depth = float.MaxValue,
|
|
Colour = Color4.Black,
|
|
Alpha = 0,
|
|
RelativeSizeAxes = Axes.Both,
|
|
});
|
|
}
|
|
}
|
|
|
|
public override bool HandleNonPositionalInput => false;
|
|
|
|
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;
|
|
|
|
// blocking touch events causes the ISourcedFromTouch versions to not be fired, potentially impeding behaviour of drawables *above* the loading layer that may utilise these.
|
|
// note that this will not work well if touch handling elements are beneath this loading layer (something to consider for the future).
|
|
case TouchEvent _:
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
protected override void PopIn()
|
|
{
|
|
backgroundDimLayer?.FadeTo(0.5f, TRANSITION_DURATION * 2, Easing.OutQuint);
|
|
base.PopIn();
|
|
}
|
|
|
|
protected override void PopOut()
|
|
{
|
|
backgroundDimLayer?.FadeOut(TRANSITION_DURATION, Easing.OutQuint);
|
|
base.PopOut();
|
|
}
|
|
|
|
protected override void Update()
|
|
{
|
|
base.Update();
|
|
|
|
MainContents.Size = new Vector2(Math.Clamp(Math.Min(DrawWidth, DrawHeight) * 0.25f, 30, 100));
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|