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

Re-introduce gridding in mixed craft tree tabs #565

Merged
merged 1 commit into from
Nov 15, 2024
Merged
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
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
Loading