Skip to content

Commit

Permalink
Localization fixes for tab nodes and metadata
Browse files Browse the repository at this point in the history
* Fixed localization not affecting tab nodes

* Reformat using statements

* Fixed metadata not being applied the first time
  • Loading branch information
Metious committed Apr 17, 2024
1 parent 307e6e6 commit 03d7ad0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
21 changes: 16 additions & 5 deletions Nautilus/Crafting/TabNode.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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}'.");
}
}

}
12 changes: 6 additions & 6 deletions Nautilus/Handlers/CraftTreeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static void AddCraftingNode(CraftTree.Type craftTree, TechType craftingIt
/// </summary>
/// <param name="craftTree">The target craft tree to edit.</param>
/// <param name="name">The ID of the tab node. Must be unique!</param>
/// <param name="displayName">The display name of the tab, which will show up when you hover your mouse on the tab.</param>
/// <param name="displayName">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.</param>
/// <param name="sprite">The sprite of the tab.</param>
public static void AddTabNode(CraftTree.Type craftTree, string name, string displayName, Atlas.Sprite sprite)
{
Expand All @@ -75,7 +75,7 @@ public static void AddTabNode(CraftTree.Type craftTree, string name, string disp
/// </summary>
/// <param name="craftTree">The target craft tree to edit.</param>
/// <param name="name">The ID of the tab node. Must be unique!</param>
/// <param name="displayName">The display name of the tab, which will show up when you hover your mouse on the tab.</param>
/// <param name="displayName">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.</param>
/// <param name="sprite">The sprite of the tab.</param>

public static void AddTabNode(CraftTree.Type craftTree, string name, string displayName, UnityEngine.Sprite sprite)
Expand All @@ -95,7 +95,7 @@ public static void AddTabNode(CraftTree.Type craftTree, string name, string disp
/// </summary>
/// <param name="craftTree">The target craft tree to edit.</param>
/// <param name="name">The ID of the tab node. Must be unique!</param>
/// <param name="displayName">The display name of the tab, which will show up when you hover your mouse on the tab.</param>
/// <param name="displayName">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.</param>
/// <param name="sprite">The sprite of the tab.</param>
/// <param name="stepsToTab">
/// <para>The steps to the target tab.</para>
Expand All @@ -120,7 +120,7 @@ public static void AddTabNode(CraftTree.Type craftTree, string name, string disp
/// </summary>
/// <param name="craftTree">The target craft tree to edit.</param>
/// <param name="name">The ID of the tab node. Must be unique!</param>
/// <param name="displayName">The display name of the tab, which will show up when you hover your mouse on the tab.</param>
/// <param name="displayName">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.</param>
/// <param name="sprite">The sprite of the tab.</param>
/// <param name="stepsToTab">
/// <para>The steps to the target tab.</para>
Expand All @@ -146,7 +146,7 @@ public static void AddTabNode(CraftTree.Type craftTree, string name, string disp
/// </summary>
/// <param name="craftTree">The target craft tree to edit.</param>
/// <param name="name">The ID of the tab node. Must be unique!</param>
/// <param name="displayName">The display name of the tab, which will show up when you hover your mouse on the tab.</param>
/// <param name="displayName">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.</param>
/// <param name="sprite">The sprite of the tab.</param>
public static void AddTabNode(CraftTree.Type craftTree, string name, string displayName, UnityEngine.Sprite sprite)
{
Expand All @@ -165,7 +165,7 @@ public static void AddTabNode(CraftTree.Type craftTree, string name, string disp
/// </summary>
/// <param name="craftTree">The target craft tree to edit.</param>
/// <param name="name">The ID of the tab node. Must be unique!</param>
/// <param name="displayName">The display name of the tab, which will show up when you hover your mouse on the tab.</param>
/// <param name="displayName">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.</param>
/// <param name="sprite">The sprite of the tab.</param>
/// <param name="stepsToTab">
/// <para>The steps to the target tab.</para>
Expand Down
5 changes: 5 additions & 0 deletions Nautilus/Patchers/LanguagePatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ internal static void InsertCustomLines(ref Language __instance)
}

if (_currentLanguage == FallbackLanguage)
{
__instance.ParseMetaData();
return;
}

var diffStrings = currentStrings.Except(fallbackStrings);

Expand All @@ -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)
Expand Down

0 comments on commit 03d7ad0

Please sign in to comment.