1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 20:13:21 +08:00

Siplify condition, allow host to always remove items

This commit is contained in:
Dan Balasescu 2021-12-09 14:11:29 +09:00
parent 25620d1eef
commit 1a0945daba
2 changed files with 43 additions and 54 deletions

View File

@ -13,6 +13,7 @@ using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Graphics.Containers;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms;
using osu.Game.Rulesets;
@ -55,6 +56,7 @@ namespace osu.Game.Tests.Visual.Online
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(500, 300),
SelectedItem = { BindTarget = Client.CurrentMatchPlayingItem },
Items = { BindTarget = Client.APIRoom!.Playlist }
};
});
@ -70,69 +72,59 @@ namespace osu.Game.Tests.Visual.Online
}
[Test]
public void TestDeleteButtonHiddenWithSingleItem()
{
AddStep("set all players queue mode", () => Client.ChangeSettings(new MultiplayerRoomSettings { QueueMode = QueueMode.AllPlayers }));
AddUntilStep("wait for queue mode change", () => Client.APIRoom?.QueueMode.Value == QueueMode.AllPlayers);
assertDeleteButtonVisibility(0, false);
addPlaylistItem(() => API.LocalUser.Value.OnlineID);
assertDeleteButtonVisibility(0, true);
deleteItem(1);
assertDeleteButtonVisibility(0, false);
}
[Test]
public void TestDeleteButtonHiddenInHostOnlyMode()
{
AddStep("set all players queue mode", () => Client.ChangeSettings(new MultiplayerRoomSettings { QueueMode = QueueMode.AllPlayers }));
AddUntilStep("wait for queue mode change", () => Client.APIRoom?.QueueMode.Value == QueueMode.AllPlayers);
addPlaylistItem(() => 1234);
AddStep("set host-only queue mode", () => Client.ChangeSettings(new MultiplayerRoomSettings { QueueMode = QueueMode.HostOnly }));
AddUntilStep("wait for queue mode change", () => Client.APIRoom?.QueueMode.Value == QueueMode.HostOnly);
assertDeleteButtonVisibility(0, false);
}
[Test]
public void TestOnlyItemOwnerHasDeleteButton()
public void TestDeleteButtonAlwaysVisibleForHost()
{
AddStep("set all players queue mode", () => Client.ChangeSettings(new MultiplayerRoomSettings { QueueMode = QueueMode.AllPlayers }));
AddUntilStep("wait for queue mode change", () => Client.APIRoom?.QueueMode.Value == QueueMode.AllPlayers);
addPlaylistItem(() => API.LocalUser.Value.OnlineID);
assertDeleteButtonVisibility(0, true);
assertDeleteButtonVisibility(1, true);
addPlaylistItem(() => 1234);
assertDeleteButtonVisibility(2, true);
}
[Test]
public void TestDeleteButtonOnlyVisibleForItemOwnerIfNotHost()
{
AddStep("set all players queue mode", () => Client.ChangeSettings(new MultiplayerRoomSettings { QueueMode = QueueMode.AllPlayers }));
AddUntilStep("wait for queue mode change", () => Client.APIRoom?.QueueMode.Value == QueueMode.AllPlayers);
AddStep("join other user", () => Client.AddUser(new APIUser { Id = 1234 }));
AddStep("set other user as host", () => Client.TransferHost(1234));
addPlaylistItem(() => API.LocalUser.Value.OnlineID);
assertDeleteButtonVisibility(1, true);
addPlaylistItem(() => 1234);
assertDeleteButtonVisibility(2, false);
AddStep("set local user as host", () => Client.TransferHost(API.LocalUser.Value.OnlineID));
assertDeleteButtonVisibility(1, true);
assertDeleteButtonVisibility(2, true);
}
[Test]
public void TestNonOwnerDoesNotHaveDeleteButton()
public void TestCurrentItemDoesNotHaveDeleteButton()
{
AddStep("set all players queue mode", () => Client.ChangeSettings(new MultiplayerRoomSettings { QueueMode = QueueMode.AllPlayers }));
AddUntilStep("wait for queue mode change", () => Client.APIRoom?.QueueMode.Value == QueueMode.AllPlayers);
addPlaylistItem(() => 1234);
assertDeleteButtonVisibility(0, true);
assertDeleteButtonVisibility(1, false);
}
[Test]
public void TestSelectedItemDoesNotHaveDeleteButton()
{
AddStep("set all players queue mode", () => Client.ChangeSettings(new MultiplayerRoomSettings { QueueMode = QueueMode.AllPlayers }));
AddUntilStep("wait for queue mode change", () => Client.APIRoom?.QueueMode.Value == QueueMode.AllPlayers);
assertDeleteButtonVisibility(0, false);
addPlaylistItem(() => API.LocalUser.Value.OnlineID);
assertDeleteButtonVisibility(0, true);
AddStep("set first playlist item as selected", () => playlist.SelectedItem.Value = playlist.Items[0]);
assertDeleteButtonVisibility(0, false);
assertDeleteButtonVisibility(1, true);
// Run through gameplay.
AddStep("set state to ready", () => Client.ChangeUserState(API.LocalUser.Value.Id, MultiplayerUserState.Ready));
AddUntilStep("local state is ready", () => Client.LocalUser?.State == MultiplayerUserState.Ready);
AddStep("start match", () => Client.StartMatch());
AddUntilStep("match started", () => Client.LocalUser?.State == MultiplayerUserState.WaitingForLoad);
AddStep("set state to loaded", () => Client.ChangeUserState(API.LocalUser.Value.Id, MultiplayerUserState.Loaded));
AddUntilStep("local state is playing", () => Client.LocalUser?.State == MultiplayerUserState.Playing);
AddStep("set state to finished play", () => Client.ChangeUserState(API.LocalUser.Value.Id, MultiplayerUserState.FinishedPlay));
AddUntilStep("local state is results", () => Client.LocalUser?.State == MultiplayerUserState.Results);
assertDeleteButtonVisibility(1, false);
}
private void addPlaylistItem(Func<int> userId)

