forked from Chicken-Bones/NotEnoughItems
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: slprime <[email protected]>
- Loading branch information
Showing
7 changed files
with
205 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
Oops, something went wrong.