limit nonstandard dragging

This commit is contained in:
Tyfon
2024-07-23 19:00:00 -07:00
parent 48faa97082
commit 960cb725ec
3 changed files with 57 additions and 2 deletions

View File

@@ -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);
}
}
}

View File

@@ -68,6 +68,7 @@ public class Plugin : BaseUnityPlugin
ReloadInPlacePatches.Enable();
BarterOfferPatches.Enable();
new UnlockCursorPatch().Enable();
LimitDragPatches.Enable();
}
public static bool InRaid()

View File

@@ -70,6 +70,8 @@ internal class Settings
public static ConfigEntry<bool> UseHomeEnd { get; set; }
public static ConfigEntry<bool> RebindPageUpDown { get; set; }
public static ConfigEntry<int> MouseScrollMulti { get; set; }
public static ConfigEntry<bool> UseRaidMouseScrollMulti { get; set; } // Advanced
public static ConfigEntry<int> MouseScrollMultiInRaid { get; set; } // Advanced
public static ConfigEntry<KeyboardShortcut> InspectKeyBind { get; set; }
public static ConfigEntry<KeyboardShortcut> OpenKeyBind { get; set; }
public static ConfigEntry<KeyboardShortcut> ExamineKeyBind { get; set; }
@@ -81,8 +83,7 @@ internal class Settings
public static ConfigEntry<KeyboardShortcut> FilterByKeyBind { get; set; }
public static ConfigEntry<KeyboardShortcut> LinkedSearchKeyBind { get; set; }
public static ConfigEntry<KeyboardShortcut> SortingTableKeyBind { get; set; }
public static ConfigEntry<bool> UseRaidMouseScrollMulti { get; set; } // Advanced
public static ConfigEntry<int> MouseScrollMultiInRaid { get; set; } // Advanced
public static ConfigEntry<bool> LimitNonstandardDrags { get; set; } // Advanced
public static ConfigEntry<bool> 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",