1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-31 17:52:54 +08:00

Merge pull request #31652 from peppy/beatmap-carousel-v2-split-panels

Split out beatmap and set panels in  beatmap carousel v2
This commit is contained in:
Bartłomiej Dach 2025-01-24 16:00:04 +01:00 committed by GitHub
commit 3c763971ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 157 additions and 52 deletions

View File

@ -131,7 +131,7 @@ namespace osu.Game.Tests.Visual.SongSelect
protected void SortBy(FilterCriteria criteria) => AddStep($"sort by {criteria.Sort}", () => Carousel.Filter(criteria));
protected void WaitForDrawablePanels() => AddUntilStep("drawable panels loaded", () => Carousel.ChildrenOfType<BeatmapCarouselPanel>().Count(), () => Is.GreaterThan(0));
protected void WaitForDrawablePanels() => AddUntilStep("drawable panels loaded", () => Carousel.ChildrenOfType<ICarouselPanel>().Count(), () => Is.GreaterThan(0));
protected void WaitForSorting() => AddUntilStep("sorting finished", () => Carousel.IsFiltering, () => Is.False);
protected void WaitForScrolling() => AddUntilStep("scroll finished", () => Scroll.Current, () => Is.EqualTo(Scroll.Target));

View File

@ -56,16 +56,16 @@ namespace osu.Game.Tests.Visual.SongSelect
WaitForDrawablePanels();
AddStep("select middle beatmap", () => Carousel.CurrentSelection = BeatmapSets.ElementAt(BeatmapSets.Count - 2));
AddStep("scroll to selected item", () => Scroll.ScrollTo(Scroll.ChildrenOfType<BeatmapCarouselPanel>().Single(p => p.Selected.Value)));
AddStep("scroll to selected item", () => Scroll.ScrollTo(Scroll.ChildrenOfType<BeatmapPanel>().Single(p => p.Selected.Value)));
WaitForScrolling();
AddStep("save selected screen position", () => positionBefore = Carousel.ChildrenOfType<BeatmapCarouselPanel>().FirstOrDefault(p => p.Selected.Value)!.ScreenSpaceDrawQuad);
AddStep("save selected screen position", () => positionBefore = Carousel.ChildrenOfType<BeatmapPanel>().FirstOrDefault(p => p.Selected.Value)!.ScreenSpaceDrawQuad);
RemoveFirstBeatmap();
WaitForSorting();
AddAssert("select screen position unchanged", () => Carousel.ChildrenOfType<BeatmapCarouselPanel>().Single(p => p.Selected.Value).ScreenSpaceDrawQuad,
AddAssert("select screen position unchanged", () => Carousel.ChildrenOfType<BeatmapPanel>().Single(p => p.Selected.Value).ScreenSpaceDrawQuad,
() => Is.EqualTo(positionBefore));
}
@ -83,11 +83,11 @@ namespace osu.Game.Tests.Visual.SongSelect
WaitForScrolling();
AddStep("save selected screen position", () => positionBefore = Carousel.ChildrenOfType<BeatmapCarouselPanel>().FirstOrDefault(p => p.Selected.Value)!.ScreenSpaceDrawQuad);
AddStep("save selected screen position", () => positionBefore = Carousel.ChildrenOfType<BeatmapPanel>().FirstOrDefault(p => p.Selected.Value)!.ScreenSpaceDrawQuad);
RemoveFirstBeatmap();
WaitForSorting();
AddAssert("select screen position unchanged", () => Carousel.ChildrenOfType<BeatmapCarouselPanel>().Single(p => p.Selected.Value).ScreenSpaceDrawQuad,
AddAssert("select screen position unchanged", () => Carousel.ChildrenOfType<BeatmapPanel>().Single(p => p.Selected.Value).ScreenSpaceDrawQuad,
() => Is.EqualTo(positionBefore));
}

View File

