mirror of https://github.com/ppy/osu
Allow host to enqeue items and items to be edited
This commit is contained in:
parent
048a495115
commit
671582a925
|
@ -87,9 +87,9 @@ public void TestCorrectItemSelectedAfterNewItemAdded()
|
|||
|
||||
private void addItem(Func<BeatmapInfo> beatmap)
|
||||
{
|
||||
AddStep("click edit button", () =>
|
||||
AddStep("click add button", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(this.ChildrenOfType<MultiplayerMatchSubScreen>().Single().AddOrEditPlaylistButton);
|
||||
InputManager.MoveMouseTo(this.ChildrenOfType<MultiplayerMatchSubScreen.AddItemButton>().Single());
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Screens.OnlinePlay;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
||||
using osuTK.Input;
|
||||
|
||||
|
@ -74,11 +75,19 @@ public void TestSettingsUpdatedWhenChangingQueueMode()
|
|||
AddUntilStep("api room updated", () => Client.APIRoom?.QueueMode.Value == QueueMode.AllPlayers);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAddItemsAsHost()
|
||||
{
|
||||
addItem(() => OtherBeatmap);
|
||||
|
||||
AddAssert("playlist contains two items", () => Client.APIRoom?.Playlist.Count == 2);
|
||||
}
|
||||
|
||||
private void selectNewItem(Func<BeatmapInfo> beatmap)
|
||||
{
|
||||
AddStep("click edit button", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(this.ChildrenOfType<MultiplayerMatchSubScreen>().Single().AddOrEditPlaylistButton);
|
||||
InputManager.MoveMouseTo(this.ChildrenOfType<DrawableRoomPlaylistItem.PlaylistEditButton>().First());
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
|
@ -90,5 +99,18 @@ private void selectNewItem(Func<BeatmapInfo> beatmap)
|
|||
AddUntilStep("wait for return to match", () => CurrentSubScreen is MultiplayerMatchSubScreen);
|
||||
AddUntilStep("selected item is new beatmap", () => Client.CurrentMatchPlayingItem.Value?.Beatmap.Value?.OnlineID == otherBeatmap.OnlineID);
|
||||
}
|
||||
|
||||
private void addItem(Func<BeatmapInfo> beatmap)
|
||||
{
|
||||
AddStep("click add button", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(this.ChildrenOfType<MultiplayerMatchSubScreen.AddItemButton>().Single());
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
AddUntilStep("wait for song select", () => CurrentSubScreen is Screens.Select.SongSelect select && select.BeatmapSetsLoaded);
|
||||
AddStep("select other beatmap", () => ((Screens.Select.SongSelect)CurrentSubScreen).FinaliseSelection(beatmap()));
|
||||
AddUntilStep("wait for return to match", () => CurrentSubScreen is MultiplayerMatchSubScreen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -416,8 +416,7 @@ public void TestPlayStartsWithCorrectBeatmapWhileAtSongSelect()
|
|||
AddStep("Enter song select", () =>
|
||||
{
|
||||
var currentSubScreen = ((Screens.OnlinePlay.Multiplayer.Multiplayer)multiplayerScreenStack.CurrentScreen).CurrentSubScreen;
|
||||
|
||||
((MultiplayerMatchSubScreen)currentSubScreen).SelectBeatmap();
|
||||
((MultiplayerMatchSubScreen)currentSubScreen).OpenSongSelection(client.CurrentMatchPlayingItem.Value);
|
||||
});
|
||||
|
||||
AddUntilStep("wait for song select", () => this.ChildrenOfType<MultiplayerMatchSongSelect>().FirstOrDefault()?.BeatmapSetsLoaded == true);
|
||||
|
|
|
@ -179,7 +179,7 @@ private class TestMultiplayerMatchSongSelect : MultiplayerMatchSongSelect
|
|||
public new BeatmapCarousel Carousel => base.Carousel;
|
||||
|
||||
public TestMultiplayerMatchSongSelect(Room room, WorkingBeatmap beatmap = null, RulesetInfo ruleset = null)
|
||||
: base(room, beatmap, ruleset)
|
||||
: base(room, null, beatmap, ruleset)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
|
@ -19,6 +20,11 @@ public class MultiplayerPlaylist : MultiplayerRoomComposite
|
|||
{
|
||||
public readonly Bindable<MultiplayerPlaylistDisplayMode> DisplayMode = new Bindable<MultiplayerPlaylistDisplayMode>();
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when an item requests to be edited.
|
||||
/// </summary>
|
||||
public Action<PlaylistItem> RequestEdit;
|
||||
|
||||
private MultiplayerQueueList queueList;
|
||||
private MultiplayerHistoryList historyList;
|
||||
private bool firstPopulation = true;
|
||||
|
@ -46,7 +52,8 @@ private void load()
|
|||
queueList = new MultiplayerQueueList
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
SelectedItem = { BindTarget = SelectedItem }
|
||||
SelectedItem = { BindTarget = SelectedItem },
|
||||
RequestEdit = item => RequestEdit?.Invoke(item)
|
||||
},
|
||||
historyList = new MultiplayerHistoryList
|
||||
{
|
||||
|
|
|
@ -78,8 +78,10 @@ protected override void LoadComplete()
|
|||
|
||||
private void updateDeleteButtonVisibility()
|
||||
{
|
||||
AllowDeletion = (Item.OwnerID == api.LocalUser.Value.OnlineID || multiplayerClient.IsHost)
|
||||
&& SelectedItem.Value != Item;
|
||||
bool isItemOwner = Item.OwnerID == api.LocalUser.Value.OnlineID || multiplayerClient.IsHost;
|
||||
|
||||
AllowDeletion = isItemOwner && SelectedItem.Value != Item;
|
||||
AllowEditing = isItemOwner;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,17 +24,22 @@ public class MultiplayerMatchSongSelect : OnlinePlaySongSelect
|
|||
[Resolved]
|
||||
private MultiplayerClient client { get; set; }
|
||||
|
||||
private readonly PlaylistItem itemToEdit;
|
||||
|
||||
private LoadingLayer loadingLayer;
|
||||
|
||||
/// <summary>
|
||||
/// Construct a new instance of multiplayer song select.
|
||||
/// </summary>
|
||||
/// <param name="room">The room.</param>
|
||||
/// <param name="itemToEdit">The item to be edited. May be null, in which case a new item will be added to the playlist.</param>
|
||||
/// <param name="beatmap">An optional initial beatmap selection to perform.</param>
|
||||
/// <param name="ruleset">An optional initial ruleset selection to perform.</param>
|
||||
public MultiplayerMatchSongSelect(Room room, WorkingBeatmap beatmap = null, RulesetInfo ruleset = null)
|
||||
public MultiplayerMatchSongSelect(Room room, PlaylistItem itemToEdit = null, WorkingBeatmap beatmap = null, RulesetInfo ruleset = null)
|
||||
: base(room)
|
||||
{
|
||||
this.itemToEdit = itemToEdit;
|
||||
|
||||
if (beatmap != null || ruleset != null)
|
||||
{
|
||||
Schedule(() =>
|
||||
|
@ -61,6 +66,7 @@ protected override void SelectItem(PlaylistItem item)
|
|||
|
||||
client.AddPlaylistItem(new MultiplayerPlaylistItem
|
||||
{
|
||||
ID = itemToEdit?.ID ?? 0,
|
||||
BeatmapID = item.BeatmapID,
|
||||
BeatmapChecksum = item.Beatmap.Value.MD5Hash,
|
||||
RulesetID = item.RulesetID,
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
using osu.Framework.Threading;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Rooms;
|
||||
|
@ -44,8 +43,6 @@ public class MultiplayerMatchSubScreen : RoomSubScreen, IHandlePresentBeatmap
|
|||
|
||||
public override string ShortTitle => "room";
|
||||
|
||||
public OsuButton AddOrEditPlaylistButton { get; private set; }
|
||||
|
||||
[Resolved]
|
||||
private MultiplayerClient client { get; set; }
|
||||
|
||||
|
@ -57,6 +54,8 @@ public class MultiplayerMatchSubScreen : RoomSubScreen, IHandlePresentBeatmap
|
|||
[CanBeNull]
|
||||
private IDisposable readyClickOperation;
|
||||
|
||||
private AddItemButton addItemButton;
|
||||
|
||||
public MultiplayerMatchSubScreen(Room room)
|
||||
: base(room)
|
||||
{
|
||||
|
@ -134,12 +133,12 @@ protected override void LoadComplete()
|
|||
new Drawable[] { new OverlinedHeader("Beatmap") },
|
||||
new Drawable[]
|
||||
{
|
||||
AddOrEditPlaylistButton = new PurpleTriangleButton
|
||||
addItemButton = new AddItemButton
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = 40,
|
||||
Action = SelectBeatmap,
|
||||
Alpha = 0
|
||||
Text = "Add item",
|
||||
Action = () => OpenSongSelection(null)
|
||||
},
|
||||
},
|
||||
null,
|
||||
|
@ -147,7 +146,8 @@ protected override void LoadComplete()
|
|||
{
|
||||
new MultiplayerPlaylist
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
RequestEdit = OpenSongSelection
|
||||
}
|
||||
},
|
||||
new[]
|
||||
|
@ -220,12 +220,12 @@ protected override void LoadComplete()
|
|||
}
|
||||
};
|
||||
|
||||
internal void SelectBeatmap()
|
||||
internal void OpenSongSelection(PlaylistItem itemToEdit)
|
||||
{
|
||||
if (!this.IsCurrentScreen())
|
||||
return;
|
||||
|
||||
this.Push(new MultiplayerMatchSongSelect(Room));
|
||||
this.Push(new MultiplayerMatchSongSelect(Room, itemToEdit));
|
||||
}
|
||||
|
||||
protected override Drawable CreateFooter() => new MultiplayerMatchFooter
|
||||
|
@ -385,23 +385,7 @@ private void onRoomUpdated()
|
|||
return;
|
||||
}
|
||||
|
||||
switch (client.Room.Settings.QueueMode)
|
||||
{
|
||||
case QueueMode.HostOnly:
|
||||
AddOrEditPlaylistButton.Text = "Edit beatmap";
|
||||
AddOrEditPlaylistButton.Alpha = client.IsHost ? 1 : 0;
|
||||
break;
|
||||
|
||||
case QueueMode.AllPlayers:
|
||||
case QueueMode.AllPlayersRoundRobin:
|
||||
AddOrEditPlaylistButton.Text = "Add beatmap";
|
||||
AddOrEditPlaylistButton.Alpha = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
AddOrEditPlaylistButton.Alpha = 0;
|
||||
break;
|
||||
}
|
||||
addItemButton.Alpha = client.IsHost || Room.QueueMode.Value != QueueMode.HostOnly ? 1 : 0;
|
||||
|
||||
Scheduler.AddOnce(UpdateMods);
|
||||
}
|
||||
|
@ -466,7 +450,7 @@ public void PresentBeatmap(WorkingBeatmap beatmap, RulesetInfo ruleset)
|
|||
return;
|
||||
}
|
||||
|
||||
this.Push(new MultiplayerMatchSongSelect(Room, beatmap, ruleset));
|
||||
this.Push(new MultiplayerMatchSongSelect(Room, SelectedItem.Value, beatmap, ruleset));
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
|
@ -481,5 +465,9 @@ protected override void Dispose(bool isDisposing)
|
|||
|
||||
modSettingChangeTracker?.Dispose();
|
||||
}
|
||||
|
||||
public class AddItemButton : PurpleTriangleButton
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,14 +33,14 @@ public abstract class OnlinePlaySongSelect : SongSelect, IOnlinePlaySubScreen
|
|||
[Resolved(typeof(Room), nameof(Room.Playlist))]
|
||||
protected BindableList<PlaylistItem> Playlist { get; private set; }
|
||||
|
||||
[CanBeNull]
|
||||
[Resolved(CanBeNull = true)]
|
||||
protected IBindable<PlaylistItem> SelectedItem { get; private set; }
|
||||
|
||||
protected override UserActivity InitialActivity => new UserActivity.InLobby(room);
|
||||
|
||||
protected readonly Bindable<IReadOnlyList<Mod>> FreeMods = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
|
||||
|
||||
[CanBeNull]
|
||||
[Resolved(CanBeNull = true)]
|
||||
private IBindable<PlaylistItem> selectedItem { get; set; }
|
||||
|
||||
private readonly FreeModSelectOverlay freeModSelectOverlay;
|
||||
private readonly Room room;
|
||||
|
||||
|
@ -80,8 +80,8 @@ protected override void LoadComplete()
|
|||
|
||||
// At this point, Mods contains both the required and allowed mods. For selection purposes, it should only contain the required mods.
|
||||
// Similarly, freeMods is currently empty but should only contain the allowed mods.
|
||||
Mods.Value = selectedItem?.Value?.RequiredMods.Select(m => m.DeepClone()).ToArray() ?? Array.Empty<Mod>();
|
||||
FreeMods.Value = selectedItem?.Value?.AllowedMods.Select(m => m.DeepClone()).ToArray() ?? Array.Empty<Mod>();
|
||||
Mods.Value = SelectedItem?.Value?.RequiredMods.Select(m => m.DeepClone()).ToArray() ?? Array.Empty<Mod>();
|
||||
FreeMods.Value = SelectedItem?.Value?.AllowedMods.Select(m => m.DeepClone()).ToArray() ?? Array.Empty<Mod>();
|
||||
|
||||
Mods.BindValueChanged(onModsChanged);
|
||||
Ruleset.BindValueChanged(onRulesetChanged);
|
||||
|
|
Loading…
Reference in New Issue