Add zoom to weapon presets and modding

This commit is contained in:
Tyfon
2024-04-19 13:16:16 -07:00
parent 9fa87095b2
commit cae878c119
2 changed files with 79 additions and 1 deletions

View File

@@ -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<WeaponPreview>();
if (ScrollTrigger == null)
{
ScrollTrigger = __instance.gameObject.AddComponent<ScrollTrigger>();
}
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<WeaponPreview>();
if (ScrollTrigger == null)
{
ScrollTrigger = __instance.gameObject.AddComponent<ScrollTrigger>();
}
ScrollTrigger.OnOnScroll += (PointerEventData eventData) =>
{
if (weaponPreview != null && __instance != null)
{
weaponPreview.Zoom(eventData.scrollDelta.y * 0.12f);
__instance.UpdatePositions();
}
};
}
}
}
}

View File

@@ -1,5 +1,4 @@
using BepInEx; using BepInEx;
using BepInEx.Configuration;
namespace UIFixes namespace UIFixes
{ {
@@ -15,6 +14,7 @@ namespace UIFixes
new TransferConfirmPatch().Enable(); new TransferConfirmPatch().Enable();
new MailReceiveAllPatch().Enable(); new MailReceiveAllPatch().Enable();
ScrollPatches.Enable(); ScrollPatches.Enable();
WeaponZoomPatch.Enable();
} }
} }
} }