Skip to content

Commit

Permalink
Made tabs and crafting nodes compatible
Browse files Browse the repository at this point in the history
Co-Authored-By: EldritchCarMaker <[email protected]>
  • Loading branch information
Metious and EldritchCarMaker committed Sep 3, 2024
1 parent fc75154 commit bb95bed
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Nautilus/Patchers/CraftTreePatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,45 @@ private static void CreateVanillaTabNode(CraftTree.Type treeType, string Display
}
InternalLogger.Info($"Reorganized {removedNodes.Count} {treeType} nodes into new {vanillaTab} tab.");
}

[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);
}

[HarmonyPostfix]
[HarmonyPatch(typeof(CraftTree), nameof(CraftTree.GetTree))]
Expand Down

0 comments on commit bb95bed

Please sign in to comment.