1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-07 01:07:20 +08:00

86 lines
2.0 KiB
C#
Raw Normal View History

2019-10-17 13:57:17 +03: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 osu.Framework.Graphics;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers;
using osuTK;
namespace osu.Game.Graphics.UserInterface
{
public abstract class LoadingButton : OsuHoverContainer
{
private bool isLoading;
public bool IsLoading
{
get => isLoading;
set
{
isLoading = value;
Enabled.Value = !isLoading;
if (value)
{
loading.Show();
2019-10-24 17:49:34 +03:00
OnLoadStarted();
2019-10-17 13:57:17 +03:00
}
else
{
loading.Hide();
2019-10-24 17:49:34 +03:00
OnLoadFinished();
2019-10-17 13:57:17 +03:00
}
}
}
public Vector2 LoadingAnimationSize
{
get => loading.Size;
set => loading.Size = value;
}
private readonly LoadingSpinner loading;
2019-10-17 13:57:17 +03:00
2019-10-17 15:24:51 +03:00
protected LoadingButton()
2019-10-17 13:57:17 +03:00
{
2019-10-24 17:49:34 +03:00
AddRange(new[]
2019-10-17 13:57:17 +03:00
{
2019-10-24 17:49:34 +03:00
CreateContent(),
loading = new LoadingSpinner
2019-10-17 13:57:17 +03:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(12)
}
});
}
protected override bool OnClick(ClickEvent e)
{
if (!Enabled.Value)
return false;
try
{
return base.OnClick(e);
}
finally
{
// run afterwards as this will disable this button.
IsLoading = true;
}
}
2019-10-24 17:49:34 +03:00
protected virtual void OnLoadStarted()
2019-10-17 13:57:17 +03:00
{
}
2019-10-24 17:49:34 +03:00
protected virtual void OnLoadFinished()
2019-10-17 13:57:17 +03:00
{
}
2019-10-24 17:49:34 +03:00
protected abstract Drawable CreateContent();
2019-10-17 13:57:17 +03:00
}
}