2018-04-13 17:19:50 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2018-07-31 13:41:31 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Configuration;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-07-31 13:50:57 +08:00
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2018-06-05 07:27:34 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2018-06-05 07:30:54 +08:00
|
|
|
|
using osu.Game.Beatmaps.Drawables;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-07-31 13:41:31 +08:00
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
|
using osu.Game.Users;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-04-18 15:04:02 +08:00
|
|
|
|
namespace osu.Game.Overlays.BeatmapSet.Buttons
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-07-31 13:50:57 +08:00
|
|
|
|
public class DownloadButton : HeaderButton, IHasTooltip
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-01-22 23:19:39 +08:00
|
|
|
|
public string TooltipText => "Download this beatmap";
|
2018-07-31 13:50:57 +08:00
|
|
|
|
|
2018-07-31 13:41:31 +08:00
|
|
|
|
private readonly IBindable<User> localUser = new Bindable<User>();
|
|
|
|
|
|
2018-06-06 14:13:37 +08:00
|
|
|
|
public DownloadButton(BeatmapSetInfo set, bool noVideo = false)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Width = 120;
|
|
|
|
|
|
2018-06-05 07:27:34 +08:00
|
|
|
|
BeatmapSetDownloader downloader;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Add(new Container
|
|
|
|
|
{
|
|
|
|
|
Depth = -1,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Padding = new MarginPadding { Horizontal = 10 },
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2018-06-05 07:27:34 +08:00
|
|
|
|
downloader = new BeatmapSetDownloader(set, noVideo),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
2018-06-06 14:13:37 +08:00
|
|
|
|
Text = "Download",
|
2018-04-13 17:19:50 +08:00
|
|
|
|
TextSize = 13,
|
|
|
|
|
Font = @"Exo2.0-Bold",
|
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
2018-06-08 07:47:27 +08:00
|
|
|
|
Text = set.OnlineInfo.HasVideo && noVideo ? "without Video" : string.Empty,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
TextSize = 11,
|
|
|
|
|
Font = @"Exo2.0-Bold",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Icon = FontAwesome.fa_download,
|
|
|
|
|
Size = new Vector2(16),
|
|
|
|
|
Margin = new MarginPadding { Right = 5 },
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
2018-06-05 07:27:34 +08:00
|
|
|
|
|
2018-06-06 14:18:42 +08:00
|
|
|
|
Action = () =>
|
|
|
|
|
{
|
2018-07-03 21:43:42 +08:00
|
|
|
|
if (downloader.DownloadState.Value == BeatmapSetDownloader.DownloadStatus.Downloading)
|
2018-06-06 14:18:42 +08:00
|
|
|
|
{
|
|
|
|
|
Content.MoveToX(-5, 50, Easing.OutSine).Then()
|
|
|
|
|
.MoveToX(5, 100, Easing.InOutSine).Then()
|
|
|
|
|
.MoveToX(-5, 100, Easing.InOutSine).Then()
|
|
|
|
|
.MoveToX(0, 50, Easing.InSine);
|
2018-07-03 21:43:42 +08:00
|
|
|
|
return;
|
2018-06-06 14:18:42 +08:00
|
|
|
|
}
|
2018-07-03 21:43:42 +08:00
|
|
|
|
|
|
|
|
|
downloader.Download();
|
2018-06-06 14:18:42 +08:00
|
|
|
|
};
|
2018-06-05 07:27:34 +08:00
|
|
|
|
|
2018-07-17 13:35:09 +08:00
|
|
|
|
downloader.DownloadState.ValueChanged += state =>
|
2018-06-05 07:27:34 +08:00
|
|
|
|
{
|
2018-07-17 13:35:09 +08:00
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case BeatmapSetDownloader.DownloadStatus.Downloaded:
|
|
|
|
|
this.FadeOut(200);
|
|
|
|
|
break;
|
|
|
|
|
case BeatmapSetDownloader.DownloadStatus.NotDownloaded:
|
|
|
|
|
this.FadeIn(200);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-06-05 07:27:34 +08:00
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2018-07-31 13:41:31 +08:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(APIAccess api)
|
|
|
|
|
{
|
|
|
|
|
localUser.BindTo(api.LocalUser);
|
|
|
|
|
Enabled.BindValueChanged(enabledChanged, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void enabledChanged(bool enabled) => this.FadeColour(enabled ? Color4.White : Color4.Gray, 200, Easing.OutQuint);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|