Only show cursor when controller is active

This commit is contained in:
PeytonPlayz595 2024-07-08 09:13:48 -07:00
parent 48f8a49dd3
commit 204b25528e
3 changed files with 25 additions and 8 deletions

View File

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

View File

@ -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<MouseEvent>() {
@ -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<MouseEvent>() {
@ -153,18 +155,21 @@ public class PlatformInput {
if(hasBeenActive()) {
mouseEvents.add(evt);
}
Controller.isActive = false;
}
});
canvas.addEventListener("mouseenter", mouseenter = new EventListener<MouseEvent>() {
@Override
public void handleEvent(MouseEvent evt) {
isMouseOverWindow = true;
Controller.isActive = false;
}
});
canvas.addEventListener("mouseleave", mouseleave = new EventListener<MouseEvent>() {
@Override
public void handleEvent(MouseEvent evt) {
isMouseOverWindow = false;
Controller.isActive = false;
}
});
win.addEventListener("keydown", keydown = new EventListener<KeyboardEvent>() {
@ -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<KeyboardEvent>() {
@ -198,6 +204,7 @@ public class PlatformInput {
}
}
keyEvents.add(evt);
Controller.isActive = false;
}
});
win.addEventListener("keypress", keypress = new EventListener<KeyboardEvent>() {
@ -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<WheelEvent>() {
@ -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<WheelEvent>() {
@Override
public void handleEvent(WheelEvent evt) {
isWindowFocused = true;
Controller.isActive = false;
}
});
win.getDocument().addEventListener("pointerlockchange", pointerlock = new EventListener<WheelEvent>() {
@ -252,6 +263,7 @@ public class PlatformInput {
}, 60);
mouseDX = 0.0D;
mouseDY = 0.0D;
Controller.isActive = false;
}
});

View File

@ -1300,15 +1300,11 @@ public class Minecraft extends ModData implements IThreadListener {
Controller.tick();
if(this.currentScreen != null) {
if(Controller.cursor == null) {
if(this.currentScreen != null && Controller.isActive && Controller.cursor == null) {
Controller.addCursor(0, 0);
}
} else {
if(Controller.cursor != null) {
} else if(Controller.cursor != null) {
Controller.removeCursor();
}
}
if (this.rightClickDelayTimer > 0) {
--this.rightClickDelayTimer;