diff --git a/NewHorizons/Builder/General/AstroObjectBuilder.cs b/NewHorizons/Builder/General/AstroObjectBuilder.cs index f51ab71f..5e5f0927 100644 --- a/NewHorizons/Builder/General/AstroObjectBuilder.cs +++ b/NewHorizons/Builder/General/AstroObjectBuilder.cs @@ -7,9 +7,10 @@ namespace NewHorizons.Builder.General { public static class AstroObjectBuilder { - public static NHAstroObject Make(GameObject body, AstroObject primaryBody, PlanetConfig config) + public static NHAstroObject Make(GameObject body, AstroObject primaryBody, PlanetConfig config, bool isVanilla) { NHAstroObject astroObject = body.AddComponent(); + astroObject.isVanilla = isVanilla; astroObject.HideDisplayName = !config.Base.hasMapMarker; astroObject.invulnerableToSun = config.Base.invulnerableToSun; diff --git a/NewHorizons/Components/Orbital/NHAstroObject.cs b/NewHorizons/Components/Orbital/NHAstroObject.cs index 2087bf8c..ed51060c 100644 --- a/NewHorizons/Components/Orbital/NHAstroObject.cs +++ b/NewHorizons/Components/Orbital/NHAstroObject.cs @@ -12,6 +12,7 @@ namespace NewHorizons.Components.Orbital public bool HideDisplayName { get; set; } public bool IsDimension { get; set; } public bool invulnerableToSun; + public bool isVanilla; public void SetOrbitalParametersFromConfig(OrbitModule orbit) { diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 8d0eceee..532052e2 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -343,7 +343,7 @@ namespace NewHorizons.Handlers body.Config.Base.hasMapMarker = false; var owRigidBody = RigidBodyBuilder.Make(go, body.Config); - var ao = AstroObjectBuilder.Make(go, null, body.Config); + var ao = AstroObjectBuilder.Make(go, null, body.Config, false); var sector = SectorBuilder.Make(go, owRigidBody, 2000f); ao._rootSector = sector; @@ -409,7 +409,7 @@ namespace NewHorizons.Handlers } var owRigidBody = RigidBodyBuilder.Make(go, body.Config); - var ao = AstroObjectBuilder.Make(go, primaryBody, body.Config); + var ao = AstroObjectBuilder.Make(go, primaryBody, body.Config, false); var sphereOfInfluence = GetSphereOfInfluence(body); @@ -702,7 +702,7 @@ namespace NewHorizons.Handlers } // Just destroy the existing AO after copying everything over - var newAO = AstroObjectBuilder.Make(go, primary, body.Config); + var newAO = AstroObjectBuilder.Make(go, primary, body.Config, true); newAO._gravityVolume = ao._gravityVolume; newAO._moon = ao._moon; newAO._name = ao._name; diff --git a/NewHorizons/Patches/MapPatches/ReferenceFramePatches.cs b/NewHorizons/Patches/MapPatches/ReferenceFramePatches.cs index a9efb8b1..ba8deac6 100644 --- a/NewHorizons/Patches/MapPatches/ReferenceFramePatches.cs +++ b/NewHorizons/Patches/MapPatches/ReferenceFramePatches.cs @@ -7,32 +7,19 @@ namespace NewHorizons.Patches.MapPatches [HarmonyPatch(typeof(ReferenceFrame))] public static class ReferenceFramePatches { - [HarmonyPrefix] + [HarmonyPostfix] [HarmonyPatch(nameof(ReferenceFrame.GetHUDDisplayName))] - public static bool ReferenceFrame_GetHUDDisplayName(ReferenceFrame __instance, ref string __result) + public static void ReferenceFrame_GetHUDDisplayName(ReferenceFrame __instance, ref string __result) { - var ao = __instance.GetAstroObject(); - - if (ao == null) return true; - - if (ao._name != AstroObject.Name.CustomString) + if (__instance.GetAstroObject() is NHAstroObject nhao && !nhao.isVanilla && !nhao.HideDisplayName) { - __result = AstroObject.AstroObjectNameToString(ao._name); - return false; + var customName = nhao.GetCustomName(); + + if (!string.IsNullOrWhiteSpace(customName)) + { + __result = TranslationHandler.GetTranslation(customName, TranslationHandler.TextType.UI, false); + } } - - __result = string.Empty; - - if (ao is NHAstroObject nhao && nhao.HideDisplayName) return false; - - var customName = ao.GetCustomName(); - - if (!string.IsNullOrWhiteSpace(customName)) - { - __result = TranslationHandler.GetTranslation(customName, TranslationHandler.TextType.UI, false); - } - - return false; } } }