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