// Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System.Collections.Generic; using osu.Framework.Configuration; namespace osu.Game.Screens.Select.Carousel { /// /// A group which ensures only one child is selected. /// public class CarouselGroup : CarouselItem { private readonly List items; public readonly Bindable Selected = new Bindable(); protected override DrawableCarouselItem CreateDrawableRepresentation() => null; public override void AddChild(CarouselItem i) { i.State.ValueChanged += v => itemStateChanged(i, v); base.AddChild(i); } public CarouselGroup(List items = null) { if (items != null) InternalChildren = items; } private void itemStateChanged(CarouselItem item, CarouselItemState value) { // todo: check state of selected item. // ensure we are the only item selected if (value == CarouselItemState.Selected) { foreach (var b in InternalChildren) { if (item == b) continue; b.State.Value = CarouselItemState.NotSelected; } State.Value = CarouselItemState.Selected; Selected.Value = item; } } } }