From 960cb725ec4e0f3187cbddd0011d3687046eca7b Mon Sep 17 00:00:00 2001 From: Tyfon <29051038+tyfon7@users.noreply.github.com> Date: Tue, 23 Jul 2024 19:00:00 -0700 Subject: [PATCH] limit nonstandard dragging --- Patches/LimitDragPatches.cs | 44 +++++++++++++++++++++++++++++++++++++ Plugin.cs | 1 + Settings.cs | 14 ++++++++++-- 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 Patches/LimitDragPatches.cs diff --git a/Patches/LimitDragPatches.cs b/Patches/LimitDragPatches.cs new file mode 100644 index 0000000..3795443 --- /dev/null +++ b/Patches/LimitDragPatches.cs @@ -0,0 +1,44 @@ +using System; +using System.Reflection; +using EFT.UI; +using HarmonyLib; +using SPT.Reflection.Patching; +using UnityEngine; +using UnityEngine.EventSystems; + +namespace UIFixes; + +public static class LimitDragPatches +{ + public static void Enable() + { + new OnDragEventPatch(typeof(DragTrigger), nameof(DragTrigger.OnDrag)).Enable(); + new OnDragEventPatch(typeof(DragTrigger), nameof(DragTrigger.OnBeginDrag)).Enable(); + new OnDragEventPatch(typeof(DragTrigger), nameof(DragTrigger.OnEndDrag)).Enable(); + + new OnDragEventPatch(typeof(UIDragComponent), "UnityEngine.EventSystems.IDragHandler.OnDrag").Enable(); + new OnDragEventPatch(typeof(UIDragComponent), "UnityEngine.EventSystems.IBeginDragHandler.OnBeginDrag").Enable(); + } + + public class OnDragEventPatch(Type type, string methodName) : ModulePatch + { + private readonly string methodName = methodName; + private readonly Type type = type; + + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(type, methodName); + } + + [PatchPrefix] + public static bool Prefix(PointerEventData eventData) + { + if (!Settings.LimitNonstandardDrags.Value) + { + return true; + } + + return eventData.button == PointerEventData.InputButton.Left && !Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.RightShift); + } + } +} \ No newline at end of file diff --git a/Plugin.cs b/Plugin.cs index 5072daa..46f2e68 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -68,6 +68,7 @@ public class Plugin : BaseUnityPlugin ReloadInPlacePatches.Enable(); BarterOfferPatches.Enable(); new UnlockCursorPatch().Enable(); + LimitDragPatches.Enable(); } public static bool InRaid() diff --git a/Settings.cs b/Settings.cs index 57863a2..f940946 100644 --- a/Settings.cs +++ b/Settings.cs @@ -70,6 +70,8 @@ internal class Settings public static ConfigEntry UseHomeEnd { get; set; } public static ConfigEntry RebindPageUpDown { get; set; } public static ConfigEntry MouseScrollMulti { get; set; } + public static ConfigEntry UseRaidMouseScrollMulti { get; set; } // Advanced + public static ConfigEntry MouseScrollMultiInRaid { get; set; } // Advanced public static ConfigEntry InspectKeyBind { get; set; } public static ConfigEntry OpenKeyBind { get; set; } public static ConfigEntry ExamineKeyBind { get; set; } @@ -81,8 +83,7 @@ internal class Settings public static ConfigEntry FilterByKeyBind { get; set; } public static ConfigEntry LinkedSearchKeyBind { get; set; } public static ConfigEntry SortingTableKeyBind { get; set; } - public static ConfigEntry UseRaidMouseScrollMulti { get; set; } // Advanced - public static ConfigEntry MouseScrollMultiInRaid { get; set; } // Advanced + public static ConfigEntry LimitNonstandardDrags { get; set; } // Advanced public static ConfigEntry ItemContextBlocksTextInputs { get; set; } // Advanced // Inventory @@ -372,6 +373,15 @@ internal class Settings null, new ConfigurationManagerAttributes { }))); + configEntries.Add(LimitNonstandardDrags = config.Bind( + InputSection, + "Limit Nonstandard Drags", + true, + new ConfigDescription( + "Constrain dragging to the left mouse, when shift is not down", + null, + new ConfigurationManagerAttributes { IsAdvanced = true }))); + configEntries.Add(ItemContextBlocksTextInputs = config.Bind( InputSection, "Block Text Inputs on Item Mouseover",