Implemented binds with key modifiers

This commit is contained in:
zeroeightsix 2018-10-09 20:22:14 +02:00
parent d3802679c7
commit 136e0155a4
7 changed files with 139 additions and 27 deletions

View File

@ -53,7 +53,7 @@ public class BindCommand extends Command {
return;
}
m.setKey(key);
m.getBind().setKey(key);
sendChatMessage("Bind for &b" + m.getName() + "&r set to &b" + rkey.toUpperCase());
}
}

View File

@ -3,6 +3,7 @@ package me.zeroeightsix.kami.gui.kami.component;
import me.zeroeightsix.kami.gui.rgui.component.listen.KeyListener;
import me.zeroeightsix.kami.gui.rgui.component.listen.MouseListener;
import me.zeroeightsix.kami.module.Module;
import me.zeroeightsix.kami.util.Bind;
import org.lwjgl.input.Keyboard;
/**
@ -15,15 +16,14 @@ public class BindButton extends EnumButton {
boolean waiting = false;
Module m;
boolean ctrl = false, shift = false, alt = false;
public BindButton(String name, Module m) {
super(name, none);
this.m = m;
int key = m.getBind();
if (key == -1)
modes = none;
else
modes = new String[]{Keyboard.getKeyName(key)};
Bind bind = m.getBind();
modes = new String[]{bind.toString()};
addKeyListener(new KeyListener() {
@Override
@ -31,20 +31,35 @@ public class BindButton extends EnumButton {
if (!waiting) return;
int key = event.getKey();
if (key == Keyboard.KEY_BACK){
m.setKey(-1);
modes = none;
if (isShift(key)) {
shift = true;
modes = new String[]{(ctrl ? "Ctrl + " : "") + (alt ? "Alt + " : "") + "Shift + "};
} else if (isCtrl(key)) {
ctrl = true;
modes = new String[]{"Ctrl + " + (alt ? "Alt + " : "") + (shift ? "Shift + " : "")};
} else if (isAlt(key)) {
alt = true;
modes = new String[]{(ctrl ? "Ctrl + " : "") + "Alt + " + (shift ? "Shift + " : "")};
} else if (key == Keyboard.KEY_BACK) {
m.getBind().setCtrl(false);
m.getBind().setShift(false);
m.getBind().setAlt(false);
m.getBind().setKey(-1);
modes = new String[]{m.getBind().toString()};
waiting = false;
} else {
m.getBind().setCtrl(ctrl);
m.getBind().setShift(shift);
m.getBind().setAlt(alt);
m.getBind().setKey(key);
modes = new String[]{m.getBind().toString()};
ctrl = alt = shift = false;
waiting = false;
return;
}
m.setKey(key);
modes = new String[]{Keyboard.getKeyName(key)};
waiting = false;
}
@Override
public void onKeyUp(KeyEvent event) {
}
});
@ -76,4 +91,18 @@ public class BindButton extends EnumButton {
}
});
}
private boolean isAlt(int key) {
return key == Keyboard.KEY_LMENU || key == Keyboard.KEY_RMENU;
}
private boolean isCtrl(int key) {
return key == Keyboard.KEY_LCONTROL || key == Keyboard.KEY_RCONTROL;
}
private boolean isShift(int key) {
return key == Keyboard.KEY_LSHIFT || key == Keyboard.KEY_RSHIFT;
}
}

View File

@ -5,8 +5,8 @@ import me.zeroeightsix.kami.event.events.RenderEvent;
import me.zeroeightsix.kami.module.modules.movement.Sprint;
import me.zeroeightsix.kami.setting.Setting;
import me.zeroeightsix.kami.setting.SettingsClass;
import me.zeroeightsix.kami.util.Bind;
import net.minecraft.client.Minecraft;
import org.lwjgl.input.Keyboard;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@ -20,7 +20,7 @@ public class Module extends SettingsClass {
private final String description = getAnnotation().description();
private final Category category = getAnnotation().category();
@Setting(name = "Bind", hidden = true)
private int bind = getAnnotation().bind();
private Bind bind = Bind.none();
@Setting(name = "Enabled", hidden = true)
private boolean enabled;
public boolean alwaysListening = false;
@ -42,16 +42,12 @@ public class Module extends SettingsClass {
public void onRender() {}
public void onWorldRender(RenderEvent event) {}
public int getBind() {
public Bind getBind() {
return bind;
}
public String getBindName() {
return bind == -1 ? "NONE" : Keyboard.getKeyName(bind);
}
public void setKey(int key) {
this.bind = key;
return bind.toString();
}
public enum Category
@ -87,7 +83,6 @@ public class Module extends SettingsClass {
{
String name();
String description() default "Descriptionless";
int bind() default 0;
Module.Category category();
boolean alwaysListening() default false;
}

View File

@ -98,8 +98,11 @@ public class ModuleManager {
public static void onBind(int eventKey) {
if (eventKey == 0) return; // if key is the 'none' key (stuff like mod key in i3 might return 0)
modules.forEach(module -> {
if (module.getBind() == eventKey)
if (module.getBind().isDown()) {
System.out.println(module.getBind() + " is down!");
module.toggle();
}
});
}

View File

@ -7,9 +7,13 @@ import org.lwjgl.input.Keyboard;
/**
* Created by 086 on 23/08/2017.
*/
@Module.Info(name = "clickGUI", description = "Opens the Click GUI", bind = Keyboard.KEY_Y, category = Module.Category.HIDDEN)
@Module.Info(name = "clickGUI", description = "Opens the Click GUI", category = Module.Category.HIDDEN)
public class ClickGUI extends Module {
public ClickGUI() {
getBind().setKey(Keyboard.KEY_Y);
}
@Override
protected void onEnable() {
if (!(mc.currentScreen instanceof DisplayGuiScreen)) {

View File

@ -1,12 +1,11 @@
package me.zeroeightsix.kami.module.modules.movement;
import me.zeroeightsix.kami.module.Module;
import org.lwjgl.input.Keyboard;
/**
* Created by 086 on 23/08/2017.
*/
@Module.Info(name = "Sprint", bind = Keyboard.KEY_A, description = "Automatically makes the player sprint", category = Module.Category.MOVEMENT)
@Module.Info(name = "Sprint", description = "Automatically makes the player sprint", category = Module.Category.MOVEMENT)
public class Sprint extends Module {
@Override

View File

@ -0,0 +1,82 @@
package me.zeroeightsix.kami.util;
import org.lwjgl.input.Keyboard;
/**
* Created by 086 on 9/10/2018.
*/
public class Bind {
boolean ctrl;
boolean alt;
boolean shift;
int key;
public Bind(boolean ctrl, boolean alt, boolean shift, int key) {
this.ctrl = ctrl;
this.alt = alt;
this.shift = shift;
this.key = key;
}
public int getKey() {
return key;
}
public boolean isCtrl() {
return ctrl;
}
public boolean isAlt() {
return alt;
}
public boolean isShift() {
return shift;
}
public boolean isEmpty() {
return !ctrl && !shift && !alt && key < 0;
}
public void setAlt(boolean alt) {
this.alt = alt;
}
public void setCtrl(boolean ctrl) {
this.ctrl = ctrl;
}
public void setKey(int key) {
this.key = key;
}
public void setShift(boolean shift) {
this.shift = shift;
}
@Override
public String toString() {
return isEmpty() ? "None" : (isCtrl() ? "Ctrl + " : "") + (isAlt() ? "Alt + " : "") + (isShift() ? "Shift + " : "") + (key < 0 ? "None" : Keyboard.getKeyName(key));
}
public boolean isDown() {
return !isEmpty() && (isShift() == isShiftDown()) && (isCtrl() == isCtrlDown()) && (isAlt() == isAltDown()) && Keyboard.isKeyDown(getKey());
}
private boolean isShiftDown() {
return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
}
private boolean isCtrlDown() {
return Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL);
}
private boolean isAltDown() {
return Keyboard.isKeyDown(Keyboard.KEY_LMENU) || Keyboard.isKeyDown(Keyboard.KEY_RMENU);
}
public static Bind none() {
return new Bind(false, false, false, -1);
}
}