diff --git a/NewHorizons/Assets/translations/english.json b/NewHorizons/Assets/translations/english.json index 9d1a4c28..c5e6db88 100644 --- a/NewHorizons/Assets/translations/english.json +++ b/NewHorizons/Assets/translations/english.json @@ -22,7 +22,8 @@ "DEBUG_PLACE_TEXT": "Place Nomai Text", "DEBUG_UNDO": "Undo", "DEBUG_REDO": "Redo", - "Vessel": "Vessel" + "Vessel": "Vessel", + "NOMAI_SHUTTLE_COMPUTER": "The shuttle]]> is currently resting at {0}]]>." }, "AchievementTranslations": { "NH_EATEN_OUTSIDE_BRAMBLE": { diff --git a/NewHorizons/Builder/Props/GravityCannonBuilder.cs b/NewHorizons/Builder/Props/GravityCannonBuilder.cs index 0ff5e845..9979e7ec 100644 --- a/NewHorizons/Builder/Props/GravityCannonBuilder.cs +++ b/NewHorizons/Builder/Props/GravityCannonBuilder.cs @@ -1,10 +1,14 @@ using NewHorizons.Builder.Props.TranslatorText; +using NewHorizons.Components.Orbital; using NewHorizons.External.Modules; using NewHorizons.External.Modules.Props; using NewHorizons.External.Modules.Props.Shuttle; +using NewHorizons.External.Modules.TranslatorText; using NewHorizons.Handlers; using NewHorizons.Utility; +using NewHorizons.Utility.OuterWilds; using NewHorizons.Utility.OWML; +using Newtonsoft.Json; using OWML.Common; using UnityEngine; @@ -76,7 +80,8 @@ namespace NewHorizons.Builder.Props gravityCannonObject.SetActive(false); var gravityCannonController = gravityCannonObject.GetComponent(); - gravityCannonController._shuttleID = ShuttleHandler.GetShuttleID(info.shuttleID); + var id = ShuttleHandler.GetShuttleID(info.shuttleID); + gravityCannonController._shuttleID = id; // Gravity controller checks string length instead of isnullorempty gravityCannonController._retrieveShipLogFact = info.retrieveReveal ?? string.Empty; @@ -86,7 +91,11 @@ namespace NewHorizons.Builder.Props if (info.computer != null) { - gravityCannonController._nomaiComputer = CreateComputer(planetGO, sector, info.computer); + // Do it next update so that the shuttle has been made + Delay.FireOnNextUpdate(() => + { + gravityCannonController._nomaiComputer = CreateComputer(planetGO, sector, info.computer, id); + }); } else { @@ -140,14 +149,23 @@ namespace NewHorizons.Builder.Props }, () => Main.IsSystemReady, 10); } - private static NomaiComputer CreateComputer(GameObject planetGO, Sector sector, GeneralPropInfo computerInfo) + private static NomaiComputer CreateComputer(GameObject planetGO, Sector sector, GeneralPropInfo computerInfo, NomaiShuttleController.ShuttleID id) { - var computerObject = DetailBuilder.Make(planetGO, sector, TranslatorTextBuilder.ComputerPrefab, new DetailInfo(computerInfo)); + // Load the position info from the GeneralPropInfo + var translatorTextInfo = new TranslatorTextInfo(); + JsonConvert.PopulateObject(JsonConvert.SerializeObject(computerInfo), translatorTextInfo); + translatorTextInfo.type = NomaiTextType.Computer; + + var shuttle = ShuttleBuilder.Shuttles[id]; + var planet = AstroObjectLocator.GetPlanetName(shuttle.GetComponentInParent()); + + var displayText = TranslationHandler.GetTranslation("NOMAI_SHUTTLE_COMPUTER", TranslationHandler.TextType.UI).Replace("{0}", planet); + NHLogger.Log(displayText); + var xmlContent = $"\r\n \r\n 1\r\n {displayText}\r\n \r\n"; + + var computerObject = TranslatorTextBuilder.Make(planetGO, sector, translatorTextInfo, null, xmlContent); var computer = computerObject.GetComponentInChildren(); - computer.SetSector(sector); - - Delay.FireOnNextUpdate(computer.ClearAllEntries); computerObject.SetActive(true); diff --git a/NewHorizons/Builder/Props/ShuttleBuilder.cs b/NewHorizons/Builder/Props/ShuttleBuilder.cs index 8ea32716..06d8dabb 100644 --- a/NewHorizons/Builder/Props/ShuttleBuilder.cs +++ b/NewHorizons/Builder/Props/ShuttleBuilder.cs @@ -3,6 +3,7 @@ using NewHorizons.External.Modules.Props; using NewHorizons.External.Modules.Props.Shuttle; using NewHorizons.Handlers; using NewHorizons.Utility; +using System.Collections.Generic; using UnityEngine; namespace NewHorizons.Builder.Props @@ -13,6 +14,8 @@ namespace NewHorizons.Builder.Props private static GameObject _orbPrefab; private static GameObject _bodyPrefab; + public static Dictionary Shuttles { get; } = new(); + internal static void InitPrefab() { if (_prefab == null) @@ -108,6 +111,8 @@ namespace NewHorizons.Builder.Props orbObject.SetActive(true); shuttleController._orb.RemoveAllLocks(); + Shuttles[id] = shuttleController; + return shuttleObject; } } diff --git a/NewHorizons/Builder/Props/TranslatorText/TranslatorTextBuilder.cs b/NewHorizons/Builder/Props/TranslatorText/TranslatorTextBuilder.cs index b189ee75..42769576 100644 --- a/NewHorizons/Builder/Props/TranslatorText/TranslatorTextBuilder.cs +++ b/NewHorizons/Builder/Props/TranslatorText/TranslatorTextBuilder.cs @@ -1,7 +1,7 @@ using NewHorizons.External; using NewHorizons.External.Modules.Props; -using NewHorizons.External.SerializableData; using NewHorizons.External.Modules.TranslatorText; +using NewHorizons.External.SerializableData; using NewHorizons.Handlers; using NewHorizons.Utility; using NewHorizons.Utility.Geometry; @@ -14,7 +14,6 @@ using System.IO; using System.Linq; using System.Xml; using UnityEngine; - using Random = UnityEngine.Random; namespace NewHorizons.Builder.Props.TranslatorText @@ -137,6 +136,11 @@ namespace NewHorizons.Builder.Props.TranslatorText return null; } + return Make(planetGO, sector, info, nhBody, xmlContent); + } + + public static GameObject Make(GameObject planetGO, Sector sector, TranslatorTextInfo info, NewHorizonsBody nhBody, string xmlContent) + { switch (info.type) { case NomaiTextType.Wall: @@ -401,7 +405,7 @@ namespace NewHorizons.Builder.Props.TranslatorText } } - private static NomaiWallText MakeWallText(GameObject go, Sector sector, TranslatorTextInfo info, string xmlPath, NewHorizonsBody nhBody) + private static NomaiWallText MakeWallText(GameObject go, Sector sector, TranslatorTextInfo info, string xmlContent, NewHorizonsBody nhBody) { GameObject nomaiWallTextObj = new GameObject("NomaiWallText"); nomaiWallTextObj.SetActive(false); @@ -418,13 +422,13 @@ namespace NewHorizons.Builder.Props.TranslatorText nomaiWallText._location = EnumUtils.Parse(info.location.ToString()); - var text = new TextAsset(xmlPath); + var text = new TextAsset(xmlContent); // Text assets need a name to be used with VoiceMod text.name = Path.GetFileNameWithoutExtension(info.xmlFile); - BuildArcs(xmlPath, nomaiWallText, nomaiWallTextObj, info, nhBody); - AddTranslation(xmlPath); + BuildArcs(xmlContent, nomaiWallText, nomaiWallTextObj, info, nhBody); + AddTranslation(xmlContent); nomaiWallText._nomaiTextAsset = text; nomaiWallText.SetTextAsset(text); diff --git a/NewHorizons/Handlers/TranslationHandler.cs b/NewHorizons/Handlers/TranslationHandler.cs index 3447c725..62da21ab 100644 --- a/NewHorizons/Handlers/TranslationHandler.cs +++ b/NewHorizons/Handlers/TranslationHandler.cs @@ -8,9 +8,9 @@ namespace NewHorizons.Handlers { public static class TranslationHandler { - private static Dictionary> _shipLogTranslationDictionary = new Dictionary>(); - private static Dictionary> _dialogueTranslationDictionary = new Dictionary>(); - private static Dictionary> _uiTranslationDictionary = new Dictionary>(); + private static Dictionary> _shipLogTranslationDictionary = new(); + private static Dictionary> _dialogueTranslationDictionary = new(); + private static Dictionary> _uiTranslationDictionary = new(); public enum TextType { @@ -93,8 +93,9 @@ namespace NewHorizons.Handlers if (!_uiTranslationDictionary.ContainsKey(language)) _uiTranslationDictionary.Add(language, new Dictionary()); foreach (var originalKey in config.UIDictionary.Keys) { - var key = originalKey.Replace("<", "<").Replace(">", ">").Replace("", ""); - var value = config.UIDictionary[originalKey].Replace("<", "<").Replace(">", ">").Replace("", ""); + // Don't remove CDATA from UI + var key = originalKey.Replace("<", "<").Replace(">", ">"); + var value = config.UIDictionary[originalKey].Replace("<", "<").Replace(">", ">"); if (!_uiTranslationDictionary[language].ContainsKey(key)) _uiTranslationDictionary[language].Add(key, value); else _uiTranslationDictionary[language][key] = value; diff --git a/NewHorizons/Utility/OuterWilds/AstroObjectLocator.cs b/NewHorizons/Utility/OuterWilds/AstroObjectLocator.cs index 88d46e51..b1aba93e 100644 --- a/NewHorizons/Utility/OuterWilds/AstroObjectLocator.cs +++ b/NewHorizons/Utility/OuterWilds/AstroObjectLocator.cs @@ -1,5 +1,7 @@ using System.Collections.Generic; using System.Linq; +using NewHorizons.Components.Orbital; +using NewHorizons.Handlers; using NewHorizons.Utility.OWML; using UnityEngine; @@ -177,5 +179,32 @@ namespace NewHorizons.Utility.OuterWilds return otherChildren.ToArray(); } + + public static string GetPlanetName(AstroObject astroObject) + { + if (astroObject != null) + { + if (astroObject is NHAstroObject nhAstroObject) + { + var customName = nhAstroObject.GetCustomName(); + + if (!string.IsNullOrWhiteSpace(customName)) + { + return TranslationHandler.GetTranslation(customName, TranslationHandler.TextType.UI, false); + } + } + else + { + AstroObject.Name astroObjectName = astroObject.GetAstroObjectName(); + + if (astroObjectName - AstroObject.Name.Sun <= 7 || astroObjectName - AstroObject.Name.TimberMoon <= 1) + { + return AstroObject.AstroObjectNameToString(astroObject.GetAstroObjectName()); + } + } + } + + return "???"; + } } }