1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-24 09:37:19 +08:00

Schedule Join operations rather than using OnLoadComplete for added safety

This commit is contained in:
Dean Herbert 2023-10-12 17:42:02 +09:00
parent a512ef5637
commit 94d7a65e40
No known key found for this signature in database
4 changed files with 28 additions and 29 deletions

View File

@ -654,14 +654,13 @@ namespace osu.Game
{
PerformFromScreen(screen =>
{
Multiplayer multiplayer = new Multiplayer();
multiplayer.OnLoadComplete += _ =>
{
multiplayer.Join(room, password);
};
if (!(screen is Multiplayer multiplayer))
screen.Push(multiplayer = new Multiplayer());
screen.Push(multiplayer);
multiplayer.Join(room, password);
});
// TODO: We should really be able to use `validScreens: new[] { typeof(Multiplayer) }` here
// but `PerformFromScreen` doesn't understand nested stacks.
}
/// <summary>

View File

@ -297,26 +297,29 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
popoverContainer.HidePopover();
}
public virtual void Join(Room room, string password, Action<Room> onSuccess = null, Action<string> onFailure = null) => Schedule(() =>
public void Join(Room room, string password, Action<Room> onSuccess = null, Action<string> onFailure = null)
{
if (joiningRoomOperation != null)
return;
joiningRoomOperation = ongoingOperationTracker?.BeginOperation();
RoomManager?.JoinRoom(room, password, _ =>
Schedule(() =>
{
Open(room);
joiningRoomOperation?.Dispose();
joiningRoomOperation = null;
onSuccess?.Invoke(room);
}, error =>
{
joiningRoomOperation?.Dispose();
joiningRoomOperation = null;
onFailure?.Invoke(error);
if (joiningRoomOperation != null)
return;
joiningRoomOperation = ongoingOperationTracker?.BeginOperation();
RoomManager?.JoinRoom(room, password, _ =>
{
Open(room);
joiningRoomOperation?.Dispose();
joiningRoomOperation = null;
onSuccess?.Invoke(room);
}, error =>
{
joiningRoomOperation?.Dispose();
joiningRoomOperation = null;
onFailure?.Invoke(error);
});
});
});
}
/// <summary>
/// Copies a room and opens it as a fresh (not-yet-created) one.

View File

@ -91,10 +91,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
protected override LoungeSubScreen CreateLounge() => new MultiplayerLoungeSubScreen();
public void Join(Room room, string? password)
{
Lounge.Join(room, password);
}
public void Join(Room room, string? password) => Schedule(() => Lounge.Join(room, password));
protected override void Dispose(bool isDisposing)
{

View File

@ -26,6 +26,8 @@ namespace osu.Game.Screens.OnlinePlay
[Cached]
protected readonly OverlayColourProvider ColourProvider = new OverlayColourProvider(OverlayColourScheme.Plum);
public IScreen CurrentSubScreen => screenStack.CurrentScreen;
public override bool CursorVisible => (screenStack?.CurrentScreen as IOnlinePlaySubScreen)?.CursorVisible ?? true;
// this is required due to PlayerLoader eventually being pushed to the main stack
@ -225,8 +227,6 @@ namespace osu.Game.Screens.OnlinePlay
((IBindable<UserActivity>)Activity).BindTo(newOsuScreen.Activity);
}
public IScreen CurrentSubScreen => screenStack.CurrentScreen;
protected abstract string ScreenTitle { get; }
protected virtual RoomManager CreateRoomManager() => new RoomManager();