From 204b25528e7caa8253b7052d7d089cfdde6b1f15 Mon Sep 17 00:00:00 2001 From: PeytonPlayz595 <106421860+PeytonPlayz595@users.noreply.github.com> Date: Mon, 8 Jul 2024 09:13:48 -0700 Subject: [PATCH] Only show cursor when controller is active --- .../net/PeytonPlayz585/shadow/input/Controller.java | 9 +++++++++ .../eaglercraft/v1_8/internal/PlatformInput.java | 12 ++++++++++++ src/teavm/java/net/minecraft/client/Minecraft.java | 12 ++++-------- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/teavm/java/net/PeytonPlayz585/shadow/input/Controller.java b/src/teavm/java/net/PeytonPlayz585/shadow/input/Controller.java index 65b76af..638398a 100644 --- a/src/teavm/java/net/PeytonPlayz585/shadow/input/Controller.java +++ b/src/teavm/java/net/PeytonPlayz585/shadow/input/Controller.java @@ -38,6 +38,7 @@ public class Controller { private static ButtonState[] button = new ButtonState[30]; public static HTMLImageElement cursor; + public static boolean isActive = false; public static final int getDX() { if(dx < 0.0) { @@ -158,6 +159,10 @@ public class Controller { } } + if(getDX() > 0 || getDY() > 0 || getDX() < 0 || getDY() < 0) { + isActive = true; + } + forward = axes[1] < -threshold; backwards = axes[1] > threshold; left = axes[0] < -threshold; @@ -174,9 +179,11 @@ public class Controller { if(button[i] == ButtonState.PRESSED) { button[i] = ButtonState.HELD; + isActive = true; } else { if(!(button[i] == ButtonState.HELD)) { button[i] = ButtonState.PRESSED; + isActive = true; } } } else if(!gamePad.getButtons()[i].isPressed() && index == activeController) { @@ -252,6 +259,7 @@ public class Controller { @Override public void handleEvent(GamepadEvent arg0) { connectedControllers.add(arg0.getGamepad().getIndex()); + isActive = true; System.out.println("Controller connected!"); } }); @@ -263,6 +271,7 @@ public class Controller { if(connectedControllers.contains(index)) { connectedControllers.remove(index); resetButtonStates(); + isActive = false; System.out.println("Controller disconnected!"); } } diff --git a/src/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformInput.java b/src/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformInput.java index f85f3ec..c4fe0d9 100644 --- a/src/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformInput.java +++ b/src/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformInput.java @@ -129,6 +129,7 @@ public class PlatformInput { int b = evt.getButton(); buttonStates[b == 1 ? 2 : (b == 2 ? 1 : b)] = true; mouseEvents.add(evt); + Controller.isActive = false; } }); canvas.addEventListener("mouseup", mouseup = new EventListener() { @@ -139,6 +140,7 @@ public class PlatformInput { int b = evt.getButton(); buttonStates[b == 1 ? 2 : (b == 2 ? 1 : b)] = false; mouseEvents.add(evt); + Controller.isActive = false; } }); canvas.addEventListener("mousemove", mousemove = new EventListener() { @@ -153,18 +155,21 @@ public class PlatformInput { if(hasBeenActive()) { mouseEvents.add(evt); } + Controller.isActive = false; } }); canvas.addEventListener("mouseenter", mouseenter = new EventListener() { @Override public void handleEvent(MouseEvent evt) { isMouseOverWindow = true; + Controller.isActive = false; } }); canvas.addEventListener("mouseleave", mouseleave = new EventListener() { @Override public void handleEvent(MouseEvent evt) { isMouseOverWindow = false; + Controller.isActive = false; } }); win.addEventListener("keydown", keydown = new EventListener() { @@ -180,6 +185,7 @@ public class PlatformInput { int ww = processFunctionKeys(w); keyStates[KeyboardConstants.getEaglerKeyFromBrowser(ww, ww == w ? evt.getLocation() : 0)] = true; keyEvents.add(evt); + Controller.isActive = false; } }); win.addEventListener("keyup", keyup = new EventListener() { @@ -198,6 +204,7 @@ public class PlatformInput { } } keyEvents.add(evt); + Controller.isActive = false; } }); win.addEventListener("keypress", keypress = new EventListener() { @@ -205,6 +212,7 @@ public class PlatformInput { public void handleEvent(KeyboardEvent evt) { evt.preventDefault(); evt.stopPropagation(); + Controller.isActive = false; if(enableRepeatEvents && evt.isRepeat()) keyEvents.add(evt); } }); @@ -215,6 +223,7 @@ public class PlatformInput { evt.stopPropagation(); mouseEvents.add(evt); mouseDWheel += evt.getDeltaY(); + Controller.isActive = false; } }); win.addEventListener("blur", new EventListener() { @@ -227,12 +236,14 @@ public class PlatformInput { for(int i = 0; i < keyStates.length; ++i) { keyStates[i] = false; } + Controller.isActive = false; } }); win.addEventListener("focus", new EventListener() { @Override public void handleEvent(WheelEvent evt) { isWindowFocused = true; + Controller.isActive = false; } }); win.getDocument().addEventListener("pointerlockchange", pointerlock = new EventListener() { @@ -252,6 +263,7 @@ public class PlatformInput { }, 60); mouseDX = 0.0D; mouseDY = 0.0D; + Controller.isActive = false; } }); diff --git a/src/teavm/java/net/minecraft/client/Minecraft.java b/src/teavm/java/net/minecraft/client/Minecraft.java index 3cbc4a3..b723115 100644 --- a/src/teavm/java/net/minecraft/client/Minecraft.java +++ b/src/teavm/java/net/minecraft/client/Minecraft.java @@ -1300,14 +1300,10 @@ public class Minecraft extends ModData implements IThreadListener { Controller.tick(); - if(this.currentScreen != null) { - if(Controller.cursor == null) { - Controller.addCursor(0, 0); - } - } else { - if(Controller.cursor != null) { - Controller.removeCursor(); - } + if(this.currentScreen != null && Controller.isActive && Controller.cursor == null) { + Controller.addCursor(0, 0); + } else if(Controller.cursor != null) { + Controller.removeCursor(); } if (this.rightClickDelayTimer > 0) {