2019-09-03 08:34:02 +02:00
|
|
|
package com.simibubi.create;
|
|
|
|
|
|
|
|
import org.lwjgl.glfw.GLFW;
|
|
|
|
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.gui.screen.Screen;
|
|
|
|
import net.minecraft.client.settings.KeyBinding;
|
|
|
|
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
|
|
|
|
|
|
|
public enum AllKeys {
|
|
|
|
|
2019-10-05 19:00:43 +02:00
|
|
|
TOOL_MENU("toolmenu", GLFW.GLFW_KEY_LEFT_ALT),
|
2019-09-03 08:34:02 +02:00
|
|
|
ACTIVATE_TOOL("", GLFW.GLFW_KEY_LEFT_CONTROL),
|
|
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
private KeyBinding keybind;
|
|
|
|
private String description;
|
|
|
|
private int key;
|
|
|
|
private boolean modifiable;
|
|
|
|
|
|
|
|
private AllKeys(String description, int defaultKey) {
|
2019-09-14 18:21:30 +02:00
|
|
|
this.description = Create.ID + ".keyinfo." + description;
|
2019-09-03 08:34:02 +02:00
|
|
|
this.key = defaultKey;
|
|
|
|
this.modifiable = !description.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void register() {
|
|
|
|
for (AllKeys key : values()) {
|
|
|
|
key.keybind = new KeyBinding(key.description, key.key, Create.NAME);
|
|
|
|
if (!key.modifiable)
|
|
|
|
continue;
|
2019-10-05 19:00:43 +02:00
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
ClientRegistry.registerKeyBinding(key.keybind);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public KeyBinding getKeybind() {
|
|
|
|
return keybind;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isPressed() {
|
|
|
|
if (!modifiable)
|
|
|
|
return isKeyDown(key);
|
|
|
|
return keybind.isKeyDown();
|
|
|
|
}
|
|
|
|
|
2020-07-22 06:57:59 +02:00
|
|
|
// TODO this should return ITextComponent
|
2019-09-03 08:34:02 +02:00
|
|
|
public String getBoundKey() {
|
2020-07-22 06:57:59 +02:00
|
|
|
return keybind.getBoundKeyLocalizedText().getUnformattedComponentText().toUpperCase();
|
2019-09-03 08:34:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getBoundCode() {
|
|
|
|
return keybind.getKey().getKeyCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isKeyDown(int key) {
|
2020-03-29 04:10:23 +02:00
|
|
|
return GLFW.glfwGetKey(Minecraft.getInstance().getWindow().getHandle(), key) != 0;
|
2019-09-03 08:34:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean ctrlDown() {
|
|
|
|
return Screen.hasControlDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean shiftDown() {
|
|
|
|
return Screen.hasShiftDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean altDown() {
|
|
|
|
return Screen.hasAltDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|