2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-07-03 21:43:42 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2018-07-03 21:43:42 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2019-03-27 18:29:27 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-06-04 17:29:35 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2019-01-18 13:28:06 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-07-13 15:28:18 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Direct
|
|
|
|
|
{
|
2019-01-18 13:28:06 +08:00
|
|
|
|
public class DownloadButton : DownloadTrackingComposite
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-01-18 13:28:06 +08:00
|
|
|
|
private readonly bool noVideo;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private readonly SpriteIcon icon;
|
2018-07-03 21:43:42 +08:00
|
|
|
|
private readonly SpriteIcon checkmark;
|
|
|
|
|
private readonly Box background;
|
|
|
|
|
|
|
|
|
|
private OsuColour colours;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-01-18 13:28:06 +08:00
|
|
|
|
private readonly ShakeContainer shakeContainer;
|
|
|
|
|
|
|
|
|
|
private readonly OsuAnimatedButton button;
|
|
|
|
|
|
2018-07-17 20:36:33 +08:00
|
|
|
|
public DownloadButton(BeatmapSetInfo beatmapSet, bool noVideo = false)
|
2019-01-18 13:28:06 +08:00
|
|
|
|
: base(beatmapSet)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-01-18 13:28:06 +08:00
|
|
|
|
this.noVideo = noVideo;
|
2018-07-17 20:36:33 +08:00
|
|
|
|
|
2019-01-18 13:28:06 +08:00
|
|
|
|
InternalChild = shakeContainer = new ShakeContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-01-18 13:28:06 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Child = button = new OsuAnimatedButton
|
2018-07-03 21:43:42 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2019-01-18 13:28:06 +08: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),
|
2019-04-02 18:55:24 +08:00
|
|
|
|
Icon = FontAwesome.Solid.Download,
|
2019-01-18 13:28:06 +08:00
|
|
|
|
},
|
|
|
|
|
checkmark = new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
X = 8,
|
|
|
|
|
Size = Vector2.Zero,
|
2019-04-02 18:55:24 +08:00
|
|
|
|
Icon = FontAwesome.Solid.Check,
|
2019-01-18 13:28:06 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-03 21:43:42 +08:00
|
|
|
|
}
|
2019-01-18 13:28:06 +08:00
|
|
|
|
};
|
2018-07-03 21:43:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2019-01-18 13:28:06 +08:00
|
|
|
|
|
2019-02-22 19:13:38 +08:00
|
|
|
|
State.BindValueChanged(state => updateState(state.NewValue), true);
|
2018-07-13 20:19:10 +08:00
|
|
|
|
FinishTransforms(true);
|
2018-07-03 21:43:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-13 15:28:18 +08:00
|
|
|
|
[BackgroundDependencyLoader(permitNulls: true)]
|
2019-01-18 13:28:06 +08:00
|
|
|
|
private void load(OsuColour colours, OsuGame game, BeatmapManager beatmaps)
|
2018-07-03 21:43:42 +08:00
|
|
|
|
{
|
|
|
|
|
this.colours = colours;
|
2018-07-17 20:36:33 +08:00
|
|
|
|
|
2019-06-11 02:13:37 +08:00
|
|
|
|
if (BeatmapSet.Value.OnlineInfo.Availability?.DownloadDisabled ?? false)
|
|
|
|
|
{
|
|
|
|
|
button.Enabled.Value = false;
|
|
|
|
|
button.TooltipText = "Unavailable";
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-18 13:28:06 +08:00
|
|
|
|
button.Action = () =>
|
2018-07-17 20:36:33 +08:00
|
|
|
|
{
|
2019-01-18 13:28:06 +08:00
|
|
|
|
switch (State.Value)
|
2018-07-17 20:36:33 +08:00
|
|
|
|
{
|
2019-01-18 13:28:06 +08:00
|
|
|
|
case DownloadState.Downloading:
|
|
|
|
|
case DownloadState.Downloaded:
|
|
|
|
|
shakeContainer.Shake();
|
2018-07-17 20:36:33 +08:00
|
|
|
|
break;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2019-01-18 13:28:06 +08:00
|
|
|
|
case DownloadState.LocallyAvailable:
|
2019-02-21 17:56:34 +08:00
|
|
|
|
game.PresentBeatmap(BeatmapSet.Value);
|
2018-07-17 20:36:33 +08:00
|
|
|
|
break;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2018-07-17 20:36:33 +08:00
|
|
|
|
default:
|
2019-02-21 17:56:34 +08:00
|
|
|
|
beatmaps.Download(BeatmapSet.Value, noVideo);
|
2018-07-17 20:36:33 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-18 13:28:06 +08:00
|
|
|
|
private void updateState(DownloadState state)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-07-13 15:28:18 +08:00
|
|
|
|
switch (state)
|
2018-07-03 21:43:42 +08:00
|
|
|
|
{
|
2019-01-18 13:28:06 +08:00
|
|
|
|
case DownloadState.NotDownloaded:
|
2018-07-03 21:43:42 +08:00
|
|
|
|
background.FadeColour(colours.Gray4, 500, Easing.InOutExpo);
|
|
|
|
|
icon.MoveToX(0, 500, Easing.InOutExpo);
|
|
|
|
|
checkmark.ScaleTo(Vector2.Zero, 500, Easing.InOutExpo);
|
|
|
|
|
break;
|
|
|
|
|
|
2019-01-18 13:28:06 +08:00
|
|
|
|
case DownloadState.Downloading:
|
2018-07-03 21:43:42 +08:00
|
|
|
|
background.FadeColour(colours.Blue, 500, Easing.InOutExpo);
|
|
|
|
|
icon.MoveToX(0, 500, Easing.InOutExpo);
|
|
|
|
|
checkmark.ScaleTo(Vector2.Zero, 500, Easing.InOutExpo);
|
|
|
|
|
break;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2019-01-18 13:28:06 +08:00
|
|
|
|
case DownloadState.Downloaded:
|
|
|
|
|
background.FadeColour(colours.Yellow, 500, Easing.InOutExpo);
|
|
|
|
|
break;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2019-01-18 13:28:06 +08:00
|
|
|
|
case DownloadState.LocallyAvailable:
|
2018-07-03 21:43:42 +08:00
|
|
|
|
background.FadeColour(colours.Green, 500, Easing.InOutExpo);
|
|
|
|
|
icon.MoveToX(-8, 500, Easing.InOutExpo);
|
|
|
|
|
checkmark.ScaleTo(new Vector2(13), 500, Easing.InOutExpo);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|