1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 15:53:21 +08:00

BeatmapSetDownloadButton -> BeatmapSetDownloader

Allows it to integrate better with existing buttons, like HeaderButton.
This commit is contained in:
DrabWeb 2018-06-04 20:12:43 -03:00
parent 4bdc1fb781
commit 698a42f145
2 changed files with 26 additions and 27 deletions

View File

@ -1,25 +1,27 @@
// 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;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Input;
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Containers;
namespace osu.Game.Graphics.UserInterface
{
public abstract class BeatmapSetDownloadButton : OsuClickableContainer
public class BeatmapSetDownloader : Drawable
{
private readonly BeatmapSetInfo set;
private readonly bool noVideo;
private BeatmapManager beatmaps;
protected readonly BindableBool Downloaded = new BindableBool();
public readonly BindableBool Downloaded = new BindableBool();
protected BeatmapSetDownloadButton(BeatmapSetInfo set, bool noVideo = false)
public event Action OnAlreadyDownloading;
public BeatmapSetDownloader(BeatmapSetInfo set, bool noVideo = false)
{
this.set = set;
this.noVideo = noVideo;
@ -35,24 +37,6 @@ namespace osu.Game.Graphics.UserInterface
// initial value
Downloaded.Value = beatmaps.QueryBeatmapSets(s => s.OnlineBeatmapSetID == set.OnlineBeatmapSetID && !s.DeletePending).Count() != 0;
Action = () =>
{
if (beatmaps.GetExistingDownload(set) != null)
{
AlreadyDownloading();
return;
}
beatmaps.Download(set, noVideo);
};
}
protected override bool OnClick(InputState state)
{
if (Enabled.Value && !Downloaded.Value)
Action?.Invoke();
return true;
}
protected override void Dispose(bool isDisposing)
@ -66,8 +50,18 @@ namespace osu.Game.Graphics.UserInterface
}
}
protected virtual void AlreadyDownloading()
public void Download()
{
if (Downloaded.Value)
return;
if (beatmaps.GetExistingDownload(set) != null)
{
OnAlreadyDownloading?.Invoke();
return;
}
beatmaps.Download(set, noVideo);
}
private void setAdded(BeatmapSetInfo s)

View File

@ -5,19 +5,22 @@ using osu.Framework.Graphics;
using osu.Framework.Input;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using OpenTK;
namespace osu.Game.Overlays.Direct
{
public class DownloadButton : BeatmapSetDownloadButton
public class DownloadButton : OsuClickableContainer
{
private readonly SpriteIcon icon;
public DownloadButton(BeatmapSetInfo set, bool noVideo = false) : base(set, noVideo)
public DownloadButton(BeatmapSetInfo set, bool noVideo = false)
{
BeatmapSetDownloader downloader;
Children = new Drawable[]
{
downloader = new BeatmapSetDownloader(set, noVideo),
icon = new SpriteIcon
{
Anchor = Anchor.Centre,
@ -27,7 +30,9 @@ namespace osu.Game.Overlays.Direct
},
};
Downloaded.ValueChanged += e =>
Action = downloader.Download;
downloader.Downloaded.ValueChanged += e =>
{
if (e)
this.FadeOut(200);