1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-18 05:39:53 +08:00

Refactor gameplay screen creation

This commit is contained in:
smoogipoo
2021-04-22 23:37:33 +09:00
Unverified
parent f8f9cf9412
commit fd0b030cf4
3 changed files with 24 additions and 19 deletions
@@ -17,7 +17,6 @@ using osu.Game.Online.Rooms;
using osu.Game.Overlays;
using osu.Game.Overlays.Mods;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Play;
namespace osu.Game.Screens.OnlinePlay.Match
{
@@ -148,14 +147,18 @@ namespace osu.Game.Screens.OnlinePlay.Match
return base.OnExiting(next);
}
protected void StartPlay(Func<Player> player) => PushTopLevelScreen(() => new PlayerLoader(player));
protected void PushTopLevelScreen(Func<Screen> screen)
protected void StartPlay()
{
sampleStart?.Play();
ParentScreen?.Push(screen());
ParentScreen?.Push(CreateGameplayScreen());
}
/// <summary>
/// Creates the gameplay screen to be entered.
/// </summary>
/// <returns>The screen to enter.</returns>
protected abstract Screen CreateGameplayScreen();
private void selectedItemChanged()
{
updateWorkingBeatmap();
@@ -416,10 +416,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
UpdateMods();
if (client.LocalUser.State == MultiplayerUserState.Spectating
&& (client.Room.State == MultiplayerRoomState.Playing || client.Room.State == MultiplayerRoomState.WaitingForLoad)
&& ParentScreen.IsCurrentScreen())
&& (client.Room.State == MultiplayerRoomState.Playing || client.Room.State == MultiplayerRoomState.WaitingForLoad))
{
PushTopLevelScreen(() => new MultiplayerSpectator(client.CurrentMatchPlayingUserIds.ToArray()));
StartPlay();
// If the current user was host, they started the match and the in-progres operation needs to be stopped now.
readyClickOperation?.Dispose();
@@ -429,16 +428,22 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
private void onLoadRequested()
{
Debug.Assert(client.Room != null);
int[] userIds = client.CurrentMatchPlayingUserIds.ToArray();
StartPlay(() => new MultiplayerPlayer(SelectedItem.Value, userIds));
StartPlay();
readyClickOperation?.Dispose();
readyClickOperation = null;
}
protected override Screen CreateGameplayScreen()
{
Debug.Assert(client.LocalUser != null);
if (client.LocalUser.State == MultiplayerUserState.Spectating)
return new MultiSpectatorScreen(client.CurrentMatchPlayingUserIds.ToArray());
return new MultiplayerPlayer(SelectedItem.Value, client.CurrentMatchPlayingUserIds.ToArray());
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
@@ -218,10 +218,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
},
new Drawable[]
{
new Footer
{
OnStart = onStart,
}
new Footer { OnStart = StartPlay }
}
},
RowDimensions = new[]
@@ -274,9 +271,9 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
}, true);
}
private void onStart() => StartPlay(() => new PlaylistsPlayer(SelectedItem.Value)
protected override Screen CreateGameplayScreen() => new PlaylistsPlayer(SelectedItem.Value)
{
Exited = () => leaderboard.RefreshScores()
});
};
}
}