1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-08 06:22:55 +08:00

Add tracking of expansion states for groups and sets

This commit is contained in:
Dean Herbert 2025-02-04 17:11:09 +09:00
parent ccdb6e4c48
commit 58560f8acf
No known key found for this signature in database
4 changed files with 42 additions and 26 deletions

View File

@ -153,7 +153,8 @@ namespace osu.Game.Tests.Visual.SongSelect
var groupingFilter = Carousel.Filters.OfType<BeatmapCarouselFilterGrouping>().Single();
GroupDefinition g = groupingFilter.GroupItems.Keys.ElementAt(group);
CarouselItem item = groupingFilter.GroupItems[g].ElementAt(panel);
// offset by one because the group itself is included in the items list.
CarouselItem item = groupingFilter.GroupItems[g].ElementAt(panel + 1);
return ReferenceEquals(Carousel.CurrentSelection, item.Model);
});

View File

@ -105,12 +105,12 @@ namespace osu.Game.Screens.SelectV2
// Special case collapsing an open group.
if (lastSelectedGroup == group)
{
setVisibilityOfGroupItems(lastSelectedGroup, false);
setExpansionStateOfGroup(lastSelectedGroup, false);
lastSelectedGroup = null;
return false;
}
setVisibleGroup(group);
setExpandedGroup(group);
return false;
case BeatmapSetInfo setInfo:
@ -127,11 +127,11 @@ namespace osu.Game.Screens.SelectV2
GroupDefinition? group = grouping.GroupItems.SingleOrDefault(kvp => kvp.Value.Any(i => ReferenceEquals(i.Model, beatmapInfo))).Key;
if (group != null)
setVisibleGroup(group);
setExpandedGroup(group);
}
else
{
setVisibleSet(beatmapInfo);
setExpandedSet(beatmapInfo);
}
return true;
@ -158,37 +158,47 @@ namespace osu.Game.Screens.SelectV2
}
}
private void setVisibleGroup(GroupDefinition group)
private void setExpandedGroup(GroupDefinition group)
{
if (lastSelectedGroup != null)
setVisibilityOfGroupItems(lastSelectedGroup, false);
setExpansionStateOfGroup(lastSelectedGroup, false);
lastSelectedGroup = group;
setVisibilityOfGroupItems(group, true);
setExpansionStateOfGroup(group, true);
}
private void setVisibilityOfGroupItems(GroupDefinition group, bool visible)
private void setExpansionStateOfGroup(GroupDefinition group, bool expanded)
{
if (grouping.GroupItems.TryGetValue(group, out var items))
{
foreach (var i in items)
i.IsVisible = visible;
{
if (i.Model is GroupDefinition)
i.IsExpanded = expanded;
else
i.IsVisible = expanded;
}
}
}
private void setVisibleSet(BeatmapInfo beatmapInfo)
private void setExpandedSet(BeatmapInfo beatmapInfo)
{
if (lastSelectedBeatmap != null)
setVisibilityOfSetItems(lastSelectedBeatmap.BeatmapSet!, false);
setExpansionStateOfSetItems(lastSelectedBeatmap.BeatmapSet!, false);
lastSelectedBeatmap = beatmapInfo;
setVisibilityOfSetItems(beatmapInfo.BeatmapSet!, true);
setExpansionStateOfSetItems(beatmapInfo.BeatmapSet!, true);
}
private void setVisibilityOfSetItems(BeatmapSetInfo set, bool visible)
private void setExpansionStateOfSetItems(BeatmapSetInfo set, bool expanded)
{
if (grouping.SetItems.TryGetValue(set, out var items))
{
foreach (var i in items)
i.IsVisible = visible;
{
if (i.Model is BeatmapSetInfo)
i.IsExpanded = expanded;
else
i.IsVisible = expanded;
}
}
}

View File

@ -65,7 +65,11 @@ namespace osu.Game.Screens.SelectV2
if (b.StarRating > starGroup)
{
starGroup = (int)Math.Floor(b.StarRating);
newItems.Add(new CarouselItem(new GroupDefinition($"{starGroup} - {++starGroup} *")) { DrawHeight = GroupPanel.HEIGHT });
var groupDefinition = new GroupDefinition($"{starGroup} - {++starGroup} *");
var groupItem = new CarouselItem(groupDefinition) { DrawHeight = GroupPanel.HEIGHT };
newItems.Add(groupItem);
groupItems[groupDefinition] = new HashSet<CarouselItem> { groupItem };
}
newItems.Add(item);
@ -91,14 +95,13 @@ namespace osu.Game.Screens.SelectV2
if (newBeatmapSet)
{
newItems.Insert(i, new CarouselItem(beatmap.BeatmapSet!) { DrawHeight = BeatmapSetPanel.HEIGHT });
var setItem = new CarouselItem(beatmap.BeatmapSet!) { DrawHeight = BeatmapSetPanel.HEIGHT };
setItems[beatmap.BeatmapSet!] = new HashSet<CarouselItem> { setItem };
newItems.Insert(i, setItem);
i++;
}
if (!setItems.TryGetValue(beatmap.BeatmapSet!, out var related))
setItems[beatmap.BeatmapSet!] = related = new HashSet<CarouselItem>();
related.Add(item);
setItems[beatmap.BeatmapSet!].Add(item);
item.IsVisible = false;
}
@ -121,10 +124,7 @@ namespace osu.Game.Screens.SelectV2
if (lastGroup != null)
{
if (!groupItems.TryGetValue(lastGroup, out var groupRelated))
groupItems[lastGroup] = groupRelated = new HashSet<CarouselItem>();
groupRelated.Add(item);
groupItems[lastGroup].Add(item);
item.IsVisible = false;
}
}

View File

@ -30,10 +30,15 @@ namespace osu.Game.Screens.SelectV2
public float DrawHeight { get; set; } = DEFAULT_HEIGHT;
/// <summary>
/// Whether this item is visible or collapsed (hidden).
/// Whether this item is visible or hidden.
/// </summary>
public bool IsVisible { get; set; } = true;
/// <summary>
/// Whether this item is expanded or not. Should only be used for headers of groups.
/// </summary>
public bool IsExpanded { get; set; }
public CarouselItem(object model)
{
Model = model;