mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-26 23:13:27 +00:00
Added hotkey utils methods (#599)
Co-authored-by: slprime <[email protected]>
This commit is contained in:
1 parent
48934d621f
commit
ac50d1b27e
7 files changed
+205
-68
No files matched your search
@@ -0,0 +1,80 @@
|
||||
package codechicken.nei.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
|
||||
public class NEIKeyboardUtils {
|
||||
|
||||
public static final int ALT_HASH = 1 << 27;
|
||||
public static final int SHIFT_HASH = 1 << 26;
|
||||
public static final int CTRL_HASH = 1 << 25;
|
||||
|
||||
private static final Map<Integer, Integer> keyHashMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
keyHashMap.put(Keyboard.KEY_LSHIFT, SHIFT_HASH);
|
||||
keyHashMap.put(Keyboard.KEY_RSHIFT, SHIFT_HASH);
|
||||
|
||||
keyHashMap.put(Keyboard.KEY_LCONTROL, CTRL_HASH);
|
||||
keyHashMap.put(Keyboard.KEY_LCONTROL, CTRL_HASH);
|
||||
|
||||
keyHashMap.put(Keyboard.KEY_LMETA, CTRL_HASH);
|
||||
keyHashMap.put(Keyboard.KEY_RMETA, CTRL_HASH);
|
||||
|
||||
keyHashMap.put(Keyboard.KEY_LMENU, ALT_HASH);
|
||||
keyHashMap.put(Keyboard.KEY_LMENU, ALT_HASH);
|
||||
}
|
||||
|
||||
private NEIKeyboardUtils() {}
|
||||
|
||||
public static boolean isHashKey(int keycode) {
|
||||
return keyHashMap.containsKey(keycode);
|
||||
}
|
||||
|
||||
public static String getHashName(int keyBind) {
|
||||
StringJoiner keyText = new StringJoiner(" + ");
|
||||
|
||||
if ((keyBind & CTRL_HASH) != 0) {
|
||||
keyText.add(NEIClientUtils.translate(Minecraft.isRunningOnMac ? "key.ctrl.mac" : "key.ctrl"));
|
||||
}
|
||||
|
||||
if ((keyBind & SHIFT_HASH) != 0) {
|
||||
keyText.add(NEIClientUtils.translate("key.shift"));
|
||||
}
|
||||
|
||||
if ((keyBind & ALT_HASH) != 0) {
|
||||
keyText.add(NEIClientUtils.translate("key.alt"));
|
||||
}
|
||||
|
||||
return keyText.toString();
|
||||
}
|
||||
|
||||
public static String getKeyName(int keyBind) {
|
||||
keyBind = keyHashMap.getOrDefault(keyBind, keyBind);
|
||||
StringJoiner keyText = new StringJoiner(" + ");
|
||||
String hashText = getHashName(keyBind);
|
||||
int keyID = unhash(keyBind);
|
||||
|
||||
if (!hashText.isEmpty()) {
|
||||
keyText.add(hashText);
|
||||
}
|
||||
|
||||
if (keyID != Keyboard.CHAR_NONE || hashText.isEmpty()) {
|
||||
keyText.add(Keyboard.getKeyName(keyID));
|
||||
}
|
||||
|
||||
return keyText.toString();
|
||||
}
|
||||
|
||||
public static int unhash(int keyBind) {
|
||||
return keyBind & ~(CTRL_HASH | SHIFT_HASH | ALT_HASH);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package codechicken.nei.util;
|
||||
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
|
||||
public class NEIMouseUtils {
|
||||
|
||||
public static final int MOUSE_BTN_NONE = Integer.MIN_VALUE;
|
||||
|
||||
public static final int MOUSE_BTN_LMB = 0;
|
||||
public static final int MOUSE_BTN_RMB = 1;
|
||||
public static final int MOUSE_BTN_MMB = 2;
|
||||
|
||||
public static final int MOUSE_SCROLL = 1 << 27;
|
||||
public static final int MOUSE_DRAG = 1 << 26;
|
||||
|
||||
private NEIMouseUtils() {}
|
||||
|
||||
public static String getHashName(int mouseBind) {
|
||||
StringJoiner mouseText = new StringJoiner(" + ");
|
||||
|
||||
if ((mouseBind & MOUSE_SCROLL) != 0) {
|
||||
mouseText.add(NEIClientUtils.translate("mouse.scroll"));
|
||||
}
|
||||
|
||||
if ((mouseBind & MOUSE_DRAG) != 0) {
|
||||
mouseText.add(NEIClientUtils.translate("mouse.drag"));
|
||||
}
|
||||
|
||||
return mouseText.toString();
|
||||
}
|
||||
|
||||
public static String getKeyName(int mouseBind) {
|
||||
StringJoiner mouseText = new StringJoiner(" + ");
|
||||
String hashText = getHashName(mouseBind < 0 ? mouseBind - MOUSE_BTN_NONE : mouseBind);
|
||||
|
||||
if (mouseBind >= 0) {
|
||||
int button = unhash(mouseBind);
|
||||
switch (button) {
|
||||
case 0:
|
||||
mouseText.add(NEIClientUtils.translate("mouse.left"));
|
||||
break;
|
||||
case 1:
|
||||
mouseText.add(NEIClientUtils.translate("mouse.right"));
|
||||
break;
|
||||
case 2:
|
||||
mouseText.add(NEIClientUtils.translate("mouse.middle"));
|
||||
break;
|
||||
default:
|
||||
mouseText.add(NEIClientUtils.translate("mouse.other", button));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hashText.isEmpty()) {
|
||||
mouseText.add(hashText);
|
||||
}
|
||||
|
||||
return mouseText.toString();
|
||||
}
|
||||
|
||||
public static int unhash(int mouseBind) {
|
||||
return mouseBind & ~(MOUSE_SCROLL | MOUSE_DRAG);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user