Merge pull request #4242 from UselessToucan/download_button_should_observe_beatmaps_availability

Update direct download button state on beatmapset removal
This commit is contained in:
Dean Herbert 2019-02-14 16:28:44 +09:00 committed by GitHub
commit 268be1c5d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,9 @@ using osu.Game.Online.API.Requests;
namespace osu.Game.Overlays.Direct
{
/// <summary>
/// A component which tracks a beatmap through potential download/import/deletion.
/// </summary>
public abstract class DownloadTrackingComposite : CompositeDrawable
{
public readonly Bindable<BeatmapSetInfo> BeatmapSet = new Bindable<BeatmapSetInfo>();
@ -51,6 +54,7 @@ namespace osu.Game.Overlays.Direct
};
beatmaps.ItemAdded += setAdded;
beatmaps.ItemRemoved += setRemoved;
}
#region Disposal
@ -105,27 +109,22 @@ namespace osu.Game.Overlays.Direct
}
}
private void onRequestSuccess(string data)
{
Schedule(() => State.Value = DownloadState.Downloaded);
}
private void onRequestSuccess(string _) => Schedule(() => State.Value = DownloadState.Downloaded);
private void onRequestProgress(float progress)
{
Schedule(() => Progress.Value = progress);
}
private void onRequestProgress(float progress) => Schedule(() => Progress.Value = progress);
private void onRequestFailure(Exception e)
{
Schedule(() => attachDownload(null));
}
private void onRequestFailure(Exception e) => Schedule(() => attachDownload(null));
private void setAdded(BeatmapSetInfo s, bool existing, bool silent)
private void setAdded(BeatmapSetInfo s, bool existing, bool silent) => setDownloadStateFromManager(s, DownloadState.LocallyAvailable);
private void setRemoved(BeatmapSetInfo s) => setDownloadStateFromManager(s, DownloadState.NotDownloaded);
private void setDownloadStateFromManager(BeatmapSetInfo s, DownloadState state) => Schedule(() =>
{
if (s.OnlineBeatmapSetID != BeatmapSet.Value?.OnlineBeatmapSetID)
return;
Schedule(() => State.Value = DownloadState.LocallyAvailable);
}
State.Value = state;
});
}
}