1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 11:47:24 +08:00
osu-lazer/osu.Game/Screens/Select/Carousel/CarouselItem.cs

63 lines
1.9 KiB
C#
Raw Normal View History

2018-01-05 19:21:19 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
2017-12-12 16:48:38 +08:00
// 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>
2017-12-16 22:56:14 +08:00
public bool Visible => State.Value != CarouselItemState.Collapsed && !Filtered;
2017-12-12 16:48:38 +08:00
2017-12-18 10:57:13 +08:00
public virtual List<DrawableCarouselItem> Drawables
2017-12-12 16:48:38 +08:00
{
2017-12-14 19:40:58 +08:00
get
2017-12-12 16:48:38 +08:00
{
2017-12-18 10:57:13 +08:00
var items = new List<DrawableCarouselItem>();
2017-12-12 16:48:38 +08:00
2017-12-14 19:40:58 +08:00
var self = drawableRepresentation.Value;
if (self?.IsPresent == true) items.Add(self);
2017-12-12 16:48:38 +08:00
return items;
2017-12-14 19:40:58 +08:00
}
}
protected CarouselItem()
{
drawableRepresentation = new Lazy<DrawableCarouselItem>(CreateDrawableRepresentation);
2017-12-12 16:48:38 +08:00
Filtered.ValueChanged += v =>
{
if (v && State == CarouselItemState.Selected)
State.Value = CarouselItemState.NotSelected;
};
2017-12-12 16:48:38 +08:00
}
2017-12-14 19:40:58 +08:00
private readonly Lazy<DrawableCarouselItem> drawableRepresentation;
2017-12-12 16:48:38 +08:00
protected abstract DrawableCarouselItem CreateDrawableRepresentation();
2017-12-14 19:40:58 +08:00
public virtual void Filter(FilterCriteria criteria)
{
}
public virtual int CompareTo(FilterCriteria criteria, CarouselItem other) => GetHashCode().CompareTo(other.GetHashCode());
2017-12-12 16:48:38 +08:00
}
2017-12-13 18:56:16 +08:00
public enum CarouselItemState
{
2017-12-16 22:56:14 +08:00
Collapsed,
2017-12-13 18:56:16 +08:00
NotSelected,
Selected,
}
2017-12-12 16:48:38 +08:00
}