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