From 26f6c5e5a5571469a810b54a68049da8a74461e2 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Thu, 9 Dec 2021 01:16:37 +0900 Subject: [PATCH] Remove ctor params from PlaylistsRoomPlaylist --- .../TestSceneDrawableRoomPlaylist.cs | 44 ++++---------- .../TestScenePlaylistsRoomPlaylist.cs | 2 +- .../Components/MatchBeatmapDetailArea.cs | 3 +- .../OnlinePlay/DrawableRoomPlaylist.cs | 60 +++++++++++++++++++ .../Playlists/PlaylistsRoomPlaylist.cs | 23 +------ .../Playlists/PlaylistsRoomSettingsOverlay.cs | 4 +- 6 files changed, 80 insertions(+), 56 deletions(-) diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoomPlaylist.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoomPlaylist.cs index 449fdaf0aa..269cd15a0f 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoomPlaylist.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoomPlaylist.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -48,7 +49,7 @@ namespace osu.Game.Tests.Visual.Multiplayer [Test] public void TestNonEditableNonSelectable() { - createPlaylist(false, false); + createPlaylist(); moveToItem(0); assertHandleVisibility(0, false); @@ -61,7 +62,7 @@ namespace osu.Game.Tests.Visual.Multiplayer [Test] public void TestEditable() { - createPlaylist(true, false); + createPlaylist(p => p.AllowReordering = p.AllowDeletion = true); moveToItem(0); assertHandleVisibility(0, true); @@ -74,7 +75,7 @@ namespace osu.Game.Tests.Visual.Multiplayer [Test] public void TestMarkInvalid() { - createPlaylist(true, true); + createPlaylist(p => p.AllowReordering = p.AllowDeletion = p.AllowSelection = true); AddStep("mark item 0 as invalid", () => playlist.Items[0].MarkInvalid()); @@ -87,7 +88,7 @@ namespace osu.Game.Tests.Visual.Multiplayer [Test] public void TestSelectable() { - createPlaylist(false, true); + createPlaylist(p => p.AllowSelection = true); moveToItem(0); assertHandleVisibility(0, false); @@ -101,7 +102,7 @@ namespace osu.Game.Tests.Visual.Multiplayer [Test] public void TestEditableSelectable() { - createPlaylist(true, true); + createPlaylist(p => p.AllowReordering = p.AllowDeletion = p.AllowSelection = true); moveToItem(0); assertHandleVisibility(0, true); @@ -115,7 +116,7 @@ namespace osu.Game.Tests.Visual.Multiplayer [Test] public void TestSelectionNotLostAfterRearrangement() { - createPlaylist(true, true); + createPlaylist(p => p.AllowReordering = p.AllowDeletion = p.AllowSelection = true); moveToItem(0); AddStep("click", () => InputManager.Click(MouseButton.Left)); @@ -180,7 +181,7 @@ namespace osu.Game.Tests.Visual.Multiplayer { AddStep("create playlist", () => { - Child = playlist = new TestPlaylist(false, false) + Child = playlist = new TestPlaylist { Anchor = Anchor.Centre, Origin = Anchor.Centre, @@ -223,7 +224,7 @@ namespace osu.Game.Tests.Visual.Multiplayer [TestCase(true)] public void TestWithOwner(bool withOwner) { - createPlaylist(false, false, withOwner); + createPlaylist(p => p.ShowItemOwners = withOwner); AddAssert("owner visible", () => playlist.ChildrenOfType().All(a => a.IsPresent == withOwner)); } @@ -245,11 +246,11 @@ namespace osu.Game.Tests.Visual.Multiplayer => AddAssert($"delete button {index} {(visible ? "is" : "is not")} visible", () => (playlist.ChildrenOfType().ElementAt(2 + index * 2).Alpha > 0) == visible); - private void createPlaylist(bool allowEdit, bool allowSelection, bool showItemOwner = false) + private void createPlaylist(Action setupPlaylist) { AddStep("create playlist", () => { - Child = playlist = new TestPlaylist(allowEdit, allowSelection, showItemOwner) + Child = playlist = new TestPlaylist { Anchor = Anchor.Centre, Origin = Anchor.Centre, @@ -295,7 +296,7 @@ namespace osu.Game.Tests.Visual.Multiplayer { AddStep("create playlist", () => { - Child = playlist = new TestPlaylist(false, false) + Child = playlist = new TestPlaylist { Anchor = Anchor.Centre, Origin = Anchor.Centre, @@ -328,27 +329,6 @@ namespace osu.Game.Tests.Visual.Multiplayer private class TestPlaylist : DrawableRoomPlaylist { public new IReadOnlyDictionary> ItemMap => base.ItemMap; - - private readonly bool allowEdit; - private readonly bool allowSelection; - private readonly bool showItemOwner; - - public TestPlaylist(bool allowEdit, bool allowSelection, bool showItemOwner = false) - { - this.allowEdit = allowEdit; - this.allowSelection = allowSelection; - this.showItemOwner = showItemOwner; - } - - protected override OsuRearrangeableListItem CreateOsuDrawable(PlaylistItem item) => base.CreateOsuDrawable(item).With(d => - { - var drawablePlaylistItem = (DrawableRoomPlaylistItem)d; - - drawablePlaylistItem.AllowReordering = allowEdit; - drawablePlaylistItem.AllowDeletion = allowEdit; - drawablePlaylistItem.AllowSelection = allowSelection; - drawablePlaylistItem.ShowItemOwner = showItemOwner; - }); } } } diff --git a/osu.Game.Tests/Visual/Multiplayer/TestScenePlaylistsRoomPlaylist.cs b/osu.Game.Tests/Visual/Multiplayer/TestScenePlaylistsRoomPlaylist.cs index 8312964b50..264f6aa2c5 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestScenePlaylistsRoomPlaylist.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestScenePlaylistsRoomPlaylist.cs @@ -180,8 +180,8 @@ namespace osu.Game.Tests.Visual.Multiplayer public new IReadOnlyDictionary> ItemMap => base.ItemMap; public TestPlaylist() - : base(true, true, true) { + AllowSelection = true; } } } diff --git a/osu.Game/Screens/OnlinePlay/Components/MatchBeatmapDetailArea.cs b/osu.Game/Screens/OnlinePlay/Components/MatchBeatmapDetailArea.cs index 761f4818e0..d56acff8c7 100644 --- a/osu.Game/Screens/OnlinePlay/Components/MatchBeatmapDetailArea.cs +++ b/osu.Game/Screens/OnlinePlay/Components/MatchBeatmapDetailArea.cs @@ -44,9 +44,10 @@ namespace osu.Game.Screens.OnlinePlay.Components { RelativeSizeAxes = Axes.Both, Padding = new MarginPadding { Bottom = 10 }, - Child = playlist = new PlaylistsRoomPlaylist(true, true, true) + Child = playlist = new PlaylistsRoomPlaylist { RelativeSizeAxes = Axes.Both, + AllowSelection = true, } } }, diff --git a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylist.cs b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylist.cs index 2eb8cd8997..4389f40afc 100644 --- a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylist.cs +++ b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylist.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Linq; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -20,6 +21,61 @@ namespace osu.Game.Screens.OnlinePlay /// public Action DeletionRequested; + private bool allowReordering; + + public bool AllowReordering + { + get => allowReordering; + set + { + allowReordering = value; + + foreach (var item in ListContainer.OfType()) + item.AllowReordering = value; + } + } + + private bool allowDeletion; + + public bool AllowDeletion + { + get => allowDeletion; + set + { + allowDeletion = value; + + foreach (var item in ListContainer.OfType()) + item.AllowDeletion = value; + } + } + + private bool allowSelection; + + public bool AllowSelection + { + get => allowSelection; + set + { + allowSelection = value; + + foreach (var item in ListContainer.OfType()) + item.AllowSelection = value; + } + } + + private bool showItemOwners; + + public bool ShowItemOwners + { + get => showItemOwners; + set + { + showItemOwners = value; + + foreach (var item in ListContainer.OfType()) + item.ShowItemOwner = value; + } + } protected override ScrollContainer CreateScrollContainer() => base.CreateScrollContainer().With(d => { @@ -35,6 +91,10 @@ namespace osu.Game.Screens.OnlinePlay { SelectedItem = { BindTarget = SelectedItem }, RequestDeletion = i => DeletionRequested?.Invoke(i), + AllowReordering = AllowReordering, + AllowDeletion = AllowDeletion, + AllowSelection = AllowSelection, + ShowItemOwner = ShowItemOwners, }; } } diff --git a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomPlaylist.cs b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomPlaylist.cs index f4df9c4406..d8c316b642 100644 --- a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomPlaylist.cs +++ b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomPlaylist.cs @@ -3,23 +3,15 @@ using System.Linq; using osu.Framework.Extensions.IEnumerableExtensions; -using osu.Framework.Graphics; -using osu.Game.Graphics.Containers; -using osu.Game.Online.Rooms; namespace osu.Game.Screens.OnlinePlay.Playlists { public class PlaylistsRoomPlaylist : DrawableRoomPlaylist { - private readonly bool allowReordering; - private readonly bool allowDeletion; - private readonly bool allowSelection; - - public PlaylistsRoomPlaylist(bool allowReordering, bool allowDeletion, bool allowSelection) + public PlaylistsRoomPlaylist() { - this.allowReordering = allowReordering; - this.allowDeletion = allowDeletion; - this.allowSelection = allowSelection; + AllowReordering = true; + AllowDeletion = true; DeletionRequested = item => { @@ -30,14 +22,5 @@ namespace osu.Game.Screens.OnlinePlay.Playlists SelectedItem.Value = nextItem ?? Items.LastOrDefault(); }; } - - protected override OsuRearrangeableListItem CreateOsuDrawable(PlaylistItem item) => base.CreateOsuDrawable(item).With(d => - { - var drawablePlaylistItem = (DrawableRoomPlaylistItem)d; - - drawablePlaylistItem.AllowReordering = allowReordering; - drawablePlaylistItem.AllowDeletion = allowDeletion; - drawablePlaylistItem.AllowSelection = allowSelection; - }); } } diff --git a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSettingsOverlay.cs b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSettingsOverlay.cs index 40b0bc7571..915ec356d5 100644 --- a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSettingsOverlay.cs +++ b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSettingsOverlay.cs @@ -205,9 +205,9 @@ namespace osu.Game.Screens.OnlinePlay.Playlists { new Drawable[] { - playlist = new PlaylistsRoomPlaylist(true, true, false) + playlist = new PlaylistsRoomPlaylist { - RelativeSizeAxes = Axes.Both + RelativeSizeAxes = Axes.Both, } }, new Drawable[]