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.creditsType = info.creditsType;
volume.gameOverText = info.gameOverText; 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; return volume;
} }

View File

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

View File

@ -7,7 +7,7 @@ namespace NewHorizons.External.Modules.Volumes.VolumeInfos
[JsonObject] [JsonObject]
public class LoadCreditsVolumeInfo : VolumeInfo public class LoadCreditsVolumeInfo : VolumeInfo
{ {
[DefaultValue("fast")] public NHCreditsType creditsType = NHCreditsType.Fast; [DefaultValue("none")] public NHCreditsType creditsType = NHCreditsType.None;
/// <summary> /// <summary>
/// Text displayed in orange on game over. For localization, put translations under UI. /// 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; public string gameOverText;
/// <summary> /// <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> /// </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 = @"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 FadeOut(float length) => Delay.StartCoroutine(FadeOutCoroutine(length));
public static void FadeIn(float length) => Delay.StartCoroutine(FadeInCoroutine(length));
private static IEnumerator FadeOutCoroutine(float length) private static IEnumerator FadeOutCoroutine(float length)
{ {
LoadManager.s_instance._fadeCanvas.enabled = true; LoadManager.s_instance._fadeCanvas.enabled = true;
@ -25,6 +27,23 @@ namespace NewHorizons.Handlers
yield return new WaitForEndOfFrame(); 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)); public static void FadeThen(float length, Action action) => Delay.StartCoroutine(FadeThenCoroutine(length, action));
private static IEnumerator FadeThenCoroutine(float length, Action action) private static IEnumerator FadeThenCoroutine(float length, Action action)