// Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; using System.Collections.Generic; using osu.Framework.Configuration; using osu.Framework.Extensions.IEnumerableExtensions; namespace osu.Game.Screens.Select.Carousel { public abstract class CarouselItem { public readonly BindableBool Filtered = new BindableBool(); public readonly Bindable State = new Bindable(CarouselItemState.NotSelected); protected virtual IEnumerable Children { get; set; } public bool Visible => State.Value != CarouselItemState.Hidden && !Filtered.Value; public readonly Lazy> Drawables; protected CarouselItem() { Drawables = new Lazy>(() => { List items = new List(); var self = CreateDrawableRepresentation(); if (self != null) items.Add(self); if (Children != null) foreach (var c in Children) items.AddRange(c.Drawables.Value); return items; }); State.ValueChanged += v => { if (Children == null) return; switch (v) { case CarouselItemState.Hidden: case CarouselItemState.NotSelected: Children.ForEach(c => c.State.Value = CarouselItemState.Hidden); break; } }; } protected abstract DrawableCarouselItem CreateDrawableRepresentation(); public virtual void Filter(FilterCriteria criteria) => Children?.ForEach(c => c.Filter(criteria)); } public enum CarouselItemState { Hidden, NotSelected, Selected, } }