mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Move children to CarouselGroup
This commit is contained in:
@ -14,15 +14,63 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
|
||||
protected override DrawableCarouselItem CreateDrawableRepresentation() => null;
|
||||
|
||||
public override void AddChild(CarouselItem i)
|
||||
public IReadOnlyList<CarouselItem> Children => InternalChildren;
|
||||
|
||||
protected List<CarouselItem> InternalChildren = new List<CarouselItem>();
|
||||
|
||||
public override List<DrawableCarouselItem> Drawables
|
||||
{
|
||||
get
|
||||
{
|
||||
var drawables = base.Drawables;
|
||||
foreach (var c in InternalChildren)
|
||||
drawables.AddRange(c.Drawables);
|
||||
return drawables;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void RemoveChild(CarouselItem i)
|
||||
{
|
||||
InternalChildren.Remove(i);
|
||||
|
||||
// it's important we do the deselection after removing, so any further actions based on
|
||||
// State.ValueChanged make decisions post-removal.
|
||||
i.State.Value = CarouselItemState.Collapsed;
|
||||
}
|
||||
|
||||
public virtual void AddChild(CarouselItem i)
|
||||
{
|
||||
i.State.ValueChanged += v => ChildItemStateChanged(i, v);
|
||||
base.AddChild(i);
|
||||
InternalChildren.Add(i);
|
||||
}
|
||||
|
||||
public CarouselGroup(List<CarouselItem> items = null)
|
||||
{
|
||||
if (items != null) InternalChildren = items;
|
||||
|
||||
State.ValueChanged += v =>
|
||||
{
|
||||
switch (v)
|
||||
{
|
||||
case CarouselItemState.Collapsed:
|
||||
case CarouselItemState.NotSelected:
|
||||
InternalChildren.ForEach(c => c.State.Value = CarouselItemState.Collapsed);
|
||||
break;
|
||||
case CarouselItemState.Selected:
|
||||
InternalChildren.ForEach(c =>
|
||||
{
|
||||
if (c.State == CarouselItemState.Collapsed) c.State.Value = CarouselItemState.NotSelected;
|
||||
});
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public override void Filter(FilterCriteria criteria)
|
||||
{
|
||||
base.Filter(criteria);
|
||||
InternalChildren.Sort((x, y) => x.CompareTo(criteria, y));
|
||||
InternalChildren.ForEach(c => c.Filter(criteria));
|
||||
}
|
||||
|
||||
protected virtual void ChildItemStateChanged(CarouselItem item, CarouselItemState value)
|
||||
|
Reference in New Issue
Block a user