Reload title screen on profile change

This commit is contained in:
Noah Pilarski 2025-02-17 19:17:50 -05:00
parent e07efa9a5c
commit 439093e65d
3 changed files with 50 additions and 1 deletions

View File

@ -13,6 +13,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.SceneManagement;
using Color = UnityEngine.Color;
namespace NewHorizons.Handlers
@ -23,6 +24,7 @@ namespace NewHorizons.Handlers
internal static NewHorizonsBody[] eligibleBodies => Main.BodyDict.Values.ToList().SelectMany(x => x).ToList()
.Where(b => (b.Config.HeightMap != null || b.Config.Atmosphere?.clouds != null) && b.Config.Star == null && b.Config.canShowOnTitle).ToArray();
internal static int eligibleCount => eligibleBodies.Count();
internal static bool reloaded = false;
public static void Init()
{
@ -48,6 +50,7 @@ namespace NewHorizons.Handlers
// Load player data for fact and persistent condition checking
var profileManager = StandaloneProfileManager.SharedInstance;
profileManager.OnProfileSignInComplete += OnProfileSignInComplete;
profileManager.PreInitialize();
profileManager.Initialize();
if (profileManager.currentProfile != null) // check if there is even a profile made yet
@ -105,6 +108,16 @@ namespace NewHorizons.Handlers
}
}
private static void OnProfileSignInComplete(ProfileManagerSignInResult result)
{
NHLogger.LogError($"OnProfileSignInComplete {result}: {StandaloneProfileManager.SharedInstance.currentProfile.profileName}");
reloaded = true;
// Taken and modified from SubmitActionLoadScene.ConfirmSubmit
LoadManager.LoadScene(OWScene.TitleScreen);
Locator.GetMenuInputModule().DisableInputs();
}
public static void InitSubtitles()
{
GameObject subtitleContainer = SearchUtilities.Find("TitleMenu/TitleCanvas/TitleLayoutGroup/Logo_EchoesOfTheEye");

View File

@ -165,7 +165,9 @@ namespace NewHorizons
if (wasUsingCustomTitleScreen != CustomTitleScreen && SceneManager.GetActiveScene().name == "TitleScreen" && _wasConfigured)
{
NHLogger.LogVerbose("Reloading");
SceneManager.LoadScene("TitleScreen", LoadSceneMode.Single);
// Taken and modified from SubmitActionLoadScene.ConfirmSubmit
LoadManager.LoadScene(OWScene.TitleScreen);
Locator.GetMenuInputModule().DisableInputs();
}
_wasConfigured = true;

View File

@ -0,0 +1,34 @@
using HarmonyLib;
using NewHorizons.Handlers;
using NewHorizons.Utility.OWML;
using OWML.Utils;
using UnityEngine;
namespace NewHorizons.Patches;
[HarmonyPatch]
internal static class TitleScenePatches
{
[HarmonyPrefix, HarmonyPatch(typeof(TitleScreenAnimation), nameof(TitleScreenAnimation.Awake))]
public static void TitleScreenAnimation_Awake(TitleScreenAnimation __instance)
{
// Skip Splash on title screen reload
if (TitleSceneHandler.reloaded)
{
TitleSceneHandler.reloaded = false;
TitleScreenAnimation titleScreenAnimation = __instance;
titleScreenAnimation._fadeDuration = 0;
titleScreenAnimation._gamepadSplash = false;
titleScreenAnimation._introPan = false;
TitleAnimationController titleAnimationController = GameObject.FindObjectOfType<TitleAnimationController>();
titleAnimationController._logoFadeDelay = 0.001f;
titleAnimationController._logoFadeDuration = 0.001f;
titleAnimationController._optionsFadeDelay = 0.001f;
titleAnimationController._optionsFadeDuration = 0.001f;
titleAnimationController._optionsFadeSpacing = 0.001f;
titleAnimationController.FadeInTitleLogo();
}
}
}