Merge pull request #22022 from Joehuu/fix-playlist-item-regressions

Fix playlist items having a random selected state after deleting and not animating when rearranging
This commit is contained in:
Salman Ahmed
2023-01-05 16:05:19 +03:00
committed by GitHub
3 changed files with 16 additions and 6 deletions

View File

@ -3,6 +3,7 @@
#nullable disable #nullable disable
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
@ -46,10 +47,14 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddAssert("item removed", () => !playlist.Items.Contains(selectedItem)); AddAssert("item removed", () => !playlist.Items.Contains(selectedItem));
} }
[Test] [TestCase(true)]
public void TestNextItemSelectedAfterDeletion() [TestCase(false)]
public void TestNextItemSelectedAfterDeletion(bool allowSelection)
{ {
createPlaylist(); createPlaylist(p =>
{
p.AllowSelection = allowSelection;
});
moveToItem(0); moveToItem(0);
AddStep("click", () => InputManager.Click(MouseButton.Left)); AddStep("click", () => InputManager.Click(MouseButton.Left));
@ -57,7 +62,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
moveToDeleteButton(0); moveToDeleteButton(0);
AddStep("click delete button", () => InputManager.Click(MouseButton.Left)); AddStep("click delete button", () => InputManager.Click(MouseButton.Left));
AddAssert("item 0 is selected", () => playlist.SelectedItem.Value == playlist.Items[0]); AddAssert("item 0 is " + (allowSelection ? "selected" : "not selected"), () => playlist.SelectedItem.Value == (allowSelection ? playlist.Items[0] : null));
} }
[Test] [Test]
@ -117,7 +122,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
InputManager.MoveMouseTo(item.ChildrenOfType<DrawableRoomPlaylistItem.PlaylistRemoveButton>().ElementAt(0), offset); InputManager.MoveMouseTo(item.ChildrenOfType<DrawableRoomPlaylistItem.PlaylistRemoveButton>().ElementAt(0), offset);
}); });
private void createPlaylist() private void createPlaylist(Action<TestPlaylist> setupPlaylist = null)
{ {
AddStep("create playlist", () => AddStep("create playlist", () =>
{ {
@ -154,6 +159,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
} }
}); });
} }
setupPlaylist?.Invoke(playlist);
}); });
AddUntilStep("wait for items to load", () => playlist.ItemMap.Values.All(i => i.IsLoaded)); AddUntilStep("wait for items to load", () => playlist.ItemMap.Values.All(i => i.IsLoaded));

View File

@ -156,6 +156,8 @@ namespace osu.Game.Screens.OnlinePlay
protected override FillFlowContainer<RearrangeableListItem<PlaylistItem>> CreateListFillFlowContainer() => new FillFlowContainer<RearrangeableListItem<PlaylistItem>> protected override FillFlowContainer<RearrangeableListItem<PlaylistItem>> CreateListFillFlowContainer() => new FillFlowContainer<RearrangeableListItem<PlaylistItem>>
{ {
LayoutDuration = 200,
LayoutEasing = Easing.OutQuint,
Spacing = new Vector2(0, 2) Spacing = new Vector2(0, 2)
}; };

View File

@ -24,7 +24,8 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
Items.Remove(item); Items.Remove(item);
SelectedItem.Value = nextItem ?? Items.LastOrDefault(); if (AllowSelection && SelectedItem.Value == item)
SelectedItem.Value = nextItem ?? Items.LastOrDefault();
}; };
} }
} }