diff --git a/Patches/WeaponZoomPatch.cs b/Patches/WeaponZoomPatch.cs new file mode 100644 index 0000000..af1d787 --- /dev/null +++ b/Patches/WeaponZoomPatch.cs @@ -0,0 +1,78 @@ +using Aki.Reflection.Patching; +using EFT.InventoryLogic; +using EFT.UI; +using EFT.UI.WeaponModding; +using HarmonyLib; +using System; +using System.Reflection; +using UnityEngine.EventSystems; + +namespace UIFixes +{ + public class WeaponZoomPatch + { + public static void Enable() + { + new EditBuildScreenZoomPatch().Enable(); + new WeaponModdingScreenZoomPatch().Enable(); + } + + public class EditBuildScreenZoomPatch : ModulePatch + { + private static ScrollTrigger ScrollTrigger; + protected override MethodBase GetTargetMethod() + { + Type type = typeof(EditBuildScreen); + return type.GetMethod("Show", [typeof(Item), typeof(Item), typeof(InventoryControllerClass), typeof(ISession)]); + } + + [PatchPrefix] + private static void Prefix(EditBuildScreen __instance) + { + WeaponPreview weaponPreview = Traverse.Create(__instance).Field("_weaponPreview").GetValue(); + if (ScrollTrigger == null) + { + ScrollTrigger = __instance.gameObject.AddComponent(); + } + + ScrollTrigger.OnOnScroll += (PointerEventData eventData) => + { + if (weaponPreview != null && __instance != null) + { + weaponPreview.Zoom(eventData.scrollDelta.y * 0.12f); + __instance.UpdatePositions(); + } + }; + } + } + + public class WeaponModdingScreenZoomPatch : ModulePatch + { + private static ScrollTrigger ScrollTrigger; + protected override MethodBase GetTargetMethod() + { + Type type = typeof(WeaponModdingScreen); + return type.GetMethod("Show", [typeof(Item), typeof(InventoryControllerClass), typeof(LootItemClass[])]); + } + + [PatchPrefix] + private static void Prefix(WeaponModdingScreen __instance) + { + WeaponPreview weaponPreview = Traverse.Create(__instance).Field("_weaponPreview").GetValue(); + if (ScrollTrigger == null) + { + ScrollTrigger = __instance.gameObject.AddComponent(); + } + + ScrollTrigger.OnOnScroll += (PointerEventData eventData) => + { + if (weaponPreview != null && __instance != null) + { + weaponPreview.Zoom(eventData.scrollDelta.y * 0.12f); + __instance.UpdatePositions(); + } + }; + } + } + } +} diff --git a/Plugin.cs b/Plugin.cs index c745410..01ecbda 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -1,5 +1,4 @@ using BepInEx; -using BepInEx.Configuration; namespace UIFixes { @@ -15,6 +14,7 @@ namespace UIFixes new TransferConfirmPatch().Enable(); new MailReceiveAllPatch().Enable(); ScrollPatches.Enable(); + WeaponZoomPatch.Enable(); } } }