mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 00:09:55 +09:00
Rename LoadingAnimation to LoadingSpinner
This commit is contained in:
106
osu.Game/Graphics/UserInterface/LoadingSpinner.cs
Normal file
106
osu.Game/Graphics/UserInterface/LoadingSpinner.cs
Normal file
@ -0,0 +1,106 @@
|
||||
// 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 osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
/// <summary>
|
||||
/// A loading spinner.
|
||||
/// </summary>
|
||||
public class LoadingSpinner : VisibilityContainer
|
||||
{
|
||||
private readonly SpriteIcon spinner;
|
||||
|
||||
protected Container MainContents;
|
||||
|
||||
protected const float TRANSITION_DURATION = 500;
|
||||
|
||||
private const float spin_duration = 900;
|
||||
|
||||
/// <summary>
|
||||
/// Constuct a new loading spinner.
|
||||
/// </summary>
|
||||
/// <param name="withBox"></param>
|
||||
public LoadingSpinner(bool withBox = false)
|
||||
{
|
||||
Size = new Vector2(60);
|
||||
|
||||
Anchor = Anchor.Centre;
|
||||
Origin = Anchor.Centre;
|
||||
|
||||
Child = MainContents = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Masking = true,
|
||||
CornerRadius = 20,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
Colour = Color4.Black,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Alpha = withBox ? 0.7f : 0
|
||||
},
|
||||
spinner = new SpriteIcon
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Scale = new Vector2(withBox ? 0.6f : 1),
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Icon = FontAwesome.Solid.CircleNotch
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private void rotate()
|
||||
{
|
||||
spinner.Spin(spin_duration * 4, RotationDirection.Clockwise);
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user