2019-01-24 17:43:03 +09: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 18:19:50 +09:00
|
|
|
|
2020-10-13 13:21:21 +09:00
|
|
|
using System;
|
2019-02-21 19:04:31 +09:00
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Select.Carousel
|
|
|
|
{
|
2020-10-13 13:21:21 +09:00
|
|
|
public abstract class CarouselItem : IComparable<CarouselItem>
|
2018-04-13 18:19:50 +09:00
|
|
|
{
|
2020-10-12 14:23:18 +09:00
|
|
|
public virtual float TotalHeight => 0;
|
|
|
|
|
2020-10-13 13:21:21 +09:00
|
|
|
/// <summary>
|
|
|
|
/// An externally defined value used to determine this item's vertical display offset relative to the carousel.
|
|
|
|
/// </summary>
|
|
|
|
public float CarouselYPosition;
|
|
|
|
|
2018-04-13 18:19:50 +09:00
|
|
|
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 20:14:18 +09:00
|
|
|
public bool Visible => State.Value != CarouselItemState.Collapsed && !Filtered.Value;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
|
|
protected CarouselItem()
|
|
|
|
{
|
2019-02-22 17:51:39 +09:00
|
|
|
Filtered.ValueChanged += filtered =>
|
2018-04-13 18:19:50 +09:00
|
|
|
{
|
2019-02-22 17:51:39 +09:00
|
|
|
if (filtered.NewValue && State.Value == CarouselItemState.Selected)
|
2018-04-13 18:19:50 +09:00
|
|
|
State.Value = CarouselItemState.NotSelected;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-04-23 19:01:01 +09:00
|
|
|
/// <summary>
|
|
|
|
/// Used as a default sort method for <see cref="CarouselItem"/>s of differing types.
|
|
|
|
/// </summary>
|
2022-07-26 09:39:30 +03:00
|
|
|
internal ulong ItemID;
|
2018-04-23 19:01:01 +09:00
|
|
|
|
2018-04-24 01:52:25 +09:00
|
|
|
/// <summary>
|
2020-10-12 12:37:32 +09:00
|
|
|
/// Create a fresh drawable version of this item.
|
2018-04-24 01:52:25 +09:00
|
|
|
/// </summary>
|
2023-01-09 18:36:55 +01:00
|
|
|
public abstract DrawableCarouselItem? CreateDrawableRepresentation();
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
|
|
public virtual void Filter(FilterCriteria criteria)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-07-26 09:39:30 +03:00
|
|
|
public virtual int CompareTo(FilterCriteria criteria, CarouselItem other) => ItemID.CompareTo(other.ItemID);
|
2020-10-13 13:21:21 +09:00
|
|
|
|
2023-01-10 18:29:56 +01:00
|
|
|
public int CompareTo(CarouselItem? other)
|
|
|
|
{
|
|
|
|
if (other == null) return 1;
|
|
|
|
|
|
|
|
return CarouselYPosition.CompareTo(other.CarouselYPosition);
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public enum CarouselItemState
|
|
|
|
{
|
|
|
|
Collapsed,
|
|
|
|
NotSelected,
|
|
|
|
Selected,
|
|
|
|
}
|
|
|
|
}
|