diff --git a/NewHorizons/Handlers/TitleSceneHandler.cs b/NewHorizons/Handlers/TitleSceneHandler.cs index f441abd6..e7062c76 100644 --- a/NewHorizons/Handlers/TitleSceneHandler.cs +++ b/NewHorizons/Handlers/TitleSceneHandler.cs @@ -19,6 +19,8 @@ namespace NewHorizons.Handlers { public static class TitleSceneHandler { + internal static Dictionary TitleScreenBuilders = new(); + public static void Init() { var planetRoot = SearchUtilities.Find("Scene/Background/PlanetPivot/PlanetRoot"); @@ -41,6 +43,7 @@ namespace NewHorizons.Handlers profileManager.currentProfileInputJSON); + // TODO: Implement handlers as well // TODO: Select one title screen and if it has shareTitleScreen set to true do all the other ones that have it true too. var (mod, config) = Main.TitleScreenConfigs.FirstOrDefault(kvp => kvp.Value.KnowsFact() && kvp.Value.HasCondition()); if (config != null) @@ -369,5 +372,30 @@ namespace NewHorizons.Handlers return meshRenderer; } + + public static void RegisterBuilder(IModBehaviour mod, Action builder, bool disableNHPlanets, bool shareTitleScreen, string conditionRequired, string factRequired) + { + TitleScreenBuilders.SafeAdd(mod, new TitleScreenBuilder(mod, builder, disableNHPlanets, shareTitleScreen, conditionRequired, factRequired)); + } + + internal class TitleScreenBuilder + { + public IModBehaviour mod; + public Action builder; + public bool disableNHPlanets; + public bool shareTitleScreen; + public string conditionRequired; + public string factRequired; + + public TitleScreenBuilder(IModBehaviour mod, Action builder, bool disableNHPlanets, bool shareTitleScreen, string conditionRequired, string factRequired) + { + this.mod = mod; + this.builder = builder; + this.disableNHPlanets = disableNHPlanets; + this.shareTitleScreen = shareTitleScreen; + this.conditionRequired = conditionRequired; + this.factRequired = factRequired; + } + } } } diff --git a/NewHorizons/INewHorizons.cs b/NewHorizons/INewHorizons.cs index c9c3579e..5a1a9b09 100644 --- a/NewHorizons/INewHorizons.cs +++ b/NewHorizons/INewHorizons.cs @@ -233,7 +233,16 @@ namespace NewHorizons /// void SetNextSpawnID(string id); - - void RegisterTitleScreenHandler(Action builder, bool deleteNHPlanets = true, bool shareTitleScreen = false, string conditionRequired = null, string factRequired = null); + /// + /// Registers a builder for the main menu. + /// Call this once before the main menu finishes loading + /// + /// + /// Builder to run when this title screen is selected. + /// If set to true, NH generated planets will not show on the title screen. If false, this title screen has the same chance as other NH planet title screens to show. + /// If set to true, this custom title screen will merge with all other custom title screens with shareTitleScreen set to true. If false, NH will randomly select between this and other valid title screens that are loaded. + /// Persistent condition required for this title screen to appear. + /// Ship log fact required for this title screen to appear. + void RegisterTitleScreenBuilder(IModBehaviour mod, Action builder, bool disableNHPlanets = true, bool shareTitleScreen = false, string conditionRequired = null, string factRequired = null); } } diff --git a/NewHorizons/NewHorizonsApi.cs b/NewHorizons/NewHorizonsApi.cs index 85e1a1a4..e2407347 100644 --- a/NewHorizons/NewHorizonsApi.cs +++ b/NewHorizons/NewHorizonsApi.cs @@ -363,10 +363,7 @@ namespace NewHorizons public void SetNextSpawnID(string id) => PlayerSpawnHandler.TargetSpawnID = id; - // TODO: Implement - public void RegisterTitleScreenHandler(Action builder, bool deleteNHPlanets = true, bool shareTitleScreen = false, string conditionRequired = null, string factRequired = null) - { - throw new NotImplementedException(); - } + public void RegisterTitleScreenBuilder(IModBehaviour mod, Action builder, bool disableNHPlanets = true, bool shareTitleScreen = false, string conditionRequired = null, string factRequired = null) + => TitleSceneHandler.RegisterBuilder(mod, builder, disableNHPlanets, shareTitleScreen, conditionRequired, factRequired); } }