mirror of
https://github.com/ppy/osu.git
synced 2025-01-06 07:02:54 +08:00
Merge pull request #1191 from peppy/direct-concurrency
Disallow concurrent download
This commit is contained in:
commit
b69c099d0f
@ -29,7 +29,7 @@ namespace osu.Game.Overlays.Direct
|
|||||||
{
|
{
|
||||||
public abstract class DirectPanel : Container
|
public abstract class DirectPanel : Container
|
||||||
{
|
{
|
||||||
protected readonly BeatmapSetInfo SetInfo;
|
public readonly BeatmapSetInfo SetInfo;
|
||||||
|
|
||||||
protected Box BlackBackground;
|
protected Box BlackBackground;
|
||||||
|
|
||||||
@ -108,10 +108,23 @@ namespace osu.Game.Overlays.Direct
|
|||||||
base.OnHoverLost(state);
|
base.OnHoverLost(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this should eventually be moved to a more central place, like BeatmapManager.
|
||||||
|
private DownloadBeatmapSetRequest downloadRequest;
|
||||||
|
|
||||||
protected void StartDownload()
|
protected void StartDownload()
|
||||||
{
|
{
|
||||||
if (api == null) return;
|
if (api == null) return;
|
||||||
|
|
||||||
|
// we already have an active download running.
|
||||||
|
if (downloadRequest != null)
|
||||||
|
{
|
||||||
|
content.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;
|
||||||
|
}
|
||||||
|
|
||||||
if (!api.LocalUser.Value.IsSupporter)
|
if (!api.LocalUser.Value.IsSupporter)
|
||||||
{
|
{
|
||||||
notifications.Post(new SimpleNotification
|
notifications.Post(new SimpleNotification
|
||||||
@ -132,16 +145,18 @@ namespace osu.Game.Overlays.Direct
|
|||||||
Text = $"Downloading {SetInfo.Metadata.Artist} - {SetInfo.Metadata.Title}",
|
Text = $"Downloading {SetInfo.Metadata.Artist} - {SetInfo.Metadata.Title}",
|
||||||
};
|
};
|
||||||
|
|
||||||
var request = new DownloadBeatmapSetRequest(SetInfo);
|
downloadRequest = new DownloadBeatmapSetRequest(SetInfo);
|
||||||
request.Failure += e =>
|
downloadRequest.Failure += e =>
|
||||||
{
|
{
|
||||||
progressBar.Current.Value = 0;
|
progressBar.Current.Value = 0;
|
||||||
progressBar.FadeOut(500);
|
progressBar.FadeOut(500);
|
||||||
downloadNotification.State = ProgressNotificationState.Completed;
|
downloadNotification.State = ProgressNotificationState.Completed;
|
||||||
Logger.Error(e, "Failed to get beatmap download information");
|
Logger.Error(e, "Failed to get beatmap download information");
|
||||||
|
|
||||||
|
downloadRequest = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
request.Progress += (current, total) =>
|
downloadRequest.Progress += (current, total) =>
|
||||||
{
|
{
|
||||||
float progress = (float)current / total;
|
float progress = (float)current / total;
|
||||||
|
|
||||||
@ -151,7 +166,7 @@ namespace osu.Game.Overlays.Direct
|
|||||||
downloadNotification.Progress = progress;
|
downloadNotification.Progress = progress;
|
||||||
};
|
};
|
||||||
|
|
||||||
request.Success += data =>
|
downloadRequest.Success += data =>
|
||||||
{
|
{
|
||||||
progressBar.Current.Value = 1;
|
progressBar.Current.Value = 1;
|
||||||
progressBar.FadeOut(500);
|
progressBar.FadeOut(500);
|
||||||
@ -165,14 +180,15 @@ namespace osu.Game.Overlays.Direct
|
|||||||
|
|
||||||
downloadNotification.CancelRequested += () =>
|
downloadNotification.CancelRequested += () =>
|
||||||
{
|
{
|
||||||
request.Cancel();
|
downloadRequest.Cancel();
|
||||||
|
downloadRequest = null;
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
notifications.Post(downloadNotification);
|
notifications.Post(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.
|
||||||
Task.Run(() => request.Perform(api));
|
Task.Run(() => downloadRequest.Perform(api));
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DownloadBeatmapSetRequest : APIDownloadRequest
|
public class DownloadBeatmapSetRequest : APIDownloadRequest
|
||||||
|
@ -30,7 +30,7 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
private readonly FillFlowContainer resultCountsContainer;
|
private readonly FillFlowContainer resultCountsContainer;
|
||||||
private readonly OsuSpriteText resultCountsText;
|
private readonly OsuSpriteText resultCountsText;
|
||||||
private readonly FillFlowContainer<DirectPanel> panels;
|
private FillFlowContainer<DirectPanel> panels;
|
||||||
|
|
||||||
protected override Color4 BackgroundColour => OsuColour.FromHex(@"485e74");
|
protected override Color4 BackgroundColour => OsuColour.FromHex(@"485e74");
|
||||||
protected override Color4 TrianglesColourLight => OsuColour.FromHex(@"465b71");
|
protected override Color4 TrianglesColourLight => OsuColour.FromHex(@"465b71");
|
||||||
@ -48,17 +48,6 @@ namespace osu.Game.Overlays
|
|||||||
if (beatmapSets?.Equals(value) ?? false) return;
|
if (beatmapSets?.Equals(value) ?? false) return;
|
||||||
beatmapSets = value;
|
beatmapSets = value;
|
||||||
|
|
||||||
if (BeatmapSets == null)
|
|
||||||
{
|
|
||||||
foreach (var p in panels.Children)
|
|
||||||
{
|
|
||||||
p.FadeOut(200);
|
|
||||||
p.Expire();
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
recreatePanels(Filter.DisplayStyleControl.DisplayStyle.Value);
|
recreatePanels(Filter.DisplayStyleControl.DisplayStyle.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,13 +97,6 @@ namespace osu.Game.Overlays
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
panels = new FillFlowContainer<DirectPanel>
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.X,
|
|
||||||
AutoSizeAxes = Axes.Y,
|
|
||||||
Spacing = new Vector2(panel_padding),
|
|
||||||
Margin = new MarginPadding { Top = 10 },
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Filter.Search.Current.ValueChanged += text => { if (text != string.Empty) Header.Tabs.Current.Value = DirectTab.Search; };
|
Filter.Search.Current.ValueChanged += text => { if (text != string.Empty) Header.Tabs.Current.Value = DirectTab.Search; };
|
||||||
@ -161,11 +143,19 @@ namespace osu.Game.Overlays
|
|||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours, APIAccess api, RulesetStore rulesets)
|
private void load(OsuColour colours, APIAccess api, RulesetStore rulesets, BeatmapManager beatmaps)
|
||||||
{
|
{
|
||||||
this.api = api;
|
this.api = api;
|
||||||
this.rulesets = rulesets;
|
this.rulesets = rulesets;
|
||||||
resultCountsContainer.Colour = colours.Yellow;
|
resultCountsContainer.Colour = colours.Yellow;
|
||||||
|
|
||||||
|
beatmaps.BeatmapSetAdded += setAdded;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setAdded(BeatmapSetInfo set)
|
||||||
|
{
|
||||||
|
// 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateResultCounts()
|
private void updateResultCounts()
|
||||||
@ -185,18 +175,38 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
private void recreatePanels(PanelDisplayStyle displayStyle)
|
private void recreatePanels(PanelDisplayStyle displayStyle)
|
||||||
{
|
{
|
||||||
|
if (panels != null)
|
||||||
|
{
|
||||||
|
panels.FadeOut(200);
|
||||||
|
panels.Expire();
|
||||||
|
panels = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (BeatmapSets == null) return;
|
if (BeatmapSets == null) return;
|
||||||
|
|
||||||
panels.ChildrenEnumerable = BeatmapSets.Select<BeatmapSetInfo, DirectPanel>(b =>
|
var newPanels = new FillFlowContainer<DirectPanel>
|
||||||
{
|
{
|
||||||
switch (displayStyle)
|
RelativeSizeAxes = Axes.X,
|
||||||
{
|
AutoSizeAxes = Axes.Y,
|
||||||
case PanelDisplayStyle.Grid:
|
Spacing = new Vector2(panel_padding),
|
||||||
return new DirectGridPanel(b) { Width = 400 };
|
Margin = new MarginPadding { Top = 10 },
|
||||||
default:
|
ChildrenEnumerable = BeatmapSets.Select<BeatmapSetInfo, DirectPanel>(b =>
|
||||||
return new DirectListPanel(b);
|
{
|
||||||
}
|
switch (displayStyle)
|
||||||
});
|
{
|
||||||
|
case PanelDisplayStyle.Grid:
|
||||||
|
return new DirectGridPanel(b) { Width = 400 };
|
||||||
|
default:
|
||||||
|
return new DirectListPanel(b);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
LoadComponentAsync(newPanels, p =>
|
||||||
|
{
|
||||||
|
if (panels != null) ScrollFlow.Remove(panels);
|
||||||
|
ScrollFlow.Add(panels = newPanels);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private GetBeatmapSetsRequest getSetsRequest;
|
private GetBeatmapSetsRequest getSetsRequest;
|
||||||
|
Loading…
Reference in New Issue
Block a user