View File

@ -8,6 +8,7 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms;
using osuTK;
@ -29,10 +30,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match.Playlist
Spacing = new Vector2(0, 2)
};
protected override DrawableRoomPlaylistItem CreateDrawablePlaylistItem(PlaylistItem item) => new QueuePlaylistItem(item)
{
Items = { BindTarget = Items }
};
protected override DrawableRoomPlaylistItem CreateDrawablePlaylistItem(PlaylistItem item) => new QueuePlaylistItem(item);
private class QueueFillFlowContainer : FillFlowContainer<RearrangeableListItem<PlaylistItem>>
{
@ -50,14 +48,15 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match.Playlist
private class QueuePlaylistItem : DrawableRoomPlaylistItem
{
public readonly IBindableList<PlaylistItem> Items = new BindableList<PlaylistItem>();
[Resolved]
private IAPIProvider api { get; set; }
[Resolved]
private MultiplayerClient multiplayerClient { get; set; }
[Resolved(typeof(Room), nameof(Room.Host))]
private Bindable<APIUser> host { get; set; }
[Resolved(typeof(Room), nameof(Room.QueueMode))]
private Bindable<QueueMode> queueMode { get; set; }
@ -72,16 +71,14 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match.Playlist
RequestDeletion = item => multiplayerClient.RemovePlaylistItem(item.ID);
Items.BindCollectionChanged((_, __) => updateDeleteButtonVisibility());
host.BindValueChanged(_ => updateDeleteButtonVisibility());
queueMode.BindValueChanged(_ => updateDeleteButtonVisibility());
SelectedItem.BindValueChanged(_ => updateDeleteButtonVisibility(), true);
}
private void updateDeleteButtonVisibility()
{
AllowDeletion = queueMode.Value != QueueMode.HostOnly
&& Items.Count > 1
&& Item.OwnerID == api.LocalUser.Value.OnlineID
AllowDeletion = (Item.OwnerID == api.LocalUser.Value.OnlineID || multiplayerClient.IsHost)
&& SelectedItem.Value != Item;
}
}