@ -97,7 +97,7 @@ namespace osu.Game.Tests.Visual.SongSelect
AddUntilStep("drawable selection restored", () => getSelectedPanel()?.Item?.Model, () => Is.EqualTo(selection));
AddAssert("drawable selection matches carousel selection", () => selection, () => Is.EqualTo(Carousel.CurrentSelection));
BeatmapCarouselPanel? getSelectedPanel() => Carousel.ChildrenOfType<BeatmapCarouselPanel>().SingleOrDefault(p => p.Selected.Value);
BeatmapPanel? getSelectedPanel() => Carousel.ChildrenOfType<BeatmapPanel>().SingleOrDefault(p => p.Selected.Value);
}
[Test]

View File

@ -141,14 +141,28 @@ namespace osu.Game.Screens.SelectV2
#region Drawable pooling
private readonly DrawablePool<BeatmapCarouselPanel> carouselPanelPool = new DrawablePool<BeatmapCarouselPanel>(100);
private readonly DrawablePool<BeatmapPanel> beatmapPanelPool = new DrawablePool<BeatmapPanel>(100);
private readonly DrawablePool<BeatmapSetPanel> setPanelPool = new DrawablePool<BeatmapSetPanel>(100);
private void setupPools()
{
AddInternal(carouselPanelPool);
AddInternal(beatmapPanelPool);
AddInternal(setPanelPool);
}
protected override Drawable GetDrawableForDisplay(CarouselItem item) => carouselPanelPool.Get();
protected override Drawable GetDrawableForDisplay(CarouselItem item)
{
switch (item.Model)
{
case BeatmapInfo:
return beatmapPanelPool.Get();
case BeatmapSetInfo:
return setPanelPool.Get();
}
throw new InvalidOperationException();
}
#endregion
}

View File

@ -57,7 +57,7 @@ namespace osu.Game.Screens.SelectV2
{
newItems.Add(new CarouselItem(b.BeatmapSet!)
{
DrawHeight = 80,
DrawHeight = BeatmapSetPanel.HEIGHT,
IsGroupSelectionTarget = true
});
}

View File

@ -16,22 +16,25 @@ using osuTK.Graphics;
namespace osu.Game.Screens.SelectV2
{
public partial class BeatmapCarouselPanel : PoolableDrawable, ICarouselPanel
public partial class BeatmapPanel : PoolableDrawable, ICarouselPanel
{
[Resolved]
private BeatmapCarousel carousel { get; set; } = null!;
private Box activationFlash = null!;
private Box background = null!;
private OsuSpriteText text = null!;
[BackgroundDependencyLoader]
private void load()
{
Size = new Vector2(500, CarouselItem.DEFAULT_HEIGHT);
Masking = true;
InternalChildren = new Drawable[]
{
background = new Box
new Box
{
Colour = Color4.Aqua.Darken(5),
Alpha = 0.8f,
RelativeSizeAxes = Axes.Both,
},
@ -69,63 +72,40 @@ namespace osu.Game.Screens.SelectV2
});
}
protected override void FreeAfterUse()
{
base.FreeAfterUse();
Item = null;
Selected.Value = false;
KeyboardSelected.Value = false;
}
protected override void PrepareForUse()
{
base.PrepareForUse();
Debug.Assert(Item != null);
var beatmap = (BeatmapInfo)Item.Model;
DrawYPosition = Item.CarouselYPosition;
Size = new Vector2(500, Item.DrawHeight);
Masking = true;
background.Colour = (Item.Model is BeatmapInfo ? Color4.Aqua : Color4.Yellow).Darken(5);
text.Text = getTextFor(Item.Model);
text.Text = $"Difficulty: {beatmap.DifficultyName} ({beatmap.StarRating:N1}*)";
this.FadeInFromZero(500, Easing.OutQuint);
}
private string getTextFor(object item)
{
switch (item)
{
case BeatmapInfo bi:
return $"Difficulty: {bi.DifficultyName} ({bi.StarRating:N1}*)";
case BeatmapSetInfo si:
return $"{si.Metadata}";
}
return "unknown";
}
protected override bool OnClick(ClickEvent e)
{
if (carousel.CurrentSelection == Item!.Model)
carousel.TryActivateSelection();
else
if (carousel.CurrentSelection != Item!.Model)
{
carousel.CurrentSelection = Item!.Model;
return true;
}
carousel.TryActivateSelection();
return true;
}
#region ICarouselPanel
public CarouselItem? Item { get; set; }
public BindableBool Selected { get; } = new BindableBool();
public BindableBool KeyboardSelected { get; } = new BindableBool();
public double DrawYPosition { get; set; }
public void Activated()
{
activationFlash.FadeOutFromOne(500, Easing.OutQuint);
}
public void Activated() => activationFlash.FadeOutFromOne(500, Easing.OutQuint);
#endregion
}
}

