1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-27 22:53:21 +08:00
osu-lazer/osu.Game/Screens/Select/Carousel/CarouselItem.cs

73 lines
2.2 KiB
C#
Raw Normal View History

2018-04-13 17:19:50 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// 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<CarouselItemState> State = new Bindable<CarouselItemState>(CarouselItemState.NotSelected);
/// <summary>
/// This item is not in a hidden state.
/// </summary>
public bool Visible => State.Value != CarouselItemState.Collapsed && !Filtered;
public virtual List<DrawableCarouselItem> Drawables
{
get
{
var items = new List<DrawableCarouselItem>();
var self = DrawableRepresentation.Value;
2018-04-13 17:19:50 +08:00
if (self?.IsPresent == true) items.Add(self);
return items;
}
}
private int creationOrder;
2018-04-13 17:19:50 +08:00
protected CarouselItem()
{
DrawableRepresentation = new Lazy<DrawableCarouselItem>(CreateDrawableRepresentation);
2018-04-13 17:19:50 +08:00
Filtered.ValueChanged += v =>
{
if (v && State == CarouselItemState.Selected)
State.Value = CarouselItemState.NotSelected;
};
}
protected readonly Lazy<DrawableCarouselItem> DrawableRepresentation;
2018-04-13 17:19:50 +08:00
/// <summary>
/// Used as a default sort method for <see cref="CarouselItem"/>s of differing types.
/// </summary>
internal ulong ChildID;
/// <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)
{
}
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,
}
}