Compare commits

...

3 Commits

Author SHA1 Message Date
PeytonPlayz595
2bb51035c2 snapshot 24w28a 2024-07-08 09:27:32 -07:00
PeytonPlayz595
204b25528e Only show cursor when controller is active 2024-07-08 09:13:48 -07:00
PeytonPlayz595
48f8a49dd3 Controller mouse click 2024-07-08 08:16:20 -07:00
7 changed files with 55 additions and 13 deletions

View File

@ -16,7 +16,7 @@ public class EaglercraftVersion {
//Client name (Shadow)
public static final String projectForkName = new String(new byte[] {83, 104, 97, 100, 111, 119 });
//Build version (number + snapshot/official)
public static final String projectForkVersion = new String(new byte[] {52, 46, 53, 32, 115, 110, 97, 112, 115, 104, 111, 116, 45, 50, 52, 119, 50, 55, 97 });
public static final String projectForkVersion = new String(new byte[] {52, 46, 53, 32, 115, 110, 97, 112, 115, 104, 111, 116, 45, 50, 52, 119, 50, 56, 97 });
//Author name (PeytonPlayz585)
public static final String projectForkVendor = new String(new byte[] {80, 101, 121, 116, 111, 110, 80, 108, 97, 121, 122, 53, 56, 53 });

View File

@ -202,8 +202,9 @@ public class WorldRenderer {
* SLOW AND STUPID COMPANION FUNCTION TO 'func_181672_a'
*/
public void setVertexState(WorldRenderer.State state) {
this.grow(state.getRawBuffer().length);
PlatformBufferFunctions.put(this.intBuffer, 0, state.getRawBuffer());
int[] rawBuffer = state.getRawBuffer();
this.grow(rawBuffer.length);
PlatformBufferFunctions.put(this.intBuffer, 0, rawBuffer);
this.vertexCount = state.getVertexCount();
this.vertexFormat = state.getVertexFormat();
}

View File

@ -40,7 +40,7 @@ public class GuiButton extends Gui {
public int id;
public boolean enabled;
public boolean visible;
protected boolean hovered;
public boolean hovered;
public float fontScale = 1.0f;
public GuiButton(int buttonId, int x, int y, String buttonText) {

View File

@ -11,7 +11,9 @@ import org.teavm.jso.dom.html.HTMLImageElement;
import org.teavm.jso.gamepad.GamepadEvent;
import net.lax1dude.eaglercraft.v1_8.Display;
import net.lax1dude.eaglercraft.v1_8.Mouse;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformRuntime;
import net.minecraft.client.Minecraft;
import org.teavm.jso.gamepad.Gamepad;
@ -27,8 +29,8 @@ public class Controller {
private static boolean left = false;
private static boolean right = false;
private static double threshold = 0.3;
//Fixes 'slight' issues of stick drift people have been complaining about
private static double threshold = 0.3;
private static double cameraThreshold = 4.0;
private static double cursorThreshold = 0.4;
@ -36,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) {
@ -156,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;
@ -172,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) {
@ -189,6 +198,10 @@ public class Controller {
updateAxes(gamePad);
updateButtons(gamePad, index);
}
if(cursor != null && isButtonPressed(0) || isButtonDown(0)) {
Minecraft.getMinecraft().currentScreen.controllerClicked(Mouse.getX(), Mouse.getY());
}
}
public static void addCursor(int x, int y) {
@ -246,6 +259,7 @@ public class Controller {
@Override
public void handleEvent(GamepadEvent arg0) {
connectedControllers.add(arg0.getGamepad().getIndex());
isActive = true;
System.out.println("Controller connected!");
}
});
@ -257,6 +271,7 @@ public class Controller {
if(connectedControllers.contains(index)) {
connectedControllers.remove(index);
resetButtonStates();
isActive = false;
System.out.println("Controller disconnected!");
}
}

View File

@ -21,6 +21,7 @@ import org.teavm.jso.dom.html.HTMLElement;
import org.teavm.jso.webgl.WebGLFramebuffer;
import org.teavm.jso.webgl.WebGLRenderbuffer;
import net.PeytonPlayz585.shadow.input.Controller;
import net.lax1dude.eaglercraft.v1_8.EagUtils;
import net.lax1dude.eaglercraft.v1_8.internal.teavm.EarlyLoadScreen;
import net.lax1dude.eaglercraft.v1_8.internal.teavm.WebGL2RenderingContext;
@ -128,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>() {
@ -138,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>() {
@ -152,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>() {
@ -179,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>() {
@ -197,6 +204,7 @@ public class PlatformInput {
}
}
keyEvents.add(evt);
Controller.isActive = false;
}
});
win.addEventListener("keypress", keypress = new EventListener<KeyboardEvent>() {
@ -204,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);
}
});
@ -214,6 +223,7 @@ public class PlatformInput {
evt.stopPropagation();
mouseEvents.add(evt);
mouseDWheel += evt.getDeltaY();
Controller.isActive = false;
}
});
win.addEventListener("blur", new EventListener<WheelEvent>() {
@ -226,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>() {
@ -251,6 +263,7 @@ public class PlatformInput {
}, 60);
mouseDX = 0.0D;
mouseDY = 0.0D;
Controller.isActive = false;
}
});
@ -503,10 +516,16 @@ public class PlatformInput {
}
public static int mouseGetX() {
if(Controller.cursor != null) {
return Controller.cursor.getOffsetLeft();
}
return mouseX;
}
public static int mouseGetY() {
if(Controller.cursor != null) {
return canvas.getClientHeight() - Controller.cursor.getOffsetTop();
}
return mouseY;
}

View File

@ -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) {

View File

@ -425,6 +425,17 @@ public abstract class GuiScreen extends Gui implements GuiYesNoCallback {
this.mc.thePlayer.sendChatMessage(msg);
}
public void controllerClicked(int x, int y) {
for (int i = 0; i < this.buttonList.size(); ++i) {
GuiButton guibutton = (GuiButton) this.buttonList.get(i);
if (guibutton.enabled && guibutton.visible && guibutton.hovered) {
this.selectedButton = guibutton;
guibutton.playPressSound(this.mc.getSoundHandler());
this.actionPerformed(guibutton);
}
}
}
/**+
* Called when the mouse is clicked. Args : mouseX, mouseY,