From 1152c4e8e9bb91b6dc5209645cc9f2da69ac5eb0 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Wed, 1 Dec 2021 19:54:39 +0900 Subject: [PATCH] Fix tests --- .../TestSceneMultiplayerPlaylist.cs | 57 +++++++++++-------- .../Match/Playlist/MultiplayerPlaylist.cs | 31 +++++----- .../MultiplayerPlaylistDisplayMode.cs | 11 ++++ 3 files changed, 60 insertions(+), 39 deletions(-) create mode 100644 osu.Game/Screens/OnlinePlay/Multiplayer/Match/Playlist/MultiplayerPlaylistDisplayMode.cs diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerPlaylist.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerPlaylist.cs index b21dbbd462..ae885685f7 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerPlaylist.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerPlaylist.cs @@ -22,6 +22,7 @@ namespace osu.Game.Tests.Visual.Multiplayer { public class TestSceneMultiplayerPlaylist : MultiplayerTestScene { + private MultiplayerPlaylist list; private BeatmapManager beatmaps; private RulesetStore rulesets; private BeatmapSetInfo importedSet; @@ -37,7 +38,7 @@ namespace osu.Game.Tests.Visual.Multiplayer [SetUp] public new void Setup() => Schedule(() => { - Child = new MultiplayerPlaylist + Child = list = new MultiplayerPlaylist { Anchor = Anchor.Centre, Origin = Anchor.Centre, @@ -175,47 +176,57 @@ namespace osu.Game.Tests.Visual.Multiplayer /// /// The item id. /// The index at which the item should appear visually. The item with index 0 is at the top of the list. - private void assertItemInQueueListStep(int playlistItemId, int visualIndex) => AddUntilStep($"{playlistItemId} in queue at pos = {visualIndex}", () => + private void assertItemInQueueListStep(int playlistItemId, int visualIndex) { - return !inHistoryList(playlistItemId) - && this.ChildrenOfType() - .Single() - .ChildrenOfType() - .OrderBy(drawable => drawable.Position.Y) - .TakeWhile(drawable => drawable.Item.ID != playlistItemId) - .Count() == visualIndex; - }); + changeDisplayModeStep(MultiplayerPlaylistDisplayMode.Queue); + + AddUntilStep($"{playlistItemId} in queue at pos = {visualIndex}", () => + { + return !inHistoryList(playlistItemId) + && this.ChildrenOfType() + .Single() + .ChildrenOfType() + .OrderBy(drawable => drawable.Position.Y) + .TakeWhile(drawable => drawable.Item.ID != playlistItemId) + .Count() == visualIndex; + }); + } /// /// Asserts the position of a given playlist item in the history list. /// /// The item id. /// The index at which the item should appear visually. The item with index 0 is at the top of the list. - private void assertItemInHistoryListStep(int playlistItemId, int visualIndex) => AddUntilStep($"{playlistItemId} in history at pos = {visualIndex}", () => + private void assertItemInHistoryListStep(int playlistItemId, int visualIndex) { - return !inQueueList(playlistItemId) - && this.ChildrenOfType() - .Single() - .ChildrenOfType() - .OrderBy(drawable => drawable.Position.Y) - .TakeWhile(drawable => drawable.Item.ID != playlistItemId) - .Count() == visualIndex; - }); + changeDisplayModeStep(MultiplayerPlaylistDisplayMode.History); + + AddUntilStep($"{playlistItemId} in history at pos = {visualIndex}", () => + { + return !inQueueList(playlistItemId) + && this.ChildrenOfType() + .Single() + .ChildrenOfType() + .OrderBy(drawable => drawable.Position.Y) + .TakeWhile(drawable => drawable.Item.ID != playlistItemId) + .Count() == visualIndex; + }); + } + + private void changeDisplayModeStep(MultiplayerPlaylistDisplayMode mode) => AddStep($"change list to {mode}", () => list.DisplayMode.Value = mode); private bool inQueueList(int playlistItemId) { return this.ChildrenOfType() .Single() - .ChildrenOfType() - .Any(i => i.Item.ID == playlistItemId); + .Items.Any(i => i.ID == playlistItemId); } private bool inHistoryList(int playlistItemId) { return this.ChildrenOfType() .Single() - .ChildrenOfType() - .Any(i => i.Item.ID == playlistItemId); + .Items.Any(i => i.ID == playlistItemId); } } } diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/Match/Playlist/MultiplayerPlaylist.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/Match/Playlist/MultiplayerPlaylist.cs index a44e086814..aebe70f95a 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/Match/Playlist/MultiplayerPlaylist.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/Match/Playlist/MultiplayerPlaylist.cs @@ -6,7 +6,6 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.UserInterface; using osu.Game.Graphics.UserInterface; using osu.Game.Online.Rooms; @@ -14,6 +13,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match.Playlist { public class MultiplayerPlaylist : MultiplayerRoomComposite { + public readonly Bindable DisplayMode = new Bindable(); + private MultiplayerQueueList queueList; private MultiplayerHistoryList historyList; private bool firstPopulation = true; @@ -21,14 +22,13 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match.Playlist [BackgroundDependencyLoader] private void load() { - TabControl displayModeTabControl; - InternalChildren = new Drawable[] { - displayModeTabControl = new OsuTabControl + new OsuTabControl { RelativeSizeAxes = Axes.X, - Height = 25 + Height = 25, + Current = { BindTarget = DisplayMode } }, new Container { @@ -49,14 +49,19 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match.Playlist } } }; - - displayModeTabControl.Current.BindValueChanged(onDisplayModeChanged, true); } - private void onDisplayModeChanged(ValueChangedEvent mode) + protected override void LoadComplete() { - historyList.FadeTo(mode.NewValue == DisplayMode.History ? 1 : 0, 100); - queueList.FadeTo(mode.NewValue == DisplayMode.Queue ? 1 : 0, 100); + base.LoadComplete(); + + DisplayMode.BindValueChanged(onDisplayModeChanged, true); + } + + private void onDisplayModeChanged(ValueChangedEvent mode) + { + historyList.FadeTo(mode.NewValue == MultiplayerPlaylistDisplayMode.History ? 1 : 0, 100); + queueList.FadeTo(mode.NewValue == MultiplayerPlaylistDisplayMode.Queue ? 1 : 0, 100); } protected override void OnRoomUpdated() @@ -107,11 +112,5 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match.Playlist PlaylistItemRemoved(item.ID); PlaylistItemAdded(item); } - - private enum DisplayMode - { - Queue, - History, - } } } diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/Match/Playlist/MultiplayerPlaylistDisplayMode.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/Match/Playlist/MultiplayerPlaylistDisplayMode.cs new file mode 100644 index 0000000000..af1fac1c79 --- /dev/null +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/Match/Playlist/MultiplayerPlaylistDisplayMode.cs @@ -0,0 +1,11 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match.Playlist +{ + public enum MultiplayerPlaylistDisplayMode + { + Queue, + History, + } +}