diff --git a/osu.Game/Screens/Select/BeatmapCarousel.cs b/osu.Game/Screens/Select/BeatmapCarousel.cs index 3f8d6af320..f9064c4963 100644 --- a/osu.Game/Screens/Select/BeatmapCarousel.cs +++ b/osu.Game/Screens/Select/BeatmapCarousel.cs @@ -77,8 +77,9 @@ namespace osu.Game.Screens.Select private readonly List panels = new List(); - private BeatmapGroup selectedGroup; + private readonly Stack> randomSelectedBeatmaps = new Stack>(); + private BeatmapGroup selectedGroup; private BeatmapPanel selectedPanel; public BeatmapCarousel() @@ -170,16 +171,21 @@ namespace osu.Game.Screens.Select } while (index != startIndex); } - public void SelectRandom() + private IEnumerable getVisibleGroups() => groups.Where(selectGroup => selectGroup.State != BeatmapGroupState.Hidden); + + public void SelectNextRandom() { - IEnumerable visibleGroups = groups.Where(selectGroup => selectGroup.State != BeatmapGroupState.Hidden); + randomSelectedBeatmaps.Push(new KeyValuePair(selectedGroup, selectedGroup.SelectedPanel)); + + var visibleGroups = getVisibleGroups(); if (!visibleGroups.Any()) return; BeatmapGroup group; + if (randomType == SelectionRandomType.RandomPermutation) { - IEnumerable notSeenGroups = visibleGroups.Except(seenGroups); + var notSeenGroups = visibleGroups.Except(seenGroups); if (!notSeenGroups.Any()) { seenGroups.Clear(); @@ -197,6 +203,27 @@ namespace osu.Game.Screens.Select selectGroup(group, panel); } + public void SelectPreviousRandom() + { + if (!randomSelectedBeatmaps.Any()) + return; + + var visibleGroups = getVisibleGroups(); + if (!visibleGroups.Any()) + return; + + while (randomSelectedBeatmaps.Any()) + { + var beatmapCoordinates = randomSelectedBeatmaps.Pop(); + var group = beatmapCoordinates.Key; + if (visibleGroups.Contains(group)) + { + selectGroup(group, beatmapCoordinates.Value); + break; + } + } + } + private FilterCriteria criteria = new FilterCriteria(); private ScheduledDelegate filterTask; diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index dc6dfdfd81..eda3cf39f6 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -154,11 +154,11 @@ namespace osu.Game.Screens.Select } [BackgroundDependencyLoader(permitNulls: true)] - private void load(BeatmapDatabase beatmaps, AudioManager audio, DialogOverlay dialog, OsuGame osu, OsuColour colours) + private void load(BeatmapDatabase beatmaps, AudioManager audio, DialogOverlay dialog, OsuGame osu, OsuColour colours, UserInputManager input) { if (Footer != null) { - Footer.AddButton(@"random", colours.Green, SelectRandom, Key.F2); + Footer.AddButton(@"random", colours.Green, () => triggerRandom(input), Key.F2); Footer.AddButton(@"options", colours.Blue, BeatmapOptions.ToggleVisibility, Key.F3); BeatmapOptions.AddButton(@"Delete", @"Beatmap", FontAwesome.fa_trash, colours.Pink, promptDelete, Key.Number4, float.MaxValue); @@ -209,7 +209,13 @@ namespace osu.Game.Screens.Select OnSelected(); } - public void SelectRandom() => carousel.SelectRandom(); + private void triggerRandom(UserInputManager input) + { + if (input.CurrentState.Keyboard.ShiftPressed) + carousel.SelectPreviousRandom(); + else + carousel.SelectNextRandom(); + } protected abstract void OnSelected();