mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 16:59:53 +09:00
Move children to CarouselGroup
This commit is contained in:
@ -53,7 +53,7 @@ namespace osu.Game.Screens.Select
|
|||||||
|
|
||||||
public override bool HandleInput => AllowSelection;
|
public override bool HandleInput => AllowSelection;
|
||||||
|
|
||||||
private IEnumerable<CarouselBeatmapSet> beatmapSets => root.Children?.OfType<CarouselBeatmapSet>() ?? new CarouselBeatmapSet[] { };
|
private IEnumerable<CarouselBeatmapSet> beatmapSets => root.Children.OfType<CarouselBeatmapSet>();
|
||||||
|
|
||||||
public IEnumerable<BeatmapSetInfo> BeatmapSets
|
public IEnumerable<BeatmapSetInfo> BeatmapSets
|
||||||
{
|
{
|
||||||
@ -277,7 +277,7 @@ namespace osu.Game.Screens.Select
|
|||||||
|
|
||||||
private void applyActiveCriteria(bool debounce, bool scroll)
|
private void applyActiveCriteria(bool debounce, bool scroll)
|
||||||
{
|
{
|
||||||
if (root.Children?.Any() != true) return;
|
if (root.Children.Any() != true) return;
|
||||||
|
|
||||||
void perform()
|
void perform()
|
||||||
{
|
{
|
||||||
|
@ -14,15 +14,63 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
|
|
||||||
protected override DrawableCarouselItem CreateDrawableRepresentation() => null;
|
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);
|
i.State.ValueChanged += v => ChildItemStateChanged(i, v);
|
||||||
base.AddChild(i);
|
InternalChildren.Add(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CarouselGroup(List<CarouselItem> items = null)
|
public CarouselGroup(List<CarouselItem> items = null)
|
||||||
{
|
{
|
||||||
if (items != null) InternalChildren = items;
|
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)
|
protected virtual void ChildItemStateChanged(CarouselItem item, CarouselItemState value)
|
||||||
|
@ -13,66 +13,28 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
|
|
||||||
public readonly Bindable<CarouselItemState> State = new Bindable<CarouselItemState>(CarouselItemState.NotSelected);
|
public readonly Bindable<CarouselItemState> State = new Bindable<CarouselItemState>(CarouselItemState.NotSelected);
|
||||||
|
|
||||||
public IReadOnlyList<CarouselItem> Children => InternalChildren;
|
|
||||||
|
|
||||||
protected List<CarouselItem> InternalChildren { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This item is not in a hidden state.
|
/// This item is not in a hidden state.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Visible => State.Value != CarouselItemState.Collapsed && !Filtered;
|
public bool Visible => State.Value != CarouselItemState.Collapsed && !Filtered;
|
||||||
|
|
||||||
public IEnumerable<DrawableCarouselItem> Drawables
|
public virtual List<DrawableCarouselItem> Drawables
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
List<DrawableCarouselItem> items = new List<DrawableCarouselItem>();
|
var items = new List<DrawableCarouselItem>();
|
||||||
|
|
||||||
var self = drawableRepresentation.Value;
|
var self = drawableRepresentation.Value;
|
||||||
if (self?.IsPresent == true) items.Add(self);
|
if (self?.IsPresent == true) items.Add(self);
|
||||||
|
|
||||||
if (InternalChildren != null)
|
|
||||||
foreach (var c in InternalChildren)
|
|
||||||
items.AddRange(c.Drawables);
|
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void AddChild(CarouselItem i) => (InternalChildren ?? (InternalChildren = new List<CarouselItem>())).Add(i);
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected CarouselItem()
|
protected CarouselItem()
|
||||||
{
|
{
|
||||||
drawableRepresentation = new Lazy<DrawableCarouselItem>(CreateDrawableRepresentation);
|
drawableRepresentation = new Lazy<DrawableCarouselItem>(CreateDrawableRepresentation);
|
||||||
|
|
||||||
State.ValueChanged += v =>
|
|
||||||
{
|
|
||||||
if (InternalChildren == null) return;
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Filtered.ValueChanged += v =>
|
Filtered.ValueChanged += v =>
|
||||||
{
|
{
|
||||||
if (v && State == CarouselItemState.Selected)
|
if (v && State == CarouselItemState.Selected)
|
||||||
@ -86,8 +48,6 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
|
|
||||||
public virtual void Filter(FilterCriteria criteria)
|
public virtual void Filter(FilterCriteria criteria)
|
||||||
{
|
{
|
||||||
InternalChildren?.Sort((x, y) => x.CompareTo(criteria, y));
|
|
||||||
InternalChildren?.ForEach(c => c.Filter(criteria));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual int CompareTo(FilterCriteria criteria, CarouselItem other) => GetHashCode().CompareTo(other.GetHashCode());
|
public virtual int CompareTo(FilterCriteria criteria, CarouselItem other) => GetHashCode().CompareTo(other.GetHashCode());
|
||||||
|
Reference in New Issue
Block a user