From 6d74a0685b7088700c71d67f0cafc1c1b60820f2 Mon Sep 17 00:00:00 2001 From: syeyoung Date: Sun, 22 Aug 2021 17:57:25 +0900 Subject: - Bug Report 295 --- .../java/kr/syeyoung/dungeonsguide/gui/MGui.java | 48 +++++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'src/main/java/kr/syeyoung/dungeonsguide/gui/MGui.java') diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/MGui.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/MGui.java index 5ee5c42a..4f09a9be 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/MGui.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/MGui.java @@ -19,7 +19,6 @@ package kr.syeyoung.dungeonsguide.gui; import kr.syeyoung.dungeonsguide.gui.elements.MRootPanel; -import kr.syeyoung.dungeonsguide.utils.GlStateUtils; import kr.syeyoung.dungeonsguide.utils.cursor.EnumCursor; import kr.syeyoung.dungeonsguide.utils.cursor.GLCursors; import lombok.Getter; @@ -27,12 +26,16 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.util.Tuple; import org.lwjgl.LWJGLException; +import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import java.awt.*; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; public class MGui extends GuiScreen { @@ -83,13 +86,29 @@ public class MGui extends GuiScreen { @Override public void keyTyped(char typedChar, int keyCode) throws IOException { try { - mainPanel.keyTyped0(typedChar, keyCode); + mainPanel.keyPressed0(typedChar, keyCode); super.keyTyped(typedChar, keyCode); } catch (Throwable e) { if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) e.printStackTrace(); } } + public void keyHeld(int keyCode, char typedChar, long heldMS) throws IOException { + try { + mainPanel.keyHeld0(typedChar, keyCode, heldMS); + } catch (Throwable e) { + if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + e.printStackTrace(); + } + } + public void keyReleased(int keyCode, char typedChar,long heldMS) throws IOException { + try { + mainPanel.keyReleased0(typedChar, keyCode, heldMS); + } catch (Throwable e) { + if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + e.printStackTrace(); + } + } @Override public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { @@ -107,6 +126,7 @@ public class MGui extends GuiScreen { public void onGuiClosed() { super.onGuiClosed(); isOpen = false; + keyLastPressed.clear(); try { Mouse.setNativeCursor(null); @@ -155,6 +175,8 @@ public class MGui extends GuiScreen { private int lastX, lastY; + + @Override public void handleMouseInput() throws IOException { if (!isOpen) return; @@ -213,6 +235,28 @@ public class MGui extends GuiScreen { e.printStackTrace(); } } + private Map> keyLastPressed = new HashMap<>(); + public void handleKeyboardInput() throws IOException + { + if (!isOpen) return; + if (Keyboard.getEventKeyState()) + { + keyLastPressed.put(Keyboard.getEventKey(), new Tuple<>(Keyboard.getEventCharacter(), System.currentTimeMillis())); + this.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey()); + } else { + Tuple val = keyLastPressed.remove(Keyboard.getEventKey()); + if (val != null) this.keyReleased(Keyboard.getEventKey(), val.getFirst(), val.getSecond()); + } + this.mc.dispatchKeypresses(); + } + @Override + public void handleInput() throws IOException { + super.handleInput(); + long currentTime = System.currentTimeMillis(); + for (Map.Entry> integerLongEntry : keyLastPressed.entrySet()) { + this.keyHeld(integerLongEntry.getKey(), integerLongEntry.getValue().getFirst(), integerLongEntry.getValue().getSecond()); + } + } } -- cgit