mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 13:05:52 +08:00
Feat: Add mouse wheel scrolling to client input
- Queue wheel notches in ClientInput for the next frame - Forward wheel deltas from the 1.8.9 screen and 26.2 input screen - Hook GuiScreen#handleMouseInput after vanilla, guarded so a missing method never disables the other input injections - Shrink HUD module font size to 10
This commit is contained in:
1 parent
d9075831e3
commit
09de736269
6 files changed
+60
-4
No files matched your search
@@ -67,6 +67,16 @@ public final class GuiInputHook extends ClassHook {
|
||||
// The empty screen is an overlay: it must not pause singleplayer.
|
||||
injectAfter(ctClass, "doesGuiPauseGame", "()Z",
|
||||
"if (orangexbridge.Hooks.isOurScreen($0)) { $_ = false; }");
|
||||
|
||||
// Wheel scrolling for the ClickGUI. Injecting after vanilla keeps its
|
||||
// mouse-button dispatch intact; the wheel event is still readable.
|
||||
try {
|
||||
injectAfter(ctClass, "handleMouseInput", "()V",
|
||||
"orangexbridge.Legacy.forwardScroll($0);");
|
||||
} catch (Throwable ignored) {
|
||||
// Scrolling is optional: never let it disable the input hooks
|
||||
// above on a runtime where this method cannot be resolved.
|
||||
}
|
||||
}
|
||||
|
||||
private void injectBefore(CtClass ctClass, String name,
|
||||
|
||||
@@ -21,6 +21,7 @@ public final class ClientInput {
|
||||
private static volatile boolean leftDown;
|
||||
private static volatile boolean rightDown;
|
||||
private static volatile boolean middleDown;
|
||||
private static double scrollAmount;
|
||||
|
||||
private static boolean started;
|
||||
private static boolean pendingOpen;
|
||||
@@ -111,6 +112,29 @@ public final class ClientInput {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Queues a wheel notch for the next frame. Positive is one notch up.
|
||||
*/
|
||||
public static synchronized void onMouseScroll(double amount) {
|
||||
if (amount != 0.0) {
|
||||
scrollAmount += amount;
|
||||
}
|
||||
}
|
||||
|
||||
public static void onMouseScroll(double x, double y, double amount) {
|
||||
onMouseMove(x, y);
|
||||
onMouseScroll(amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the wheel amount accumulated since the previous call.
|
||||
*/
|
||||
public static synchronized double consumeScroll() {
|
||||
double amount = scrollAmount;
|
||||
scrollAmount = 0.0;
|
||||
return amount;
|
||||
}
|
||||
|
||||
public static void reset() {
|
||||
if (open) {
|
||||
System.out.println("[OrangeX] Input screen closed");
|
||||
@@ -119,6 +143,7 @@ public final class ClientInput {
|
||||
leftDown = false;
|
||||
rightDown = false;
|
||||
middleDown = false;
|
||||
scrollAmount = 0.0;
|
||||
}
|
||||
|
||||
public static boolean isOpen() {
|
||||
|
||||
+19
-2
@@ -1,5 +1,6 @@
|
||||
package cn.xiaozhou233.orangex.input.internal.v1_8_9;
|
||||
|
||||
import cn.xiaozhou233.orangex.event.facade.InputEvents;
|
||||
import cn.xiaozhou233.orangex.hook.ClassPoolUtils;
|
||||
import cn.xiaozhou233.orangex.hook.HookManager;
|
||||
import cn.xiaozhou233.orangex.hook.JuiceAgentBridge;
|
||||
@@ -272,13 +273,29 @@ public final class V1_8_9Input implements VersionInput {
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by injected {@code GuiScreen}/{@code KeyBinding} code to ignore
|
||||
* LWJGL auto-repeat events.
|
||||
* Used by injected {@code GuiScreen} code to ignore LWJGL auto-repeat
|
||||
* events.
|
||||
*/
|
||||
public static boolean isRepeatEvent() {
|
||||
return Keyboard.isRepeatEvent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after {@code GuiScreen#handleMouseInput} ran. The wheel event is
|
||||
* still readable at this point and must not consume the vanilla mouse
|
||||
* button dispatch.
|
||||
*/
|
||||
public static void forwardScroll(Object screen) {
|
||||
if (!InputEvents.isOurInputScreen(screen)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int wheel = Mouse.getEventDWheel();
|
||||
if (wheel != 0) {
|
||||
ClientInput.onMouseScroll(wheel > 0 ? 1.0 : -1.0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getGuiMouseX() {
|
||||
Object screen = shellScreen;
|
||||
|
||||
@@ -63,7 +63,7 @@ public final class V26_2InputScreen extends Screen {
|
||||
@Override
|
||||
public boolean mouseScrolled(double x, double y,
|
||||
double scrollX, double scrollY) {
|
||||
ClientInput.onMouseMove(x, y);
|
||||
ClientInput.onMouseScroll(x, y, scrollY);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public class HUD extends Module {
|
||||
private static final float RAINBOW_CYCLE = 6000f;
|
||||
|
||||
private static final int LOGO_FONT_SIZE = 22;
|
||||
private static final int MODULE_FONT_SIZE = 14;
|
||||
private static final int MODULE_FONT_SIZE = 10;
|
||||
|
||||
private static final int LOGO_START_X = 5;
|
||||
private static final int LOGO_START_Y = 5;
|
||||
|
||||
@@ -14,6 +14,10 @@ public final class Legacy {
|
||||
return V1_8_9Input.isRepeatEvent();
|
||||
}
|
||||
|
||||
public static void forwardScroll(Object screen) {
|
||||
V1_8_9Input.forwardScroll(screen);
|
||||
}
|
||||
|
||||
private Legacy() {
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user