Support translating star system names (#136)

Fixes #136
This commit is contained in:
Nick 2022-05-19 17:00:13 -04:00
parent 5962c652bd
commit 39840b18a7
3 changed files with 27 additions and 19 deletions

View File

@ -87,9 +87,9 @@ namespace NewHorizons.Components
*/ */
} }
public void AddSystemCard(string starSystem) public void AddSystemCard(string uniqueID)
{ {
var card = CreateCard(starSystem, root.transform, new Vector2(_nextCardIndex++ * 200, 0)); var card = CreateCard(uniqueID, root.transform, new Vector2(_nextCardIndex++ * 200, 0));
_starSystemCards.Add(card); _starSystemCards.Add(card);
} }
@ -132,7 +132,7 @@ namespace NewHorizons.Components
} }
} }
public GameObject CreateCard(string uniqueName, Transform parent, Vector2 position) public GameObject CreateCard(string uniqueID, Transform parent, Vector2 position)
{ {
if (_cardTemplate == null) if (_cardTemplate == null)
{ {
@ -143,12 +143,14 @@ namespace NewHorizons.Components
var newCard = GameObject.Instantiate(_cardTemplate, parent); var newCard = GameObject.Instantiate(_cardTemplate, parent);
var textComponent = newCard.transform.Find("EntryCardRoot/NameBackground/Name").GetComponent<UnityEngine.UI.Text>(); var textComponent = newCard.transform.Find("EntryCardRoot/NameBackground/Name").GetComponent<UnityEngine.UI.Text>();
var name = UniqueNameToString(uniqueName);
var name = UniqueIDToName(uniqueID);
textComponent.text = name; textComponent.text = name;
if (name.Length > 17) textComponent.fontSize = 10; if (name.Length > 17) textComponent.fontSize = 10;
newCard.SetActive(true); newCard.SetActive(true);
newCard.transform.name = uniqueName; newCard.transform.name = uniqueID;
newCard.transform.localPosition = new Vector3(position.x, position.y, 40); newCard.transform.localPosition = new Vector3(position.x, position.y, 40);
newCard.transform.localRotation = Quaternion.Euler(0, 0, 0); newCard.transform.localRotation = Quaternion.Euler(0, 0, 0);
@ -157,15 +159,15 @@ namespace NewHorizons.Components
Texture texture = null; Texture texture = null;
try try
{ {
if (uniqueName.Equals("SolarSystem")) if (uniqueID.Equals("SolarSystem"))
{ {
texture = ImageUtilities.GetTexture(Main.Instance, "AssetBundle/hearthian system.png"); texture = ImageUtilities.GetTexture(Main.Instance, "AssetBundle/hearthian system.png");
} }
else else
{ {
var path = $"planets/{uniqueName}.png"; var path = $"planets/{uniqueID}.png";
Logger.Log($"Trying to load {path}"); Logger.Log($"Trying to load {path}");
texture = ImageUtilities.GetTexture(Main.SystemDict[uniqueName].Mod, path); texture = ImageUtilities.GetTexture(Main.SystemDict[uniqueID].Mod, path);
} }
} }
catch (Exception) { } catch (Exception) { }
@ -272,13 +274,19 @@ namespace NewHorizons.Components
} }
} }
public string UniqueNameToString(string uniqueName) public string UniqueIDToName(string uniqueID)
{ {
if (uniqueName.Equals("SolarSystem")) return "Hearthian System"; var name = TranslationHandler.GetTranslation(uniqueID, TranslationHandler.TextType.UI);
var splitString = uniqueName.Split('.'); // If it can't find a translation it just returns the key
if (!name.Equals(uniqueID)) return name;
// Else we return a default name
if (uniqueID.Equals("SolarSystem")) return "Hearthian System";
var splitString = uniqueID.Split('.');
if (splitString.Length > 1) splitString = splitString.Skip(1).ToArray(); if (splitString.Length > 1) splitString = splitString.Skip(1).ToArray();
var name = string.Join("", splitString).SplitCamelCase(); name = string.Join("", splitString).SplitCamelCase();
return name; return name;
} }
@ -308,10 +316,10 @@ namespace NewHorizons.Components
Locator._rfTracker.UntargetReferenceFrame(); Locator._rfTracker.UntargetReferenceFrame();
GlobalMessenger.FireEvent("UntargetReferenceFrame"); GlobalMessenger.FireEvent("UntargetReferenceFrame");
_warpNotificationData = new NotificationData($"AUTOPILOT LOCKED TO:\n{UniqueNameToString(shipLogEntryCard.name).ToUpper()}"); _warpNotificationData = new NotificationData($"AUTOPILOT LOCKED TO:\n{UniqueIDToName(shipLogEntryCard.name).ToUpper()}");
NotificationManager.SharedInstance.PostNotification(_warpNotificationData, true); NotificationManager.SharedInstance.PostNotification(_warpNotificationData, true);
_warpPrompt.SetText($"<CMD> Engage Warp To {UniqueNameToString(shipLogEntryCard.name)}"); _warpPrompt.SetText($"<CMD> Engage Warp To {UniqueIDToName(shipLogEntryCard.name)}");
} }
private void RemoveWarpTarget(bool playSound = false) private void RemoveWarpTarget(bool playSound = false)

View File

@ -54,7 +54,7 @@ namespace NewHorizons.Handlers
{ {
if (system.Config.factRequiredForWarp != default) if (system.Config.factRequiredForWarp != default)
{ {
RegisterFactForSystem(system.Config.factRequiredForWarp, system.Name); RegisterFactForSystem(system.Config.factRequiredForWarp, system.UniqueID);
} }
} }
@ -68,7 +68,7 @@ namespace NewHorizons.Handlers
{ {
foreach (var system in _systems) foreach (var system in _systems)
{ {
if (system.Config.canEnterViaWarpDrive && system.Spawn?.ShipSpawnPoint != null && HasUnlockedSystem(system.Name)) if (system.Config.canEnterViaWarpDrive && system.Spawn?.ShipSpawnPoint != null && HasUnlockedSystem(system.UniqueID))
{ {
return true; return true;
} }

View File

@ -5,14 +5,14 @@ namespace NewHorizons.Utility
{ {
public class NewHorizonsSystem public class NewHorizonsSystem
{ {
public NewHorizonsSystem(string name, StarSystemConfig config, IModBehaviour mod) public NewHorizonsSystem(string uniqueID, StarSystemConfig config, IModBehaviour mod)
{ {
Name = name; UniqueID = uniqueID;
Config = config; Config = config;
Mod = mod; Mod = mod;
} }
public string Name; public string UniqueID;
public SpawnModule Spawn = null; public SpawnModule Spawn = null;
public SpawnPoint SpawnPoint = null; public SpawnPoint SpawnPoint = null;
public StarSystemConfig Config; public StarSystemConfig Config;