This commit is contained in:
Noah Pilarski 2025-02-17 14:20:22 -05:00
parent 2869544b92
commit d9441f5140
4 changed files with 22 additions and 12 deletions

View File

@ -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; }
}
/// <summary>

View File

@ -76,9 +76,9 @@ namespace NewHorizons
/// <summary>
/// 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.
/// </summary>
UnityEvent<string> GetTitleScreenLoadedEvent();
UnityEvent<string, int> GetTitleScreenLoadedEvent();
/// <summary>
/// An event invoked when NH has finished building the title screen.

View File

@ -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<string, int> { }
public StringIndexEvent OnTitleScreenLoaded = new();
public UnityEvent OnAllTitleScreensLoaded = new();
/// <summary>

View File

@ -90,7 +90,7 @@ namespace NewHorizons
public UnityEvent<string> GetChangeStarSystemEvent() => Main.Instance.OnChangeStarSystem;
public UnityEvent<string> GetStarSystemLoadedEvent() => Main.Instance.OnStarSystemLoaded;
public UnityEvent<string> GetBodyLoadedEvent() => Main.Instance.OnPlanetLoaded;
public UnityEvent<string> GetTitleScreenLoadedEvent() => Main.Instance.OnTitleScreenLoaded;
public UnityEvent<string, int> GetTitleScreenLoadedEvent() => Main.Instance.OnTitleScreenLoaded;
public UnityEvent GetAllTitleScreensLoadedEvent() => Main.Instance.OnAllTitleScreensLoaded;
public bool SetDefaultSystem(string name)