1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 12:25:04 +08:00

Make Room.QueueMode non-bindable

This commit is contained in:
Dan Balasescu 2024-11-13 18:57:51 +09:00
parent 7e3e5208f0
commit 198681e644
No known key found for this signature in database
13 changed files with 67 additions and 43 deletions

View File

@ -74,7 +74,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddStep("open room", () => multiplayerComponents.ChildrenOfType<LoungeSubScreen>().Single().Open(new Room
{
Name = "Test Room",
QueueMode = { Value = Mode },
QueueMode = Mode,
Playlist =
{
new PlaylistItem(InitialBeatmap)
@ -96,7 +96,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
[Test]
public void TestCreatedWithCorrectMode()
{
AddUntilStep("room created with correct mode", () => MultiplayerClient.ClientAPIRoom?.QueueMode.Value == Mode);
AddUntilStep("room created with correct mode", () => MultiplayerClient.ClientAPIRoom?.QueueMode == Mode);
}
protected void RunGameplay()

View File

@ -165,7 +165,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
new DrawableMatchRoom(new Room
{
Name = "A host-only room",
QueueMode = { Value = QueueMode.HostOnly },
QueueMode = QueueMode.HostOnly,
Type = MatchType.HeadToHead,
})
{
@ -174,7 +174,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
new DrawableMatchRoom(new Room
{
Name = "An all-players, team-versus room",
QueueMode = { Value = QueueMode.AllPlayers },
QueueMode = QueueMode.AllPlayers,
Type = MatchType.TeamVersus
})
{
@ -183,7 +183,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
new DrawableMatchRoom(new Room
{
Name = "A round-robin room",
QueueMode = { Value = QueueMode.AllPlayersRoundRobin },
QueueMode = QueueMode.AllPlayersRoundRobin,
Type = MatchType.HeadToHead
})
{

View File

@ -46,7 +46,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
QueueMode = QueueMode.AllPlayers
}).WaitSafely());
AddUntilStep("api room updated", () => MultiplayerClient.ClientAPIRoom?.QueueMode.Value == QueueMode.AllPlayers);
AddUntilStep("api room updated", () => MultiplayerClient.ClientAPIRoom?.QueueMode == QueueMode.AllPlayers);
}
[Test]

View File

@ -792,7 +792,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
roomManager.AddServerSideRoom(new Room
{
Name = "Test Room",
QueueMode = { Value = QueueMode.AllPlayers },
QueueMode = QueueMode.AllPlayers,
Playlist =
{
new PlaylistItem(beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.Ruleset.OnlineID == 0)).BeatmapInfo)
@ -837,7 +837,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
createRoom(() => new Room
{
Name = "Test Room",
QueueMode = { Value = QueueMode.AllPlayers },
QueueMode = QueueMode.AllPlayers,
Playlist =
{
new PlaylistItem(beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.Ruleset.OnlineID == 0)).BeatmapInfo)
@ -873,7 +873,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
createRoom(() => new Room
{
Name = "Test Room",
QueueMode = { Value = QueueMode.AllPlayers },
QueueMode = QueueMode.AllPlayers,
Playlist =
{
new PlaylistItem(beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.Ruleset.OnlineID == 0)).BeatmapInfo)
@ -912,7 +912,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
createRoom(() => new Room
{
Name = "Test Room",
QueueMode = { Value = QueueMode.AllPlayers },
QueueMode = QueueMode.AllPlayers,
Playlist =
{
new PlaylistItem(beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.Ruleset.OnlineID == 0)).BeatmapInfo)
@ -943,7 +943,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
createRoom(() => new Room
{
Name = "Test Room",
QueueMode = { Value = QueueMode.AllPlayers },
QueueMode = QueueMode.AllPlayers,
Playlist =
{
new PlaylistItem(beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.Ruleset.OnlineID == 0)).BeatmapInfo)
@ -1023,7 +1023,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
createRoom(() => new Room
{
Name = "Test Room",
QueueMode = { Value = QueueMode.AllPlayers },
QueueMode = QueueMode.AllPlayers,
Playlist =
{
new PlaylistItem(beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.Ruleset.OnlineID == 0)).BeatmapInfo)

View File

@ -69,7 +69,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
public void TestDeleteButtonAlwaysVisibleForHost()
{
AddStep("set all players queue mode", () => MultiplayerClient.ChangeSettings(new MultiplayerRoomSettings { QueueMode = QueueMode.AllPlayers }).WaitSafely());
AddUntilStep("wait for queue mode change", () => MultiplayerClient.ClientAPIRoom?.QueueMode.Value == QueueMode.AllPlayers);
AddUntilStep("wait for queue mode change", () => MultiplayerClient.ClientAPIRoom?.QueueMode == QueueMode.AllPlayers);
addPlaylistItem(() => API.LocalUser.Value.OnlineID);
assertDeleteButtonVisibility(1, true);
@ -81,7 +81,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
public void TestDeleteButtonOnlyVisibleForItemOwnerIfNotHost()
{
AddStep("set all players queue mode", () => MultiplayerClient.ChangeSettings(new MultiplayerRoomSettings { QueueMode = QueueMode.AllPlayers }).WaitSafely());
AddUntilStep("wait for queue mode change", () => MultiplayerClient.ClientAPIRoom?.QueueMode.Value == QueueMode.AllPlayers);
AddUntilStep("wait for queue mode change", () => MultiplayerClient.ClientAPIRoom?.QueueMode == QueueMode.AllPlayers);
AddStep("join other user", () => MultiplayerClient.AddUser(new APIUser { Id = 1234 }));
AddStep("set other user as host", () => MultiplayerClient.TransferHost(1234));
@ -100,7 +100,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
public void TestSingleItemDoesNotHaveDeleteButton()
{
AddStep("set all players queue mode", () => MultiplayerClient.ChangeSettings(new MultiplayerRoomSettings { QueueMode = QueueMode.AllPlayers }).WaitSafely());
AddUntilStep("wait for queue mode change", () => MultiplayerClient.ClientAPIRoom?.QueueMode.Value == QueueMode.AllPlayers);
AddUntilStep("wait for queue mode change", () => MultiplayerClient.ClientAPIRoom?.QueueMode == QueueMode.AllPlayers);
assertDeleteButtonVisibility(0, false);
}
@ -109,7 +109,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
public void TestCurrentItemHasDeleteButtonIfNotSingle()
{
AddStep("set all players queue mode", () => MultiplayerClient.ChangeSettings(new MultiplayerRoomSettings { QueueMode = QueueMode.AllPlayers }).WaitSafely());
AddUntilStep("wait for queue mode change", () => MultiplayerClient.ClientAPIRoom?.QueueMode.Value == QueueMode.AllPlayers);
AddUntilStep("wait for queue mode change", () => MultiplayerClient.ClientAPIRoom?.QueueMode == QueueMode.AllPlayers);
addPlaylistItem(() => API.LocalUser.Value.OnlineID);

View File

@ -845,7 +845,7 @@ namespace osu.Game.Online.Multiplayer
APIRoom.Password.Value = Room.Settings.Password;
APIRoom.Status = string.IsNullOrEmpty(Room.Settings.Password) ? new RoomStatusOpen() : new RoomStatusOpenPrivate();
APIRoom.Type = Room.Settings.MatchType;
APIRoom.QueueMode.Value = Room.Settings.QueueMode;
APIRoom.QueueMode = Room.Settings.QueueMode;
APIRoom.AutoStartDuration.Value = Room.Settings.AutoStartDuration;
APIRoom.CurrentPlaylistItem = APIRoom.Playlist.Single(item => item.ID == settings.PlaylistItemId);
APIRoom.AutoSkip.Value = Room.Settings.AutoSkip;

View File

@ -66,6 +66,15 @@ namespace osu.Game.Online.Rooms
set => SetField(ref type, value);
}
/// <summary>
/// The playlist queueing mode. Only valid for multiplayer rooms.
/// </summary>
public QueueMode QueueMode
{
get => queueMode;
set => SetField(ref queueMode, value);
}
/// <summary>
/// Represents the current item selected within the room.
/// </summary>
@ -96,6 +105,7 @@ namespace osu.Game.Online.Rooms
set => SetField(ref availability, value);
}
[JsonProperty("id")]
private long? roomId;
@ -113,6 +123,10 @@ namespace osu.Game.Online.Rooms
[JsonProperty("type")]
private MatchType type;
[JsonConverter(typeof(SnakeCaseStringEnumConverter))]
[JsonProperty("queue_mode")]
private QueueMode queueMode;
[JsonProperty("current_playlist_item")]
private PlaylistItem? currentPlaylistItem;
@ -141,17 +155,6 @@ namespace osu.Game.Online.Rooms
[Cached]
public readonly Bindable<int?> MaxAttempts = new Bindable<int?>();
[Cached]
public readonly Bindable<QueueMode> QueueMode = new Bindable<QueueMode>();
[JsonConverter(typeof(SnakeCaseStringEnumConverter))]
[JsonProperty("queue_mode")]
private QueueMode queueMode
{
get => QueueMode.Value;
set => QueueMode.Value = value;
}
[Cached]
public readonly Bindable<TimeSpan> AutoStartDuration = new Bindable<TimeSpan>();
@ -257,7 +260,7 @@ namespace osu.Game.Online.Rooms
ParticipantCount.Value = other.ParticipantCount.Value;
EndDate.Value = other.EndDate.Value;
UserScore.Value = other.UserScore.Value;
QueueMode.Value = other.QueueMode.Value;
QueueMode = other.QueueMode;
AutoStartDuration.Value = other.AutoStartDuration.Value;
DifficultyRange.Value = other.DifficultyRange.Value;
PlaylistItemStats.Value = other.PlaylistItemStats.Value;

View File

@ -341,7 +341,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
pills.AddRange(new OnlinePlayComposite[]
{
new MatchTypePill(Room),
new QueueModePill(),
new QueueModePill(Room),
});
}

View File

@ -1,24 +1,42 @@
// 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 osu.Framework.Bindables;
using System.ComponentModel;
using osu.Framework.Extensions;
using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms;
namespace osu.Game.Screens.OnlinePlay.Lounge.Components
{
public partial class QueueModePill : OnlinePlayPill
{
private readonly Room room;
public QueueModePill(Room room)
{
this.room = room;
}
protected override void LoadComplete()
{
base.LoadComplete();
QueueMode.BindValueChanged(onQueueModeChanged, true);
room.PropertyChanged += onRoomPropertyChanged;
updateRoomQueueMode();
}
private void onQueueModeChanged(ValueChangedEvent<QueueMode> mode)
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
TextFlow.Text = mode.NewValue.GetLocalisableDescription();
if (e.PropertyName == nameof(Room.QueueMode))
updateRoomQueueMode();
}
private void updateRoomQueueMode()
=> TextFlow.Text = room.QueueMode.GetLocalisableDescription();
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
room.PropertyChanged -= onRoomPropertyChanged;
}
}
}

View File

@ -352,7 +352,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
TypePicker.Current.BindValueChanged(type => typeLabel.Text = type.NewValue.GetLocalisableDescription(), true);
MaxParticipants.BindValueChanged(count => MaxParticipantsField.Text = count.NewValue?.ToString(), true);
Password.BindValueChanged(password => PasswordTextBox.Text = password.NewValue ?? string.Empty, true);
QueueMode.BindValueChanged(mode => QueueModeDropdown.Current.Value = mode.NewValue, true);
AutoStartDuration.BindValueChanged(duration => startModeDropdown.Current.Value = (StartMode)(int)duration.NewValue.TotalSeconds, true);
AutoSkip.BindValueChanged(autoSkip => AutoSkipCheckbox.Current.Value = autoSkip.NewValue, true);
@ -377,6 +376,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
updateRoomName();
updateRoomType();
updateRoomQueueMode();
}
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
@ -390,6 +390,10 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
case nameof(Room.Type):
updateRoomName();
break;
case nameof(Room.QueueMode):
updateRoomQueueMode();
break;
}
}
@ -399,6 +403,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
private void updateRoomType()
=> TypePicker.Current.Value = room.Type;
private void updateRoomQueueMode()
=> QueueModeDropdown.Current.Value = room.QueueMode;
protected override void Update()
{
base.Update();
@ -443,7 +450,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
room.Name = NameField.Text;
room.Type = TypePicker.Current.Value;
room.Password.Value = PasswordTextBox.Current.Value;
room.QueueMode.Value = QueueModeDropdown.Current.Value;
room.QueueMode = QueueModeDropdown.Current.Value;
room.AutoStartDuration.Value = autoStartDuration;
room.AutoSkip.Value = AutoSkipCheckbox.Current.Value;

View File

@ -358,7 +358,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
Activity.Value = new UserActivity.InLobby(Room);
}
private bool localUserCanAddItem => client.IsHost || Room.QueueMode.Value != QueueMode.HostOnly;
private bool localUserCanAddItem => client.IsHost || Room.QueueMode != QueueMode.HostOnly;
private void updateCurrentItem()
{

View File

@ -6,7 +6,6 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms;
namespace osu.Game.Screens.OnlinePlay
@ -52,9 +51,6 @@ namespace osu.Game.Screens.OnlinePlay
[Resolved(typeof(Room))]
protected Bindable<TimeSpan?> Duration { get; private set; } = null!;
[Resolved(typeof(Room))]
protected Bindable<QueueMode> QueueMode { get; private set; } = null!;
[Resolved(typeof(Room))]
protected Bindable<TimeSpan> AutoStartDuration { get; private set; } = null!;

View File

@ -233,7 +233,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
Name = ServerAPIRoom.Name,
MatchType = ServerAPIRoom.Type,
Password = password ?? string.Empty,
QueueMode = ServerAPIRoom.QueueMode.Value,
QueueMode = ServerAPIRoom.QueueMode,
AutoStartDuration = ServerAPIRoom.AutoStartDuration.Value
},
Playlist = ServerAPIRoom.Playlist.Select(CreateMultiplayerPlaylistItem).ToList(),