Skip to content
Draft
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
41 changes: 41 additions & 0 deletions Nautilus/Patchers/CraftDataPatcher.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using BepInEx.Logging;
using HarmonyLib;
using Nautilus.Handlers;
Expand Down Expand Up @@ -111,6 +112,46 @@ private static void CraftDataGetTechTypePrefix(GameObject obj, out GameObject go
__result = TechType.None;
return;
}

[HarmonyPatch(typeof(uGUI_CraftingMenu.Node), nameof(uGUI_CraftingMenu.Node.GetEnumerator), MethodType.Enumerator)]
[HarmonyPrefix]
public static bool OrderNodes(uGUI_CraftingMenu.Node __instance, ref IEnumerator<uGUI_CraftingMenu.Node> __result)
{
//The number of nodes to space out each tab node by
//Also equal to the width of the crafting grid
//In other words, if the grid is 3 wide (a 3x3 grid, roughly)
//We space them out every 3 nodes
//Meaning the craft nodes are always on the leftmost side
var offset = Mathf.CeilToInt(Mathf.Sqrt(__instance.childCount));
var tabs = __instance.nodes.Where(node => node is uGUI_CraftingMenu.Node craftMenuNode && craftMenuNode.action == TreeAction.Expand).ToList();

if (tabs.Count == 0)
{
// Run original
return true;
}

var craftNodes = __instance.nodes.Where(node => !tabs.Contains(node)).ToList();

var sortedNodes = new List<uGUI_CraftingMenu.Node>();

var tabsUsed = 0;

for (var i = 0; i < __instance.childCount; i++)
{
if(i % offset == 0 && tabs.Count > tabsUsed)
{
sortedNodes.Add((uGUI_CraftingMenu.Node)tabs[tabsUsed]);
tabsUsed++;
continue;
}
sortedNodes.Add((uGUI_CraftingMenu.Node)craftNodes[i - tabsUsed]);
}

__result = sortedNodes.GetEnumerator();
// Skip original
return false;
}

private static bool NeedsPatching = true;

Expand Down