fade is weird when flashing back right after game over screen

This commit is contained in:
Nick 2024-04-01 00:04:42 -04:00
parent 8f40db40b3
commit 4a06a5891d
5 changed files with 46 additions and 9 deletions

View File

@ -13,7 +13,7 @@ namespace NewHorizons.Builder.Volumes
volume.creditsType = info.creditsType;
volume.gameOverText = info.gameOverText;
volume.deathType = EnumUtils.Parse(info.deathType.ToString(), DeathType.Default);
volume.deathType = info.deathType == null ? null : EnumUtils.Parse(info.deathType.ToString(), DeathType.Default);
return volume;
}

View File

@ -10,10 +10,10 @@ namespace NewHorizons.Components.Volumes
{
internal class LoadCreditsVolume : BaseVolume
{
public NHCreditsType creditsType = NHCreditsType.Fast;
public NHCreditsType creditsType = NHCreditsType.None;
public string gameOverText;
public DeathType deathType = DeathType.Default;
public DeathType? deathType = DeathType.Default;
private GameOverController _gameOverController;
private PlayerCameraEffectController _playerCameraEffectController;
@ -43,15 +43,28 @@ namespace NewHorizons.Components.Volumes
// The PlayerCameraEffectController is what actually kills us, so convince it we're already dead
Locator.GetDeathManager()._isDead = true;
_playerCameraEffectController.OnPlayerDeath(deathType);
var fadeLength = 2f;
if (deathType is DeathType nonNullDeathType)
{
_playerCameraEffectController.OnPlayerDeath(nonNullDeathType);
fadeLength = _playerCameraEffectController._deathFadeLength;
}
else
{
FadeHandler.FadeOut(fadeLength);
}
yield return new WaitForSeconds(_playerCameraEffectController._deathFadeLength);
yield return new WaitForSeconds(fadeLength);
if (!string.IsNullOrEmpty(gameOverText) && _gameOverController != null)
{
_gameOverController._deathText.text = TranslationHandler.GetTranslation(gameOverText, TranslationHandler.TextType.UI);
_gameOverController.SetupGameOverScreen(5f);
// Make sure the fade handler is off now
FadeHandler.FadeIn(0f);
// We set this to true to stop it from loading the credits scene, so we can do it ourselves
_gameOverController._loading = true;
@ -81,6 +94,9 @@ namespace NewHorizons.Components.Volumes
TimelineObliterationController.s_hasRealityEnded = true;
LoadManager.LoadScene(OWScene.Credits_Fast, LoadManager.FadeType.ToBlack);
break;
default:
GlobalMessenger.FireEvent("TriggerFlashback");
break;
}
}
}

View File

@ -7,7 +7,7 @@ namespace NewHorizons.External.Modules.Volumes.VolumeInfos
[JsonObject]
public class LoadCreditsVolumeInfo : VolumeInfo
{
[DefaultValue("fast")] public NHCreditsType creditsType = NHCreditsType.Fast;
[DefaultValue("none")] public NHCreditsType creditsType = NHCreditsType.None;
/// <summary>
/// Text displayed in orange on game over. For localization, put translations under UI.
@ -15,8 +15,8 @@ namespace NewHorizons.External.Modules.Volumes.VolumeInfos
public string gameOverText;
/// <summary>
/// The type of death the player will have if they enter this volume.
/// The type of death the player will have if they enter this volume. Don't set to have the camera just fade out.
/// </summary>
[DefaultValue("default")] public NHDeathType deathType = NHDeathType.Default;
[DefaultValue("default")] public NHDeathType? deathType = null;
}
}

View File

@ -11,6 +11,8 @@ namespace NewHorizons.External.SerializableEnums
[EnumMember(Value = @"final")] Final = 1,
[EnumMember(Value = @"kazoo")] Kazoo = 2
[EnumMember(Value = @"kazoo")] Kazoo = 2,
[EnumMember(Value = @"none")] None = 3
}
}

View File

@ -9,6 +9,8 @@ namespace NewHorizons.Handlers
{
public static void FadeOut(float length) => Delay.StartCoroutine(FadeOutCoroutine(length));
public static void FadeIn(float length) => Delay.StartCoroutine(FadeInCoroutine(length));
private static IEnumerator FadeOutCoroutine(float length)
{
LoadManager.s_instance._fadeCanvas.enabled = true;
@ -25,6 +27,23 @@ namespace NewHorizons.Handlers
yield return new WaitForEndOfFrame();
}
private static IEnumerator FadeInCoroutine(float length)
{
float startTime = Time.unscaledTime;
float endTime = Time.unscaledTime + length;
while (Time.unscaledTime < endTime)
{
LoadManager.s_instance._fadeImage.color = Color.Lerp(Color.black, Color.clear, (Time.unscaledTime - startTime) / length);
yield return new WaitForEndOfFrame();
}
LoadManager.s_instance._fadeCanvas.enabled = false;
LoadManager.s_instance._fadeImage.color = Color.clear;
yield return new WaitForEndOfFrame();
}
public static void FadeThen(float length, Action action) => Delay.StartCoroutine(FadeThenCoroutine(length, action));
private static IEnumerator FadeThenCoroutine(float length, Action action)