1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:28:00 +08:00

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();
AddStep("load chat display", () => Child = chatDisplay = new GameplayChatDisplay
AddStep("load chat display", () => Child = chatDisplay = new GameplayChatDisplay(SelectedRoom.Value)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,

View File

@ -25,7 +25,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
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
{
[Resolved(typeof(Room), nameof(Room.RoomID))]
private Bindable<long?> roomId { get; set; }
[Resolved(typeof(Room), nameof(Room.ChannelId))]
private Bindable<int> channelId { get; set; }
private readonly IBindable<long?> roomId = new Bindable<long?>();
private readonly IBindable<int> channelId = new Bindable<int>();
[Resolved(CanBeNull = true)]
private ChannelManager channelManager { get; set; }
private readonly bool leaveChannelOnDispose;
public MatchChatDisplay(bool leaveChannelOnDispose = true)
public MatchChatDisplay(Room room, bool leaveChannelOnDispose = true)
: base(true)
{
this.leaveChannelOnDispose = leaveChannelOnDispose;
roomId.BindTo(room.RoomID);
channelId.BindTo(room.ChannelId);
}
protected override void LoadComplete()

View File

@ -7,6 +7,7 @@ using osu.Framework.Graphics;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Input.Bindings;
using osu.Game.Online.Rooms;
using osu.Game.Screens.OnlinePlay.Match.Components;
using osu.Game.Screens.Play;
@ -29,8 +30,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
public override bool PropagateNonPositionalInputSubTree => true;
public GameplayChatDisplay()
: base(leaveChannelOnDispose: false)
public GameplayChatDisplay(Room room)
: base(room, leaveChannelOnDispose: false)
{
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 MatchChatDisplay { RelativeSizeAxes = Axes.Both } }
new Drawable[] { new MatchChatDisplay(Room) { RelativeSizeAxes = Axes.Both } }
},
RowDimensions = new[]
{
@ -395,7 +395,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
return new MultiSpectatorScreen(users.Take(PlayerGrid.MAX_PLAYERS).ToArray());
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>
/// Construct a multiplayer player.
/// </summary>
/// <param name="room">The room.</param>
/// <param name="playlistItem">The playlist item to be played.</param>
/// <param name="users">The users which are participating in this game.</param>
public MultiplayerPlayer(PlaylistItem playlistItem, MultiplayerRoomUser[] users)
: base(playlistItem, new PlayerConfiguration
public MultiplayerPlayer(Room room, PlaylistItem playlistItem, MultiplayerRoomUser[] users)
: base(room, playlistItem, new PlayerConfiguration
{
AllowPause = false,
AllowRestart = false,
@ -92,7 +93,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
}
});
LoadComponentAsync(new GameplayChatDisplay
LoadComponentAsync(new GameplayChatDisplay(Room)
{
Expanded = { BindTarget = HUDOverlay.ShowHud },
}, chat => leaderboardFlow.Insert(2, chat));

View File

@ -20,8 +20,8 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
{
public Action Exited;
public PlaylistsPlayer(PlaylistItem playlistItem, PlayerConfiguration configuration = null)
: base(playlistItem, configuration)
public PlaylistsPlayer(Room room, PlaylistItem playlistItem, PlayerConfiguration configuration = null)
: 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[] { new OverlinedHeader("Chat"), },
new Drawable[] { new MatchChatDisplay { RelativeSizeAxes = Axes.Both } }
new Drawable[] { new MatchChatDisplay(Room) { RelativeSizeAxes = Axes.Both } }
},
RowDimensions = new[]
{
@ -199,7 +199,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
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()
});

View File

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