From 30a15729ec351e199b37654a5743f90af6cfd36f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 18 Dec 2017 02:46:53 +0900 Subject: [PATCH] Fix event handling from outside carousel being scheduled at the wrong level Was causing BeatmapSet's Set to run *after* newer events were received. --- osu.Game/Screens/Select/BeatmapCarousel.cs | 62 ++++++++++++---------- osu.Game/Screens/Select/SongSelect.cs | 30 ++--------- 2 files changed, 38 insertions(+), 54 deletions(-) diff --git a/osu.Game/Screens/Select/BeatmapCarousel.cs b/osu.Game/Screens/Select/BeatmapCarousel.cs index 4ec62877bf..c18f917645 100644 --- a/osu.Game/Screens/Select/BeatmapCarousel.cs +++ b/osu.Game/Screens/Select/BeatmapCarousel.cs @@ -110,42 +110,48 @@ namespace osu.Game.Screens.Select public void RemoveBeatmapSet(BeatmapSetInfo beatmapSet) { - var existingSet = beatmapSets.FirstOrDefault(b => b.BeatmapSet.ID == beatmapSet.ID); + Schedule(() => + { + var existingSet = beatmapSets.FirstOrDefault(b => b.BeatmapSet.ID == beatmapSet.ID); - if (existingSet == null) - return; + if (existingSet == null) + return; - root.RemoveChild(existingSet); - itemsCache.Invalidate(); + root.RemoveChild(existingSet); + itemsCache.Invalidate(); + }); } public void UpdateBeatmapSet(BeatmapSetInfo beatmapSet) { - CarouselBeatmapSet existingSet = beatmapSets.FirstOrDefault(b => b.BeatmapSet.ID == beatmapSet.ID); - - bool hadSelection = existingSet?.State?.Value == CarouselItemState.Selected; - - var newSet = createCarouselSet(beatmapSet); - - if (existingSet != null) - root.RemoveChild(existingSet); - - if (newSet == null) + Schedule(() => { + CarouselBeatmapSet existingSet = beatmapSets.FirstOrDefault(b => b.BeatmapSet.ID == beatmapSet.ID); + + bool hadSelection = existingSet?.State?.Value == CarouselItemState.Selected; + + var newSet = createCarouselSet(beatmapSet); + + if (existingSet != null) + root.RemoveChild(existingSet); + + if (newSet == null) + { + itemsCache.Invalidate(); + SelectNext(); + return; + } + + root.AddChild(newSet); + + applyActiveCriteria(false, false); + + //check if we can/need to maintain our current selection. + if (hadSelection) + select((CarouselItem)newSet.Beatmaps.FirstOrDefault(b => b.Beatmap.ID == selectedBeatmap?.Beatmap.ID) ?? newSet); + itemsCache.Invalidate(); - SelectNext(); - return; - } - - root.AddChild(newSet); - - applyActiveCriteria(false, false); - - //check if we can/need to maintain our current selection. - if (hadSelection) - select((CarouselItem)newSet.Beatmaps.FirstOrDefault(b => b.Beatmap.ID == selectedBeatmap?.Beatmap.ID) ?? newSet); - - itemsCache.Invalidate(); + }); } public void SelectBeatmap(BeatmapInfo beatmap) diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index 1fea4d0ccb..b5fba7d88d 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -417,32 +417,10 @@ namespace osu.Game.Screens.Select } } - private void onBeatmapSetAdded(BeatmapSetInfo s) => Schedule(() => carousel.UpdateBeatmapSet(s)); - - private void onBeatmapSetRemoved(BeatmapSetInfo s) => Schedule(() => - { - carousel.RemoveBeatmapSet(s); - if (carousel.SelectedBeatmap == null) - Beatmap.SetDefault(); - }); - - private void onBeatmapRestored(BeatmapInfo beatmap) - { - Schedule(() => - { - var beatmapSet = beatmaps.QueryBeatmapSet(s => s.ID == beatmap.BeatmapSetInfoID); - carousel.UpdateBeatmapSet(beatmapSet); - }); - } - - private void onBeatmapHidden(BeatmapInfo beatmap) - { - Schedule(() => - { - var beatmapSet = beatmaps.QueryBeatmapSet(s => s.ID == beatmap.BeatmapSetInfoID); - carousel.UpdateBeatmapSet(beatmapSet); - }); - } + private void onBeatmapSetAdded(BeatmapSetInfo s) => carousel.UpdateBeatmapSet(s); + private void onBeatmapSetRemoved(BeatmapSetInfo s) => carousel.RemoveBeatmapSet(s); + private void onBeatmapRestored(BeatmapInfo b) => carousel.UpdateBeatmapSet(beatmaps.QueryBeatmapSet(s => s.ID == b.BeatmapSetInfoID)); + private void onBeatmapHidden(BeatmapInfo b) => carousel.UpdateBeatmapSet(beatmaps.QueryBeatmapSet(s => s.ID == b.BeatmapSetInfoID)); private void carouselBeatmapsLoaded() {