From 03d7ad0fbef97df1834a57ee85ccf264f68fd59e Mon Sep 17 00:00:00 2001 From: Metious <71298690+Metious@users.noreply.github.com> Date: Wed, 17 Apr 2024 17:30:48 +0330 Subject: [PATCH] Localization fixes for tab nodes and metadata * Fixed localization not affecting tab nodes * Reformat using statements * Fixed metadata not being applied the first time --- Nautilus/Crafting/TabNode.cs | 21 ++++++++++++++++----- Nautilus/Handlers/CraftTreeHandler.cs | 12 ++++++------ Nautilus/Patchers/LanguagePatcher.cs | 5 +++++ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Nautilus/Crafting/TabNode.cs b/Nautilus/Crafting/TabNode.cs index 0cc2378b..06b7b937 100644 --- a/Nautilus/Crafting/TabNode.cs +++ b/Nautilus/Crafting/TabNode.cs @@ -1,7 +1,8 @@ namespace Nautilus.Crafting; -using Nautilus.Assets; -using Nautilus.Patchers; +using Assets; +using Handlers; +using Utility; #if SUBNAUTICA using Sprite = Atlas.Sprite; @@ -15,15 +16,25 @@ internal class TabNode : Node internal Sprite Sprite { get; set; } internal string DisplayName { get; set; } internal string Name { get; set; } + internal string Id { get; } - internal TabNode(string[] path, CraftTree.Type scheme, Sprite sprite, string name, string displayName, string language = "English") : base(path, scheme) + internal TabNode(string[] path, CraftTree.Type scheme, Sprite sprite, string name, string displayName) : base(path, scheme) { Sprite = sprite; DisplayName = displayName; Name = name; + Id = $"{Scheme.ToString()}_{Name}"; - ModSprite.Add(new ModSprite(SpriteManager.Group.Category, $"{Scheme.ToString()}_{Name}", Sprite)); - LanguagePatcher.AddCustomLanguageLine($"{Scheme.ToString()}Menu_{Name}", DisplayName, language); + ModSprite.Add(new ModSprite(SpriteManager.Group.Category, Id, Sprite)); + + if (!string.IsNullOrEmpty(displayName)) + { + LanguageHandler.SetLanguageLine(Id, displayName); + } + else if (string.IsNullOrEmpty(Language.main.Get(name))) + { + InternalLogger.Warn($"Display name was not specified and no existing language line has been found for Tab node '{name}'."); + } } } diff --git a/Nautilus/Handlers/CraftTreeHandler.cs b/Nautilus/Handlers/CraftTreeHandler.cs index 7034edf0..d7fbaaf3 100644 --- a/Nautilus/Handlers/CraftTreeHandler.cs +++ b/Nautilus/Handlers/CraftTreeHandler.cs @@ -56,7 +56,7 @@ public static void AddCraftingNode(CraftTree.Type craftTree, TechType craftingIt /// /// The target craft tree to edit. /// The ID of the tab node. Must be unique! - /// The display name of the tab, which will show up when you hover your mouse on the tab. + /// The display name of the tab, which will show up when you hover your mouse on the tab. If null or empty, this will use the language line "{craftTreeName}_{tabName}" instead. /// The sprite of the tab. public static void AddTabNode(CraftTree.Type craftTree, string name, string displayName, Atlas.Sprite sprite) { @@ -75,7 +75,7 @@ public static void AddTabNode(CraftTree.Type craftTree, string name, string disp /// /// The target craft tree to edit. /// The ID of the tab node. Must be unique! - /// The display name of the tab, which will show up when you hover your mouse on the tab. + /// The display name of the tab, which will show up when you hover your mouse on the tab. If null or empty, this will use the language line "{craftTreeName}_{tabName}" instead. /// The sprite of the tab. public static void AddTabNode(CraftTree.Type craftTree, string name, string displayName, UnityEngine.Sprite sprite) @@ -95,7 +95,7 @@ public static void AddTabNode(CraftTree.Type craftTree, string name, string disp /// /// The target craft tree to edit. /// The ID of the tab node. Must be unique! - /// The display name of the tab, which will show up when you hover your mouse on the tab. + /// The display name of the tab, which will show up when you hover your mouse on the tab. If null or empty, this will use the language line "{craftTreeName}_{tabName}" instead. /// The sprite of the tab. /// /// The steps to the target tab. @@ -120,7 +120,7 @@ public static void AddTabNode(CraftTree.Type craftTree, string name, string disp /// /// The target craft tree to edit. /// The ID of the tab node. Must be unique! - /// The display name of the tab, which will show up when you hover your mouse on the tab. + /// The display name of the tab, which will show up when you hover your mouse on the tab. If null or empty, this will use the language line "{craftTreeName}_{tabName}" instead. /// The sprite of the tab. /// /// The steps to the target tab. @@ -146,7 +146,7 @@ public static void AddTabNode(CraftTree.Type craftTree, string name, string disp /// /// The target craft tree to edit. /// The ID of the tab node. Must be unique! - /// The display name of the tab, which will show up when you hover your mouse on the tab. + /// The display name of the tab, which will show up when you hover your mouse on the tab. If null or empty, this will use the language line "{craftTreeName}_{tabName}" instead. /// The sprite of the tab. public static void AddTabNode(CraftTree.Type craftTree, string name, string displayName, UnityEngine.Sprite sprite) { @@ -165,7 +165,7 @@ public static void AddTabNode(CraftTree.Type craftTree, string name, string disp /// /// The target craft tree to edit. /// The ID of the tab node. Must be unique! - /// The display name of the tab, which will show up when you hover your mouse on the tab. + /// The display name of the tab, which will show up when you hover your mouse on the tab. If null or empty, this will use the language line "{craftTreeName}_{tabName}" instead. /// The sprite of the tab. /// /// The steps to the target tab. diff --git a/Nautilus/Patchers/LanguagePatcher.cs b/Nautilus/Patchers/LanguagePatcher.cs index 0b5d3cd9..3f3fa157 100644 --- a/Nautilus/Patchers/LanguagePatcher.cs +++ b/Nautilus/Patchers/LanguagePatcher.cs @@ -63,7 +63,10 @@ internal static void InsertCustomLines(ref Language __instance) } if (_currentLanguage == FallbackLanguage) + { + __instance.ParseMetaData(); return; + } var diffStrings = currentStrings.Except(fallbackStrings); @@ -72,6 +75,8 @@ internal static void InsertCustomLines(ref Language __instance) { __instance.strings[currentOnlyString.Key] = currentOnlyString.Value; } + + __instance.ParseMetaData(); } private static void LoadLanguageFilePrefix(string language)