mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 06:42:54 +08:00
PlayerLoader creates a new instance of the Player class on Restart
This commit is contained in:
parent
78273d76e3
commit
aa466d0e84
@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user