2018-06-04 17:08:39 +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
|
|
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Configuration;
|
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
|
|
|
|
public abstract class BeatmapSetDownloadButton : OsuClickableContainer
|
|
|
|
|
{
|
|
|
|
|
private readonly BeatmapSetInfo set;
|
|
|
|
|
private readonly bool noVideo;
|
|
|
|
|
|
2018-06-04 17:34:48 +08:00
|
|
|
|
private BeatmapManager beatmaps;
|
|
|
|
|
|
2018-06-04 17:47:39 +08:00
|
|
|
|
protected readonly BindableBool Downloaded = new BindableBool();
|
2018-06-04 17:08:39 +08:00
|
|
|
|
|
|
|
|
|
protected BeatmapSetDownloadButton(BeatmapSetInfo set, bool noVideo = false)
|
|
|
|
|
{
|
|
|
|
|
this.set = set;
|
|
|
|
|
this.noVideo = noVideo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2018-06-04 18:10:33 +08:00
|
|
|
|
private void load(BeatmapManager beatmaps)
|
2018-06-04 17:08:39 +08:00
|
|
|
|
{
|
2018-06-04 17:34:48 +08:00
|
|
|
|
this.beatmaps = beatmaps;
|
2018-06-04 17:08:39 +08:00
|
|
|
|
|
2018-06-04 17:34:48 +08:00
|
|
|
|
beatmaps.ItemAdded += setAdded;
|
|
|
|
|
beatmaps.ItemRemoved += setRemoved;
|
2018-06-04 17:08:39 +08:00
|
|
|
|
|
2018-06-04 17:47:39 +08:00
|
|
|
|
// initial value
|
|
|
|
|
Downloaded.Value = beatmaps.QueryBeatmapSets(s => s.OnlineBeatmapSetID == set.OnlineBeatmapSetID && !s.DeletePending).Count() != 0;
|
2018-06-04 17:08:39 +08:00
|
|
|
|
|
|
|
|
|
Action = () =>
|
|
|
|
|
{
|
|
|
|
|
if (beatmaps.GetExistingDownload(set) != null)
|
|
|
|
|
{
|
|
|
|
|
AlreadyDownloading();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
beatmaps.Download(set, noVideo);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnClick(InputState state)
|
|
|
|
|
{
|
2018-06-04 17:47:39 +08:00
|
|
|
|
if (Enabled.Value && !Downloaded.Value)
|
2018-06-04 17:08:39 +08:00
|
|
|
|
Action?.Invoke();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-04 17:34:48 +08:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
|
|
|
|
if (beatmaps != null)
|
|
|
|
|
{
|
|
|
|
|
beatmaps.ItemAdded -= setAdded;
|
|
|
|
|
beatmaps.ItemRemoved -= setRemoved;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-04 17:47:39 +08:00
|
|
|
|
protected virtual void AlreadyDownloading()
|
|
|
|
|
{
|
|
|
|
|
}
|
2018-06-04 17:34:48 +08:00
|
|
|
|
|
|
|
|
|
private void setAdded(BeatmapSetInfo s)
|
|
|
|
|
{
|
|
|
|
|
if (s.OnlineBeatmapSetID == set.OnlineBeatmapSetID)
|
2018-06-04 17:47:39 +08:00
|
|
|
|
Downloaded.Value = true;
|
2018-06-04 17:34:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setRemoved(BeatmapSetInfo s)
|
|
|
|
|
{
|
|
|
|
|
if (s.OnlineBeatmapSetID == set.OnlineBeatmapSetID)
|
2018-06-04 17:47:39 +08:00
|
|
|
|
Downloaded.Value = false;
|
2018-06-04 17:34:48 +08:00
|
|
|
|
}
|
2018-06-04 17:08:39 +08:00
|
|
|
|
}
|
|
|
|
|
}
|