OCD patch to fix toggle behavior

This commit is contained in:
Tyfon
2024-05-23 02:28:48 -07:00
parent 9a1333934b
commit b4c404f8d7

View File

@@ -0,0 +1,72 @@
using Aki.Reflection.Patching;
using EFT.UI.Ragfair;
using HarmonyLib;
using System.Reflection;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace UIFixes
{
// This fix is anal AF
public class FixTogglesPatches
{
public static void Enable()
{
new DoNotToggleOnMouseOverPatch().Enable();
new ToggleOnOpenPatch().Enable();
new ToggleOnClosePatch().Enable();
}
public class DoNotToggleOnMouseOverPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(CategoryView), nameof(CategoryView.PointerEnterHandler));
}
[PatchPostfix]
public static void Postfix(PointerEventData eventData, Image ____toggleImage, Sprite ____closeSprite, bool ___bool_3)
{
if (!___bool_3)
{
____toggleImage.sprite = ____closeSprite;
}
}
}
public class ToggleOnOpenPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(CategoryView), nameof(CategoryView.OpenCategory));
}
[PatchPostfix]
public static void Postfix(Image ____toggleImage, Sprite ____openSprite, bool ___bool_3)
{
if (___bool_3)
{
____toggleImage.sprite = ____openSprite;
}
}
}
public class ToggleOnClosePatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(CategoryView), nameof(CategoryView.OpenCategory));
}
[PatchPostfix]
public static void Postfix(Image ____toggleImage, Sprite ____closeSprite, bool ___bool_3)
{
if (!___bool_3)
{
____toggleImage.sprite = ____closeSprite;
}
}
}
}
}