2019-07-02 10:25:30 +00: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 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2019-07-02 10:25:30 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Online;
|
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
2021-02-02 07:57:08 +00:00
|
|
|
|
public partial class DownloadButton : GrayButton
|
2019-07-02 10:25:30 +00:00
|
|
|
|
{
|
2020-02-14 13:14:00 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private OsuColour colours { get; set; }
|
2019-07-02 10:25:30 +00:00
|
|
|
|
|
2021-02-02 07:57:08 +00:00
|
|
|
|
public readonly Bindable<DownloadState> State = new Bindable<DownloadState>();
|
|
|
|
|
|
|
|
|
|
private SpriteIcon checkmark;
|
|
|
|
|
|
2019-07-03 03:02:35 +00:00
|
|
|
|
public DownloadButton()
|
2021-02-02 07:57:08 +00:00
|
|
|
|
: base(FontAwesome.Solid.Download)
|
2019-07-02 10:25:30 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2020-02-14 13:14:00 +00:00
|
|
|
|
private void load()
|
2019-07-02 10:25:30 +00:00
|
|
|
|
{
|
2021-04-19 01:35:44 +00:00
|
|
|
|
Add(checkmark = new SpriteIcon
|
2021-02-02 07:57:08 +00:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
X = 8,
|
|
|
|
|
Size = Vector2.Zero,
|
|
|
|
|
Icon = FontAwesome.Solid.Check,
|
|
|
|
|
});
|
|
|
|
|
|
2019-07-02 10:25:30 +00:00
|
|
|
|
State.BindValueChanged(updateState, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateState(ValueChangedEvent<DownloadState> state)
|
|
|
|
|
{
|
|
|
|
|
switch (state.NewValue)
|
|
|
|
|
{
|
|
|
|
|
case DownloadState.NotDownloaded:
|
2021-02-02 07:57:08 +00:00
|
|
|
|
Background.FadeColour(colours.Gray4, 500, Easing.InOutExpo);
|
|
|
|
|
Icon.MoveToX(0, 500, Easing.InOutExpo);
|
2019-07-02 10:25:30 +00:00
|
|
|
|
checkmark.ScaleTo(Vector2.Zero, 500, Easing.InOutExpo);
|
2020-07-10 11:22:51 +00:00
|
|
|
|
TooltipText = "Download";
|
2019-07-02 10:25:30 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DownloadState.Downloading:
|
2021-02-02 07:57:08 +00:00
|
|
|
|
Background.FadeColour(colours.Blue, 500, Easing.InOutExpo);
|
|
|
|
|
Icon.MoveToX(0, 500, Easing.InOutExpo);
|
2019-07-02 10:25:30 +00:00
|
|
|
|
checkmark.ScaleTo(Vector2.Zero, 500, Easing.InOutExpo);
|
2020-07-10 11:22:51 +00:00
|
|
|
|
TooltipText = "Downloading...";
|
2019-07-02 10:25:30 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2021-01-13 15:04:29 +00:00
|
|
|
|
case DownloadState.Importing:
|
2021-02-02 07:57:08 +00:00
|
|
|
|
Background.FadeColour(colours.Yellow, 500, Easing.InOutExpo);
|
2020-07-10 11:22:51 +00:00
|
|
|
|
TooltipText = "Importing";
|
2019-07-02 10:25:30 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DownloadState.LocallyAvailable:
|
2021-02-02 07:57:08 +00:00
|
|
|
|
Background.FadeColour(colours.Green, 500, Easing.InOutExpo);
|
|
|
|
|
Icon.MoveToX(-8, 500, Easing.InOutExpo);
|
2019-07-02 10:25:30 +00:00
|
|
|
|
checkmark.ScaleTo(new Vector2(13), 500, Easing.InOutExpo);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|