1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 15:43:22 +08:00

Change carousel terminology to not use Children / InternalChildren

This commit is contained in:
Dean Herbert 2022-07-21 16:06:06 +09:00
parent 55bde4eeb0
commit a05d7f4d8c
6 changed files with 44 additions and 42 deletions

View File

@ -102,7 +102,7 @@ namespace osu.Game.Screens.Select
private readonly NoResultsPlaceholder noResultsPlaceholder; private readonly NoResultsPlaceholder noResultsPlaceholder;
private IEnumerable<CarouselBeatmapSet> beatmapSets => root.Children.OfType<CarouselBeatmapSet>(); private IEnumerable<CarouselBeatmapSet> beatmapSets => root.Items.OfType<CarouselBeatmapSet>();
// todo: only used for testing, maybe remove. // todo: only used for testing, maybe remove.
private bool loadedTestBeatmaps; private bool loadedTestBeatmaps;
@ -300,7 +300,7 @@ namespace osu.Game.Screens.Select
if (!root.BeatmapSetsByID.TryGetValue(beatmapSetID, out var existingSet)) if (!root.BeatmapSetsByID.TryGetValue(beatmapSetID, out var existingSet))
return; return;
root.RemoveChild(existingSet); root.RemoveItem(existingSet);
itemsCache.Invalidate(); itemsCache.Invalidate();
if (!Scroll.UserScrolling) if (!Scroll.UserScrolling)
@ -321,7 +321,7 @@ namespace osu.Game.Screens.Select
if (newSet != null) if (newSet != null)
{ {
root.AddChild(newSet); root.AddItem(newSet);
// check if we can/need to maintain our current selection. // check if we can/need to maintain our current selection.
if (previouslySelectedID != null) if (previouslySelectedID != null)
@ -415,7 +415,7 @@ namespace osu.Game.Screens.Select
if (selectedBeatmap == null) if (selectedBeatmap == null)
return; return;
var unfilteredDifficulties = selectedBeatmapSet.Children.Where(s => !s.Filtered.Value).ToList(); var unfilteredDifficulties = selectedBeatmapSet.Items.Where(s => !s.Filtered.Value).ToList();
int index = unfilteredDifficulties.IndexOf(selectedBeatmap); int index = unfilteredDifficulties.IndexOf(selectedBeatmap);
@ -798,7 +798,7 @@ namespace osu.Game.Screens.Select
scrollTarget = null; scrollTarget = null;
foreach (CarouselItem item in root.Children) foreach (CarouselItem item in root.Items)
{ {
if (item.Filtered.Value) if (item.Filtered.Value)
continue; continue;
@ -964,26 +964,26 @@ namespace osu.Game.Screens.Select
this.carousel = carousel; this.carousel = carousel;
} }
public override void AddChild(CarouselItem i) public override void AddItem(CarouselItem i)
{ {
CarouselBeatmapSet set = (CarouselBeatmapSet)i; CarouselBeatmapSet set = (CarouselBeatmapSet)i;
BeatmapSetsByID.Add(set.BeatmapSet.ID, set); BeatmapSetsByID.Add(set.BeatmapSet.ID, set);
base.AddChild(i); base.AddItem(i);
} }
public void RemoveChild(Guid beatmapSetID) public void RemoveChild(Guid beatmapSetID)
{ {
if (BeatmapSetsByID.TryGetValue(beatmapSetID, out var carouselBeatmapSet)) if (BeatmapSetsByID.TryGetValue(beatmapSetID, out var carouselBeatmapSet))
RemoveChild(carouselBeatmapSet); RemoveItem(carouselBeatmapSet);
} }
public override void RemoveChild(CarouselItem i) public override void RemoveItem(CarouselItem i)
{ {
CarouselBeatmapSet set = (CarouselBeatmapSet)i; CarouselBeatmapSet set = (CarouselBeatmapSet)i;
BeatmapSetsByID.Remove(set.BeatmapSet.ID); BeatmapSetsByID.Remove(set.BeatmapSet.ID);
base.RemoveChild(i); base.RemoveItem(i);
} }
protected override void PerformSelection() protected override void PerformSelection()

View File

@ -21,7 +21,7 @@ namespace osu.Game.Screens.Select.Carousel
switch (State.Value) switch (State.Value)
{ {
case CarouselItemState.Selected: case CarouselItemState.Selected:
return DrawableCarouselBeatmapSet.HEIGHT + Children.Count(c => c.Visible) * DrawableCarouselBeatmap.HEIGHT; return DrawableCarouselBeatmapSet.HEIGHT + Items.Count(c => c.Visible) * DrawableCarouselBeatmap.HEIGHT;
default: default:
return DrawableCarouselBeatmapSet.HEIGHT; return DrawableCarouselBeatmapSet.HEIGHT;
@ -29,7 +29,7 @@ namespace osu.Game.Screens.Select.Carousel
} }
} }
public IEnumerable<CarouselBeatmap> Beatmaps => InternalChildren.OfType<CarouselBeatmap>(); public IEnumerable<CarouselBeatmap> Beatmaps => Items.OfType<CarouselBeatmap>();
public BeatmapSetInfo BeatmapSet; public BeatmapSetInfo BeatmapSet;
@ -44,15 +44,15 @@ namespace osu.Game.Screens.Select.Carousel
.OrderBy(b => b.Ruleset) .OrderBy(b => b.Ruleset)
.ThenBy(b => b.StarRating) .ThenBy(b => b.StarRating)
.Select(b => new CarouselBeatmap(b)) .Select(b => new CarouselBeatmap(b))
.ForEach(AddChild); .ForEach(AddItem);
} }
protected override CarouselItem GetNextToSelect() protected override CarouselItem GetNextToSelect()
{ {
if (LastSelected == null || LastSelected.Filtered.Value) if (LastSelected == null || LastSelected.Filtered.Value)
{ {
if (GetRecommendedBeatmap?.Invoke(Children.OfType<CarouselBeatmap>().Where(b => !b.Filtered.Value).Select(b => b.BeatmapInfo)) is BeatmapInfo recommended) if (GetRecommendedBeatmap?.Invoke(Items.OfType<CarouselBeatmap>().Where(b => !b.Filtered.Value).Select(b => b.BeatmapInfo)) is BeatmapInfo recommended)
return Children.OfType<CarouselBeatmap>().First(b => b.BeatmapInfo.Equals(recommended)); return Items.OfType<CarouselBeatmap>().First(b => b.BeatmapInfo.Equals(recommended));
} }
return base.GetNextToSelect(); return base.GetNextToSelect();
@ -122,7 +122,7 @@ namespace osu.Game.Screens.Select.Carousel
public override void Filter(FilterCriteria criteria) public override void Filter(FilterCriteria criteria)
{ {
base.Filter(criteria); base.Filter(criteria);
Filtered.Value = InternalChildren.All(i => i.Filtered.Value); Filtered.Value = Items.All(i => i.Filtered.Value);
} }
public override string ToString() => BeatmapSet.ToString(); public override string ToString() => BeatmapSet.ToString();

View File

@ -13,9 +13,9 @@ namespace osu.Game.Screens.Select.Carousel
{ {
public override DrawableCarouselItem? CreateDrawableRepresentation() => null; public override DrawableCarouselItem? CreateDrawableRepresentation() => null;
public IReadOnlyList<CarouselItem> Children => InternalChildren; public IReadOnlyList<CarouselItem> Items => items;
protected List<CarouselItem> InternalChildren = new List<CarouselItem>(); private List<CarouselItem> items = new List<CarouselItem>();
/// <summary> /// <summary>
/// Used to assign a monotonically increasing ID to children as they are added. This member is /// Used to assign a monotonically increasing ID to children as they are added. This member is
@ -27,16 +27,18 @@ namespace osu.Game.Screens.Select.Carousel
private FilterCriteria? lastCriteria; private FilterCriteria? lastCriteria;
public virtual void RemoveChild(CarouselItem i) protected int GetIndexOfItem(CarouselItem lastSelected) => items.IndexOf(lastSelected);
public virtual void RemoveItem(CarouselItem i)
{ {
InternalChildren.Remove(i); items.Remove(i);
// it's important we do the deselection after removing, so any further actions based on // it's important we do the deselection after removing, so any further actions based on
// State.ValueChanged make decisions post-removal. // State.ValueChanged make decisions post-removal.
i.State.Value = CarouselItemState.Collapsed; i.State.Value = CarouselItemState.Collapsed;
} }
public virtual void AddChild(CarouselItem i) public virtual void AddItem(CarouselItem i)
{ {
i.State.ValueChanged += state => ChildItemStateChanged(i, state.NewValue); i.State.ValueChanged += state => ChildItemStateChanged(i, state.NewValue);
i.ChildID = ++currentChildID; i.ChildID = ++currentChildID;
@ -45,21 +47,21 @@ namespace osu.Game.Screens.Select.Carousel
{ {
i.Filter(lastCriteria); i.Filter(lastCriteria);
int index = InternalChildren.BinarySearch(i, criteriaComparer); int index = items.BinarySearch(i, criteriaComparer);
if (index < 0) index = ~index; // BinarySearch hacks multiple return values with 2's complement. if (index < 0) index = ~index; // BinarySearch hacks multiple return values with 2's complement.
InternalChildren.Insert(index, i); items.Insert(index, i);
} }
else else
{ {
// criteria may be null for initial population. the filtering will be applied post-add. // criteria may be null for initial population. the filtering will be applied post-add.
InternalChildren.Add(i); items.Add(i);
} }
} }
public CarouselGroup(List<CarouselItem>? items = null) public CarouselGroup(List<CarouselItem>? items = null)
{ {
if (items != null) InternalChildren = items; if (items != null) this.items = items;
State.ValueChanged += state => State.ValueChanged += state =>
{ {
@ -67,11 +69,11 @@ namespace osu.Game.Screens.Select.Carousel
{ {
case CarouselItemState.Collapsed: case CarouselItemState.Collapsed:
case CarouselItemState.NotSelected: case CarouselItemState.NotSelected:
InternalChildren.ForEach(c => c.State.Value = CarouselItemState.Collapsed); this.items.ForEach(c => c.State.Value = CarouselItemState.Collapsed);
break; break;
case CarouselItemState.Selected: case CarouselItemState.Selected:
InternalChildren.ForEach(c => this.items.ForEach(c =>
{ {
if (c.State.Value == CarouselItemState.Collapsed) c.State.Value = CarouselItemState.NotSelected; if (c.State.Value == CarouselItemState.Collapsed) c.State.Value = CarouselItemState.NotSelected;
}); });
@ -84,11 +86,11 @@ namespace osu.Game.Screens.Select.Carousel
{ {
base.Filter(criteria); base.Filter(criteria);
InternalChildren.ForEach(c => c.Filter(criteria)); items.ForEach(c => c.Filter(criteria));
// IEnumerable<T>.OrderBy() is used instead of List<T>.Sort() to ensure sorting stability // IEnumerable<T>.OrderBy() is used instead of List<T>.Sort() to ensure sorting stability
criteriaComparer = Comparer<CarouselItem>.Create((x, y) => x.CompareTo(criteria, y)); criteriaComparer = Comparer<CarouselItem>.Create((x, y) => x.CompareTo(criteria, y));
InternalChildren = InternalChildren.OrderBy(c => c, criteriaComparer).ToList(); items = items.OrderBy(c => c, criteriaComparer).ToList();
lastCriteria = criteria; lastCriteria = criteria;
} }
@ -98,7 +100,7 @@ namespace osu.Game.Screens.Select.Carousel
// ensure we are the only item selected // ensure we are the only item selected
if (value == CarouselItemState.Selected) if (value == CarouselItemState.Selected)
{ {
foreach (var b in InternalChildren) foreach (var b in items)
{ {
if (item == b) continue; if (item == b) continue;

View File

@ -49,9 +49,9 @@ namespace osu.Game.Screens.Select.Carousel
attemptSelection(); attemptSelection();
} }
public override void RemoveChild(CarouselItem i) public override void RemoveItem(CarouselItem i)
{ {
base.RemoveChild(i); base.RemoveItem(i);
if (i != LastSelected) if (i != LastSelected)
updateSelectedIndex(); updateSelectedIndex();
@ -64,16 +64,16 @@ namespace osu.Game.Screens.Select.Carousel
addingChildren = true; addingChildren = true;
foreach (var i in items) foreach (var i in items)
AddChild(i); AddItem(i);
addingChildren = false; addingChildren = false;
attemptSelection(); attemptSelection();
} }
public override void AddChild(CarouselItem i) public override void AddItem(CarouselItem i)
{ {
base.AddChild(i); base.AddItem(i);
if (!addingChildren) if (!addingChildren)
attemptSelection(); attemptSelection();
} }
@ -103,15 +103,15 @@ namespace osu.Game.Screens.Select.Carousel
if (State.Value != CarouselItemState.Selected) return; if (State.Value != CarouselItemState.Selected) return;
// we only perform eager selection if none of our children are in a selected state already. // we only perform eager selection if none of our children are in a selected state already.
if (Children.Any(i => i.State.Value == CarouselItemState.Selected)) return; if (Items.Any(i => i.State.Value == CarouselItemState.Selected)) return;
PerformSelection(); PerformSelection();
} }
protected virtual CarouselItem GetNextToSelect() protected virtual CarouselItem GetNextToSelect()
{ {
return Children.Skip(lastSelectedIndex).FirstOrDefault(i => !i.Filtered.Value) ?? return Items.Skip(lastSelectedIndex).FirstOrDefault(i => !i.Filtered.Value) ??
Children.Reverse().Skip(InternalChildren.Count - lastSelectedIndex).FirstOrDefault(i => !i.Filtered.Value); Items.Reverse().Skip(Items.Count - lastSelectedIndex).FirstOrDefault(i => !i.Filtered.Value);
} }
protected virtual void PerformSelection() protected virtual void PerformSelection()
@ -131,6 +131,6 @@ namespace osu.Game.Screens.Select.Carousel
updateSelectedIndex(); updateSelectedIndex();
} }
private void updateSelectedIndex() => lastSelectedIndex = LastSelected == null ? 0 : Math.Max(0, InternalChildren.IndexOf(LastSelected)); private void updateSelectedIndex() => lastSelectedIndex = LastSelected == null ? 0 : Math.Max(0, GetIndexOfItem(LastSelected));
} }
} }

View File

@ -152,7 +152,7 @@ namespace osu.Game.Screens.Select.Carousel
{ {
var carouselBeatmapSet = (CarouselBeatmapSet)Item; var carouselBeatmapSet = (CarouselBeatmapSet)Item;
var visibleBeatmaps = carouselBeatmapSet.Children.Where(c => c.Visible).ToArray(); var visibleBeatmaps = carouselBeatmapSet.Items.Where(c => c.Visible).ToArray();
// if we are already displaying all the correct beatmaps, only run animation updates. // if we are already displaying all the correct beatmaps, only run animation updates.
// note that the displayed beatmaps may change due to the applied filter. // note that the displayed beatmaps may change due to the applied filter.

View File

@ -53,7 +53,7 @@ namespace osu.Game.Screens.Select.Carousel
if (item is CarouselGroup group) if (item is CarouselGroup group)
{ {
foreach (var c in group.Children) foreach (var c in group.Items)
c.Filtered.ValueChanged -= onStateChange; c.Filtered.ValueChanged -= onStateChange;
} }
} }
@ -117,7 +117,7 @@ namespace osu.Game.Screens.Select.Carousel
if (Item is CarouselGroup group) if (Item is CarouselGroup group)
{ {
foreach (var c in group.Children) foreach (var c in group.Items)
c.Filtered.ValueChanged += onStateChange; c.Filtered.ValueChanged += onStateChange;
} }
} }