diff options
author | syeyoung <cyougn06@naver.com> | 2022-01-11 23:32:49 +0900 |
---|---|---|
committer | syeyoung <cyougn06@naver.com> | 2022-01-11 23:32:49 +0900 |
commit | 97ad0ab478e7ab75ab8e78c9235961d2f2df6553 (patch) | |
tree | 5ac82967253179b90847932b34aa4427db12ac51 /src/main/java/kr | |
parent | f8ad945e1f078d904fd839ccc7f07ee17eec5203 (diff) | |
download | Skyblock-Dungeons-Guide-97ad0ab478e7ab75ab8e78c9235961d2f2df6553.tar.gz Skyblock-Dungeons-Guide-97ad0ab478e7ab75ab8e78c9235961d2f2df6553.tar.bz2 Skyblock-Dungeons-Guide-97ad0ab478e7ab75ab8e78c9235961d2f2df6553.zip |
- Fix Keys repeating and re-implement key repeat mechanics using Keyboard.enableRepeatEvents
(this breaks with current latest version of neu, but it should be fixed in neu's side)
Diffstat (limited to 'src/main/java/kr')
4 files changed, 27 insertions, 38 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/MParameterEdit.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/MParameterEdit.java index 8ed0e028..6f791bcf 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/MParameterEdit.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/MParameterEdit.java @@ -177,15 +177,15 @@ public class MParameterEdit extends MPanel { } @Override - public void keyHeld0(char typedChar, int keyCode, long heldMS) { + public void keyHeld0(char typedChar, int keyCode) { if (isDisabled.test(featureParameter)) return; - super.keyHeld0(typedChar, keyCode, heldMS); + super.keyHeld0(typedChar, keyCode); } @Override - public void keyReleased0(char typedChar, int keyCode, long heldMS) { + public void keyReleased0(char typedChar, int keyCode) { if (isDisabled.test(featureParameter)) return; - super.keyReleased0(typedChar, keyCode, heldMS); + super.keyReleased0(typedChar, keyCode); } @Override diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/MGui.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/MGui.java index 4f09a9be..13c9e00f 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/MGui.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/MGui.java @@ -54,6 +54,7 @@ public class MGui extends GuiScreen { @Override public void initGui() { super.initGui(); + Keyboard.enableRepeatEvents(true); isOpen = true; ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); mainPanel.setBounds(new Rectangle(0,0,Minecraft.getMinecraft().displayWidth,Minecraft.getMinecraft().displayHeight)); @@ -93,17 +94,17 @@ public class MGui extends GuiScreen { e.printStackTrace(); } } - public void keyHeld(int keyCode, char typedChar, long heldMS) throws IOException { + public void keyHeld(int keyCode, char typedChar) throws IOException { try { - mainPanel.keyHeld0(typedChar, keyCode, heldMS); + mainPanel.keyHeld0(typedChar, keyCode); } 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 { + public void keyReleased(int keyCode, char typedChar) throws IOException { try { - mainPanel.keyReleased0(typedChar, keyCode, heldMS); + mainPanel.keyReleased0(typedChar, keyCode); } catch (Throwable e) { if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) e.printStackTrace(); @@ -125,8 +126,8 @@ public class MGui extends GuiScreen { @Override public void onGuiClosed() { super.onGuiClosed(); + Keyboard.enableRepeatEvents(false); isOpen = false; - keyLastPressed.clear(); try { Mouse.setNativeCursor(null); @@ -235,17 +236,18 @@ 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()); + if (Keyboard.isRepeatEvent()) + this.keyHeld(Keyboard.getEventKey(), Keyboard.getEventCharacter()); + else + 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.keyReleased(Keyboard.getEventKey(), Keyboard.getEventCharacter()); } this.mc.dispatchKeypresses(); @@ -253,10 +255,7 @@ public class MGui extends GuiScreen { @Override public void handleInput() throws IOException { +// Keyboard.enableRepeatEvents(true); // i hope it's temproary solution 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 c71f8312..b79ec148 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java @@ -200,24 +200,24 @@ public class MPanel { keyPressed(typedChar, keyCode); } public void keyPressed(char typedChar, int keyCode) {} - public void keyHeld0(char typedChar, int keyCode, long heldMS) { + public void keyHeld0(char typedChar, int keyCode) { for (MPanel childComponent : getChildComponents()) { - childComponent.keyHeld0(typedChar, keyCode, heldMS); + childComponent.keyHeld0(typedChar, keyCode); } if (isFocused) - keyHeld(typedChar, keyCode, heldMS); + keyHeld(typedChar, keyCode); } - public void keyHeld(char typedChar, int keyCode, long heldMS) {} - public void keyReleased0(char typedChar, int keyCode, long heldMS) { + public void keyHeld(char typedChar, int keyCode) {} + public void keyReleased0(char typedChar, int keyCode) { for (MPanel childComponent : getChildComponents()) { - childComponent.keyReleased0(typedChar, keyCode, heldMS); + childComponent.keyReleased0(typedChar, keyCode); } if (isFocused) - keyReleased(typedChar, keyCode, heldMS); + keyReleased(typedChar, keyCode); } - public void keyReleased(char typedChar, int keyCode, long heldMS) {} + public void keyReleased(char typedChar, int keyCode) {} public boolean mouseClicked0(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int mouseButton) { 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 653cd2d9..d87c08e3 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java @@ -205,25 +205,15 @@ public class MTextField extends MPanel { } } - private Map<Integer, Long> callKeyHeldIfAfter = new HashMap<>(); @Override - public void keyHeld(char typedChar, int keyCode, long heldMS) { + public void keyHeld(char typedChar, int keyCode) { 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); + this.keyPressed(typedChar, 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 |