diff --git a/Patches/SliderPatch.cs b/Patches/SliderPatch.cs new file mode 100644 index 0000000..8953d19 --- /dev/null +++ b/Patches/SliderPatch.cs @@ -0,0 +1,73 @@ +using EFT.UI; +using HarmonyLib; +using SPT.Reflection.Patching; +using System.Reflection; +using UnityEngine; +using UnityEngine.UI; + +namespace UIFixes; + +public static class SliderPatches +{ + public static void Enable() + { + new IntSliderPatch().Enable(); + new StepSliderPatch().Enable(); + } + + public class IntSliderPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(IntSlider), nameof(IntSlider.Awake)); + } + + [PatchPostfix] + public static void Postfix(Slider ____slider) + { + ____slider.GetOrAddComponent().Init(____slider); + } + } + + public class StepSliderPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(StepSlider), nameof(StepSlider.Awake)); + } + + [PatchPostfix] + public static void Postfix(Slider ____slider) + { + ____slider.GetOrAddComponent().Init(____slider); + } + } + + public class SliderMouseListener : MonoBehaviour + { + private Slider slider; + + public void Init(Slider slider) + { + this.slider = slider; + } + + public void Update() + { + if (slider == null) + { + return; + } + + if (Input.mouseScrollDelta.y > float.Epsilon) + { + slider.value = Mathf.Min(slider.value + 1, slider.maxValue); + + } + else if (Input.mouseScrollDelta.y < -float.Epsilon) + { + slider.value = Mathf.Max(slider.value - 1, slider.minValue); + } + } + } +} \ No newline at end of file diff --git a/Plugin.cs b/Plugin.cs index 5ad6d83..ca3f3db 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -79,6 +79,7 @@ public class Plugin : BaseUnityPlugin TacticalBindsPatches.Enable(); AddOfferContextMenuPatches.Enable(); new OperationQueuePatch().Enable(); + SliderPatches.Enable(); } public static bool InRaid()