2019-10-17 18:57:17 +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.
|
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2021-11-05 15:12:41 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-10-17 18:57:17 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2021-11-05 15:12:41 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-10-17 18:57:17 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public abstract partial class LoadingButton : OsuHoverContainer
|
2019-10-17 18:57:17 +08:00
|
|
|
|
{
|
|
|
|
|
private bool isLoading;
|
|
|
|
|
|
|
|
|
|
public bool IsLoading
|
|
|
|
|
{
|
|
|
|
|
get => isLoading;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
isLoading = value;
|
|
|
|
|
|
|
|
|
|
Enabled.Value = !isLoading;
|
|
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
|
loading.Show();
|
|
|
|
|
else
|
|
|
|
|
loading.Hide();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Vector2 LoadingAnimationSize
|
|
|
|
|
{
|
|
|
|
|
get => loading.Size;
|
|
|
|
|
set => loading.Size = value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-21 14:33:31 +08:00
|
|
|
|
private readonly LoadingSpinner loading;
|
2019-10-17 18:57:17 +08:00
|
|
|
|
|
2019-10-17 20:24:51 +08:00
|
|
|
|
protected LoadingButton()
|
2022-11-03 16:47:29 +08:00
|
|
|
|
: base(HoverSampleSet.Button)
|
2019-10-17 18:57:17 +08:00
|
|
|
|
{
|
2021-11-05 15:12:41 +08:00
|
|
|
|
Add(loading = new LoadingSpinner
|
2019-10-17 18:57:17 +08:00
|
|
|
|
{
|
2021-11-05 15:12:41 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Size = new Vector2(12),
|
|
|
|
|
Depth = -1,
|
2019-10-17 18:57:17 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-05 15:12:41 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
|
|
|
|
Add(CreateContent());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
loading.State.BindValueChanged(s =>
|
|
|
|
|
{
|
|
|
|
|
if (s.NewValue == Visibility.Visible)
|
|
|
|
|
OnLoadStarted();
|
|
|
|
|
else
|
|
|
|
|
OnLoadFinished();
|
|
|
|
|
}, true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 18:57:17 +08:00
|
|
|
|
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 22:49:34 +08:00
|
|
|
|
protected virtual void OnLoadStarted()
|
2019-10-17 18:57:17 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-24 22:49:34 +08:00
|
|
|
|
protected virtual void OnLoadFinished()
|
2019-10-17 18:57:17 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-24 22:49:34 +08:00
|
|
|
|
protected abstract Drawable CreateContent();
|
2019-10-17 18:57:17 +08:00
|
|
|
|
}
|
|
|
|
|
}
|