2019-01-24 16:43:03 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2019-02-21 18:04:31 +08:00
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Select.Carousel
|
|
|
|
{
|
|
|
|
public abstract class CarouselItem
|
|
|
|
{
|
|
|
|
public readonly BindableBool Filtered = new BindableBool();
|
|
|
|
|
|
|
|
public readonly Bindable<CarouselItemState> State = new Bindable<CarouselItemState>(CarouselItemState.NotSelected);
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// This item is not in a hidden state.
|
|
|
|
/// </summary>
|
2020-03-04 19:14:18 +08:00
|
|
|
public bool Visible => State.Value != CarouselItemState.Collapsed && !Filtered.Value;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
public virtual List<DrawableCarouselItem> Drawables
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
var items = new List<DrawableCarouselItem>();
|
|
|
|
|
2018-04-24 00:52:25 +08:00
|
|
|
var self = DrawableRepresentation.Value;
|
2018-04-13 17:19:50 +08:00
|
|
|
if (self?.IsPresent == true) items.Add(self);
|
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected CarouselItem()
|
|
|
|
{
|
2018-04-24 00:52:25 +08:00
|
|
|
DrawableRepresentation = new Lazy<DrawableCarouselItem>(CreateDrawableRepresentation);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2019-02-22 16:51:39 +08:00
|
|
|
Filtered.ValueChanged += filtered =>
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2019-02-22 16:51:39 +08:00
|
|
|
if (filtered.NewValue && State.Value == CarouselItemState.Selected)
|
2018-04-13 17:19:50 +08:00
|
|
|
State.Value = CarouselItemState.NotSelected;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-04-24 00:52:25 +08:00
|
|
|
protected readonly Lazy<DrawableCarouselItem> DrawableRepresentation;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-04-23 18:01:01 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Used as a default sort method for <see cref="CarouselItem"/>s of differing types.
|
|
|
|
/// </summary>
|
|
|
|
internal ulong ChildID;
|
|
|
|
|
2018-04-24 00:52:25 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Create a fresh drawable version of this item. If you wish to consume the current representation, use <see cref="DrawableRepresentation"/> instead.
|
|
|
|
/// </summary>
|
2018-04-13 17:19:50 +08:00
|
|
|
protected abstract DrawableCarouselItem CreateDrawableRepresentation();
|
|
|
|
|
|
|
|
public virtual void Filter(FilterCriteria criteria)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-04-23 18:01:01 +08:00
|
|
|
public virtual int CompareTo(FilterCriteria criteria, CarouselItem other) => ChildID.CompareTo(other.ChildID);
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public enum CarouselItemState
|
|
|
|
{
|
|
|
|
Collapsed,
|
|
|
|
NotSelected,
|
|
|
|
Selected,
|
|
|
|
}
|
|
|
|
}
|