diff options
5 files changed, 89 insertions, 9 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/location/GuiGuiLocationConfig.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/location/GuiGuiLocationConfig.java index 8ce2aa8f..48c046c3 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/location/GuiGuiLocationConfig.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/location/GuiGuiLocationConfig.java @@ -136,7 +136,7 @@ public class GuiGuiLocationConfig extends MGui { @Override public void keyTyped(char typedChar, int keyCode) throws IOException { try { - getMainPanel().keyTyped0(typedChar, keyCode); + getMainPanel().keyPressed0(typedChar, keyCode); if (keyCode == 1) { Minecraft.getMinecraft().displayGuiScreen(before); 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<Integer, Tuple<Character, Long>> 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<Character, Long> 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<Integer, Tuple<Character, Long>> integerLongEntry : keyLastPressed.entrySet()) { + this.keyHeld(integerLongEntry.getKey(), integerLongEntry.getValue().getFirst(), integerLongEntry.getValue().getSecond()); + } + } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java index d155b9d4..c71f8312 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java @@ -191,15 +191,34 @@ public class MPanel { public void resize(int parentWidth, int parentHeight) {} - public void keyTyped0(char typedChar, int keyCode) { + public void keyPressed0(char typedChar, int keyCode) { for (MPanel childComponent : getChildComponents()) { - childComponent.keyTyped0(typedChar, keyCode); + childComponent.keyPressed0(typedChar, keyCode); } if (isFocused) - keyTyped(typedChar, keyCode); + keyPressed(typedChar, keyCode); } - public void keyTyped(char typedChar, int keyCode) {} + public void keyPressed(char typedChar, int keyCode) {} + public void keyHeld0(char typedChar, int keyCode, long heldMS) { + for (MPanel childComponent : getChildComponents()) { + childComponent.keyHeld0(typedChar, keyCode, heldMS); + } + + if (isFocused) + keyHeld(typedChar, keyCode, heldMS); + } + public void keyHeld(char typedChar, int keyCode, long heldMS) {} + public void keyReleased0(char typedChar, int keyCode, long heldMS) { + for (MPanel childComponent : getChildComponents()) { + childComponent.keyReleased0(typedChar, keyCode, heldMS); + } + + if (isFocused) + keyReleased(typedChar, keyCode, heldMS); + } + public void keyReleased(char typedChar, int keyCode, long heldMS) {} + public boolean mouseClicked0(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int mouseButton) { int relMousex = relMouseX0 - getBounds().x; diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java index b40acd02..653cd2d9 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java @@ -37,6 +37,8 @@ import java.awt.*; import java.awt.datatransfer.*; import java.awt.event.KeyEvent; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; @Getter public class MTextField extends MPanel { @@ -203,10 +205,25 @@ public class MTextField extends MPanel { } } + private Map<Integer, Long> callKeyHeldIfAfter = new HashMap<>(); @Override - public void keyTyped(char typedChar, int keycode) { + public void keyHeld(char typedChar, int keyCode, long heldMS) { if (!isFocused) return; + Long callAfter = callKeyHeldIfAfter.get(keyCode); + if (callAfter == null) return; + if (callAfter <= System.currentTimeMillis()) this.keyPressed(typedChar, keyCode); + } + + @Override + public void keyReleased(char typedChar, int keyCode, long heldMS) { + callKeyHeldIfAfter.remove(keyCode); + } + @Override + public void keyPressed(char typedChar, int keycode) { + if (!isFocused) return; + if (callKeyHeldIfAfter.containsKey(keycode)) callKeyHeldIfAfter.put(keycode, System.currentTimeMillis()+50); + else callKeyHeldIfAfter.put(keycode, System.currentTimeMillis() + 750); if (selectionStart == -1) { if (keycode == 199) { // home diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/panes/RoomDataDisplayPane.java b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/panes/RoomDataDisplayPane.java index 6c866ec9..bd3da672 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/panes/RoomDataDisplayPane.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/panes/RoomDataDisplayPane.java @@ -95,7 +95,7 @@ public class RoomDataDisplayPane extends MPanel { } @Override - public void keyTyped(char typedChar, int keyCode) { + public void keyPressed(char typedChar, int keyCode) { int[][] blocks = dungeonRoom.getDungeonRoomInfo().getBlocks(); if (selectedX != -1 && selectedY != -1 && selectedY < blocks.length && selectedX < blocks[0].length) { dungeonRoom.getDungeonRoomInfo().getBlocks()[selectedY][selectedX] = -1; |