Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow ordering certain carousel panels behind others #31802

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions osu.Game/Screens/SelectV2/BeatmapCarouselFilterGrouping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ public async Task<IEnumerable<CarouselItem>> Run(IEnumerable<CarouselItem> items
{
starGroup = (int)Math.Floor(b.StarRating);
var groupDefinition = new GroupDefinition($"{starGroup} - {++starGroup} *");
var groupItem = new CarouselItem(groupDefinition) { DrawHeight = GroupPanel.HEIGHT };

var groupItem = new CarouselItem(groupDefinition)
{
DrawHeight = GroupPanel.HEIGHT,
DepthLayer = -2
};

newItems.Add(groupItem);
groupItems[groupDefinition] = new HashSet<CarouselItem> { groupItem };
Expand Down Expand Up @@ -95,7 +100,12 @@ public async Task<IEnumerable<CarouselItem>> Run(IEnumerable<CarouselItem> items

if (newBeatmapSet)
{
var setItem = new CarouselItem(beatmap.BeatmapSet!) { DrawHeight = BeatmapSetPanel.HEIGHT };
var setItem = new CarouselItem(beatmap.BeatmapSet!)
{
DrawHeight = BeatmapSetPanel.HEIGHT,
DepthLayer = -1
};

setItems[beatmap.BeatmapSet!] = new HashSet<CarouselItem> { setItem };
newItems.Insert(i, setItem);
i++;
Expand Down
7 changes: 5 additions & 2 deletions osu.Game/Screens/SelectV2/Carousel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,9 @@
updateDisplayedRange(range);
}

double selectedYPos = currentSelection?.CarouselItem?.CarouselYPosition ?? 0;

Check failure on line 553 in osu.Game/Screens/SelectV2/Carousel.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Conditional access qualifier expression is never null according to nullable reference types' annotations in osu.Game\Screens\SelectV2\Carousel.cs on line 553
double maximumDistanceFromSelection = scroll.Panels.Select(p => Math.Abs(((ICarouselPanel)p).DrawYPosition - selectedYPos)).DefaultIfEmpty().Max();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't run linq in Update as a rule. Why can't this just be scroll.Panels[^1]?


foreach (var panel in scroll.Panels)
{
var c = (ICarouselPanel)panel;
Expand All @@ -558,8 +561,8 @@
if (c.Item == null)
continue;

double selectedYPos = currentSelection?.CarouselItem?.CarouselYPosition ?? 0;
scroll.Panels.ChangeChildDepth(panel, (float)Math.Abs(c.DrawYPosition - selectedYPos));
float normalisedDepth = (float)(Math.Abs(selectedYPos - c.DrawYPosition) / maximumDistanceFromSelection);
scroll.Panels.ChangeChildDepth(panel, normalisedDepth + c.Item.DepthLayer);

if (c.DrawYPosition != c.Item.CarouselYPosition)
c.DrawYPosition = Interpolation.DampContinuously(c.DrawYPosition, c.Item.CarouselYPosition, 50, Time.Elapsed);
Expand Down
6 changes: 6 additions & 0 deletions osu.Game/Screens/SelectV2/CarouselItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
/// </summary>
public float DrawHeight { get; set; } = DEFAULT_HEIGHT;

/// <summary>
/// A number that defines the layer which this <see cref="CarouselItem"/> should be placed on depth-wise.
/// The higher the number, the farther the panel associated with this item is taken to the background.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should mention that this is relative to other panels, rather than "to the background" (because it doesn't make too much sense when they are never really approaching any background).

/// </summary>
public int DepthLayer { get; set; } = 0;

Check failure on line 36 in osu.Game/Screens/SelectV2/CarouselItem.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Initializing property by default value is redundant in osu.Game\Screens\SelectV2\CarouselItem.cs on line 36

/// <summary>
/// Whether this item is visible or hidden.
/// </summary>
Expand Down
Loading