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.
|
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Online;
|
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
2019-07-03 03:02:35 +00:00
|
|
|
|
public class DownloadButton : OsuAnimatedButton
|
2019-07-02 10:25:30 +00:00
|
|
|
|
{
|
|
|
|
|
public readonly Bindable<DownloadState> State = new Bindable<DownloadState>();
|
|
|
|
|
|
|
|
|
|
private readonly SpriteIcon icon;
|
|
|
|
|
private readonly SpriteIcon checkmark;
|
|
|
|
|
private readonly Box background;
|
|
|
|
|
|
2020-02-14 13:14:00 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private OsuColour colours { get; set; }
|
2019-07-02 10:25:30 +00:00
|
|
|
|
|
2019-07-03 03:02:35 +00:00
|
|
|
|
public DownloadButton()
|
2019-07-02 10:25:30 +00:00
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
background = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Depth = float.MaxValue
|
|
|
|
|
},
|
|
|
|
|
icon = new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Size = new Vector2(13),
|
|
|
|
|
Icon = FontAwesome.Solid.Download,
|
|
|
|
|
},
|
|
|
|
|
checkmark = new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
X = 8,
|
|
|
|
|
Size = Vector2.Zero,
|
|
|
|
|
Icon = FontAwesome.Solid.Check,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2020-02-14 13:14:00 +00:00
|
|
|
|
private void load()
|
2019-07-02 10:25:30 +00:00
|
|
|
|
{
|
|
|
|
|
State.BindValueChanged(updateState, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateState(ValueChangedEvent<DownloadState> state)
|
|
|
|
|
{
|
|
|
|
|
switch (state.NewValue)
|
|
|
|
|
{
|
|
|
|
|
case DownloadState.NotDownloaded:
|
|
|
|
|
background.FadeColour(colours.Gray4, 500, Easing.InOutExpo);
|
|
|
|
|
icon.MoveToX(0, 500, Easing.InOutExpo);
|
|
|
|
|
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:
|
|
|
|
|
background.FadeColour(colours.Blue, 500, Easing.InOutExpo);
|
|
|
|
|
icon.MoveToX(0, 500, Easing.InOutExpo);
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
case DownloadState.Downloaded:
|
|
|
|
|
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:
|
|
|
|
|
background.FadeColour(colours.Green, 500, Easing.InOutExpo);
|
|
|
|
|
icon.MoveToX(-8, 500, Easing.InOutExpo);
|
|
|
|
|
checkmark.ScaleTo(new Vector2(13), 500, Easing.InOutExpo);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|