Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localization not affecting tab nodes & Language Metadata #536

Merged
merged 3 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading