mirror of
https://github.com/ppy/osu.git
synced 2025-01-30 07:32:55 +08:00
Maintain download progress between switching result views.
- Check for existing download requests on creating DirectPanel - Actually remove downloaded beatmap from results
This commit is contained in:
parent
31a507372a
commit
00306b6e38
@ -68,7 +68,7 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
private readonly APIAccess api;
|
private readonly APIAccess api;
|
||||||
|
|
||||||
private readonly Dictionary<BeatmapSetInfo, DownloadBeatmapSetRequest> downloadsMap;
|
private readonly Dictionary<int?, DownloadBeatmapSetRequest> downloadsMap;
|
||||||
|
|
||||||
// ReSharper disable once NotAccessedField.Local (we should keep a reference to this so it is not finalised)
|
// ReSharper disable once NotAccessedField.Local (we should keep a reference to this so it is not finalised)
|
||||||
private BeatmapIPCChannel ipc;
|
private BeatmapIPCChannel ipc;
|
||||||
@ -100,7 +100,7 @@ namespace osu.Game.Beatmaps
|
|||||||
if (importHost != null)
|
if (importHost != null)
|
||||||
ipc = new BeatmapIPCChannel(importHost, this);
|
ipc = new BeatmapIPCChannel(importHost, this);
|
||||||
|
|
||||||
downloadsMap = new Dictionary<BeatmapSetInfo, DownloadBeatmapSetRequest>();
|
downloadsMap = new Dictionary<int?, DownloadBeatmapSetRequest>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -191,9 +191,10 @@ namespace osu.Game.Beatmaps
|
|||||||
/// Download a beatmap
|
/// Download a beatmap
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="beatmapSetInfo">The beatmap to be downloaded</param>
|
/// <param name="beatmapSetInfo">The beatmap to be downloaded</param>
|
||||||
|
/// <returns>The new <see cref="DownloadBeatmapSetRequest"/>, or null if a download already exists for the same beatmap.</returns>
|
||||||
public DownloadBeatmapSetRequest Download(BeatmapSetInfo beatmapSetInfo)
|
public DownloadBeatmapSetRequest Download(BeatmapSetInfo beatmapSetInfo)
|
||||||
{
|
{
|
||||||
if (api == null || downloadsMap.ContainsKey(beatmapSetInfo)) return null;
|
if (api == null || downloadsMap.ContainsKey(beatmapSetInfo.OnlineBeatmapSetID)) return null;
|
||||||
|
|
||||||
ProgressNotification downloadNotification = new ProgressNotification
|
ProgressNotification downloadNotification = new ProgressNotification
|
||||||
{
|
{
|
||||||
@ -216,24 +217,26 @@ namespace osu.Game.Beatmaps
|
|||||||
using (var archive = new OszArchiveReader(stream))
|
using (var archive = new OszArchiveReader(stream))
|
||||||
Import(archive);
|
Import(archive);
|
||||||
|
|
||||||
downloadsMap.Remove(beatmapSetInfo);
|
downloadsMap.Remove(beatmapSetInfo.OnlineBeatmapSetID);
|
||||||
};
|
};
|
||||||
|
|
||||||
request.Failure += data =>
|
request.Failure += data =>
|
||||||
{
|
{
|
||||||
downloadNotification.State = ProgressNotificationState.Completed;
|
downloadNotification.State = ProgressNotificationState.Completed;
|
||||||
Logger.Error(data, "Failed to get beatmap download information");
|
Logger.Error(data, "Failed to get beatmap download information");
|
||||||
downloadsMap.Remove(beatmapSetInfo);
|
downloadsMap.Remove(beatmapSetInfo.OnlineBeatmapSetID);
|
||||||
};
|
};
|
||||||
|
|
||||||
downloadNotification.CancelRequested += () =>
|
downloadNotification.CancelRequested += () =>
|
||||||
{
|
{
|
||||||
Logger.Log("Cancel requested");
|
Logger.Log("Cancel requested");
|
||||||
downloadsMap.Remove(beatmapSetInfo);
|
downloadsMap[beatmapSetInfo.OnlineBeatmapSetID].Cancel();
|
||||||
|
downloadsMap.Remove(beatmapSetInfo.OnlineBeatmapSetID);
|
||||||
|
downloadNotification.State = ProgressNotificationState.Cancelled;
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
downloadsMap[beatmapSetInfo] = request;
|
downloadsMap[beatmapSetInfo.OnlineBeatmapSetID] = request;
|
||||||
PostNotification?.Invoke(downloadNotification);
|
PostNotification?.Invoke(downloadNotification);
|
||||||
|
|
||||||
// don't run in the main api queue as this is a long-running task.
|
// don't run in the main api queue as this is a long-running task.
|
||||||
@ -243,11 +246,11 @@ namespace osu.Game.Beatmaps
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check if a beatmap is already downloading.
|
/// Get an existing download request if it exists.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="beatmap">The <see cref="BeatmapSetInfo"/>to check against.</param>
|
/// <param name="beatmap">The <see cref="BeatmapSetInfo"/> whose download request is wanted.</param>
|
||||||
/// <returns>true if a download request already exists, false if it doesn't.</returns>
|
/// <returns>The <see cref="DownloadBeatmapSetRequest"/> object if it exists, or null.</returns>
|
||||||
public bool IsDownloading(BeatmapSetInfo beatmap) => downloadsMap.ContainsKey(beatmap);
|
public DownloadBeatmapSetRequest GetExistingDownload(BeatmapSetInfo beatmap) => downloadsMap.GetOrDefault(beatmap.OnlineBeatmapSetID);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete a beatmap from the manager.
|
/// Delete a beatmap from the manager.
|
||||||
|
@ -22,6 +22,7 @@ using osu.Game.Online.API;
|
|||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Game.Beatmaps.IO;
|
using osu.Game.Beatmaps.IO;
|
||||||
using osu.Game.Overlays.Notifications;
|
using osu.Game.Overlays.Notifications;
|
||||||
|
using osu.Game.Online.API.Requests;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Direct
|
namespace osu.Game.Overlays.Direct
|
||||||
{
|
{
|
||||||
@ -40,6 +41,44 @@ namespace osu.Game.Overlays.Direct
|
|||||||
private BeatmapManager beatmaps;
|
private BeatmapManager beatmaps;
|
||||||
private NotificationOverlay notifications;
|
private NotificationOverlay notifications;
|
||||||
|
|
||||||
|
private DownloadBeatmapSetRequest downloadRequest;
|
||||||
|
protected DownloadBeatmapSetRequest DownloadRequest
|
||||||
|
{
|
||||||
|
get { return downloadRequest; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value == null) return;
|
||||||
|
|
||||||
|
downloadRequest = value;
|
||||||
|
|
||||||
|
progressBar.FadeIn(400, Easing.OutQuint);
|
||||||
|
progressBar.ResizeHeightTo(4, 400, Easing.OutQuint);
|
||||||
|
|
||||||
|
progressBar.Current.Value = 0;
|
||||||
|
|
||||||
|
downloadRequest.Failure += e =>
|
||||||
|
{
|
||||||
|
progressBar.Current.Value = 0;
|
||||||
|
progressBar.FadeOut(500);
|
||||||
|
Logger.Error(e, "Failed to get beatmap download information");
|
||||||
|
};
|
||||||
|
|
||||||
|
downloadRequest.Progress += (current, total) =>
|
||||||
|
{
|
||||||
|
float progress = (float)current / total;
|
||||||
|
|
||||||
|
progressBar.Current.Value = progress;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
downloadRequest.Success += data =>
|
||||||
|
{
|
||||||
|
progressBar.Current.Value = 1;
|
||||||
|
progressBar.FadeOut(500);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override Container<Drawable> Content => content;
|
protected override Container<Drawable> Content => content;
|
||||||
|
|
||||||
protected DirectPanel(BeatmapSetInfo setInfo)
|
protected DirectPanel(BeatmapSetInfo setInfo)
|
||||||
@ -97,6 +136,8 @@ namespace osu.Game.Overlays.Direct
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
DownloadRequest = beatmaps.GetExistingDownload(SetInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnHover(InputState state)
|
protected override bool OnHover(InputState state)
|
||||||
@ -128,7 +169,7 @@ namespace osu.Game.Overlays.Direct
|
|||||||
}
|
}
|
||||||
|
|
||||||
// we already have an active download running.
|
// we already have an active download running.
|
||||||
if (beatmaps.IsDownloading(SetInfo))
|
if ((DownloadRequest = beatmaps.Download(SetInfo)) == null)
|
||||||
{
|
{
|
||||||
content.MoveToX(-5, 50, Easing.OutSine).Then()
|
content.MoveToX(-5, 50, Easing.OutSine).Then()
|
||||||
.MoveToX(5, 100, Easing.InOutSine).Then()
|
.MoveToX(5, 100, Easing.InOutSine).Then()
|
||||||
@ -136,34 +177,6 @@ namespace osu.Game.Overlays.Direct
|
|||||||
.MoveToX(0, 50, Easing.InSine).Then();
|
.MoveToX(0, 50, Easing.InSine).Then();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var downloadRequest = beatmaps.Download(SetInfo);
|
|
||||||
|
|
||||||
progressBar.FadeIn(400, Easing.OutQuint);
|
|
||||||
progressBar.ResizeHeightTo(4, 400, Easing.OutQuint);
|
|
||||||
|
|
||||||
progressBar.Current.Value = 0;
|
|
||||||
|
|
||||||
downloadRequest.Failure += e =>
|
|
||||||
{
|
|
||||||
progressBar.Current.Value = 0;
|
|
||||||
progressBar.FadeOut(500);
|
|
||||||
Logger.Error(e, "Failed to get beatmap download information");
|
|
||||||
};
|
|
||||||
|
|
||||||
downloadRequest.Progress += (current, total) =>
|
|
||||||
{
|
|
||||||
float progress = (float)current / total;
|
|
||||||
|
|
||||||
progressBar.Current.Value = progress;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
downloadRequest.Success += data =>
|
|
||||||
{
|
|
||||||
progressBar.Current.Value = 1;
|
|
||||||
progressBar.FadeOut(500);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
|
@ -47,9 +47,22 @@ namespace osu.Game.Overlays
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (beatmapSets?.Equals(value) ?? false) return;
|
if (beatmapSets?.Equals(value) ?? false) return;
|
||||||
|
|
||||||
beatmapSets = value;
|
beatmapSets = value;
|
||||||
|
|
||||||
recreatePanels(Filter.DisplayStyleControl.DisplayStyle.Value);
|
if (beatmapSets == null) return;
|
||||||
|
|
||||||
|
var artists = new List<string>();
|
||||||
|
var songs = new List<string>();
|
||||||
|
var tags = new List<string>();
|
||||||
|
foreach (var s in beatmapSets)
|
||||||
|
{
|
||||||
|
artists.Add(s.Metadata.Artist);
|
||||||
|
songs.Add(s.Metadata.Title);
|
||||||
|
tags.AddRange(s.Metadata.Tags.Split(' '));
|
||||||
|
}
|
||||||
|
|
||||||
|
ResultAmounts = new ResultCounts(distinctCount(artists), distinctCount(songs), distinctCount(tags));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,6 +172,7 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
// if a new map was imported, we should remove it from search results (download completed etc.)
|
// if a new map was imported, we should remove it from search results (download completed etc.)
|
||||||
panels?.FirstOrDefault(p => p.SetInfo.OnlineBeatmapSetID == set.OnlineBeatmapSetID)?.FadeOut(400).Expire();
|
panels?.FirstOrDefault(p => p.SetInfo.OnlineBeatmapSetID == set.OnlineBeatmapSetID)?.FadeOut(400).Expire();
|
||||||
|
BeatmapSets = BeatmapSets.Where(b => b.OnlineBeatmapSetID != set.OnlineBeatmapSetID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateResultCounts()
|
private void updateResultCounts()
|
||||||
@ -244,19 +258,7 @@ namespace osu.Game.Overlays
|
|||||||
Select(response => response.ToBeatmapSet(rulesets)).
|
Select(response => response.ToBeatmapSet(rulesets)).
|
||||||
Where(b => (beatmaps.QueryBeatmapSet(q => q.OnlineBeatmapSetID == b.OnlineBeatmapSetID) == null));
|
Where(b => (beatmaps.QueryBeatmapSet(q => q.OnlineBeatmapSetID == b.OnlineBeatmapSetID) == null));
|
||||||
|
|
||||||
if (BeatmapSets == null) return;
|
recreatePanels(Filter.DisplayStyleControl.DisplayStyle.Value);
|
||||||
|
|
||||||
var artists = new List<string>();
|
|
||||||
var songs = new List<string>();
|
|
||||||
var tags = new List<string>();
|
|
||||||
foreach (var s in BeatmapSets)
|
|
||||||
{
|
|
||||||
artists.Add(s.Metadata.Artist);
|
|
||||||
songs.Add(s.Metadata.Title);
|
|
||||||
tags.AddRange(s.Metadata.Tags.Split(' '));
|
|
||||||
}
|
|
||||||
|
|
||||||
ResultAmounts = new ResultCounts(distinctCount(artists), distinctCount(songs), distinctCount(tags));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
api.Queue(getSetsRequest);
|
api.Queue(getSetsRequest);
|
||||||
|
Loading…
Reference in New Issue
Block a user