Skip to content

Commit

Permalink
Re-introduce gridding in mixed craft tree tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeTwentyThree committed Nov 15, 2024
1 parent 931ffb1 commit ac06938
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Nautilus/Patchers/CraftDataPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 })]
Expand Down

0 comments on commit ac06938

Please sign in to comment.