1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 19:32:55 +08:00

Remove ctor params from PlaylistsRoomPlaylist

This commit is contained in:
Dan Balasescu 2021-12-09 01:16:37 +09:00
parent 3be4d8b68d
commit 26f6c5e5a5
6 changed files with 80 additions and 56 deletions

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
@ -48,7 +49,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
[Test] [Test]
public void TestNonEditableNonSelectable() public void TestNonEditableNonSelectable()
{ {
createPlaylist(false, false); createPlaylist();
moveToItem(0); moveToItem(0);
assertHandleVisibility(0, false); assertHandleVisibility(0, false);
@ -61,7 +62,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
[Test] [Test]
public void TestEditable() public void TestEditable()
{ {
createPlaylist(true, false); createPlaylist(p => p.AllowReordering = p.AllowDeletion = true);
moveToItem(0); moveToItem(0);
assertHandleVisibility(0, true); assertHandleVisibility(0, true);
@ -74,7 +75,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
[Test] [Test]
public void TestMarkInvalid() 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()); AddStep("mark item 0 as invalid", () => playlist.Items[0].MarkInvalid());
@ -87,7 +88,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
[Test] [Test]
public void TestSelectable() public void TestSelectable()
{ {
createPlaylist(false, true); createPlaylist(p => p.AllowSelection = true);
moveToItem(0); moveToItem(0);
assertHandleVisibility(0, false); assertHandleVisibility(0, false);
@ -101,7 +102,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
[Test] [Test]
public void TestEditableSelectable() public void TestEditableSelectable()
{ {
createPlaylist(true, true); createPlaylist(p => p.AllowReordering = p.AllowDeletion = p.AllowSelection = true);
moveToItem(0); moveToItem(0);
assertHandleVisibility(0, true); assertHandleVisibility(0, true);
@ -115,7 +116,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
[Test] [Test]
public void TestSelectionNotLostAfterRearrangement() public void TestSelectionNotLostAfterRearrangement()
{ {
createPlaylist(true, true); createPlaylist(p => p.AllowReordering = p.AllowDeletion = p.AllowSelection = true);
moveToItem(0); moveToItem(0);
AddStep("click", () => InputManager.Click(MouseButton.Left)); AddStep("click", () => InputManager.Click(MouseButton.Left));
@ -180,7 +181,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
AddStep("create playlist", () => AddStep("create playlist", () =>
{ {
Child = playlist = new TestPlaylist(false, false) Child = playlist = new TestPlaylist
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
@ -223,7 +224,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
[TestCase(true)] [TestCase(true)]
public void TestWithOwner(bool withOwner) public void TestWithOwner(bool withOwner)
{ {
createPlaylist(false, false, withOwner); createPlaylist(p => p.ShowItemOwners = withOwner);
AddAssert("owner visible", () => playlist.ChildrenOfType<UpdateableAvatar>().All(a => a.IsPresent == withOwner)); AddAssert("owner visible", () => playlist.ChildrenOfType<UpdateableAvatar>().All(a => a.IsPresent == withOwner));
} }
@ -245,11 +246,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
=> AddAssert($"delete button {index} {(visible ? "is" : "is not")} visible", => AddAssert($"delete button {index} {(visible ? "is" : "is not")} visible",
() => (playlist.ChildrenOfType<DrawableRoomPlaylistItem.PlaylistRemoveButton>().ElementAt(2 + index * 2).Alpha > 0) == visible); () => (playlist.ChildrenOfType<DrawableRoomPlaylistItem.PlaylistRemoveButton>().ElementAt(2 + index * 2).Alpha > 0) == visible);
private void createPlaylist(bool allowEdit, bool allowSelection, bool showItemOwner = false) private void createPlaylist(Action<TestPlaylist> setupPlaylist)
{ {
AddStep("create playlist", () => AddStep("create playlist", () =>
{ {
Child = playlist = new TestPlaylist(allowEdit, allowSelection, showItemOwner) Child = playlist = new TestPlaylist
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
@ -295,7 +296,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
AddStep("create playlist", () => AddStep("create playlist", () =>
{ {
Child = playlist = new TestPlaylist(false, false) Child = playlist = new TestPlaylist
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
@ -328,27 +329,6 @@ namespace osu.Game.Tests.Visual.Multiplayer
private class TestPlaylist : DrawableRoomPlaylist private class TestPlaylist : DrawableRoomPlaylist
{ {
public new IReadOnlyDictionary<PlaylistItem, RearrangeableListItem<PlaylistItem>> ItemMap => base.ItemMap; public new IReadOnlyDictionary<PlaylistItem, RearrangeableListItem<PlaylistItem>> 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<PlaylistItem> CreateOsuDrawable(PlaylistItem item) => base.CreateOsuDrawable(item).With(d =>
{
var drawablePlaylistItem = (DrawableRoomPlaylistItem)d;
drawablePlaylistItem.AllowReordering = allowEdit;
drawablePlaylistItem.AllowDeletion = allowEdit;
drawablePlaylistItem.AllowSelection = allowSelection;
drawablePlaylistItem.ShowItemOwner = showItemOwner;
});
} }
} }
} }

View File

@ -180,8 +180,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
public new IReadOnlyDictionary<PlaylistItem, RearrangeableListItem<PlaylistItem>> ItemMap => base.ItemMap; public new IReadOnlyDictionary<PlaylistItem, RearrangeableListItem<PlaylistItem>> ItemMap => base.ItemMap;
public TestPlaylist() public TestPlaylist()
: base(true, true, true)
{ {
AllowSelection = true;
} }
} }
} }

View File

@ -44,9 +44,10 @@ namespace osu.Game.Screens.OnlinePlay.Components
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Bottom = 10 }, Padding = new MarginPadding { Bottom = 10 },
Child = playlist = new PlaylistsRoomPlaylist(true, true, true) Child = playlist = new PlaylistsRoomPlaylist
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
AllowSelection = true,
} }
} }
}, },

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Linq;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -20,6 +21,61 @@ namespace osu.Game.Screens.OnlinePlay
/// </summary> /// </summary>
public Action<PlaylistItem> DeletionRequested; public Action<PlaylistItem> DeletionRequested;
private bool allowReordering;
public bool AllowReordering
{
get => allowReordering;
set
{
allowReordering = value;
foreach (var item in ListContainer.OfType<DrawableRoomPlaylistItem>())
item.AllowReordering = value;
}
}
private bool allowDeletion;
public bool AllowDeletion
{
get => allowDeletion;
set
{
allowDeletion = value;
foreach (var item in ListContainer.OfType<DrawableRoomPlaylistItem>())
item.AllowDeletion = value;
}
}
private bool allowSelection;
public bool AllowSelection
{
get => allowSelection;
set
{
allowSelection = value;
foreach (var item in ListContainer.OfType<DrawableRoomPlaylistItem>())
item.AllowSelection = value;
}
}
private bool showItemOwners;
public bool ShowItemOwners
{
get => showItemOwners;
set
{
showItemOwners = value;
foreach (var item in ListContainer.OfType<DrawableRoomPlaylistItem>())
item.ShowItemOwner = value;
}
}
protected override ScrollContainer<Drawable> CreateScrollContainer() => base.CreateScrollContainer().With(d => protected override ScrollContainer<Drawable> CreateScrollContainer() => base.CreateScrollContainer().With(d =>
{ {
@ -35,6 +91,10 @@ namespace osu.Game.Screens.OnlinePlay
{ {
SelectedItem = { BindTarget = SelectedItem }, SelectedItem = { BindTarget = SelectedItem },
RequestDeletion = i => DeletionRequested?.Invoke(i), RequestDeletion = i => DeletionRequested?.Invoke(i),
AllowReordering = AllowReordering,
AllowDeletion = AllowDeletion,
AllowSelection = AllowSelection,
ShowItemOwner = ShowItemOwners,
}; };
} }
} }

View File

@ -3,23 +3,15 @@
using System.Linq; using System.Linq;
using osu.Framework.Extensions.IEnumerableExtensions; 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 namespace osu.Game.Screens.OnlinePlay.Playlists
{ {
public class PlaylistsRoomPlaylist : DrawableRoomPlaylist public class PlaylistsRoomPlaylist : DrawableRoomPlaylist
{ {
private readonly bool allowReordering; public PlaylistsRoomPlaylist()
private readonly bool allowDeletion;
private readonly bool allowSelection;
public PlaylistsRoomPlaylist(bool allowReordering, bool allowDeletion, bool allowSelection)
{ {
this.allowReordering = allowReordering; AllowReordering = true;
this.allowDeletion = allowDeletion; AllowDeletion = true;
this.allowSelection = allowSelection;
DeletionRequested = item => DeletionRequested = item =>
{ {
@ -30,14 +22,5 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
SelectedItem.Value = nextItem ?? Items.LastOrDefault(); SelectedItem.Value = nextItem ?? Items.LastOrDefault();
}; };
} }
protected override OsuRearrangeableListItem<PlaylistItem> CreateOsuDrawable(PlaylistItem item) => base.CreateOsuDrawable(item).With(d =>
{
var drawablePlaylistItem = (DrawableRoomPlaylistItem)d;
drawablePlaylistItem.AllowReordering = allowReordering;
drawablePlaylistItem.AllowDeletion = allowDeletion;
drawablePlaylistItem.AllowSelection = allowSelection;
});
} }
} }

View File

@ -205,9 +205,9 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
{ {
new Drawable[] new Drawable[]
{ {
playlist = new PlaylistsRoomPlaylist(true, true, false) playlist = new PlaylistsRoomPlaylist
{ {
RelativeSizeAxes = Axes.Both RelativeSizeAxes = Axes.Both,
} }
}, },
new Drawable[] new Drawable[]