diff --git a/Nautilus/Patchers/CraftDataPatcher.cs b/Nautilus/Patchers/CraftDataPatcher.cs index 0fb2b3b4..2a198c85 100644 --- a/Nautilus/Patchers/CraftDataPatcher.cs +++ b/Nautilus/Patchers/CraftDataPatcher.cs @@ -78,6 +78,45 @@ internal static void Patch(Harmony harmony) InternalLogger.Log("CraftDataPatcher is done.", LogLevel.Debug); } + + [HarmonyPatch(typeof(uGUI_CraftingMenu), nameof(uGUI_CraftingMenu.IsGrid))] + [HarmonyPrefix] + private static bool ShouldGridPostfix(uGUI_CraftingMenu.Node node, ref bool __result) + { + __result = ShouldGrid(); + return false; + + bool ShouldGrid() + { + var craftings = 0; + var tabs = 0; + + foreach (var child in node) + { + if (child.action == TreeAction.Expand) + { + tabs++; + } + else if (child.action == TreeAction.Craft) + { + craftings++; + } + } + + return craftings > tabs; + } + } + + [HarmonyPatch(typeof(uGUI_CraftingMenu), nameof(uGUI_CraftingMenu.Collapse))] + [HarmonyPostfix] + private static void CollapsePostfix(uGUI_CraftingMenu.Node parent) + { + if (parent == null) return; + + if (parent.action != TreeAction.Craft) return; + + parent.icon.SetActive(false); + } [HarmonyPrefix] [HarmonyPatch(typeof(CraftData), nameof(CraftData.GetTechType), new Type[] { typeof(GameObject), typeof(GameObject) }, argumentVariations: new ArgumentType[] { ArgumentType.Normal, ArgumentType.Out })]