Fix multiplayer crashing when entering gameplay

This commit is contained in:
smoogipoo 2021-08-24 13:22:06 +09:00
parent c2974cfc65
commit df170afbc4
9 changed files with 27 additions and 23 deletions

View File

@ -39,7 +39,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
base.SetUpSteps(); base.SetUpSteps();
AddStep("load chat display", () => Child = chatDisplay = new GameplayChatDisplay AddStep("load chat display", () => Child = chatDisplay = new GameplayChatDisplay(SelectedRoom.Value)
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,

View File

@ -25,7 +25,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddStep("initialise gameplay", () => AddStep("initialise gameplay", () =>
{ {
Stack.Push(player = new MultiplayerPlayer(Client.CurrentMatchPlayingItem.Value, Client.Room?.Users.ToArray())); Stack.Push(player = new MultiplayerPlayer(Client.APIRoom, Client.CurrentMatchPlayingItem.Value, Client.Room?.Users.ToArray()));
}); });
} }

View File

@ -10,21 +10,21 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
{ {
public class MatchChatDisplay : StandAloneChatDisplay public class MatchChatDisplay : StandAloneChatDisplay
{ {
[Resolved(typeof(Room), nameof(Room.RoomID))] private readonly IBindable<long?> roomId = new Bindable<long?>();
private Bindable<long?> roomId { get; set; } private readonly IBindable<int> channelId = new Bindable<int>();
[Resolved(typeof(Room), nameof(Room.ChannelId))]
private Bindable<int> channelId { get; set; }
[Resolved(CanBeNull = true)] [Resolved(CanBeNull = true)]
private ChannelManager channelManager { get; set; } private ChannelManager channelManager { get; set; }
private readonly bool leaveChannelOnDispose; private readonly bool leaveChannelOnDispose;
public MatchChatDisplay(bool leaveChannelOnDispose = true) public MatchChatDisplay(Room room, bool leaveChannelOnDispose = true)
: base(true) : base(true)
{ {
this.leaveChannelOnDispose = leaveChannelOnDispose; this.leaveChannelOnDispose = leaveChannelOnDispose;
roomId.BindTo(room.RoomID);
channelId.BindTo(room.ChannelId);
} }
protected override void LoadComplete() protected override void LoadComplete()

View File

@ -7,6 +7,7 @@ using osu.Framework.Graphics;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Input.Bindings; using osu.Game.Input.Bindings;
using osu.Game.Online.Rooms;
using osu.Game.Screens.OnlinePlay.Match.Components; using osu.Game.Screens.OnlinePlay.Match.Components;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
@ -29,8 +30,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
public override bool PropagateNonPositionalInputSubTree => true; public override bool PropagateNonPositionalInputSubTree => true;
public GameplayChatDisplay() public GameplayChatDisplay(Room room)
: base(leaveChannelOnDispose: false) : base(room, leaveChannelOnDispose: false)
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;

View File

@ -173,7 +173,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
}, },
}, },
new Drawable[] { new OverlinedHeader("Chat") { Margin = new MarginPadding { Vertical = 5 }, }, }, new Drawable[] { new OverlinedHeader("Chat") { Margin = new MarginPadding { Vertical = 5 }, }, },
new Drawable[] { new MatchChatDisplay { RelativeSizeAxes = Axes.Both } } new Drawable[] { new MatchChatDisplay(Room) { RelativeSizeAxes = Axes.Both } }
}, },
RowDimensions = new[] RowDimensions = new[]
{ {
@ -395,7 +395,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
return new MultiSpectatorScreen(users.Take(PlayerGrid.MAX_PLAYERS).ToArray()); return new MultiSpectatorScreen(users.Take(PlayerGrid.MAX_PLAYERS).ToArray());
default: default:
return new PlayerLoader(() => new MultiplayerPlayer(SelectedItem.Value, users)); return new PlayerLoader(() => new MultiplayerPlayer(Room, SelectedItem.Value, users));
} }
} }

View File

