full function keybinds
This commit is contained in:
parent
dc1e189d38
commit
d70d0dc0d0
8 changed files with 451 additions and 63 deletions
|
@ -1,7 +1,8 @@
|
|||
package me.kawaiizenbo.moonlight.module.settings;
|
||||
|
||||
import me.kawaiizenbo.moonlight.ui.clickgui.KeybindScreen;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import me.kawaiizenbo.moonlight.util.KeycodeUtils;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.text.Text;
|
||||
|
@ -9,6 +10,7 @@ import net.minecraft.text.Text;
|
|||
public class KeycodeSetting extends Setting
|
||||
{
|
||||
public int value;
|
||||
private boolean isWaiting = false;
|
||||
|
||||
public KeycodeSetting(String name, int value)
|
||||
{
|
||||
|
@ -19,11 +21,14 @@ public class KeycodeSetting extends Setting
|
|||
@Override
|
||||
public void mouseClicked(double mouseX, double mouseY, int button)
|
||||
{
|
||||
if (isWaiting)
|
||||
{
|
||||
isWaiting = false;
|
||||
return;
|
||||
}
|
||||
if (hovered((int)mouseX, (int)mouseY) && button == 0)
|
||||
{
|
||||
KeybindScreen kbs = new KeybindScreen();
|
||||
MinecraftClient.getInstance().setScreen(kbs);
|
||||
this.value = kbs.returnedKeycode;
|
||||
isWaiting = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,9 +37,34 @@ public class KeycodeSetting extends Setting
|
|||
{
|
||||
super.render(drawContext, x, y, mouseX, mouseY, textRenderer);
|
||||
drawContext.drawTextWithShadow(textRenderer, Text.literal(name), x+2, y+8, 0xFFFFFF);
|
||||
String key = java.awt.event.KeyEvent.getKeyText(value);
|
||||
if (value == 0) key = "";
|
||||
int twidth = textRenderer.getWidth(key);
|
||||
drawContext.drawTextWithShadow(textRenderer, key, x+190-twidth, y+8, 0xFFFFFF);
|
||||
if (isWaiting)
|
||||
{
|
||||
String waiting = "Press any key.";
|
||||
int twwidth = textRenderer.getWidth(waiting);
|
||||
drawContext.drawTextWithShadow(textRenderer, waiting, x+190-twwidth, y+8, 0xFFFFFF);
|
||||
}
|
||||
else
|
||||
{
|
||||
String key = KeycodeUtils.keyTable[value];
|
||||
if (value == GLFW.GLFW_KEY_UNKNOWN) key = "";
|
||||
int twidth = textRenderer.getWidth(key);
|
||||
drawContext.drawTextWithShadow(textRenderer, key, x+190-twidth, y+8, 0xFFFFFF);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(int keyCode, int scanCode, int modifiers)
|
||||
{
|
||||
if (isWaiting)
|
||||
{
|
||||
if (keyCode == 256)
|
||||
{
|
||||
// escape was pressed, exit safely
|
||||
isWaiting = false;
|
||||
return;
|
||||
}
|
||||
value = keyCode;
|
||||
isWaiting = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue