1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 07:32:54 +08:00
osu-lazer/osu.Game/Beatmaps/Drawables/BeatmapSetDownloader.cs

79 lines
2.1 KiB
C#
Raw Normal View History

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;
2018-06-04 17:08:39 +08:00
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
2018-06-04 17:08:39 +08:00
namespace osu.Game.Beatmaps.Drawables
2018-06-04 17:08:39 +08:00
{
public class BeatmapSetDownloader : Drawable
2018-06-04 17:08:39 +08:00
{
private readonly BeatmapSetInfo set;
private readonly bool noVideo;
private BeatmapManager beatmaps;
public readonly BindableBool Downloaded = new BindableBool();
2018-06-04 17:08:39 +08:00
public event Action OnAlreadyDownloading;
public BeatmapSetDownloader(BeatmapSetInfo set, bool noVideo = false)
2018-06-04 17:08:39 +08:00
{
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
{
this.beatmaps = beatmaps;
2018-06-04 17:08:39 +08:00
beatmaps.ItemAdded += setAdded;
beatmaps.ItemRemoved += setRemoved;
2018-06-04 17:08: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
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (beatmaps != null)
{
beatmaps.ItemAdded -= setAdded;
beatmaps.ItemRemoved -= setRemoved;
}
}
public void Download()
{
if (Downloaded.Value)
return;
if (beatmaps.GetExistingDownload(set) != null)
{
OnAlreadyDownloading?.Invoke();
return;
}
beatmaps.Download(set, noVideo);
}
private void setAdded(BeatmapSetInfo s)
{
if (s.OnlineBeatmapSetID == set.OnlineBeatmapSetID)
Downloaded.Value = true;
}
private void setRemoved(BeatmapSetInfo s)
{
if (s.OnlineBeatmapSetID == set.OnlineBeatmapSetID)
Downloaded.Value = false;
}
2018-06-04 17:08:39 +08:00
}
}