Merge pull request 'Added replacement method for Game.UI.InventoryPanelScrollEngine:ScrollPanelByMouseWheel to improve scroll wheel speed.' (#1) from Zhang/CLre:master into master
This commit is contained in:
commit
0a33d2406f
1 changed files with 39 additions and 0 deletions
39
CLre/Fixes/InventoryPanelScrollEngineFix.cs
Normal file
39
CLre/Fixes/InventoryPanelScrollEngineFix.cs
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
using HarmonyLib;
|
||||||
|
using System.Reflection;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace CLre.Fixes
|
||||||
|
{
|
||||||
|
[Bugfix(name = "ScrollSpeedImprovement",
|
||||||
|
description = "Improve mouse wheel scroll speed in inventory",
|
||||||
|
more = "https://trello.com/c/elL8IVdn/4-scroll-menus-are-insensitive",
|
||||||
|
component = BugfixType.HarmonyPatch, id = 4)]
|
||||||
|
[HarmonyPatch]
|
||||||
|
class InventoryPanelScrollEngine_ScrollPanelByMouseWheel_Patch
|
||||||
|
{
|
||||||
|
[HarmonyPrefix]
|
||||||
|
public static bool BeforeMethodCall(ref object panelScrollComponent, ref float scrollValue)
|
||||||
|
{
|
||||||
|
if (panelScrollComponent == null) return true; // If it's null, we don't try to handle it.
|
||||||
|
// We, perhaps dangerously, assume that we'll only get a panelScrollComponent.
|
||||||
|
PropertyInfo scrollbar = panelScrollComponent.GetType().GetProperty("scrollbar", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
||||||
|
UnityEngine.UI.Scrollbar sb = scrollbar.GetValue(panelScrollComponent) as UnityEngine.UI.Scrollbar;
|
||||||
|
float num = -scrollValue * (sb.size * 0.3f);
|
||||||
|
float num2 = sb.value;
|
||||||
|
num2 = Mathf.Clamp01(num2 + num);
|
||||||
|
sb.value = num2;
|
||||||
|
return false; // Tell harmony not to invoke the original method
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HarmonyTargetMethod]
|
||||||
|
public static MethodBase Target()
|
||||||
|
{
|
||||||
|
MethodInfo methodtopatch = AccessTools.Method("Game.UI.InventoryPanelScrollEngine:ScrollPanelByMouseWheel");
|
||||||
|
if (null == methodtopatch) API.Utility.Logging.MetaLog("Intercepting Game.UI.InventoryPanelScrollEngine:ScrollPanelByMouseWheel() failed");
|
||||||
|
return methodtopatch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue