mirror of
https://github.com/ppy/osu.git
synced 2025-03-05 19:12:56 +08:00
BeatmapSetDownloadButton -> BeatmapSetDownloader
Allows it to integrate better with existing buttons, like HeaderButton.
This commit is contained in:
parent
4bdc1fb781
commit
698a42f145
@ -1,25 +1,27 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Configuration;
|
using osu.Framework.Configuration;
|
||||||
using osu.Framework.Input;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Graphics.Containers;
|
|
||||||
|
|
||||||
namespace osu.Game.Graphics.UserInterface
|
namespace osu.Game.Graphics.UserInterface
|
||||||
{
|
{
|
||||||
public abstract class BeatmapSetDownloadButton : OsuClickableContainer
|
public class BeatmapSetDownloader : Drawable
|
||||||
{
|
{
|
||||||
private readonly BeatmapSetInfo set;
|
private readonly BeatmapSetInfo set;
|
||||||
private readonly bool noVideo;
|
private readonly bool noVideo;
|
||||||
|
|
||||||
private BeatmapManager beatmaps;
|
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.set = set;
|
||||||
this.noVideo = noVideo;
|
this.noVideo = noVideo;
|
||||||
@ -35,24 +37,6 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
|
|
||||||
// initial value
|
// initial value
|
||||||
Downloaded.Value = beatmaps.QueryBeatmapSets(s => s.OnlineBeatmapSetID == set.OnlineBeatmapSetID && !s.DeletePending).Count() != 0;
|
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)
|
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)
|
private void setAdded(BeatmapSetInfo s)
|
@ -5,19 +5,22 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Input;
|
using osu.Framework.Input;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Direct
|
namespace osu.Game.Overlays.Direct
|
||||||
{
|
{
|
||||||
public class DownloadButton : BeatmapSetDownloadButton
|
public class DownloadButton : OsuClickableContainer
|
||||||
{
|
{
|
||||||
private readonly SpriteIcon icon;
|
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[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
|
downloader = new BeatmapSetDownloader(set, noVideo),
|
||||||
icon = new SpriteIcon
|
icon = new SpriteIcon
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
@ -27,7 +30,9 @@ namespace osu.Game.Overlays.Direct
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Downloaded.ValueChanged += e =>
|
Action = downloader.Download;
|
||||||
|
|
||||||
|
downloader.Downloaded.ValueChanged += e =>
|
||||||
{
|
{
|
||||||
if (e)
|
if (e)
|
||||||
this.FadeOut(200);
|
this.FadeOut(200);
|
||||||
|
Loading…
Reference in New Issue
Block a user