mirror of
https://github.com/osukey/osukey.git
synced 2025-05-29 01:17:35 +09: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 BeatmapInfo BeatmapInfo;
|
||||||
|
|
||||||
|
public Action OnRestart;
|
||||||
|
|
||||||
public bool IsPaused => !interpolatedSourceClock.IsRunning;
|
public bool IsPaused => !interpolatedSourceClock.IsRunning;
|
||||||
|
|
||||||
public bool HasFailed { get; private set; }
|
public bool HasFailed { get; private set; }
|
||||||
@ -243,20 +245,9 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
public void Restart()
|
public void Restart()
|
||||||
{
|
{
|
||||||
sourceClock.Stop(); // If the clock is running and Restart is called the game will lag until relaunch
|
System.Diagnostics.Debug.WriteLine("TEST");
|
||||||
|
OnRestart?.Invoke();
|
||||||
var newPlayer = new Player();
|
Exit();
|
||||||
|
|
||||||
ValidForResume = false;
|
|
||||||
|
|
||||||
LoadComponentAsync(newPlayer, delegate
|
|
||||||
{
|
|
||||||
newPlayer.RestartCount = RestartCount + 1;
|
|
||||||
if (!Push(newPlayer))
|
|
||||||
{
|
|
||||||
// Error(?)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScheduledDelegate onCompletionEvent;
|
private ScheduledDelegate onCompletionEvent;
|
||||||
|
@ -19,15 +19,22 @@ namespace osu.Game.Screens.Play
|
|||||||
{
|
{
|
||||||
public class PlayerLoader : OsuScreen
|
public class PlayerLoader : OsuScreen
|
||||||
{
|
{
|
||||||
private readonly Player player;
|
private Player player;
|
||||||
|
|
||||||
private readonly OsuLogo logo;
|
private readonly OsuLogo logo;
|
||||||
private BeatmapMetadataDisplay info;
|
private BeatmapMetadataDisplay info;
|
||||||
|
|
||||||
|
private bool showOverlays = false;
|
||||||
|
internal override bool ShowOverlays => showOverlays;
|
||||||
|
|
||||||
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap);
|
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap);
|
||||||
|
|
||||||
public PlayerLoader(Player player)
|
public PlayerLoader(Player player)
|
||||||
{
|
{
|
||||||
ValidForResume = false;
|
ValidForResume = false;
|
||||||
|
|
||||||
|
player.OnRestart = restart;
|
||||||
|
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
@ -38,6 +45,7 @@ namespace osu.Game.Screens.Play
|
|||||||
Interactive = false,
|
Interactive = false,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -53,6 +61,30 @@ namespace osu.Game.Screens.Play
|
|||||||
LoadComponentAsync(player);
|
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)
|
protected override void OnEntering(Screen last)
|
||||||
{
|
{
|
||||||
base.OnEntering(last);
|
base.OnEntering(last);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user