Skip to content

Commit

Permalink
Removed old keybind saving. Made some changes to console screen and k…
Browse files Browse the repository at this point in the history
…eyboard.
  • Loading branch information
tanishisherewithhh committed Apr 27, 2024
1 parent b11b785 commit affdfef
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 60 deletions.
1 change: 0 additions & 1 deletion src/main/java/dev/heliosclient/HeliosClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ public void onInitialize() {
}
HeliosExecutor.shutdown();
});
MC.getSession().getUsername();

MC.execute(()->{
while(MC.getWindow() == null){
Expand Down
21 changes: 14 additions & 7 deletions src/main/java/dev/heliosclient/managers/KeybindManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import dev.heliosclient.event.events.input.MouseReleaseEvent;
import dev.heliosclient.event.listener.Listener;
import dev.heliosclient.module.Module_;
import dev.heliosclient.module.settings.KeyBind;
import dev.heliosclient.scripting.LuaFile;
import dev.heliosclient.scripting.LuaScriptManager;
import dev.heliosclient.ui.clickgui.ClickGUIScreen;
Expand Down Expand Up @@ -36,14 +37,16 @@ public KeybindManager() {
public void keyPressedEvent(KeyPressedEvent event) {
int key = event.getKey();

if (key == HeliosClient.CLICKGUI.clickGUIKeyBind.value && !(HeliosClient.MC.currentScreen instanceof ChatScreen) && !(HeliosClient.MC.currentScreen instanceof AbstractInventoryScreen)
&& !(HeliosClient.MC.currentScreen instanceof GameMenuScreen)) {
ClickGUIScreen.INSTANCE.onLoad();
HeliosClient.MC.setScreen(ClickGUIScreen.INSTANCE);
}
if (key == HeliosClient.CLICKGUI.consoleScreen.value) {
HeliosClient.MC.setScreen(HeliosClient.CONSOLE);
if(!KeyBind.listening && !KeyBind.listeningKey) {
if (key == HeliosClient.CLICKGUI.clickGUIKeyBind.value && shouldOpen()) {
ClickGUIScreen.INSTANCE.onLoad();
HeliosClient.MC.setScreen(ClickGUIScreen.INSTANCE);
}
if (key == HeliosClient.CLICKGUI.consoleScreen.value && shouldOpen()) {
HeliosClient.MC.setScreen(HeliosClient.CONSOLE);
}
}

if (HeliosClient.MC.currentScreen != null) return;

for (Module_ module : ModuleManager.INSTANCE.modules) {
Expand Down Expand Up @@ -150,6 +153,10 @@ public void onTick(TickEvent.WORLD event) {
lastRightClick = currentTime;
}
}
public boolean shouldOpen(){
return !(HeliosClient.MC.currentScreen instanceof ChatScreen) && !(HeliosClient.MC.currentScreen instanceof AbstractInventoryScreen)
&& !(HeliosClient.MC.currentScreen instanceof GameMenuScreen);
}

public int getLeftCPS() {
return CPS[0];
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/heliosclient/mixin/KeyboardMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public abstract class KeyboardMixin {
@Unique
private static final MinecraftClient mc = MinecraftClient.getInstance();

@Inject(method = "onKey", at = @At("TAIL"), cancellable = true)
@Inject(method = "onKey", at = @At("HEAD"), cancellable = true)
public void onKey(long window, int key, int scancode, int action, int modifiers, CallbackInfo info) {
if (action == GLFW.GLFW_PRESS) { //Fixes a bug
KeyPressedEvent event = new KeyPressedEvent(window, key, scancode, action, modifiers);
Expand Down
33 changes: 19 additions & 14 deletions src/main/java/dev/heliosclient/module/settings/KeyBind.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package dev.heliosclient.module.settings;

import com.moandjiezana.toml.Toml;
import dev.heliosclient.HeliosClient;
import dev.heliosclient.managers.ColorManager;
import dev.heliosclient.managers.EventManager;
import dev.heliosclient.ui.clickgui.Tooltip;
import dev.heliosclient.util.ColorUtils;
import dev.heliosclient.util.KeycodeToString;
import dev.heliosclient.util.render.Renderer2D;
import dev.heliosclient.util.fontutils.FontRenderers;
Expand All @@ -23,6 +25,7 @@ public class KeyBind extends Setting<Integer> {
public static boolean listeningMouse = false;
public int value;
public static boolean listening = false;
public boolean isListening = false;

public KeyBind(String name, String description, ISettingChange iSettingChange, Integer value, BooleanSupplier shouldRender, int defaultValue) {
super(shouldRender, defaultValue);
Expand All @@ -39,7 +42,7 @@ public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY
super.render(drawContext, x, y, mouseX, mouseY, textRenderer);
int defaultColor = ColorManager.INSTANCE.defaultTextColor();

if (listening) {
if (isListening) {
Renderer2D.drawFixedString(drawContext.getMatrices(), name + ": §lLISTENING", x + 2, y + 8, defaultColor);
} else if (value == -1) {
Renderer2D.drawFixedString(drawContext.getMatrices(), name + ": None", x + 2, y + 8, defaultColor);
Expand All @@ -64,7 +67,7 @@ public void renderCompact(DrawContext drawContext, int x, int y, int mouseX, int
super.renderCompact(drawContext, x, y, mouseX, mouseY, textRenderer);
int defaultColor = ColorManager.INSTANCE.defaultTextColor();

if (listening) {
if (isListening) {
FontRenderers.Small_fxfontRenderer.drawString(drawContext.getMatrices(), name + ": §lLISTENING", x + 2, y + 6, defaultColor);
} else if (value == -1) {
FontRenderers.Small_fxfontRenderer.drawString(drawContext.getMatrices(), name + ": None", x + 2, y + 6, defaultColor);
Expand All @@ -86,16 +89,17 @@ public void renderCompact(DrawContext drawContext, int x, int y, int mouseX, int

@Override
public void keyPressed(int keyCode, int scanCode, int modifiers) {
if (listening) {
if (isListening) {
if (keyCode == GLFW.GLFW_KEY_BACKSPACE || keyCode == GLFW.GLFW_KEY_ESCAPE) {
this.value = -1;
} else {
this.value = keyCode;
}
iSettingChange.onSettingChange(this);
listening = false;
listeningKey = false;
listeningMouse = false;
iSettingChange.onSettingChange(this);
isListening = false;
}
}

Expand All @@ -104,43 +108,44 @@ public void mouseClicked(double mouseX, double mouseY, int button) {
if (hoveredSetting((int) mouseX, (int) mouseY) && hoveredOverReset(mouseX, mouseY)) {
value = defaultValue;
iSettingChange.onSettingChange(this);
isListening = false;
listeningKey = false;
listeningMouse = false;
listening = false;
}

if (listeningMouse && listening) {
if (listeningMouse && isListening) {
value = button;
iSettingChange.onSettingChange(this);
isListening = !isListening;
listening = !listening;
listeningKey = false;
listeningMouse = false;
}
if (hovered((int) mouseX, (int) mouseY) && button == 0 && !listeningMouse) {
if (hovered((int) mouseX, (int) mouseY) && button == 0 && !listeningMouse && !isListening) {
listening = !listening;
listeningKey = !listeningKey;
isListening = true;
listeningMouse = true;
}
}

@Override
public Object saveToToml(List<Object> objectList) {
return value == -1 ? "None" : (char) value;

//The actual key code.
objectList.add(value);
return objectList;
}

@Override
public void loadFromToml(Map<String, Object> MAP, Toml toml) {
super.loadFromToml(MAP,toml);
if(toml.getString(name.replace(" ", "")) == null){
if(toml.getList(this.name.replace(" ", "")) == null){
value = defaultValue;
return;
}
if (Objects.equals(toml.getString(name.replace(" ", "")), "None")) {
value = -1;
} else {
char ch = toml.getString(name.replace(" ", "")).toLowerCase().charAt(0);
value = KeycodeToString.charToGLFWKeycode(ch);
}
value = Integer.parseInt(toml.getList(this.name.replace(" ", "")).get(0).toString());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,14 @@ public class ClickGUI extends Module_ {
.description("The key to open the ClickGUI screen")
.value(GLFW.GLFW_KEY_RIGHT_SHIFT)
.defaultValue(GLFW.GLFW_KEY_RIGHT_SHIFT)
.onSettingChange(this)
.build()
);
public KeyBind consoleScreen = sgConfig.add(new KeyBind.Builder()
.name("Console Screen bind")
.description("The key to open the console / minecraft terminal screen")
.value(-1)
.onSettingChange(this)
.build()
);
public StringSetting configPath = sgConfig.add(new StringSetting.Builder()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/heliosclient/system/ConsoleAppender.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void append(LogEvent event) {
message = ColorUtils.yellow + "[HeliosClient] " + ColorUtils.reset + message;
}
if(event.getLoggerName().contains("net.minecraft") || event.getLoggerName().contains("com.mojang")){
message = ColorUtils.green + "[Minecraft] " + ColorUtils.reset + message;
message = ColorUtils.darkGreen + "[Minecraft] " + ColorUtils.reset + message;
}
if(event.getLoggerName().contains("Fabric")){
message = ColorUtils.darkAqua + "[Fabric] " + ColorUtils.reset + message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {

@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if(this.enterBox.isFocused() && (keyCode == GLFW.GLFW_KEY_ENTER || keyCode == GLFW.GLFW_KEY_KP_ENTER)){
if(keyCode == GLFW.GLFW_KEY_ENTER || keyCode == GLFW.GLFW_KEY_KP_ENTER){
if (!enterBox.getValue().isEmpty()) {
HeliosClient.LOGGER.info(enterBox.getValue());
enterBox.setText("");
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/dev/heliosclient/util/InputBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY

renderBackground(drawContext);

Renderer2D.enableScissor(x,y,width,height);
float textHeight = Renderer2D.getFxStringHeight();
float textY = y + (height - textHeight) / 2; // Center the text vertically

Expand All @@ -197,7 +198,7 @@ public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY
} else {
displayFirstSegment(drawContext, textY);
}

Renderer2D.disableScissor();

drawSelectionBox(drawContext, textY, textHeight);
}
Expand Down Expand Up @@ -396,6 +397,7 @@ public boolean canWrite() {
public void paste() {
// Get the text from the system clipboard
String clipboardText = MinecraftClient.getInstance().keyboard.getClipboard();
clipboardText = clipboardText.replace("\n","");

// If text is selected, replace it with the clipboard text
// Otherwise, insert the clipboard text at the cursor position
Expand Down
34 changes: 0 additions & 34 deletions src/main/java/dev/heliosclient/util/KeycodeToString.java
Original file line number Diff line number Diff line change
Expand Up @@ -391,38 +391,4 @@ public static String translateShort(Integer keyCode) {
}
return keyName;
}

public static int charToGLFWKeycode(char c) {
// Convert the char to uppercase
c = Character.toUpperCase(c);

// Check if the char is a printable alphanumeric character
if (c >= 'A' && c <= 'Z') {
// Return the corresponding GLFW keycode
return GLFW_KEY_A + (c - 'A');
}
if (c >= '0' && c <= '9') {
// Return the corresponding GLFW keycode
return GLFW_KEY_0 + (c - '0');
}

// Check if the char is a printable non-alphanumeric character
return switch (c) {
case ' ' -> GLFW_KEY_SPACE;
case '\'' -> GLFW_KEY_APOSTROPHE;
case ',' -> GLFW_KEY_COMMA;
case '-' -> GLFW_KEY_MINUS;
case '.' -> GLFW_KEY_PERIOD;
case '/' -> GLFW_KEY_SLASH;
case ';' -> GLFW_KEY_SEMICOLON;
case '=' -> GLFW_KEY_EQUAL;
case '[' -> GLFW_KEY_LEFT_BRACKET;
case '\\' -> GLFW_KEY_BACKSLASH;
case ']' -> GLFW_KEY_RIGHT_BRACKET;
case '`' -> GLFW_KEY_GRAVE_ACCENT;
default -> GLFW_KEY_UNKNOWN;
};
}


}

0 comments on commit affdfef

Please sign in to comment.