mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 14:32:55 +08:00
Hook up download logic with BeatmapSetOverlay download buttons.
- Add noVideo option to DownloadBeatmapSetRequest - Make Download fire an event with new download instead of returning it
This commit is contained in:
parent
067985cad3
commit
16e48ed187
@ -18,6 +18,7 @@ using osu.Framework.Platform;
|
||||
using osu.Game.Beatmaps.Formats;
|
||||
using osu.Game.Beatmaps.IO;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.IO;
|
||||
using osu.Game.IPC;
|
||||
using osu.Game.Online.API;
|
||||
@ -52,6 +53,11 @@ namespace osu.Game.Beatmaps
|
||||
/// </summary>
|
||||
public event Action<BeatmapInfo> BeatmapRestored;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a beatmap download begins.
|
||||
/// </summary>
|
||||
public event Action<DownloadBeatmapSetRequest> BeatmapDownloadBegan;
|
||||
|
||||
/// <summary>
|
||||
/// A default representation of a WorkingBeatmap to use when no beatmap is available.
|
||||
/// </summary>
|
||||
@ -221,21 +227,29 @@ namespace osu.Game.Beatmaps
|
||||
/// Downloads a beatmap.
|
||||
/// </summary>
|
||||
/// <param name="beatmapSetInfo">The <see cref="BeatmapSetInfo"/> to be downloaded.</param>
|
||||
/// <returns>A new <see cref="DownloadBeatmapSetRequest"/>, or an existing one if a download is already in progress.</returns>
|
||||
public DownloadBeatmapSetRequest Download(BeatmapSetInfo beatmapSetInfo)
|
||||
/// <param name="noVideo">Whether the beatmap should be downloaded without video. Defaults to false.</param>
|
||||
public void Download(BeatmapSetInfo beatmapSetInfo, bool noVideo = false)
|
||||
{
|
||||
var existing = GetExistingDownload(beatmapSetInfo);
|
||||
|
||||
if (existing != null) return existing;
|
||||
if (existing != null || api == null) return;
|
||||
|
||||
if (api == null) return null;
|
||||
if (!api.LocalUser.Value.IsSupporter)
|
||||
{
|
||||
PostNotification?.Invoke(new SimpleNotification
|
||||
{
|
||||
Icon = FontAwesome.fa_superpowers,
|
||||
Text = "You gotta be a supporter to download for now 'yo"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
ProgressNotification downloadNotification = new ProgressNotification
|
||||
{
|
||||
Text = $"Downloading {beatmapSetInfo.Metadata.Artist} - {beatmapSetInfo.Metadata.Title}",
|
||||
};
|
||||
|
||||
var request = new DownloadBeatmapSetRequest(beatmapSetInfo);
|
||||
var request = new DownloadBeatmapSetRequest(beatmapSetInfo, noVideo);
|
||||
|
||||
request.DownloadProgressed += progress =>
|
||||
{
|
||||
@ -280,8 +294,7 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
// don't run in the main api queue as this is a long-running task.
|
||||
Task.Factory.StartNew(() => request.Perform(api), TaskCreationOptions.LongRunning);
|
||||
|
||||
return request;
|
||||
BeatmapDownloadBegan?.Invoke(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -12,13 +12,16 @@ namespace osu.Game.Online.API.Requests
|
||||
|
||||
public Action<float> DownloadProgressed;
|
||||
|
||||
public DownloadBeatmapSetRequest(BeatmapSetInfo set)
|
||||
private readonly bool noVideo;
|
||||
|
||||
public DownloadBeatmapSetRequest(BeatmapSetInfo set, bool noVideo)
|
||||
{
|
||||
this.noVideo = noVideo;
|
||||
BeatmapSet = set;
|
||||
|
||||
Progress += (current, total) => DownloadProgressed?.Invoke((float) current / total);
|
||||
}
|
||||
|
||||
protected override string Target => $@"beatmapsets/{BeatmapSet.OnlineBeatmapSetID}/download";
|
||||
protected override string Target => $@"beatmapsets/{BeatmapSet.OnlineBeatmapSetID}/download{(noVideo ? "?noVideo=1" : "")}";
|
||||
}
|
||||
}
|
||||
|
@ -27,12 +27,17 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
private readonly Container coverContainer;
|
||||
private readonly OsuSpriteText title, artist;
|
||||
private readonly AuthorInfo author;
|
||||
private readonly Container downloadButtonsContainer;
|
||||
public Details Details;
|
||||
|
||||
private BeatmapManager beatmaps;
|
||||
|
||||
private DelayedLoadWrapper cover;
|
||||
|
||||
public readonly BeatmapPicker Picker;
|
||||
|
||||
private bool isDownloading => beatmaps.GetExistingDownload(BeatmapSet) != null;
|
||||
|
||||
private BeatmapSetInfo beatmapSet;
|
||||
public BeatmapSetInfo BeatmapSet
|
||||
{
|
||||
@ -162,7 +167,7 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new FavouriteButton(),
|
||||
new Container
|
||||
downloadButtonsContainer = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding { Left = buttons_height + buttons_spacing },
|
||||
@ -172,7 +177,10 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Alpha = 0f,
|
||||
Child = new DownloadButton("Download", @""),
|
||||
Child = new DownloadButton("Download", @"")
|
||||
{
|
||||
Action = () => download(false),
|
||||
},
|
||||
},
|
||||
videoButtons = new FillFlowContainer
|
||||
{
|
||||
@ -181,8 +189,14 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
Alpha = 0f,
|
||||
Children = new[]
|
||||
{
|
||||
new DownloadButton("Download", "with Video"),
|
||||
new DownloadButton("Download", "without Video"),
|
||||
new DownloadButton("Download", "with Video")
|
||||
{
|
||||
Action = () => download(false),
|
||||
},
|
||||
new DownloadButton("Download", "without Video")
|
||||
{
|
||||
Action = () => download(true),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -220,9 +234,25 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
private void load(OsuColour colours, BeatmapManager beatmaps)
|
||||
{
|
||||
tabsBg.Colour = colours.Gray3;
|
||||
this.beatmaps = beatmaps;
|
||||
}
|
||||
|
||||
private void download(bool video)
|
||||
{
|
||||
if (beatmaps.GetExistingDownload(BeatmapSet) != null)
|
||||
{
|
||||
downloadButtonsContainer.MoveToX(-5, 50, Easing.OutSine).Then()
|
||||
.MoveToX(5, 100, Easing.InOutSine).Then()
|
||||
.MoveToX(-5, 100, Easing.InOutSine).Then()
|
||||
.MoveToX(0, 50, Easing.InSine).Then();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
beatmaps.Download(BeatmapSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,11 +24,14 @@ namespace osu.Game.Overlays
|
||||
public const float X_PADDING = 40;
|
||||
public const float RIGHT_WIDTH = 275;
|
||||
|
||||
private BeatmapSetInfo currentBeatmap;
|
||||
|
||||
private readonly Header header;
|
||||
private readonly Info info;
|
||||
|
||||
private APIAccess api;
|
||||
private RulesetStore rulesets;
|
||||
private BeatmapManager manager;
|
||||
|
||||
// receive input outside our bounds so we can trigger a close event on ourselves.
|
||||
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => true;
|
||||
@ -83,10 +86,17 @@ namespace osu.Game.Overlays
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(APIAccess api, RulesetStore rulesets)
|
||||
private void load(APIAccess api, RulesetStore rulesets, BeatmapManager manager)
|
||||
{
|
||||
this.api = api;
|
||||
this.rulesets = rulesets;
|
||||
this.manager = manager;
|
||||
|
||||
manager.BeatmapSetAdded += beatmap =>
|
||||
{
|
||||
if (beatmap.OnlineBeatmapSetID == currentBeatmap.OnlineBeatmapSetID)
|
||||
Hide();
|
||||
};
|
||||
}
|
||||
|
||||
protected override void PopIn()
|
||||
@ -118,7 +128,7 @@ namespace osu.Game.Overlays
|
||||
|
||||
public void ShowBeatmapSet(BeatmapSetInfo set)
|
||||
{
|
||||
header.BeatmapSet = info.BeatmapSet = set;
|
||||
currentBeatmap = header.BeatmapSet = info.BeatmapSet = set;
|
||||
Show();
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ using osu.Framework.Input;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Game.Overlays.Notifications;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Audio.Track;
|
||||
@ -109,6 +108,8 @@ namespace osu.Game.Overlays.Direct
|
||||
|
||||
if (downloadRequest != null)
|
||||
attachDownload(downloadRequest);
|
||||
|
||||
beatmaps.BeatmapDownloadBegan += attachDownload;
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
@ -151,16 +152,6 @@ namespace osu.Game.Overlays.Direct
|
||||
|
||||
protected void StartDownload()
|
||||
{
|
||||
if (!api.LocalUser.Value.IsSupporter)
|
||||
{
|
||||
notifications.Post(new SimpleNotification
|
||||
{
|
||||
Icon = FontAwesome.fa_superpowers,
|
||||
Text = "You gotta be a supporter to download for now 'yo"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (beatmaps.GetExistingDownload(SetInfo) != null)
|
||||
{
|
||||
// we already have an active download running.
|
||||
@ -172,13 +163,14 @@ namespace osu.Game.Overlays.Direct
|
||||
return;
|
||||
}
|
||||
|
||||
var request = beatmaps.Download(SetInfo);
|
||||
|
||||
attachDownload(request);
|
||||
beatmaps.Download(SetInfo);
|
||||
}
|
||||
|
||||
private void attachDownload(DownloadBeatmapSetRequest request)
|
||||
{
|
||||
if (request.BeatmapSet.OnlineBeatmapSetID != SetInfo.OnlineBeatmapSetID)
|
||||
return;
|
||||
|
||||
progressBar.FadeIn(400, Easing.OutQuint);
|
||||
progressBar.ResizeHeightTo(4, 400, Easing.OutQuint);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user