diff --git a/osu.Game/Screens/Select/Carousel/CarouselGroup.cs b/osu.Game/Screens/Select/Carousel/CarouselGroup.cs index 7ea6e7c82b..a1f44763d6 100644 --- a/osu.Game/Screens/Select/Carousel/CarouselGroup.cs +++ b/osu.Game/Screens/Select/Carousel/CarouselGroup.cs @@ -16,6 +16,12 @@ namespace osu.Game.Screens.Select.Carousel protected List InternalChildren = new List(); + /// + /// Used to assign a monotonically increasing ID to children as they are added. This member is + /// incremented whenever a child is added. + /// + private ulong currentChildID; + public override List 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); } diff --git a/osu.Game/Screens/Select/Carousel/CarouselItem.cs b/osu.Game/Screens/Select/Carousel/CarouselItem.cs index 2efc928984..0de32c12f1 100644 --- a/osu.Game/Screens/Select/Carousel/CarouselItem.cs +++ b/osu.Game/Screens/Select/Carousel/CarouselItem.cs @@ -31,6 +31,8 @@ namespace osu.Game.Screens.Select.Carousel } } + private int creationOrder; + protected CarouselItem() { drawableRepresentation = new Lazy(CreateDrawableRepresentation); @@ -44,13 +46,18 @@ namespace osu.Game.Screens.Select.Carousel private readonly Lazy drawableRepresentation; + /// + /// Used as a default sort method for s of differing types. + /// + 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