From b5ec327c3b2301fc19ae5306472284f935cc3efe Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 12 Mar 2024 13:19:58 -0400 Subject: [PATCH 1/6] Track new fog warp volumes and only patch those --- .../Builder/Props/BrambleNodeBuilder.cs | 11 +++++++ .../VolumePatches/FogWarpVolumePatches.cs | 31 ++++++++++++++++--- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs index 3e5437e7..a6d2122f 100644 --- a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs +++ b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs @@ -33,12 +33,17 @@ namespace NewHorizons.Builder.Props private static GameObject _brambleSeedPrefab; private static GameObject _brambleNodePrefab; + private static HashSet _nhFogWarpVolumes = new(); + + public static bool IsNHFogWarpVolume(FogWarpVolume volume) => _nhFogWarpVolumes.Contains(volume); + public static void Init(PlanetConfig[] dimensionConfigs) { _unpairedNodes.Clear(); _propagatedSignals.Clear(); namedNodes.Clear(); builtBrambleNodes.Clear(); + _nhFogWarpVolumes.Clear(); PropagateSignals(dimensionConfigs); } @@ -190,6 +195,12 @@ namespace NewHorizons.Builder.Props collider.enabled = true; } + // We track all the fog warp volumes that NH created so we can only effect those in patches, this way we leave base game stuff alone. + foreach (var fogWarpVolume in brambleNode.GetComponentsInChildren(true).Append(brambleNode.GetComponent())) + { + _nhFogWarpVolumes.Add(fogWarpVolume); + } + var innerFogWarpVolume = brambleNode.GetComponent(); var outerFogWarpVolume = GetOuterFogWarpVolumeFromAstroObject(go); var fogLight = brambleNode.GetComponent(); diff --git a/NewHorizons/Patches/VolumePatches/FogWarpVolumePatches.cs b/NewHorizons/Patches/VolumePatches/FogWarpVolumePatches.cs index f63bad81..8deb368b 100644 --- a/NewHorizons/Patches/VolumePatches/FogWarpVolumePatches.cs +++ b/NewHorizons/Patches/VolumePatches/FogWarpVolumePatches.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using NewHorizons.Builder.Props; using UnityEngine; namespace NewHorizons.Patches.VolumePatches @@ -8,20 +9,40 @@ namespace NewHorizons.Patches.VolumePatches { [HarmonyPrefix] [HarmonyPatch(typeof(SphericalFogWarpVolume), nameof(SphericalFogWarpVolume.IsProbeOnly))] - public static bool SphericalFogWarpVolume_IsProbeOnly(SphericalFogWarpVolume __instance, out bool __result) + public static bool SphericalFogWarpVolume_IsProbeOnly(SphericalFogWarpVolume __instance, ref bool __result) { + // Do not affect base game volumes + if (!BrambleNodeBuilder.IsNHFogWarpVolume(__instance)) + { + return true; + } + __result = Mathf.Approximately(__instance._exitRadius / __instance._warpRadius, 2f); // Check the ratio between these to determine if seed, instead of just < 10 return false; } [HarmonyPrefix] [HarmonyPatch(typeof(FogWarpVolume), nameof(FogWarpVolume.GetFogThickness))] - public static bool FogWarpVolume_GetFogThickness(FogWarpVolume __instance, out float __result) + public static bool FogWarpVolume_GetFogThickness(FogWarpVolume __instance, ref float __result) { - if (__instance is InnerFogWarpVolume sph) __result = sph._exitRadius; - else __result = 50; // 50f is hardcoded as the return value in the base game + // Do not affect base game volumes + if (!BrambleNodeBuilder.IsNHFogWarpVolume(__instance)) + { + return true; + } - return false; + if (__instance is InnerFogWarpVolume sph) + { + __result = sph._exitRadius; + return false; + } + else + { + // Base game is hardcoded to this + // Except for capsule volumes so either those are unused or whoever said this is a liar! + __result = 50f; + return true; + } } } } From 7bfe3d2fd1b099be2f5fcfce6369f9630a233265 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 12 Mar 2024 13:26:22 -0400 Subject: [PATCH 2/6] Remove unused volume --- NewHorizons/Components/Volumes/NHInnerFogWarpVolume.cs | 8 -------- NewHorizons/Patches/VolumePatches/FogWarpVolumePatches.cs | 3 ++- 2 files changed, 2 insertions(+), 9 deletions(-) delete mode 100644 NewHorizons/Components/Volumes/NHInnerFogWarpVolume.cs diff --git a/NewHorizons/Components/Volumes/NHInnerFogWarpVolume.cs b/NewHorizons/Components/Volumes/NHInnerFogWarpVolume.cs deleted file mode 100644 index 70d74979..00000000 --- a/NewHorizons/Components/Volumes/NHInnerFogWarpVolume.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace NewHorizons.Components.Volumes -{ - public class NHInnerFogWarpVolume : InnerFogWarpVolume - { - public override bool IsProbeOnly() => _exitRadius <= 6; - public override float GetFogThickness() => _exitRadius; - } -} diff --git a/NewHorizons/Patches/VolumePatches/FogWarpVolumePatches.cs b/NewHorizons/Patches/VolumePatches/FogWarpVolumePatches.cs index 8deb368b..a4999837 100644 --- a/NewHorizons/Patches/VolumePatches/FogWarpVolumePatches.cs +++ b/NewHorizons/Patches/VolumePatches/FogWarpVolumePatches.cs @@ -17,7 +17,8 @@ namespace NewHorizons.Patches.VolumePatches return true; } - __result = Mathf.Approximately(__instance._exitRadius / __instance._warpRadius, 2f); // Check the ratio between these to determine if seed, instead of just < 10 + // Check the ratio between these to determine if seed, instead of just < 10 + __result = Mathf.Approximately(__instance._exitRadius / __instance._warpRadius, 2f); return false; } From b1b7f439050a869ada768a53f9a9e6f956754709 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 12 Mar 2024 13:59:31 -0400 Subject: [PATCH 3/6] Fix bramble seeds being the wrong size --- NewHorizons/Builder/Props/BrambleNodeBuilder.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs index a6d2122f..2aa1075e 100644 --- a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs +++ b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs @@ -250,6 +250,12 @@ namespace NewHorizons.Builder.Props foreach(Transform child in brambleNode.transform) { child.localScale = Vector3.one * config.scale; + + // The fog on bramble seeds has a specific scale we need to copy over + if (child.name == "VolumetricFogSphere (2)") + { + child.localScale *= 6.3809f; + } } innerFogWarpVolume._warpRadius *= config.scale; innerFogWarpVolume._exitRadius *= config.scale; From c615902702cd39cfe3cf01e2f8e49a76312a51f2 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 12 Mar 2024 16:01:38 -0400 Subject: [PATCH 4/6] Subtitles can now be larger, added subtitle to api (outsider compat) --- NewHorizons/Handlers/SubtitlesHandler.cs | 74 +++++++++++++++++------- NewHorizons/INewHorizons.cs | 8 +++ NewHorizons/NewHorizonsApi.cs | 2 + 3 files changed, 64 insertions(+), 20 deletions(-) diff --git a/NewHorizons/Handlers/SubtitlesHandler.cs b/NewHorizons/Handlers/SubtitlesHandler.cs index de283b54..04706388 100644 --- a/NewHorizons/Handlers/SubtitlesHandler.cs +++ b/NewHorizons/Handlers/SubtitlesHandler.cs @@ -14,9 +14,6 @@ namespace NewHorizons.Handlers public static int SUBTITLE_HEIGHT = 97; public static int SUBTITLE_WIDTH = 669; // nice - public Graphic graphic; - public Image image; - public float fadeSpeed = 0.005f; public float fade = 1; public bool fadingAway = true; @@ -29,13 +26,27 @@ namespace NewHorizons.Handlers public static readonly int PAUSE_TIMER_MAX = 50; public int pauseTimer = PAUSE_TIMER_MAX; + private Image _subtitleDisplay; + private Graphic _graphic; + + private static List<(IModBehaviour mod, string filePath)> _additionalSubtitles = new(); + + public static void RegisterAdditionalSubtitle(IModBehaviour mod, string filePath) + { + _additionalSubtitles.Add((mod, filePath)); + } + public void CheckForEOTE() { if (!eoteSubtitleHasBeenInserted) { if (Main.HasDLC) { - if (eoteSprite != null) possibleSubtitles.Insert(0, eoteSprite); // ensure that the Echoes of the Eye subtitle always appears first + if (eoteSprite != null) + { + // Don't make it appear first actually because we have mods to display! + possibleSubtitles.Add(eoteSprite); + } eoteSubtitleHasBeenInserted = true; } } @@ -43,18 +54,24 @@ namespace NewHorizons.Handlers public void Start() { + // We preserve the current image to add it to our custom subtitle + // We also need this element to preserve its size GetComponent().alpha = 1; - graphic = GetComponent(); - image = GetComponent(); - - graphic.enabled = true; - image.enabled = true; - + var image = GetComponent(); eoteSprite = image.sprite; + image.sprite = null; + image.enabled = false; + var layout = GetComponent(); + layout.minHeight = SUBTITLE_HEIGHT; CheckForEOTE(); - image.sprite = null; // Just in case. I don't know how not having the dlc changes the subtitle game object + // We add our subtitles as a child object so that their sizing doesnt shift the layout of the main menu + _subtitleDisplay = new GameObject().AddComponent(); + _subtitleDisplay.transform.parent = transform; + _subtitleDisplay.transform.localPosition = new Vector3(0, 0, 0); + _subtitleDisplay.transform.localScale = new Vector3(0.75f, 0.75f, 0.75f); + _graphic = _subtitleDisplay.gameObject.GetAddComponent(); AddSubtitles(); } @@ -73,6 +90,10 @@ namespace NewHorizons.Handlers AddSubtitle(mod, "subtitle.png"); } } + foreach (var pair in _additionalSubtitles) + { + AddSubtitle(pair.mod, pair.filePath); + } } public void AddSubtitle(IModBehaviour mod, string filepath) @@ -82,7 +103,7 @@ namespace NewHorizons.Handlers var tex = ImageUtilities.GetTexture(mod, filepath, false); if (tex == null) return; - var sprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, SUBTITLE_HEIGHT), new Vector2(0.5f, 0.5f), 100.0f); + var sprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, Mathf.Max(SUBTITLE_HEIGHT, tex.height)), new Vector2(0.5f, 0.5f), 100.0f); AddSubtitle(sprite); } @@ -95,12 +116,23 @@ namespace NewHorizons.Handlers { CheckForEOTE(); - if (possibleSubtitles.Count == 0) return; + if (possibleSubtitles.Count == 0) + { + return; + } - if (image.sprite == null) image.sprite = possibleSubtitles[0]; + _subtitleDisplay.transform.localPosition = new Vector3(0, -36, 0); + + if (_subtitleDisplay.sprite == null) + { + _subtitleDisplay.sprite = possibleSubtitles[0]; + } // don't fade transition subtitles if there's only one subtitle - if (possibleSubtitles.Count <= 1) return; + if (possibleSubtitles.Count <= 1) + { + return; + } if (pauseTimer > 0) { @@ -111,7 +143,7 @@ namespace NewHorizons.Handlers if (fadingAway) { fade -= fadeSpeed; - + if (fade <= 0) { fade = 0; @@ -122,7 +154,7 @@ namespace NewHorizons.Handlers else { fade += fadeSpeed; - + if (fade >= 1) { fade = 1; @@ -131,14 +163,16 @@ namespace NewHorizons.Handlers } } - graphic.color = new Color(1, 1, 1, fade); + _graphic.color = new Color(1, 1, 1, fade); } public void ChangeSubtitle() { subtitleIndex = (subtitleIndex + 1) % possibleSubtitles.Count; - - image.sprite = possibleSubtitles[subtitleIndex]; + + _subtitleDisplay.sprite = possibleSubtitles[subtitleIndex]; + var ratio = SUBTITLE_WIDTH / _subtitleDisplay.sprite.texture.width; + _subtitleDisplay.rectTransform.sizeDelta = new Vector2(_subtitleDisplay.sprite.texture.width, _subtitleDisplay.sprite.texture.height) * ratio; } } } diff --git a/NewHorizons/INewHorizons.cs b/NewHorizons/INewHorizons.cs index 22132568..4dfd2d1f 100644 --- a/NewHorizons/INewHorizons.cs +++ b/NewHorizons/INewHorizons.cs @@ -207,5 +207,13 @@ namespace NewHorizons /// string GetTranslationForOtherText(string text); #endregion + + /// + /// Registers a subtitle for the main menu. + /// Call this once before the main menu finishes loading + /// + /// + /// + void AddSubtitle(IModBehaviour mod, string filePath); } } diff --git a/NewHorizons/NewHorizonsApi.cs b/NewHorizons/NewHorizonsApi.cs index a96673d5..6a165fa2 100644 --- a/NewHorizons/NewHorizonsApi.cs +++ b/NewHorizons/NewHorizonsApi.cs @@ -336,5 +336,7 @@ namespace NewHorizons public string GetTranslationForUI(string text) => TranslationHandler.GetTranslation(text, TranslationHandler.TextType.UI); public string GetTranslationForOtherText(string text) => TranslationHandler.GetTranslation(text, TranslationHandler.TextType.OTHER); + + public void AddSubtitle(IModBehaviour mod, string filePath) => SubtitlesHandler.RegisterAdditionalSubtitle(mod, filePath); } } From 90c3b9b785cdbd534371a5b6986439515aff19c1 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 12 Mar 2024 16:19:05 -0400 Subject: [PATCH 5/6] Fix subtitle breaking when theres only one --- NewHorizons/Handlers/SubtitlesHandler.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NewHorizons/Handlers/SubtitlesHandler.cs b/NewHorizons/Handlers/SubtitlesHandler.cs index 04706388..7207a8a5 100644 --- a/NewHorizons/Handlers/SubtitlesHandler.cs +++ b/NewHorizons/Handlers/SubtitlesHandler.cs @@ -72,6 +72,7 @@ namespace NewHorizons.Handlers _subtitleDisplay.transform.localPosition = new Vector3(0, 0, 0); _subtitleDisplay.transform.localScale = new Vector3(0.75f, 0.75f, 0.75f); _graphic = _subtitleDisplay.gameObject.GetAddComponent(); + _subtitleDisplay.gameObject.GetAddComponent().minWidth = SUBTITLE_WIDTH; AddSubtitles(); } @@ -126,6 +127,8 @@ namespace NewHorizons.Handlers if (_subtitleDisplay.sprite == null) { _subtitleDisplay.sprite = possibleSubtitles[0]; + // Always call this in case we stop changing subtitles after + ChangeSubtitle(); } // don't fade transition subtitles if there's only one subtitle From 4997b915f6675cca3d1a99ce94584f438827fa7c Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 12 Mar 2024 18:00:54 -0400 Subject: [PATCH 6/6] Just return true --- NewHorizons/Patches/VolumePatches/FogWarpVolumePatches.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/NewHorizons/Patches/VolumePatches/FogWarpVolumePatches.cs b/NewHorizons/Patches/VolumePatches/FogWarpVolumePatches.cs index a4999837..41f3e652 100644 --- a/NewHorizons/Patches/VolumePatches/FogWarpVolumePatches.cs +++ b/NewHorizons/Patches/VolumePatches/FogWarpVolumePatches.cs @@ -39,9 +39,6 @@ namespace NewHorizons.Patches.VolumePatches } else { - // Base game is hardcoded to this - // Except for capsule volumes so either those are unused or whoever said this is a liar! - __result = 50f; return true; } }