From 11234d3c60d5b941d8487caf446ba0c85a6871f4 Mon Sep 17 00:00:00 2001 From: Roman Kapustin Date: Tue, 12 Feb 2019 21:20:49 +0300 Subject: [PATCH 1/4] Update direct download button state on beatmap import and removal --- osu.Game/Overlays/Direct/DownloadButton.cs | 9 +++++++++ .../Direct/DownloadTrackingComposite.cs | 20 ++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/osu.Game/Overlays/Direct/DownloadButton.cs b/osu.Game/Overlays/Direct/DownloadButton.cs index 201a79f58a..b3372bf237 100644 --- a/osu.Game/Overlays/Direct/DownloadButton.cs +++ b/osu.Game/Overlays/Direct/DownloadButton.cs @@ -76,6 +76,9 @@ namespace osu.Game.Overlays.Direct { this.colours = colours; + beatmaps.ItemAdded += (set, existing, silent) => updateState(BeatmapSet.Value); + beatmaps.ItemRemoved += set => updateState(BeatmapSet.Value); + button.Action = () => { switch (State.Value) @@ -94,6 +97,12 @@ namespace osu.Game.Overlays.Direct }; } + private void updateState(BeatmapSetInfo set) + { + if (set.OnlineBeatmapSetID == BeatmapSet.Value.OnlineBeatmapSetID) + UpdateState(BeatmapSet.Value); + } + private void updateState(DownloadState state) { switch (state) diff --git a/osu.Game/Overlays/Direct/DownloadTrackingComposite.cs b/osu.Game/Overlays/Direct/DownloadTrackingComposite.cs index f255403e81..eabc02d66e 100644 --- a/osu.Game/Overlays/Direct/DownloadTrackingComposite.cs +++ b/osu.Game/Overlays/Direct/DownloadTrackingComposite.cs @@ -34,15 +34,7 @@ namespace osu.Game.Overlays.Direct { this.beatmaps = beatmaps; - BeatmapSet.BindValueChanged(set => - { - if (set == null) - attachDownload(null); - else if (beatmaps.QueryBeatmapSets(s => s.OnlineBeatmapSetID == set.OnlineBeatmapSetID).Any()) - State.Value = DownloadState.LocallyAvailable; - else - attachDownload(beatmaps.GetExistingDownload(set)); - }, true); + BeatmapSet.BindValueChanged(UpdateState, true); beatmaps.BeatmapDownloadBegan += download => { @@ -53,6 +45,16 @@ namespace osu.Game.Overlays.Direct beatmaps.ItemAdded += setAdded; } + protected void UpdateState(BeatmapSetInfo set) + { + if (set == null) + attachDownload(null); + else if (this.beatmaps.QueryBeatmapSets(s => s.OnlineBeatmapSetID == set.OnlineBeatmapSetID && !s.DeletePending).Any()) + State.Value = DownloadState.LocallyAvailable; + else + attachDownload(this.beatmaps.GetExistingDownload(set)); + } + #region Disposal protected override void Dispose(bool isDisposing) From 99046f16e8edbd16a39ab49f6f1cb83b38510fc3 Mon Sep 17 00:00:00 2001 From: Roman Kapustin Date: Wed, 13 Feb 2019 22:04:49 +0300 Subject: [PATCH 2/4] Revert "Update direct download button state on beatmap import and removal" This reverts commit 11234d3c60d5b941d8487caf446ba0c85a6871f4. --- osu.Game/Overlays/Direct/DownloadButton.cs | 9 --------- .../Direct/DownloadTrackingComposite.cs | 20 +++++++++---------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/osu.Game/Overlays/Direct/DownloadButton.cs b/osu.Game/Overlays/Direct/DownloadButton.cs index b3372bf237..201a79f58a 100644 --- a/osu.Game/Overlays/Direct/DownloadButton.cs +++ b/osu.Game/Overlays/Direct/DownloadButton.cs @@ -76,9 +76,6 @@ namespace osu.Game.Overlays.Direct { this.colours = colours; - beatmaps.ItemAdded += (set, existing, silent) => updateState(BeatmapSet.Value); - beatmaps.ItemRemoved += set => updateState(BeatmapSet.Value); - button.Action = () => { switch (State.Value) @@ -97,12 +94,6 @@ namespace osu.Game.Overlays.Direct }; } - private void updateState(BeatmapSetInfo set) - { - if (set.OnlineBeatmapSetID == BeatmapSet.Value.OnlineBeatmapSetID) - UpdateState(BeatmapSet.Value); - } - private void updateState(DownloadState state) { switch (state) diff --git a/osu.Game/Overlays/Direct/DownloadTrackingComposite.cs b/osu.Game/Overlays/Direct/DownloadTrackingComposite.cs index eabc02d66e..f255403e81 100644 --- a/osu.Game/Overlays/Direct/DownloadTrackingComposite.cs +++ b/osu.Game/Overlays/Direct/DownloadTrackingComposite.cs @@ -34,7 +34,15 @@ namespace osu.Game.Overlays.Direct { this.beatmaps = beatmaps; - BeatmapSet.BindValueChanged(UpdateState, true); + BeatmapSet.BindValueChanged(set => + { + if (set == null) + attachDownload(null); + else if (beatmaps.QueryBeatmapSets(s => s.OnlineBeatmapSetID == set.OnlineBeatmapSetID).Any()) + State.Value = DownloadState.LocallyAvailable; + else + attachDownload(beatmaps.GetExistingDownload(set)); + }, true); beatmaps.BeatmapDownloadBegan += download => { @@ -45,16 +53,6 @@ namespace osu.Game.Overlays.Direct beatmaps.ItemAdded += setAdded; } - protected void UpdateState(BeatmapSetInfo set) - { - if (set == null) - attachDownload(null); - else if (this.beatmaps.QueryBeatmapSets(s => s.OnlineBeatmapSetID == set.OnlineBeatmapSetID && !s.DeletePending).Any()) - State.Value = DownloadState.LocallyAvailable; - else - attachDownload(this.beatmaps.GetExistingDownload(set)); - } - #region Disposal protected override void Dispose(bool isDisposing) From a289cb7c6a8f8b5b47983c0320f86d21eae16f91 Mon Sep 17 00:00:00 2001 From: Roman Kapustin Date: Wed, 13 Feb 2019 22:11:46 +0300 Subject: [PATCH 3/4] Handle beatmapset removal in DownloadTrackingComposite --- osu.Game/Overlays/Direct/DownloadTrackingComposite.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/Direct/DownloadTrackingComposite.cs b/osu.Game/Overlays/Direct/DownloadTrackingComposite.cs index f255403e81..f7d9264af0 100644 --- a/osu.Game/Overlays/Direct/DownloadTrackingComposite.cs +++ b/osu.Game/Overlays/Direct/DownloadTrackingComposite.cs @@ -51,6 +51,7 @@ namespace osu.Game.Overlays.Direct }; beatmaps.ItemAdded += setAdded; + beatmaps.ItemRemoved += setRemoved; } #region Disposal @@ -120,12 +121,16 @@ namespace osu.Game.Overlays.Direct Schedule(() => attachDownload(null)); } - private void setAdded(BeatmapSetInfo s, bool existing, bool silent) + private void setAdded(BeatmapSetInfo s, bool existing, bool silent) => setDownloadState(s, DownloadState.Downloaded); + + private void setRemoved(BeatmapSetInfo s) => setDownloadState(s, DownloadState.NotDownloaded); + + private void setDownloadState(BeatmapSetInfo s, DownloadState state) { if (s.OnlineBeatmapSetID != BeatmapSet.Value?.OnlineBeatmapSetID) return; - Schedule(() => State.Value = DownloadState.LocallyAvailable); + Schedule(() => State.Value = state); } } } From a5f1f9830bfc0c13d3db751d65ea39bbba1e29e0 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 14 Feb 2019 16:21:01 +0900 Subject: [PATCH 4/4] Fix potential schedule race case and regression in enum setting --- .../Direct/DownloadTrackingComposite.cs | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/osu.Game/Overlays/Direct/DownloadTrackingComposite.cs b/osu.Game/Overlays/Direct/DownloadTrackingComposite.cs index f7d9264af0..d9eb827834 100644 --- a/osu.Game/Overlays/Direct/DownloadTrackingComposite.cs +++ b/osu.Game/Overlays/Direct/DownloadTrackingComposite.cs @@ -11,6 +11,9 @@ using osu.Game.Online.API.Requests; namespace osu.Game.Overlays.Direct { + /// + /// A component which tracks a beatmap through potential download/import/deletion. + /// public abstract class DownloadTrackingComposite : CompositeDrawable { public readonly Bindable BeatmapSet = new Bindable(); @@ -106,31 +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) => setDownloadState(s, DownloadState.Downloaded); + private void setAdded(BeatmapSetInfo s, bool existing, bool silent) => setDownloadStateFromManager(s, DownloadState.LocallyAvailable); - private void setRemoved(BeatmapSetInfo s) => setDownloadState(s, DownloadState.NotDownloaded); + private void setRemoved(BeatmapSetInfo s) => setDownloadStateFromManager(s, DownloadState.NotDownloaded); - private void setDownloadState(BeatmapSetInfo s, DownloadState state) + private void setDownloadStateFromManager(BeatmapSetInfo s, DownloadState state) => Schedule(() => { if (s.OnlineBeatmapSetID != BeatmapSet.Value?.OnlineBeatmapSetID) return; - Schedule(() => State.Value = state); - } + State.Value = state; + }); } }