mirror of
https://github.com/osukey/osukey.git
synced 2025-08-07 00:23:59 +09:00
Merge pull request #16198 from smoogipoo/fix-current-item-before-population
Fix delete button showing on current item before beatmap retrieval
This commit is contained in:
@ -6,7 +6,6 @@ using System.Linq;
|
|||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Audio;
|
using osu.Framework.Audio;
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
@ -26,8 +25,6 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
{
|
{
|
||||||
public class TestSceneMultiplayerQueueList : MultiplayerTestScene
|
public class TestSceneMultiplayerQueueList : MultiplayerTestScene
|
||||||
{
|
{
|
||||||
private readonly Bindable<PlaylistItem> selectedItem = new Bindable<PlaylistItem>();
|
|
||||||
|
|
||||||
[Cached(typeof(UserLookupCache))]
|
[Cached(typeof(UserLookupCache))]
|
||||||
private readonly TestUserLookupCache userLookupCache = new TestUserLookupCache();
|
private readonly TestUserLookupCache userLookupCache = new TestUserLookupCache();
|
||||||
|
|
||||||
@ -50,14 +47,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
|
|
||||||
AddStep("create playlist", () =>
|
AddStep("create playlist", () =>
|
||||||
{
|
{
|
||||||
selectedItem.Value = null;
|
|
||||||
|
|
||||||
Child = playlist = new MultiplayerQueueList
|
Child = playlist = new MultiplayerQueueList
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Size = new Vector2(500, 300),
|
Size = new Vector2(500, 300),
|
||||||
SelectedItem = { BindTarget = selectedItem },
|
|
||||||
Items = { BindTarget = Client.APIRoom!.Playlist }
|
Items = { BindTarget = Client.APIRoom!.Playlist }
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@ -111,12 +105,14 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
|
|
||||||
addPlaylistItem(() => API.LocalUser.Value.OnlineID);
|
addPlaylistItem(() => API.LocalUser.Value.OnlineID);
|
||||||
|
|
||||||
AddStep("select item 0", () => selectedItem.Value = playlist.ChildrenOfType<RearrangeableListItem<PlaylistItem>>().ElementAt(0).Model);
|
|
||||||
assertDeleteButtonVisibility(0, false);
|
assertDeleteButtonVisibility(0, false);
|
||||||
assertDeleteButtonVisibility(1, true);
|
assertDeleteButtonVisibility(1, true);
|
||||||
|
|
||||||
AddStep("select item 1", () => selectedItem.Value = playlist.ChildrenOfType<RearrangeableListItem<PlaylistItem>>().ElementAt(1).Model);
|
AddStep("finish current item", () => Client.FinishCurrentItem());
|
||||||
assertDeleteButtonVisibility(0, true);
|
AddUntilStep("wait for next item to be selected", () => Client.Room?.Settings.PlaylistItemId == 2);
|
||||||
|
AddUntilStep("wait for two items in playlist", () => playlist.ChildrenOfType<DrawableRoomPlaylistItem>().Count() == 2);
|
||||||
|
|
||||||
|
assertDeleteButtonVisibility(0, false);
|
||||||
assertDeleteButtonVisibility(1, false);
|
assertDeleteButtonVisibility(1, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +137,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void assertDeleteButtonVisibility(int index, bool visible)
|
private void assertDeleteButtonVisibility(int index, bool visible)
|
||||||
=> AddUntilStep($"delete button {index} {(visible ? "is" : "is not")} visible",
|
=> AddUntilStep($"delete button {index} {(visible ? "is" : "is not")} visible", () =>
|
||||||
() => (playlist.ChildrenOfType<DrawableRoomPlaylistItem.PlaylistRemoveButton>().ElementAt(index).Alpha > 0) == visible);
|
{
|
||||||
|
var button = playlist.ChildrenOfType<DrawableRoomPlaylistItem.PlaylistRemoveButton>().ElementAtOrDefault(index);
|
||||||
|
return (button?.Alpha > 0) == visible;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ using osu.Framework.Bindables;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
@ -54,12 +53,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match.Playlist
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private MultiplayerClient multiplayerClient { get; set; }
|
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; }
|
|
||||||
|
|
||||||
public QueuePlaylistItem(PlaylistItem item)
|
public QueuePlaylistItem(PlaylistItem item)
|
||||||
: base(item)
|
: base(item)
|
||||||
{
|
{
|
||||||
@ -71,17 +64,29 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match.Playlist
|
|||||||
|
|
||||||
RequestDeletion = item => multiplayerClient.RemovePlaylistItem(item.ID);
|
RequestDeletion = item => multiplayerClient.RemovePlaylistItem(item.ID);
|
||||||
|
|
||||||
host.BindValueChanged(_ => updateDeleteButtonVisibility());
|
multiplayerClient.RoomUpdated += onRoomUpdated;
|
||||||
queueMode.BindValueChanged(_ => updateDeleteButtonVisibility());
|
onRoomUpdated();
|
||||||
SelectedItem.BindValueChanged(_ => updateDeleteButtonVisibility(), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onRoomUpdated() => Scheduler.AddOnce(updateDeleteButtonVisibility);
|
||||||
|
|
||||||
private void updateDeleteButtonVisibility()
|
private void updateDeleteButtonVisibility()
|
||||||
{
|
{
|
||||||
|
if (multiplayerClient.Room == null)
|
||||||
|
return;
|
||||||
|
|
||||||
bool isItemOwner = Item.OwnerID == api.LocalUser.Value.OnlineID || multiplayerClient.IsHost;
|
bool isItemOwner = Item.OwnerID == api.LocalUser.Value.OnlineID || multiplayerClient.IsHost;
|
||||||
|
|
||||||
AllowDeletion = isItemOwner && SelectedItem.Value != Item;
|
AllowDeletion = isItemOwner && !Item.Expired && Item.ID != multiplayerClient.Room.Settings.PlaylistItemId;
|
||||||
AllowEditing = isItemOwner;
|
AllowEditing = isItemOwner && !Item.Expired;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool isDisposing)
|
||||||
|
{
|
||||||
|
base.Dispose(isDisposing);
|
||||||
|
|
||||||
|
if (multiplayerClient != null)
|
||||||
|
multiplayerClient.RoomUpdated -= onRoomUpdated;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user