oni-priority-ux/mod/Patches/BuildMenuCategoriesScreen.cs

46 lines
1.7 KiB
C#

using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using HarmonyLib;
using KMod;
namespace PriorityUX {
[HarmonyPatch(typeof(BuildMenuCategoriesScreen))]
public class BuildMenuCategoriesScreenPatches {
[HarmonyPatch(nameof(BuildMenuCategoriesScreen.OnKeyDown))]
[HarmonyPrefix]
static bool BuildMenu_OnKeyDown_Prefix(KButtonEvent e) {
Debug.Log("BuildMenu_OnKeyDown_Prefix" + e);
FieldInfo productInfoScreenField = typeof(BuildMenu).GetField("productInfoScreen", BindingFlags.NonPublic | BindingFlags.Instance);
Debug.Log(productInfoScreenField);
ProductInfoScreen ___productInfoScreen = (ProductInfoScreen)productInfoScreenField.GetValue(BuildMenu.Instance);
MaterialSelectionPanel msp = ___productInfoScreen.materialSelectionPanel;
if (___productInfoScreen.gameObject.activeSelf && msp.gameObject.activeSelf) {
MaterialSelectionPanelPatches.OnKeyDown(e, msp);
}
return true;
}
[HarmonyPatch(nameof(BuildMenuCategoriesScreen.OnKeyUp))]
[HarmonyPrefix]
static bool BuildMenu_OnKeyUp_Prefix(KButtonEvent e) {
Debug.Log("BuildMenu_OnKeyUp_Prefix" + e);
FieldInfo productInfoScreenField = typeof(BuildMenu).GetField("productInfoScreen", BindingFlags.NonPublic | BindingFlags.Instance);
Debug.Log(productInfoScreenField);
ProductInfoScreen ___productInfoScreen = (ProductInfoScreen)productInfoScreenField.GetValue(BuildMenu.Instance);
MaterialSelectionPanel msp = ___productInfoScreen.materialSelectionPanel;
if (___productInfoScreen.gameObject.activeSelf && msp.gameObject.activeSelf) {
MaterialSelectionPanelPatches.OnKeyUp(e, msp);
}
return true;
}
}
}