2019-07-03 11:02:35 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 16:43:03 +08:00
|
|
|
|
// 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-06-04 17:29:35 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
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;
|
2019-06-12 01:31:01 +08:00
|
|
|
|
using osu.Game.Online;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Direct
|
|
|
|
|
{
|
2019-07-03 11:02:35 +08:00
|
|
|
|
public class PanelDownloadButton : BeatmapDownloadTrackingComposite
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-06-27 12:38:21 +08:00
|
|
|
|
protected bool DownloadEnabled => button.Enabled.Value;
|
2019-06-27 12:35:14 +08:00
|
|
|
|
|
2019-01-18 13:28:06 +08:00
|
|
|
|
private readonly bool noVideo;
|
2018-07-03 21:43:42 +08:00
|
|
|
|
|
2019-01-18 13:28:06 +08:00
|
|
|
|
private readonly ShakeContainer shakeContainer;
|
2019-07-03 11:02:35 +08:00
|
|
|
|
private readonly DownloadButton button;
|
2019-01-18 13:28:06 +08:00
|
|
|
|
|
2019-07-03 11:02:35 +08:00
|
|
|
|
public PanelDownloadButton(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,
|
2019-07-03 11:02:35 +08:00
|
|
|
|
Child = button = new DownloadButton
|
2018-07-03 21:43:42 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2019-07-02 18:25:30 +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-07-02 18:25:30 +08:00
|
|
|
|
button.State.BindTo(State);
|
2018-07-13 20:19:10 +08:00
|
|
|
|
FinishTransforms(true);
|
2018-07-03 21:43:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-27 12:35:14 +08:00
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2019-07-02 18:43:47 +08:00
|
|
|
|
private void load(OsuGame game, BeatmapManager beatmaps)
|
2018-07-03 21:43:42 +08:00
|
|
|
|
{
|
2020-02-14 14:01:30 +08:00
|
|
|
|
if (BeatmapSet.Value?.OnlineInfo?.Availability?.DownloadDisabled ?? false)
|
2019-06-11 02:13:37 +08:00
|
|
|
|
{
|
2019-06-27 12:35:14 +08:00
|
|
|
|
button.Enabled.Value = false;
|
2020-01-15 03:26:54 +08:00
|
|
|
|
button.TooltipText = "this beatmap is currently not available for download.";
|
2019-06-11 02:14:12 +08:00
|
|
|
|
return;
|
2019-06-11 02:13:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
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:
|
2020-02-14 14:01:30 +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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|