mirror of
https://github.com/ppy/osu.git
synced 2024-11-07 12:27:25 +08:00
46 lines
1.7 KiB
C#
46 lines
1.7 KiB
C#
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
using System.Linq;
|
|
|
|
namespace osu.Game.Screens.Select.Carousel
|
|
{
|
|
/// <summary>
|
|
/// A group which ensures at least one child is selected (if the group itself is selected).
|
|
/// </summary>
|
|
public class CarouselGroupEagerSelect : CarouselGroup
|
|
{
|
|
public CarouselGroupEagerSelect()
|
|
{
|
|
State.ValueChanged += v =>
|
|
{
|
|
if (v == CarouselItemState.Selected)
|
|
{
|
|
foreach (var c in InternalChildren.Where(c => c.State.Value == CarouselItemState.Hidden))
|
|
c.State.Value = CarouselItemState.NotSelected;
|
|
|
|
if (InternalChildren.Any(c => c.Visible) && InternalChildren.All(c => c.State != CarouselItemState.Selected))
|
|
InternalChildren.First(c => c.Visible).State.Value = CarouselItemState.Selected;
|
|
}
|
|
};
|
|
}
|
|
|
|
protected override void ItemStateChanged(CarouselItem item, CarouselItemState value)
|
|
{
|
|
base.ItemStateChanged(item, value);
|
|
|
|
if (value == CarouselItemState.NotSelected)
|
|
{
|
|
if (Children.All(i => i.State != CarouselItemState.Selected))
|
|
{
|
|
var first = Children.FirstOrDefault(i => !i.Filtered);
|
|
if (first != null)
|
|
{
|
|
first.State.Value = CarouselItemState.Selected;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|