2019-07-03 12:02:35 +09:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 17:43:03 +09:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2020-04-12 16:00:05 +03:00
|
|
|
|
using System;
|
2018-07-03 19:13:42 +05:30
|
|
|
|
using osu.Framework.Allocation;
|
2020-04-12 21:57:35 +03:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
using osu.Framework.Graphics;
|
2018-06-04 06:29:35 -03:00
|
|
|
|
using osu.Game.Beatmaps;
|
2020-04-11 14:08:16 +03:00
|
|
|
|
using osu.Game.Configuration;
|
2019-01-18 14:28:06 +09:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-07-13 16:28:18 +09:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2019-06-11 23:01:01 +05:30
|
|
|
|
using osu.Game.Online;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2020-04-21 16:03:18 +09:00
|
|
|
|
namespace osu.Game.Overlays.BeatmapListing.Panels
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2020-04-21 16:03:18 +09:00
|
|
|
|
public class BeatmapPanelDownloadButton : BeatmapDownloadTrackingComposite
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2019-06-27 13:38:21 +09:00
|
|
|
|
protected bool DownloadEnabled => button.Enabled.Value;
|
2019-06-27 13:35:14 +09:00
|
|
|
|
|
2020-04-13 15:13:35 +09:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Currently selected beatmap. Used to present the correct difficulty after completing a download.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public readonly IBindable<BeatmapInfo> SelectedBeatmap = new Bindable<BeatmapInfo>();
|
2020-04-12 16:00:05 +03:00
|
|
|
|
|
2019-01-18 14:28:06 +09:00
|
|
|
|
private readonly ShakeContainer shakeContainer;
|
2019-07-03 12:02:35 +09:00
|
|
|
|
private readonly DownloadButton button;
|
2020-04-13 17:28:02 +03:00
|
|
|
|
private Bindable<bool> noVideoSetting;
|
2019-01-18 14:28:06 +09:00
|
|
|
|
|
2020-04-21 16:03:18 +09:00
|
|
|
|
public BeatmapPanelDownloadButton(BeatmapSetInfo beatmapSet)
|
2019-01-18 14:28:06 +09:00
|
|
|
|
: base(beatmapSet)
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2019-01-18 14:28:06 +09:00
|
|
|
|
InternalChild = shakeContainer = new ShakeContainer
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2019-01-18 14:28:06 +09:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2019-07-03 12:02:35 +09:00
|
|
|
|
Child = button = new DownloadButton
|
2018-07-03 19:13:42 +05:30
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2019-07-02 15:55:30 +05:30
|
|
|
|
},
|
2019-01-18 14:28:06 +09:00
|
|
|
|
};
|
2018-07-03 19:13:42 +05:30
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2019-01-18 14:28:06 +09:00
|
|
|
|
|
2019-07-02 15:55:30 +05:30
|
|
|
|
button.State.BindTo(State);
|
2018-07-13 21:19:10 +09:00
|
|
|
|
FinishTransforms(true);
|
2018-07-03 19:13:42 +05:30
|
|
|
|
}
|
|
|
|
|
|
2019-06-27 13:35:14 +09:00
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2020-04-11 14:08:16 +03:00
|
|
|
|
private void load(OsuGame game, BeatmapManager beatmaps, OsuConfigManager osuConfig)
|
2018-07-03 19:13:42 +05:30
|
|
|
|
{
|
2020-04-13 17:28:02 +03:00
|
|
|
|
noVideoSetting = osuConfig.GetBindable<bool>(OsuSetting.PreferNoVideo);
|
2020-04-12 21:57:35 +03:00
|
|
|
|
|
2019-01-18 14:28:06 +09:00
|
|
|
|
button.Action = () =>
|
2018-07-17 21:36:33 +09:00
|
|
|
|
{
|
2019-01-18 14:28:06 +09:00
|
|
|
|
switch (State.Value)
|
2018-07-17 21:36:33 +09:00
|
|
|
|
{
|
2019-01-18 14:28:06 +09:00
|
|
|
|
case DownloadState.Downloading:
|
|
|
|
|
case DownloadState.Downloaded:
|
|
|
|
|
shakeContainer.Shake();
|
2018-07-17 21:36:33 +09:00
|
|
|
|
break;
|
2019-04-01 12:44:46 +09:00
|
|
|
|
|
2019-01-18 14:28:06 +09:00
|
|
|
|
case DownloadState.LocallyAvailable:
|
2020-04-12 16:00:05 +03:00
|
|
|
|
Predicate<BeatmapInfo> findPredicate = null;
|
2020-04-13 15:13:35 +09:00
|
|
|
|
if (SelectedBeatmap.Value != null)
|
|
|
|
|
findPredicate = b => b.OnlineBeatmapID == SelectedBeatmap.Value.OnlineBeatmapID;
|
2020-04-12 16:00:05 +03:00
|
|
|
|
|
|
|
|
|
game?.PresentBeatmap(BeatmapSet.Value, findPredicate);
|
2018-07-17 21:36:33 +09:00
|
|
|
|
break;
|
2019-04-01 12:44:46 +09:00
|
|
|
|
|
2018-07-17 21:36:33 +09:00
|
|
|
|
default:
|
2020-04-12 21:57:35 +03:00
|
|
|
|
beatmaps.Download(BeatmapSet.Value, noVideoSetting.Value);
|
2018-07-17 21:36:33 +09:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
};
|
2020-05-09 18:09:17 +09:00
|
|
|
|
|
|
|
|
|
State.BindValueChanged(state =>
|
|
|
|
|
{
|
|
|
|
|
switch (state.NewValue)
|
|
|
|
|
{
|
|
|
|
|
case DownloadState.LocallyAvailable:
|
|
|
|
|
button.Enabled.Value = true;
|
2020-07-10 20:25:52 +09:00
|
|
|
|
button.TooltipText = "Go to beatmap";
|
2020-05-09 18:09:17 +09:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
if (BeatmapSet.Value?.OnlineInfo?.Availability?.DownloadDisabled ?? false)
|
|
|
|
|
{
|
|
|
|
|
button.Enabled.Value = false;
|
|
|
|
|
button.TooltipText = "this beatmap is currently not available for download.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}, true);
|
2018-04-13 18:19:50 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|