|
1 | 1 | package com.teammoeg.chorda.client; |
2 | 2 |
|
3 | 3 | import org.lwjgl.glfw.GLFW; |
| 4 | +import org.lwjgl.system.MemoryUtil; |
4 | 5 |
|
5 | | -import com.mojang.blaze3d.platform.InputConstants; |
6 | 6 |
|
7 | 7 | import net.minecraft.client.Minecraft; |
8 | 8 | import net.minecraft.client.gui.screens.Screen; |
| 9 | +import net.minecraft.client.resources.sounds.SimpleSoundInstance; |
| 10 | +import net.minecraft.sounds.SoundEvents; |
9 | 11 |
|
10 | 12 | public class CInputHelper { |
11 | 13 |
|
12 | 14 | public CInputHelper() { |
13 | 15 | } |
14 | | - public boolean shift(int modifiers) { |
| 16 | + public static boolean isShift(int modifiers) { |
15 | 17 | return (modifiers & GLFW.GLFW_MOD_SHIFT) != 0; |
16 | 18 | } |
17 | 19 |
|
18 | | - public boolean control(int modifiers) { |
| 20 | + public static boolean isControl(int modifiers) { |
19 | 21 | return (modifiers & GLFW.GLFW_MOD_CONTROL) != 0; |
20 | 22 | } |
21 | 23 |
|
22 | | - public boolean alt(int modifiers) { |
| 24 | + public static boolean isAlt(int modifiers) { |
23 | 25 | return (modifiers & GLFW.GLFW_MOD_ALT) != 0; |
24 | 26 | } |
25 | | - |
26 | | - public boolean start(int modifiers) { |
27 | | - return (modifiers & GLFW.GLFW_MOD_SUPER) != 0; |
28 | | - } |
29 | | - |
30 | | - public boolean numLock(int modifiers) { |
31 | | - return (modifiers & GLFW.GLFW_MOD_NUM_LOCK) != 0; |
32 | | - } |
33 | | - |
34 | | - public boolean capsLock(int modifiers) { |
35 | | - return (modifiers & GLFW.GLFW_MOD_CAPS_LOCK) != 0; |
36 | | - } |
37 | | - public boolean onlyControl(int modifiers) { |
38 | | - return control(modifiers) && !shift(modifiers) && !alt(modifiers); |
39 | | - } |
40 | | - public boolean esc(int keyCode) { |
| 27 | + public static boolean isEsc(int keyCode) { |
41 | 28 | return keyCode==GLFW.GLFW_KEY_ESCAPE; |
42 | 29 | } |
43 | 30 |
|
44 | | - public boolean escOrInventory(int keyCode,int scanCode) { |
| 31 | + public static boolean shouldCloseMenu(int keyCode,int scanCode) { |
45 | 32 |
|
46 | | - return esc(keyCode) || Minecraft.getInstance().options.keyInventory.matches(keyCode, scanCode); |
| 33 | + return isEsc(keyCode) || ClientUtils.mc().options.keyInventory.matches(keyCode, scanCode); |
47 | 34 | } |
48 | 35 |
|
49 | | - public boolean enter(int keyCode) { |
| 36 | + public static boolean isEnter(int keyCode) { |
50 | 37 | return keyCode==GLFW.GLFW_KEY_ENTER; |
51 | 38 | } |
52 | 39 |
|
53 | | - public boolean backspace(int keyCode) { |
| 40 | + public static boolean isBackspace(int keyCode) { |
54 | 41 | return keyCode==GLFW.GLFW_KEY_BACKSPACE; |
55 | 42 | } |
56 | 43 |
|
57 | | - public boolean cut(int keyCode) { |
| 44 | + public static boolean isCut(int keyCode) { |
58 | 45 | return Screen.isCut(keyCode); |
59 | 46 | } |
60 | 47 |
|
61 | | - public boolean paste(int keyCode) { |
| 48 | + public static boolean isPaste(int keyCode) { |
62 | 49 | return Screen.isPaste(keyCode); |
63 | 50 | } |
64 | 51 |
|
65 | | - public boolean copy(int keyCode) { |
| 52 | + public static boolean isCopy(int keyCode) { |
66 | 53 | return Screen.isCopy(keyCode); |
67 | 54 | } |
68 | 55 |
|
69 | | - public boolean selectAll(int keyCode) { |
| 56 | + public static boolean isSelectAll(int keyCode) { |
70 | 57 | return Screen.isSelectAll(keyCode); |
71 | 58 | } |
72 | 59 |
|
73 | | - public boolean deselectAll(int keyCode) { |
74 | | - return keyCode == GLFW.GLFW_KEY_D && Screen.hasControlDown() && !Screen.hasShiftDown() && !Screen.hasAltDown(); |
| 60 | + public static boolean isDeselectAll(int keyCode) { |
| 61 | + return keyCode == GLFW.GLFW_KEY_D && Screen.hasControlDown(); |
| 62 | + } |
| 63 | + public static String getClipboardText() { |
| 64 | + return ClientUtils.mc().keyboardHandler.getClipboard(); |
| 65 | + } |
| 66 | + |
| 67 | + public static void setClipboardText(String string) { |
| 68 | + ClientUtils.mc().keyboardHandler.setClipboard(string); |
| 69 | + } |
| 70 | + public static boolean isShiftKeyDown() { |
| 71 | + return Screen.hasShiftDown(); |
| 72 | + } |
| 73 | + |
| 74 | + public static boolean isCtrlKeyDown() { |
| 75 | + return Screen.hasControlDown(); |
| 76 | + } |
| 77 | + public static boolean isKeyPressed(int keyCode) { |
| 78 | + return GLFW.glfwGetKey(Minecraft.getInstance().getWindow().getWindow(), keyCode) == GLFW.GLFW_PRESS; |
| 79 | + } |
| 80 | + public static void playClickSound() { |
| 81 | + ClientUtils.mc().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK.value(), 1)); |
| 82 | + } |
| 83 | + public static boolean isMouseLeftDown() { |
| 84 | + return GLFW.glfwGetMouseButton(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_MOUSE_BUTTON_LEFT) == GLFW.GLFW_PRESS; |
| 85 | + } |
| 86 | + public static boolean isMouseRightDown() { |
| 87 | + return GLFW.glfwGetMouseButton(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_MOUSE_BUTTON_RIGHT) == GLFW.GLFW_PRESS; |
75 | 88 | } |
| 89 | + public enum Cursor{ |
| 90 | + NORMAL(GLFW.GLFW_ARROW_CURSOR), |
| 91 | + IBEAM(GLFW.GLFW_IBEAM_CURSOR), |
| 92 | + CROSSHAIR(GLFW.GLFW_CROSSHAIR_CURSOR), |
| 93 | + HAND(GLFW.GLFW_HAND_CURSOR), |
| 94 | + HRESIZE(GLFW.GLFW_HRESIZE_CURSOR), |
| 95 | + VRESIZE(GLFW.GLFW_VRESIZE_CURSOR); |
| 96 | + |
| 97 | + private final int type; |
| 98 | + private long handle = 0L; |
| 99 | + |
| 100 | + Cursor(int type) { |
| 101 | + this.type = type; |
| 102 | + } |
| 103 | + public void use() { |
| 104 | + long window = Minecraft.getInstance().getWindow().getWindow(); |
| 105 | + |
| 106 | + if (handle == 0) { |
| 107 | + handle = GLFW.glfwCreateStandardCursor(type); |
| 108 | + } |
| 109 | + |
| 110 | + GLFW.glfwSetCursor(window, handle); |
| 111 | + } |
| 112 | + public static void reset() { |
| 113 | + long window = Minecraft.getInstance().getWindow().getWindow(); |
| 114 | + GLFW.glfwSetCursor(window, MemoryUtil.NULL); |
| 115 | + } |
| 116 | + } |
| 117 | + |
76 | 118 | } |
0 commit comments