mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 11:42:56 +08:00
Merge pull request #16647 from peppy/song-select-scroll-position-during-delete
Ensure beatmap carousel scroll position is maintained during deletion operations
This commit is contained in:
commit
d1158acb82
@ -9,6 +9,7 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Rulesets;
|
||||
@ -40,6 +41,36 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
this.rulesets = rulesets;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestScrollPositionMaintainedOnAdd()
|
||||
{
|
||||
loadBeatmaps(count: 1, randomDifficulties: false);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
AddRepeatStep("Add some sets", () => carousel.UpdateBeatmapSet(TestResources.CreateTestBeatmapSetInfo()), 4);
|
||||
|
||||
checkSelectionIsCentered();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestScrollPositionMaintainedOnDelete()
|
||||
{
|
||||
loadBeatmaps(count: 50, randomDifficulties: false);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
AddRepeatStep("Remove some sets", () =>
|
||||
carousel.RemoveBeatmapSet(carousel.Items.Select(item => item.Item)
|
||||
.OfType<CarouselBeatmapSet>()
|
||||
.OrderBy(item => item.GetHashCode())
|
||||
.First(item => item.State.Value != CarouselItemState.Selected && item.Visible).BeatmapSet), 4);
|
||||
|
||||
checkSelectionIsCentered();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestManyPanels()
|
||||
{
|
||||
@ -813,6 +844,18 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
carousel.Items.Count(s => (diff ? s.Item is CarouselBeatmap : s.Item is CarouselBeatmapSet) && s.Item.Visible) == count);
|
||||
}
|
||||
|
||||
private void checkSelectionIsCentered()
|
||||
{
|
||||
AddAssert("Selected panel is centered", () =>
|
||||
{
|
||||
return Precision.AlmostEquals(
|
||||
carousel.ScreenSpaceDrawQuad.Centre,
|
||||
carousel.Items
|
||||
.First(i => i.Item.State.Value == CarouselItemState.Selected)
|
||||
.ScreenSpaceDrawQuad.Centre, 100);
|
||||
});
|
||||
}
|
||||
|
||||
private void checkNoSelection() => AddAssert("Selection is null", () => currentSelection == null);
|
||||
|
||||
private void nextRandom() =>
|
||||
|
@ -286,6 +286,9 @@ namespace osu.Game.Screens.Select
|
||||
|
||||
root.RemoveChild(existingSet);
|
||||
itemsCache.Invalidate();
|
||||
|
||||
if (!Scroll.UserScrolling)
|
||||
ScrollToSelected(true);
|
||||
});
|
||||
|
||||
public void UpdateBeatmapSet(BeatmapSetInfo beatmapSet) => Schedule(() =>
|
||||
@ -311,13 +314,10 @@ namespace osu.Game.Screens.Select
|
||||
|
||||
itemsCache.Invalidate();
|
||||
|
||||
Schedule(() =>
|
||||
{
|
||||
if (!Scroll.UserScrolling)
|
||||
ScrollToSelected(true);
|
||||
if (!Scroll.UserScrolling)
|
||||
ScrollToSelected(true);
|
||||
|
||||
BeatmapSetsChanged?.Invoke();
|
||||
});
|
||||
BeatmapSetsChanged?.Invoke();
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
Reference in New Issue
Block a user