View File

@ -0,0 +1,101 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Diagnostics;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Pooling;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Sprites;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.SelectV2
{
public partial class BeatmapSetPanel : PoolableDrawable, ICarouselPanel
{
public const float HEIGHT = CarouselItem.DEFAULT_HEIGHT * 2;
[Resolved]
private BeatmapCarousel carousel { get; set; } = null!;
private OsuSpriteText text = null!;
[BackgroundDependencyLoader]
private void load()
{
Size = new Vector2(500, HEIGHT);
Masking = true;
InternalChildren = new Drawable[]
{
new Box
{
Colour = Color4.Yellow.Darken(5),
Alpha = 0.8f,
RelativeSizeAxes = Axes.Both,
},
text = new OsuSpriteText
{
Padding = new MarginPadding(5),
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
}
};
KeyboardSelected.BindValueChanged(value =>
{
if (value.NewValue)
{
BorderThickness = 5;
BorderColour = Color4.Pink;
}
else
{
BorderThickness = 0;
}
});
}
protected override void PrepareForUse()
{
base.PrepareForUse();
Debug.Assert(Item != null);
Debug.Assert(Item.IsGroupSelectionTarget);
var beatmapSetInfo = (BeatmapSetInfo)Item.Model;
text.Text = $"{beatmapSetInfo.Metadata}";
this.FadeInFromZero(500, Easing.OutQuint);
}
protected override bool OnClick(ClickEvent e)
{
carousel.CurrentSelection = Item!.Model;
return true;
}
#region ICarouselPanel
public CarouselItem? Item { get; set; }
public BindableBool Selected { get; } = new BindableBool();
public BindableBool KeyboardSelected { get; } = new BindableBool();
public double DrawYPosition { get; set; }
public void Activated()
{
// sets should never be activated.
throw new InvalidOperationException();
}
#endregion
}
}

View File

@ -540,11 +540,13 @@ namespace osu.Game.Screens.SelectV2
{
var c = (ICarouselPanel)panel;
// panel in the process of expiring, ignore it.
if (c.Item == null)
continue;
if (panel.Depth != c.DrawYPosition)
scroll.Panels.ChangeChildDepth(panel, (float)c.DrawYPosition);
Debug.Assert(c.Item != null);
if (c.DrawYPosition != c.Item.CarouselYPosition)
c.DrawYPosition = Interpolation.DampContinuously(c.DrawYPosition, c.Item.CarouselYPosition, 50, Time.Elapsed);
@ -631,7 +633,9 @@ namespace osu.Game.Screens.SelectV2
if (drawable is not ICarouselPanel carouselPanel)
throw new InvalidOperationException($"Carousel panel drawables must implement {typeof(ICarouselPanel)}");
carouselPanel.DrawYPosition = item.CarouselYPosition;
carouselPanel.Item = item;
scroll.Add(drawable);
}
@ -650,6 +654,12 @@ namespace osu.Game.Screens.SelectV2
{
panel.FinishTransforms();
panel.Expire();
var carouselPanel = (ICarouselPanel)panel;
carouselPanel.Item = null;
carouselPanel.Selected.Value = false;
carouselPanel.KeyboardSelected.Value = false;
}
#endregion