From f9b87ad08ca752b6f4962340be71acfc0f13cbb8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 2 Mar 2017 22:02:29 +0900 Subject: [PATCH] Fix selection on entry to song select. Also only shows sets with beatmaps for current play mode. --- osu.Game/Screens/Select/CarouselContainer.cs | 2 +- osu.Game/Screens/Select/PlaySongSelect.cs | 47 +++++++++++++------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/osu.Game/Screens/Select/CarouselContainer.cs b/osu.Game/Screens/Select/CarouselContainer.cs index b05fd6c9fc..fd29cab2fd 100644 --- a/osu.Game/Screens/Select/CarouselContainer.cs +++ b/osu.Game/Screens/Select/CarouselContainer.cs @@ -245,7 +245,7 @@ namespace osu.Game.Screens.Select scrollableContent.Add(panel); } } - SelectGroup(groups.FirstOrDefault(), groups.First().BeatmapPanels.FirstOrDefault()); + } private static float offsetX(float dist, float halfHeight) diff --git a/osu.Game/Screens/Select/PlaySongSelect.cs b/osu.Game/Screens/Select/PlaySongSelect.cs index 4252de2978..1e60e74470 100644 --- a/osu.Game/Screens/Select/PlaySongSelect.cs +++ b/osu.Game/Screens/Select/PlaySongSelect.cs @@ -33,7 +33,7 @@ namespace osu.Game.Screens.Select { public class PlaySongSelect : OsuScreen { - private Bindable playMode; + private Bindable playMode = new Bindable(); private BeatmapDatabase database; protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap); @@ -75,7 +75,7 @@ namespace osu.Game.Screens.Select [BackgroundDependencyLoader(permitNulls: true)] private void load(BeatmapDatabase beatmaps, AudioManager audio, DialogOverlay dialog, Framework.Game game, - OsuGame osuGame, OsuColour colours) + OsuGame osu, OsuColour colours) { const float carousel_width = 640; const float filter_height = 100; @@ -111,7 +111,7 @@ namespace osu.Game.Screens.Select { RelativeSizeAxes = Axes.X, Height = filter_height, - FilterChanged = filterChanged, + FilterChanged = () => filterChanged(), Exit = Exit, }, beatmapInfoWedge = new BeatmapInfoWedge @@ -146,11 +146,9 @@ namespace osu.Game.Screens.Select footer.AddButton(@"random", colours.Green, carousel.SelectRandom); footer.AddButton(@"options", colours.Blue, null); - if (osuGame != null) - { - playMode = osuGame.PlayMode; - playMode.ValueChanged += playMode_ValueChanged; - } + if (osu != null) + playMode.BindTo(osu.PlayMode); + playMode.ValueChanged += playMode_ValueChanged; if (database == null) database = beatmaps; @@ -171,7 +169,7 @@ namespace osu.Game.Screens.Select private ScheduledDelegate filterTask; - private void filterChanged() + private void filterChanged(bool debounce = true, bool eagerSelection = true) { filterTask?.Cancel(); filterTask = Scheduler.AddDelayed(() => @@ -183,25 +181,42 @@ namespace osu.Game.Screens.Select foreach (var beatmapGroup in carousel) { var set = beatmapGroup.BeatmapSet; - bool match = string.IsNullOrEmpty(search) + + bool hasCurrentMode = set.Beatmaps.Any(bm => bm.Mode == playMode); + + bool match = hasCurrentMode; + + match &= string.IsNullOrEmpty(search) || (set.Metadata.Artist ?? "").IndexOf(search, StringComparison.InvariantCultureIgnoreCase) != -1 || (set.Metadata.ArtistUnicode ?? "").IndexOf(search, StringComparison.InvariantCultureIgnoreCase) != -1 || (set.Metadata.Title ?? "").IndexOf(search, StringComparison.InvariantCultureIgnoreCase) != -1 || (set.Metadata.TitleUnicode ?? "").IndexOf(search, StringComparison.InvariantCultureIgnoreCase) != -1; + if (match) { - beatmapGroup.State = BeatmapGroupState.Collapsed; if (newSelection == null || beatmapGroup.BeatmapSet.OnlineBeatmapSetID == Beatmap.BeatmapSetInfo.OnlineBeatmapSetID) + { + if (newSelection != null) + newSelection.State = BeatmapGroupState.Collapsed; newSelection = beatmapGroup; + } + else + beatmapGroup.State = BeatmapGroupState.Collapsed; } else { beatmapGroup.State = BeatmapGroupState.Hidden; } } + if (newSelection != null) - carousel.SelectBeatmap(newSelection.BeatmapSet.Beatmaps[0], false); - }, 250); + { + if (newSelection.BeatmapPanels.Any(b => b.Beatmap.ID == Beatmap.BeatmapInfo.ID)) + carousel.SelectBeatmap(Beatmap.BeatmapInfo, false); + else if (eagerSelection) + carousel.SelectBeatmap(newSelection.BeatmapSet.Beatmaps[0], false); + } + }, debounce ? 250 : 0); } private void onBeatmapSetAdded(BeatmapSetInfo s) => Schedule(() => addBeatmapSet(s, Game, true)); @@ -262,8 +277,6 @@ namespace osu.Game.Screens.Select protected override void Dispose(bool isDisposing) { base.Dispose(isDisposing); - if (playMode != null) - playMode.ValueChanged -= playMode_ValueChanged; database.BeatmapSetAdded -= onBeatmapSetAdded; database.BeatmapSetRemoved -= onBeatmapSetRemoved; @@ -273,6 +286,7 @@ namespace osu.Game.Screens.Select private void playMode_ValueChanged(object sender, EventArgs e) { + filterChanged(false); } private void changeBackground(WorkingBeatmap beatmap) @@ -358,6 +372,8 @@ namespace osu.Game.Screens.Select carousel.AddGroup(group); + filterChanged(false, false); + if (Beatmap == null || select) carousel.SelectBeatmap(beatmapSet.Beatmaps.First()); else @@ -391,7 +407,6 @@ namespace osu.Game.Screens.Select if (token.IsCancellationRequested) return; addBeatmapSet(beatmapSet, game); } - filterChanged(); } protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)