@ -45,10 +45,11 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
/// <summary> /// <summary>
/// Construct a multiplayer player. /// Construct a multiplayer player.
/// </summary> /// </summary>
/// <param name="room">The room.</param>
/// <param name="playlistItem">The playlist item to be played.</param> /// <param name="playlistItem">The playlist item to be played.</param>
/// <param name="users">The users which are participating in this game.</param> /// <param name="users">The users which are participating in this game.</param>
public MultiplayerPlayer(PlaylistItem playlistItem, MultiplayerRoomUser[] users) public MultiplayerPlayer(Room room, PlaylistItem playlistItem, MultiplayerRoomUser[] users)
: base(playlistItem, new PlayerConfiguration : base(room, playlistItem, new PlayerConfiguration
{ {
AllowPause = false, AllowPause = false,
AllowRestart = false, AllowRestart = false,
@ -92,7 +93,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
} }
}); });
LoadComponentAsync(new GameplayChatDisplay LoadComponentAsync(new GameplayChatDisplay(Room)
{ {
Expanded = { BindTarget = HUDOverlay.ShowHud }, Expanded = { BindTarget = HUDOverlay.ShowHud },
}, chat => leaderboardFlow.Insert(2, chat)); }, chat => leaderboardFlow.Insert(2, chat));

View File

@ -20,8 +20,8 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
{ {
public Action Exited; public Action Exited;
public PlaylistsPlayer(PlaylistItem playlistItem, PlayerConfiguration configuration = null) public PlaylistsPlayer(Room room, PlaylistItem playlistItem, PlayerConfiguration configuration = null)
: base(playlistItem, configuration) : base(room, playlistItem, configuration)
{ {
} }

View File

@ -158,7 +158,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
}, },
new Drawable[] { leaderboard = new MatchLeaderboard { RelativeSizeAxes = Axes.Both }, }, new Drawable[] { leaderboard = new MatchLeaderboard { RelativeSizeAxes = Axes.Both }, },
new Drawable[] { new OverlinedHeader("Chat"), }, new Drawable[] { new OverlinedHeader("Chat"), },
new Drawable[] { new MatchChatDisplay { RelativeSizeAxes = Axes.Both } } new Drawable[] { new MatchChatDisplay(Room) { RelativeSizeAxes = Axes.Both } }
}, },
RowDimensions = new[] RowDimensions = new[]
{ {
@ -199,7 +199,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
Logger.Log($"Polling adjusted (selection: {selectionPollingComponent.TimeBetweenPolls.Value})"); Logger.Log($"Polling adjusted (selection: {selectionPollingComponent.TimeBetweenPolls.Value})");
} }
protected override Screen CreateGameplayScreen() => new PlayerLoader(() => new PlaylistsPlayer(SelectedItem.Value) protected override Screen CreateGameplayScreen() => new PlayerLoader(() => new PlaylistsPlayer(Room, SelectedItem.Value)
{ {
Exited = () => leaderboard.RefreshScores() Exited = () => leaderboard.RefreshScores()
}); });

View File

@ -1,7 +1,6 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
@ -14,15 +13,18 @@ namespace osu.Game.Screens.Play
/// </summary> /// </summary>
public abstract class RoomSubmittingPlayer : SubmittingPlayer public abstract class RoomSubmittingPlayer : SubmittingPlayer
{ {
[Resolved(typeof(Room), nameof(Room.RoomID))] protected readonly IBindable<long?> RoomId = new Bindable<long?>();
protected Bindable<long?> RoomId { get; private set; }
protected readonly PlaylistItem PlaylistItem; protected readonly PlaylistItem PlaylistItem;
protected readonly Room Room;
protected RoomSubmittingPlayer(PlaylistItem playlistItem, PlayerConfiguration configuration = null) protected RoomSubmittingPlayer(Room room, PlaylistItem playlistItem, PlayerConfiguration configuration = null)
: base(configuration) : base(configuration)
{ {
Room = room;
PlaylistItem = playlistItem; PlaylistItem = playlistItem;
RoomId.BindTo(room.RoomID);
} }
protected override APIRequest<APIScoreToken> CreateTokenRequest() protected override APIRequest<APIScoreToken> CreateTokenRequest()