diff --git a/NewHorizons/Handlers/TitleSceneHandler.cs b/NewHorizons/Handlers/TitleSceneHandler.cs index 2a21e6ea..e3fe01a7 100644 --- a/NewHorizons/Handlers/TitleSceneHandler.cs +++ b/NewHorizons/Handlers/TitleSceneHandler.cs @@ -453,6 +453,7 @@ namespace NewHorizons.Handlers public void Add(ITitleScreenBuilder builder) { list.Add(builder); + builder.Index = list.IndexOf(builder); } public bool IsValid => GetRelevantBuilder() != null; @@ -484,23 +485,23 @@ namespace NewHorizons.Handlers public void Build() { - NHLogger.LogVerbose("Building handler: " + mod.ModHelper.Manifest.UniqueName); + NHLogger.LogVerbose($"Building handler {mod.ModHelper.Manifest.UniqueName} #{index}"); try { builder.Invoke(SearchUtilities.Find("Scene")); } catch (Exception e) { - NHLogger.LogError(e); + NHLogger.LogError($"Error while building title screen handler {mod.ModHelper.Manifest.UniqueName} #{index}: {e}"); } try { - Main.Instance.OnTitleScreenLoaded?.Invoke(mod.ModHelper.Manifest.UniqueName); + Main.Instance.OnTitleScreenLoaded?.Invoke(mod.ModHelper.Manifest.UniqueName, index); } catch (Exception e) { - NHLogger.LogError($"Error in event handler for OnTitleScreenLoaded on title screen {mod.ModHelper.Manifest.UniqueName}: {e}"); + NHLogger.LogError($"Error in event handler for OnTitleScreenLoaded on title screen {mod.ModHelper.Manifest.UniqueName} #{index}: {e}"); } } @@ -513,6 +514,9 @@ namespace NewHorizons.Handlers public bool KnowsFact() => string.IsNullOrEmpty(factRequired) || StandaloneProfileManager.SharedInstance.currentProfile != null && ShipLogHandler.KnowsFact(factRequired); public bool HasCondition() => string.IsNullOrEmpty(persistentConditionRequired) || StandaloneProfileManager.SharedInstance.currentProfile != null && PlayerData.GetPersistentCondition(persistentConditionRequired); + + private int index = -1; + public int Index { get => index; set => index = value; } } internal class TitleScreenConfigBuilder : ITitleScreenBuilder @@ -528,23 +532,23 @@ namespace NewHorizons.Handlers public void Build() { - NHLogger.LogVerbose("Building config: " + mod.ModHelper.Manifest.UniqueName); + NHLogger.LogVerbose($"Building config {mod.ModHelper.Manifest.UniqueName} #{index}"); try { BuildConfig(mod, config); } catch (Exception e) { - NHLogger.LogError(e); + NHLogger.LogError($"Error while building title screen config {mod.ModHelper.Manifest.UniqueName} #{index}: {e}"); } try { - Main.Instance.OnTitleScreenLoaded?.Invoke(mod.ModHelper.Manifest.UniqueName); + Main.Instance.OnTitleScreenLoaded?.Invoke(mod.ModHelper.Manifest.UniqueName, index); } catch (Exception e) { - NHLogger.LogError($"Error in event handler for OnTitleScreenLoaded on title screen {mod.ModHelper.Manifest.UniqueName}: {e}"); + NHLogger.LogError($"Error in event handler for OnTitleScreenLoaded on title screen {mod.ModHelper.Manifest.UniqueName} #{index}: {e}"); } } @@ -557,6 +561,9 @@ namespace NewHorizons.Handlers public bool KnowsFact() => string.IsNullOrEmpty(config.factRequiredForTitle) || StandaloneProfileManager.SharedInstance.currentProfile != null && ShipLogHandler.KnowsFact(config.factRequiredForTitle); public bool HasCondition() => string.IsNullOrEmpty(config.persistentConditionRequiredForTitle) || StandaloneProfileManager.SharedInstance.currentProfile != null && PlayerData.GetPersistentCondition(config.persistentConditionRequiredForTitle); + + private int index = -1; + public int Index { get => index; set => index = value; } } internal interface ITitleScreenBuilder @@ -570,6 +577,8 @@ namespace NewHorizons.Handlers void Build(); bool KnowsFact(); bool HasCondition(); + + int Index { get; set; } } /// diff --git a/NewHorizons/INewHorizons.cs b/NewHorizons/INewHorizons.cs index 9d85239c..07512ad6 100644 --- a/NewHorizons/INewHorizons.cs +++ b/NewHorizons/INewHorizons.cs @@ -76,9 +76,9 @@ namespace NewHorizons /// /// An event invoked when NH has finished building a title screen. - /// Gives the unique name of the mod the title screen builder was from. + /// Gives the unique name of the mod the title screen builder was from and the index for when you have multiple title screens. /// - UnityEvent GetTitleScreenLoadedEvent(); + UnityEvent GetTitleScreenLoadedEvent(); /// /// An event invoked when NH has finished building the title screen. diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 3fc6b689..8569da89 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -112,7 +112,8 @@ namespace NewHorizons public StringEvent OnChangeStarSystem = new(); public StringEvent OnStarSystemLoaded = new(); public StringEvent OnPlanetLoaded = new(); - public StringEvent OnTitleScreenLoaded = new(); + public class StringIndexEvent : UnityEvent { } + public StringIndexEvent OnTitleScreenLoaded = new(); public UnityEvent OnAllTitleScreensLoaded = new(); /// diff --git a/NewHorizons/NewHorizonsApi.cs b/NewHorizons/NewHorizonsApi.cs index 80a318d1..14a4fdcf 100644 --- a/NewHorizons/NewHorizonsApi.cs +++ b/NewHorizons/NewHorizonsApi.cs @@ -90,7 +90,7 @@ namespace NewHorizons public UnityEvent GetChangeStarSystemEvent() => Main.Instance.OnChangeStarSystem; public UnityEvent GetStarSystemLoadedEvent() => Main.Instance.OnStarSystemLoaded; public UnityEvent GetBodyLoadedEvent() => Main.Instance.OnPlanetLoaded; - public UnityEvent GetTitleScreenLoadedEvent() => Main.Instance.OnTitleScreenLoaded; + public UnityEvent GetTitleScreenLoadedEvent() => Main.Instance.OnTitleScreenLoaded; public UnityEvent GetAllTitleScreensLoadedEvent() => Main.Instance.OnAllTitleScreensLoaded; public bool SetDefaultSystem(string name)