Improve the first run progress button to show loading and completion status

This commit is contained in:
Dean Herbert 2022-05-16 19:21:19 +09:00
parent d13c1d5d5a
commit ef5b2233d7
2 changed files with 106 additions and 42 deletions

View File

@ -0,0 +1,103 @@
// 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.
#nullable enable
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2;
using osuTK;
namespace osu.Game.Overlays.FirstRunSetup
{
public class ProgressRoundedButton : RoundedButton
{
public new Action? Action;
[Resolved]
private OsuColour colours { get; set; } = null!;
private ProgressBar progressBar = null!;
private LoadingSpinner loading = null!;
private SpriteIcon tick = null!;
public ProgressRoundedButton()
{
base.Action = () =>
{
loading.Show();
Enabled.Value = false;
Action?.Invoke();
};
}
protected override void LoadComplete()
{
base.LoadComplete();
AddRange(new Drawable[]
{
progressBar = new ProgressBar(false)
{
RelativeSizeAxes = Axes.Both,
Blending = BlendingParameters.Additive,
FillColour = BackgroundColour,
Alpha = 0.5f,
Depth = float.MinValue
},
new Container
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Margin = new MarginPadding(15),
Size = new Vector2(20),
Children = new Drawable[]
{
loading = new LoadingSpinner
{
RelativeSizeAxes = Axes.Both,
Size = Vector2.One,
},
tick = new SpriteIcon
{
Icon = FontAwesome.Solid.Check,
RelativeSizeAxes = Axes.Both,
Size = Vector2.One,
Alpha = 0,
}
}
},
});
}
public void Complete()
{
loading.Hide();
tick.FadeIn(500, Easing.OutQuint);
Background.FadeColour(colours.Green, 500, Easing.OutQuint);
progressBar.FillColour = colours.Green;
this.TransformBindableTo(progressBar.Current, 1, 500, Easing.OutQuint);
}
public void Abort()
{
loading.Hide();
Enabled.Value = true;
this.TransformBindableTo(progressBar.Current, 0, 500, Easing.OutQuint);
}
public void SetProgress(double progress, bool animated)
{
this.TransformBindableTo(progressBar.Current, progress, animated ? 500 : 0, Easing.OutQuint);
}
}
}

View File

@ -14,8 +14,6 @@
using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Localisation;
using osu.Game.Online;
using osuTK;
@ -127,7 +125,10 @@ private void load(LegacyImportManager? legacyImportManager)
if (t.IsCompletedSuccessfully)
importBeatmapsButton.Complete();
else
{
importBeatmapsButton.Enabled.Value = true;
importBeatmapsButton.Abort();
}
}));
}
},
@ -214,45 +215,5 @@ void updateProgress()
downloadBundledButton.SetProgress(progress, true);
}
}
private class ProgressRoundedButton : RoundedButton
{
[Resolved]
private OsuColour colours { get; set; } = null!;
private ProgressBar progressBar = null!;
protected override void LoadComplete()
{
base.LoadComplete();
Add(progressBar = new ProgressBar(false)
{
RelativeSizeAxes = Axes.Both,
Blending = BlendingParameters.Additive,
FillColour = BackgroundColour,
Alpha = 0.5f,
Depth = float.MinValue
});
}
public void Complete()
{
Enabled.Value = false;
Background.FadeColour(colours.Green, 500, Easing.OutQuint);
progressBar.FillColour = colours.Green;
this.TransformBindableTo(progressBar.Current, 1, 500, Easing.OutQuint);
}
public void SetProgress(double progress, bool animated)
{
if (!Enabled.Value)
return;
this.TransformBindableTo(progressBar.Current, progress, animated ? 500 : 0, Easing.OutQuint);
}
}
}
}