1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 08:33:21 +08:00

Play with delegate

This commit is contained in:
Dean Herbert 2018-12-26 22:16:35 +09:00
parent a1fa914c66
commit 8cf30bdb6a
5 changed files with 32 additions and 21 deletions

View File

@ -17,7 +17,7 @@ namespace osu.Game.Tests.Visual
{
Beatmap.Value = new DummyWorkingBeatmap(game);
AddStep("load dummy beatmap", () => Add(loader = new PlayerLoader(new Player
AddStep("load dummy beatmap", () => Add(loader = new PlayerLoader(() => new Player
{
AllowPause = false,
AllowLeadIn = false,
@ -30,9 +30,9 @@ namespace osu.Game.Tests.Visual
AddStep("load slow dummy beatmap", () =>
{
SlowLoadPlayer slow;
SlowLoadPlayer slow = null;
Add(loader = new PlayerLoader(slow = new SlowLoadPlayer
Add(loader = new PlayerLoader(() => slow = new SlowLoadPlayer
{
AllowPause = false,
AllowLeadIn = false,

View File

@ -317,7 +317,7 @@ namespace osu.Game
Beatmap.Value = BeatmapManager.GetWorkingBeatmap(databasedBeatmap);
Beatmap.Value.Mods.Value = databasedScoreInfo.Mods;
currentScreen.Push(new PlayerLoader(new ReplayPlayer(databasedScore)));
currentScreen.Push(new PlayerLoader(() => new ReplayPlayer(databasedScore)));
}
}

View File

@ -167,10 +167,12 @@ namespace osu.Game.Screens.Multi.Match
{
default:
case GameTypeTimeshift _:
var player = new TimeshiftPlayer(room, room.Playlist.First().ID);
player.Exited += _ => leaderboard.RefreshScores();
pushGameplayScreen?.Invoke(new PlayerLoader(() => {
var player = new TimeshiftPlayer(room, room.Playlist.First().ID);
player.Exited += _ => leaderboard.RefreshScores();
pushGameplayScreen?.Invoke(new PlayerLoader(player));
return player;
}));
break;
}
}

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Linq;
using System.Threading.Tasks;
using osu.Framework.Allocation;
@ -24,6 +25,7 @@ namespace osu.Game.Screens.Play
{
public class PlayerLoader : ScreenWithBeatmapBackground
{
private readonly Func<Player> createPlayer;
private static readonly Vector2 background_blur = new Vector2(15);
private Player player;
@ -35,15 +37,15 @@ namespace osu.Game.Screens.Play
private Task loadTask;
public PlayerLoader(Player player)
public PlayerLoader(Func<Player> createPlayer)
{
this.player = player;
this.createPlayer = createPlayer;
}
player.RestartRequested = () =>
{
hideOverlays = true;
ValidForResume = true;
};
private void restartRequested()
{
hideOverlays = true;
ValidForResume = true;
}
[BackgroundDependencyLoader]
@ -71,7 +73,7 @@ namespace osu.Game.Screens.Play
}
});
loadTask = LoadComponentAsync(player, playerLoaded);
loadNewPlayer();
}
private void playerLoaded(Player player) => info.Loading = false;
@ -85,15 +87,22 @@ namespace osu.Game.Screens.Play
info.Loading = true;
//we will only be resumed if the player has requested a re-run (see ValidForResume setting above)
loadTask = LoadComponentAsync(player = new Player
{
RestartCount = player.RestartCount + 1,
RestartRequested = player.RestartRequested,
}, playerLoaded);
loadNewPlayer();
this.Delay(400).Schedule(pushWhenLoaded);
}
private void loadNewPlayer()
{
var restartCount = player?.RestartCount + 1 ?? 0;
player = createPlayer();
player.RestartCount = restartCount;
player.RestartRequested = restartRequested;
loadTask = LoadComponentAsync(player, playerLoaded);
}
private void contentIn()
{
Content.ScaleTo(1, 650, Easing.OutQuint);

View File

@ -62,7 +62,7 @@ namespace osu.Game.Screens.Select
SampleConfirm?.Play();
LoadComponentAsync(player = new PlayerLoader(new Player()), l =>
LoadComponentAsync(player = new PlayerLoader(() => new Player()), l =>
{
if (IsCurrentScreen) Push(player);
});