1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 08:07:24 +08:00

PlayerLoader creates a new instance of the Player class on Restart

This commit is contained in:
ocboogie 2017-04-17 21:30:51 -07:00
parent 78273d76e3
commit aa466d0e84
4 changed files with 38 additions and 83 deletions

View File

@ -1,31 +0,0 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Testing;
using osu.Game.Database;
using osu.Game.Screens.Select;
using System.Linq;
using osu.Game.Screens.Play;
using OpenTK;
namespace osu.Desktop.VisualTests.Tests
{
public class TestCasePlayerLoadingScreen : TestCase
{
public override string Description => @"Loading screen in player";
public override void Reset()
{
base.Reset();
Add(new LoadingScreen
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
});
}
}
}

View File

@ -1,37 +0,0 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Screens.Backgrounds;
using osu.Game.Screens.Menu;
using OpenTK;
namespace osu.Game.Screens.Play
{
public class LoadingScreen : OsuScreen
{
private string loadingText = "loading...";
[BackgroundDependencyLoader]
private void load()
{
Add(
new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = loadingText,
TextSize = 48,
Font = @"Exo2.0-MediumItalic"
}
);
}
}
}

View File

@ -35,6 +35,8 @@ namespace osu.Game.Screens.Play
public BeatmapInfo BeatmapInfo;
public Action OnRestart;
public bool IsPaused => !interpolatedSourceClock.IsRunning;
public bool HasFailed { get; private set; }
@ -243,20 +245,9 @@ namespace osu.Game.Screens.Play
public void Restart()
{
sourceClock.Stop(); // If the clock is running and Restart is called the game will lag until relaunch
var newPlayer = new Player();
ValidForResume = false;
LoadComponentAsync(newPlayer, delegate
{
newPlayer.RestartCount = RestartCount + 1;
if (!Push(newPlayer))
{
// Error(?)
}
});
System.Diagnostics.Debug.WriteLine("TEST");
OnRestart?.Invoke();
Exit();
}
private ScheduledDelegate onCompletionEvent;

View File

@ -19,15 +19,22 @@ namespace osu.Game.Screens.Play
{
public class PlayerLoader : OsuScreen
{
private readonly Player player;
private Player player;
private readonly OsuLogo logo;
private BeatmapMetadataDisplay info;
private bool showOverlays = false;
internal override bool ShowOverlays => showOverlays;
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap);
public PlayerLoader(Player player)
{
ValidForResume = false;
player.OnRestart = restart;
this.player = player;
Children = new Drawable[]
@ -38,6 +45,7 @@ namespace osu.Game.Screens.Play
Interactive = false,
},
};
}
[BackgroundDependencyLoader]
@ -53,6 +61,30 @@ namespace osu.Game.Screens.Play
LoadComponentAsync(player);
}
protected override void OnResuming(Screen last)
{
base.OnResuming(last);
if (last != player) return;
var newPlayer = new Player
{
RestartCount = player.RestartCount + 1,
OnRestart = restart
};
player = newPlayer;
LoadComponentAsync(newPlayer, delegate
{
if (!Push(newPlayer))
Exit();
ValidForResume = false;
});
}
private void restart()
{
showOverlays = false;
ValidForResume = true;
}
protected override void OnEntering(Screen last)
{
base.OnEntering(last);