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-04-13 17:19:50 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2017-06-12 15:40:53 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-02-21 14:31:40 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2019-03-27 18:29:27 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-07 12:52:19 +08:00
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
2018-12-06 15:29:41 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A loading spinner.
|
|
|
|
|
/// </summary>
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class LoadingSpinner : VisibilityContainer
|
2017-02-07 12:52:19 +08:00
|
|
|
|
{
|
2017-08-03 13:36:21 +08:00
|
|
|
|
private readonly SpriteIcon spinner;
|
2018-06-22 11:30:40 +08:00
|
|
|
|
|
2020-06-12 12:38:20 +08:00
|
|
|
|
protected override bool StartHidden => true;
|
|
|
|
|
|
2020-02-21 14:31:40 +08:00
|
|
|
|
protected Container MainContents;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-03-11 12:20:31 +08:00
|
|
|
|
public const float TRANSITION_DURATION = 500;
|
2020-02-21 14:31:40 +08:00
|
|
|
|
|
|
|
|
|
private const float spin_duration = 900;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constuct a new loading spinner.
|
|
|
|
|
/// </summary>
|
2020-02-21 14:35:40 +08:00
|
|
|
|
/// <param name="withBox">Whether the spinner should have a surrounding black box for visibility.</param>
|
2020-03-11 01:49:34 +08:00
|
|
|
|
/// <param name="inverted">Whether colours should be inverted (black spinner instead of white).</param>
|
|
|
|
|
public LoadingSpinner(bool withBox = false, bool inverted = false)
|
2017-02-07 12:52:19 +08:00
|
|
|
|
{
|
2020-02-21 14:31:40 +08:00
|
|
|
|
Size = new Vector2(60);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-06-12 15:40:53 +08:00
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
|
Origin = Anchor.Centre;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-02-21 14:31:40 +08:00
|
|
|
|
Child = MainContents = new Container
|
2017-06-12 15:40:53 +08:00
|
|
|
|
{
|
2020-02-21 14:31:40 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Masking = true,
|
|
|
|
|
CornerRadius = 20,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Children = new Drawable[]
|
2018-06-22 11:30:40 +08:00
|
|
|
|
{
|
2020-02-21 14:31:40 +08:00
|
|
|
|
new Box
|
|
|
|
|
{
|
2020-03-11 01:49:34 +08:00
|
|
|
|
Colour = inverted ? Color4.White : Color4.Black,
|
2020-02-21 14:31:40 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Alpha = withBox ? 0.7f : 0
|
|
|
|
|
},
|
|
|
|
|
spinner = new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2020-03-11 01:49:34 +08:00
|
|
|
|
Colour = inverted ? Color4.Black : Color4.White,
|
2020-02-21 14:31:40 +08:00
|
|
|
|
Scale = new Vector2(withBox ? 0.6f : 1),
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Icon = FontAwesome.Solid.CircleNotch
|
|
|
|
|
}
|
2017-06-12 15:40:53 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-06-12 15:40:53 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-02-21 14:31:40 +08:00
|
|
|
|
rotate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
MainContents.CornerRadius = MainContents.DrawWidth / 4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
if (Alpha < 0.5f)
|
|
|
|
|
// reset animation if the user can't see us.
|
|
|
|
|
rotate();
|
|
|
|
|
|
|
|
|
|
MainContents.ScaleTo(1, TRANSITION_DURATION, Easing.OutQuint);
|
|
|
|
|
this.FadeIn(TRANSITION_DURATION * 2, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
|
|
|
|
MainContents.ScaleTo(0.8f, TRANSITION_DURATION / 2, Easing.In);
|
|
|
|
|
this.FadeOut(TRANSITION_DURATION, Easing.OutQuint);
|
2017-02-07 12:52:19 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-02-21 14:31:40 +08:00
|
|
|
|
private void rotate()
|
|
|
|
|
{
|
2020-02-23 04:00:38 +08:00
|
|
|
|
spinner.Spin(spin_duration * 3.5f, RotationDirection.Clockwise);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-02-21 14:31:40 +08:00
|
|
|
|
MainContents.RotateTo(0).Then()
|
|
|
|
|
.RotateTo(90, spin_duration, Easing.InOutQuart).Then()
|
|
|
|
|
.RotateTo(180, spin_duration, Easing.InOutQuart).Then()
|
|
|
|
|
.RotateTo(270, spin_duration, Easing.InOutQuart).Then()
|
|
|
|
|
.RotateTo(360, spin_duration, Easing.InOutQuart).Then()
|
|
|
|
|
.Loop();
|
|
|
|
|
}
|
2017-02-07 12:52:19 +08:00
|
|
|
|
}
|
2017-06-12 15:40:53 +08:00
|
|
|
|
}
|