Fix cursor movement using controller

This commit is contained in:
PeytonPlayz595 2024-07-07 20:03:09 -07:00
parent 54806c33c7
commit af42bbe2fa
2 changed files with 24 additions and 37 deletions

View File

@ -11,6 +11,7 @@ import org.teavm.jso.dom.html.HTMLImageElement;
import org.teavm.jso.gamepad.GamepadEvent; import org.teavm.jso.gamepad.GamepadEvent;
import net.lax1dude.eaglercraft.v1_8.Display; import net.lax1dude.eaglercraft.v1_8.Display;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformRuntime;
import org.teavm.jso.gamepad.Gamepad; import org.teavm.jso.gamepad.Gamepad;
@ -29,6 +30,7 @@ public class Controller {
private static double threshold = 0.3; private static double threshold = 0.3;
//Fixes 'slight' issues of stick drift people have been complaining about //Fixes 'slight' issues of stick drift people have been complaining about
private static double cameraThreshold = 4.0; private static double cameraThreshold = 4.0;
private static double cursorThreshold = 0.4;
private static int activeController = -1; private static int activeController = -1;
private static ButtonState[] states = new ButtonState[30]; private static ButtonState[] states = new ButtonState[30];
@ -142,35 +144,16 @@ public class Controller {
dy = -axes[3] * multiplier; dy = -axes[3] * multiplier;
if(cursor != null) { if(cursor != null) {
double dx1; int dx1 = getDX();
double dy1 = dy; int dy1 = getDY();
if(dx1 < 0.0) { if(dx1 > 0 || dx1 < 0) {
if(dx1 < -cameraThreshold) { updateCursorX(dx1);
dx1 = dx;
}
} else if(dx > 0.0) {
if(dx > cameraThreshold) {
dx1 = dx;
}
} else {
dx1 = 0;
} }
if(dy1 < 0.0) { if(dy1 > 0 || dy1 < 0) {
if(dy1 < -cameraThreshold) { updateCursorY(-dy1);
dy1 = dy;
} }
} else if(dy1 > 0.0) {
if(dy1 > cameraThreshold) {
dy1 = dy;
}
} else {
dy1 = 0;
}
updateCursor((int)dx1, (int)dy1);
} }
forward = axes[1] < -threshold; forward = axes[1] < -threshold;
@ -213,8 +196,9 @@ public class Controller {
cursor.setAttribute("id", "cursor"); cursor.setAttribute("id", "cursor");
cursor.setSrc(cursorSrc); cursor.setSrc(cursorSrc);
cursor.setAttribute("draggable", "false"); cursor.setAttribute("draggable", "false");
cursor.getStyle().setProperty("left", "0px"); cursor.getStyle().setProperty("position", "fixed");
cursor.getStyle().setProperty("top", "0px"); cursor.getStyle().setProperty("top", "0");
cursor.getStyle().setProperty("left", "0");
cursor.getStyle().setProperty("width", "auto"); cursor.getStyle().setProperty("width", "auto");
cursor.getStyle().setProperty("height", "auto"); cursor.getStyle().setProperty("height", "auto");
@ -229,15 +213,18 @@ public class Controller {
cursor = null; cursor = null;
} }
private static void updateCursor(int dx, int dy) { private static void updateCursorX(int x) {
int dx1 = cursor.getAbsoluteLeft() + dx; int newX = cursor.getOffsetLeft() + x;
int dy1 = cursor.getAbsoluteTop() + dy;
int x = Math.min(Math.max(dx1, 0), Display.getWidth() - cursor.getWidth()); newX = Math.max(0, Math.min(newX, PlatformRuntime.canvas.getClientWidth() - cursor.getWidth()));
int y = Math.min(Math.max(dy1, 0), Display.getHeight() - cursor.getHeight()); cursor.getStyle().setProperty("left", Integer.toString(newX) + "px");
}
cursor.getStyle().setProperty("left", dx1 + "px"); private static void updateCursorY(int y) {
cursor.getStyle().setProperty("top", dy1 + "px"); int newY = cursor.getOffsetTop() + y;
newY = Math.max(0, Math.min(newY, PlatformRuntime.canvas.getClientHeight() - cursor.getHeight()));
cursor.getStyle().setProperty("top", Integer.toString(newY) + "px");
} }
private static Gamepad getGamepad(int index) { private static Gamepad getGamepad(int index) {

View File

@ -33,7 +33,7 @@ public class PlatformOpenGL {
private static final Logger logger = LogManager.getLogger("PlatformOpenGL"); private static final Logger logger = LogManager.getLogger("PlatformOpenGL");
static WebGL2RenderingContext ctx = null; public static WebGL2RenderingContext ctx = null;
static boolean hasDebugRenderInfoExt = false; static boolean hasDebugRenderInfoExt = false;
static boolean hasFramebufferHDR16FSupport = false; static boolean hasFramebufferHDR16FSupport = false;