mirror of
https://github.com/ppy/osu.git
synced 2025-03-05 22:02:56 +08:00
Replace SkipWhile()
LINQ with a while loop
This commit is contained in:
parent
b484bd1af3
commit
a8d869c31c
@ -99,31 +99,32 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
PerformSelection();
|
PerformSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Finds the item this group would select next if it attempted selection
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>An unfiltered item nearest to the last selected one or null if all items are filtered</returns>
|
||||||
protected virtual CarouselItem GetNextToSelect()
|
protected virtual CarouselItem GetNextToSelect()
|
||||||
{
|
{
|
||||||
// our return value should be the item (that is not filtered and) that is nearest to the previously selected one
|
int forwardsIndex = lastSelectedIndex;
|
||||||
|
int backwardsIndex = lastSelectedIndex;
|
||||||
|
|
||||||
// find nearest such item going forwards in selection
|
while (true)
|
||||||
int forwardsDistance = 0;
|
|
||||||
var forwards = Children.Skip(lastSelectedIndex).SkipWhile(item =>
|
|
||||||
{
|
{
|
||||||
forwardsDistance++;
|
if (forwardsIndex >= Children.Count)
|
||||||
return item.Filtered.Value;
|
return Children.Reverse().Skip(Children.Count - backwardsIndex).FirstOrDefault(item => !item.Filtered.Value);
|
||||||
}).FirstOrDefault();
|
|
||||||
// and backwards
|
|
||||||
int backwardsDistance = 0;
|
|
||||||
var backwards = Children.Reverse().Skip(InternalChildren.Count - lastSelectedIndex - 1).SkipWhile(item =>
|
|
||||||
{
|
|
||||||
backwardsDistance++;
|
|
||||||
return item.Filtered.Value;
|
|
||||||
}).FirstOrDefault();
|
|
||||||
|
|
||||||
// if only one direction had such an item, return that
|
if (backwardsIndex < 0)
|
||||||
if (forwards == null || backwards == null)
|
return Children.Skip(forwardsIndex).FirstOrDefault(item => !item.Filtered.Value);
|
||||||
return forwards ?? backwards;
|
|
||||||
|
|
||||||
// else return the closest item
|
if (!Children[forwardsIndex].Filtered.Value)
|
||||||
return forwardsDistance < backwardsDistance ? forwards : backwards;
|
return Children[forwardsIndex];
|
||||||
|
|
||||||
|
if (!Children[backwardsIndex].Filtered.Value)
|
||||||
|
return Children[backwardsIndex];
|
||||||
|
|
||||||
|
forwardsIndex++;
|
||||||
|
backwardsIndex--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void PerformSelection()
|
protected virtual void PerformSelection()
|
||||||
|
Loading…
Reference in New Issue
Block a user