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
|
|
|
|
|
2020-04-12 21:00:05 +08:00
|
|
|
|
using System;
|
2018-07-03 21:43:42 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2020-04-13 02:57:35 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2021-10-27 19:49:15 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-06-04 17:29:35 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2020-04-11 19:08:16 +08:00
|
|
|
|
using osu.Game.Configuration;
|
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;
|
2021-10-29 16:58:46 +08:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-04-21 15:03:18 +08:00
|
|
|
|
namespace osu.Game.Overlays.BeatmapListing.Panels
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-10-27 19:49:15 +08:00
|
|
|
|
public class BeatmapPanelDownloadButton : CompositeDrawable
|
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
|
|
|
|
|
2020-04-13 14:13:35 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Currently selected beatmap. Used to present the correct difficulty after completing a download.
|
|
|
|
|
/// </summary>
|
2021-10-29 16:58:46 +08:00
|
|
|
|
public readonly IBindable<APIBeatmap> SelectedBeatmap = new Bindable<APIBeatmap>();
|
2020-04-12 21:00:05 +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;
|
2020-04-13 22:28:02 +08:00
|
|
|
|
private Bindable<bool> noVideoSetting;
|
2019-01-18 13:28:06 +08:00
|
|
|
|
|
2021-10-27 19:49:15 +08:00
|
|
|
|
protected readonly BeatmapDownloadTracker DownloadTracker;
|
|
|
|
|
|
|
|
|
|
protected readonly Bindable<DownloadState> State = new Bindable<DownloadState>();
|
|
|
|
|
|
2021-10-29 16:58:46 +08:00
|
|
|
|
private readonly IBeatmapSetInfo beatmapSet;
|
2021-10-27 19:49:15 +08:00
|
|
|
|
|
2021-10-29 16:58:46 +08:00
|
|
|
|
public BeatmapPanelDownloadButton(IBeatmapSetInfo beatmapSet)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-10-27 19:49:15 +08:00
|
|
|
|
this.beatmapSet = beatmapSet;
|
2021-10-27 20:26:26 +08:00
|
|
|
|
|
2021-10-27 19:49:15 +08:00
|
|
|
|
InternalChildren = new Drawable[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-10-27 19:49:15 +08:00
|
|
|
|
shakeContainer = new ShakeContainer
|
2018-07-03 21:43:42 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2021-10-27 19:49:15 +08:00
|
|
|
|
Child = button = new DownloadButton
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2021-10-27 20:26:26 +08:00
|
|
|
|
State = { BindTarget = State }
|
2021-10-27 19:49:15 +08:00
|
|
|
|
},
|
2019-07-02 18:25:30 +08:00
|
|
|
|
},
|
2021-10-27 19:49:15 +08:00
|
|
|
|
DownloadTracker = new BeatmapDownloadTracker(beatmapSet)
|
|
|
|
|
{
|
|
|
|
|
State = { BindTarget = State }
|
|
|
|
|
}
|
2019-01-18 13:28:06 +08:00
|
|
|
|
};
|
2021-08-10 14:14:43 +08:00
|
|
|
|
|
|
|
|
|
button.Add(new DownloadProgressBar(beatmapSet)
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Depth = -1,
|
|
|
|
|
});
|
2018-07-03 21:43:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-27 12:35:14 +08:00
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2020-04-11 19:08:16 +08:00
|
|
|
|
private void load(OsuGame game, BeatmapManager beatmaps, OsuConfigManager osuConfig)
|
2018-07-03 21:43:42 +08:00
|
|
|
|
{
|
2020-04-13 22:28:02 +08:00
|
|
|
|
noVideoSetting = osuConfig.GetBindable<bool>(OsuSetting.PreferNoVideo);
|
2020-04-13 02:57:35 +08:00
|
|
|
|
|
2019-01-18 13:28:06 +08:00
|
|
|
|
button.Action = () =>
|
2018-07-17 20:36:33 +08:00
|
|
|
|
{
|
2021-10-27 19:49:15 +08:00
|
|
|
|
switch (DownloadTracker.State.Value)
|
2018-07-17 20:36:33 +08:00
|
|
|
|
{
|
2019-01-18 13:28:06 +08:00
|
|
|
|
case DownloadState.Downloading:
|
2021-01-13 23:04:29 +08:00
|
|
|
|
case DownloadState.Importing:
|
2019-01-18 13:28:06 +08:00
|
|
|
|
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-04-12 21:00:05 +08:00
|
|
|
|
Predicate<BeatmapInfo> findPredicate = null;
|
2020-04-13 14:13:35 +08:00
|
|
|
|
if (SelectedBeatmap.Value != null)
|
2021-10-29 16:58:46 +08:00
|
|
|
|
findPredicate = b => b.OnlineBeatmapID == SelectedBeatmap.Value.OnlineID;
|
2020-04-12 21:00:05 +08:00
|
|
|
|
|
2021-10-27 19:49:15 +08:00
|
|
|
|
game?.PresentBeatmap(beatmapSet, findPredicate);
|
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:
|
2021-11-03 02:22:39 +08:00
|
|
|
|
beatmaps.Download(beatmapSet, noVideoSetting.Value);
|
2018-07-17 20:36:33 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
};
|
2020-05-09 17:09:17 +08:00
|
|
|
|
|
2021-10-27 20:26:26 +08:00
|
|
|
|
State.BindValueChanged(state =>
|
2020-05-09 17:09:17 +08:00
|
|
|
|
{
|
|
|
|
|
switch (state.NewValue)
|
|
|
|
|
{
|
|
|
|
|
case DownloadState.LocallyAvailable:
|
|
|
|
|
button.Enabled.Value = true;
|
2020-07-10 19:25:52 +08:00
|
|
|
|
button.TooltipText = "Go to beatmap";
|
2020-05-09 17:09:17 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2021-10-29 16:58:46 +08:00
|
|
|
|
if ((beatmapSet as IBeatmapSetOnlineInfo)?.Availability.DownloadDisabled == true)
|
2020-05-09 17:09:17 +08:00
|
|
|
|
{
|
|
|
|
|
button.Enabled.Value = false;
|
|
|
|
|
button.TooltipText = "this beatmap is currently not available for download.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}, true);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2021-10-27 20:26:26 +08:00
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
FinishTransforms(true);
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|