1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 18:42:56 +08:00

Fix instability in carousel item sorting

This commit is contained in:
Dean Herbert 2018-04-23 19:01:01 +09:00
parent 8b1b605c09
commit 2d1cef79d6
2 changed files with 15 additions and 1 deletions

View File

@ -16,6 +16,12 @@ namespace osu.Game.Screens.Select.Carousel
protected List<CarouselItem> InternalChildren = new List<CarouselItem>();
/// <summary>
/// Used to assign a monotonically increasing ID to children as they are added. This member is
/// incremented whenever a child is added.
/// </summary>
private ulong currentChildID;
public override List<DrawableCarouselItem> Drawables
{
get
@ -39,6 +45,7 @@ namespace osu.Game.Screens.Select.Carousel
public virtual void AddChild(CarouselItem i)
{
i.State.ValueChanged += v => ChildItemStateChanged(i, v);
i.ChildID = ++currentChildID;
InternalChildren.Add(i);
}

View File

@ -31,6 +31,8 @@ namespace osu.Game.Screens.Select.Carousel
}
}
private int creationOrder;
protected CarouselItem()
{
drawableRepresentation = new Lazy<DrawableCarouselItem>(CreateDrawableRepresentation);
@ -44,13 +46,18 @@ namespace osu.Game.Screens.Select.Carousel
private readonly Lazy<DrawableCarouselItem> drawableRepresentation;
/// <summary>
/// Used as a default sort method for <see cref="CarouselItem"/>s of differing types.
/// </summary>
internal ulong ChildID;
protected abstract DrawableCarouselItem CreateDrawableRepresentation();
public virtual void Filter(FilterCriteria criteria)
{
}
public virtual int CompareTo(FilterCriteria criteria, CarouselItem other) => GetHashCode().CompareTo(other.GetHashCode());
public virtual int CompareTo(FilterCriteria criteria, CarouselItem other) => ChildID.CompareTo(other.ChildID);
}
public enum CarouselItemState