// Copyright (c) 2007-2018 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; namespace osu.Game.Screens.Select.Carousel { public abstract class CarouselItem { public readonly BindableBool Filtered = new BindableBool(); public readonly Bindable State = new Bindable(CarouselItemState.NotSelected); /// /// This item is not in a hidden state. /// public bool Visible => State.Value != CarouselItemState.Collapsed && !Filtered; public virtual List Drawables { get { var items = new List(); var self = DrawableRepresentation.Value; if (self?.IsPresent == true) items.Add(self); return items; } } private int creationOrder; protected CarouselItem() { DrawableRepresentation = new Lazy(CreateDrawableRepresentation); Filtered.ValueChanged += v => { if (v && State == CarouselItemState.Selected) State.Value = CarouselItemState.NotSelected; }; } protected readonly Lazy DrawableRepresentation; /// /// Used as a default sort method for s of differing types. /// internal ulong ChildID; /// /// Create a fresh drawable version of this item. If you wish to consume the current representation, use instead. /// protected abstract DrawableCarouselItem CreateDrawableRepresentation(); public virtual void Filter(FilterCriteria criteria) { } public virtual int CompareTo(FilterCriteria criteria, CarouselItem other) => ChildID.CompareTo(other.ChildID); } public enum CarouselItemState { Collapsed, NotSelected, Selected, } }