1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 08:52:55 +08:00

Merge pull request #2127 from peppy/fix-song-select-iteration

Fix song select iteration when all panels are filtered
This commit is contained in:
Dan Balasescu 2018-02-28 21:52:00 +09:00 committed by GitHub
commit 1936498392
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -207,6 +207,12 @@ namespace osu.Game.Tests.Visual
checkVisibleItemCount(true, 0);
AddAssert("Selection is null", () => currentSelection == null);
advanceSelection(true);
AddAssert("Selection is null", () => currentSelection == null);
advanceSelection(false);
AddAssert("Selection is null", () => currentSelection == null);
AddStep("Un-filter", () => carousel.Filter(new FilterCriteria(), false));
AddAssert("Selection is non-null", () => currentSelection != null);

View File

@ -192,7 +192,9 @@ namespace osu.Game.Screens.Select
/// <param name="skipDifficulties">Whether to skip individual difficulties and only increment over full groups.</param>
public void SelectNext(int direction = 1, bool skipDifficulties = true)
{
if (!Items.Any())
var visibleItems = Items.Where(s => !s.Item.Filtered).ToList();
if (!visibleItems.Any())
return;
DrawableCarouselItem drawable = null;
@ -202,15 +204,15 @@ namespace osu.Game.Screens.Select
// we can fix this by changing this method to not reference drawables / Items in the first place.
return;
int originalIndex = Items.IndexOf(drawable);
int originalIndex = visibleItems.IndexOf(drawable);
int currentIndex = originalIndex;
// local function to increment the index in the required direction, wrapping over extremities.
int incrementIndex() => currentIndex = (currentIndex + direction + Items.Count) % Items.Count;
int incrementIndex() => currentIndex = (currentIndex + direction + visibleItems.Count) % visibleItems.Count;
while (incrementIndex() != originalIndex)
{
var item = Items[currentIndex].Item;
var item = visibleItems[currentIndex].Item;
if (item.Filtered || item.State == CarouselItemState.Selected) continue;