Skip to content

Commit

Permalink
Fixed Button rendering. Changed lockcanvas in Painter to ButtonSettin…
Browse files Browse the repository at this point in the history
…g from BooleanSetting. Removed debug statement.
  • Loading branch information
tanishisherewithhh committed Aug 24, 2024
1 parent 54d18f0 commit 9aefa64
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 58 deletions.
15 changes: 8 additions & 7 deletions src/main/java/dev/heliosclient/module/Module_.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,14 @@ public void loadFromFile(Map<String, Object> MAP) {
for (SettingGroup settingGroup : this.settingGroups) {
for (Setting<?> setting : settingGroup.getSettings()) {
if (!setting.shouldSaveAndLoad()) continue;
//Any error caught should not cause the whole config system to fail to load.
//Hopefully
try {
setting.loadFromFile(MAP);
} catch (Exception e) {
e.printStackTrace();
}

//Any error caught should not cause the whole config system to fail to load.
//Hopefully
try {
setting.loadFromFile(MAP);
} catch (Exception e) {
e.printStackTrace();
}
if (setting == this.active && this.isActive()) {
this.onEnable();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public void loadFromFile(Map<String, Object> MAP) {
super.loadFromFile(MAP);

String filePath = (String) MAP.get("File");
if(filePath.equals("unknown")) return;
if(filePath == null || filePath.equals("unknown")) return;
spamFile = new File(filePath);

if (spamFile.exists() && spamFile.isFile()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import dev.heliosclient.module.settings.lists.EntityTypeListSetting;
import dev.heliosclient.system.TickRate;
import dev.heliosclient.util.SortMethod;
import dev.heliosclient.util.TickTimer;
import dev.heliosclient.util.player.PlayerUtils;
import dev.heliosclient.util.player.TargetUtils;
import dev.heliosclient.util.render.TargetRenderer;
Expand Down Expand Up @@ -146,7 +147,7 @@ public class TriggerBot extends Module_ {
);
TargetUtils targetFinder = new TargetUtils();

private int delay;
private TickTimer timer = new TickTimer();
private Entity targetEntity;

public TriggerBot() {
Expand All @@ -162,7 +163,7 @@ public TriggerBot() {
@Override
public void onEnable() {
super.onEnable();
delay = 0;
timer = new TickTimer();
}

private boolean isTeamMate(LivingEntity targetEntity) {
Expand Down Expand Up @@ -193,13 +194,7 @@ public boolean shouldAttack() {
if (smartDelay.value) {
return mc.player.getAttackCooldownProgress(baseTimer) >= 1;
} else {
if (this.delay < baseTimer) {
this.delay++;
return false;
} else {
this.delay = 0;
return true;
}
return timer.incrementAndEvery((int) baseTimer);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import dev.heliosclient.module.Module_;
import dev.heliosclient.module.settings.*;
import dev.heliosclient.module.settings.buttonsetting.ButtonSetting;
import dev.heliosclient.util.blocks.BlockUtils;
import dev.heliosclient.util.ChatUtils;
import dev.heliosclient.util.ColorUtils;
import dev.heliosclient.util.FileUtils;
import dev.heliosclient.util.blocks.BlockUtils;
import dev.heliosclient.util.player.InventoryUtils;
import dev.heliosclient.util.render.Renderer3D;
import dev.heliosclient.util.render.color.QuadColor;
Expand Down Expand Up @@ -162,14 +162,12 @@ public class Painter extends Module_ {
.shouldRender(() -> !autoRotate.value)
.build()
);
BooleanSetting lockCanvas = sgGeneral.add(new BooleanSetting.Builder()
.name("Lock Canvas")
.description("Locks canvas to the current set direction and position")
.value(false)
.defaultValue(false)
.onSettingChange(this)
ButtonSetting canvasState = sgGeneral.add(new ButtonSetting.Builder()
.name("Canvas state")
.description("Locks canvas to the current set direction and position or unlocks the canvas to return to normal")
.build()
);

KeyBind lockCanvasKey = sgGeneral.add(new KeyBind.Builder()
.name("Lock Canvas Key")
.description("Keybind to lock canvas")
Expand Down Expand Up @@ -285,25 +283,26 @@ public Painter() {
ChatUtils.sendHeliosMsg(ColorUtils.red + "File selected is not selected.");
}
});

canvasState.addButton("Lock",0,0, this::lock);
canvasState.addButton("Unlock",1,0, this::unlock);

}

@SubscribeEvent
public void keyPressedEvent(KeyPressedEvent e) {
if (e.getKey() == lockCanvasKey.value) {
if (!isLocked) {
lock();
lockCanvas.setValue(isLocked);
} else {
unlock();
lockCanvas.setValue(isLocked);
}
}
}

@Override
public void onEnable() {
super.onEnable();
isLocked = !lockCanvas.value;
ticksPassed = 0;

loadCanvas();
Expand All @@ -326,12 +325,6 @@ private void loadCanvas(){
@SubscribeEvent
public void onTick(TickEvent.CLIENT event) {
if(!HeliosClient.shouldUpdate()) return;

if (lockCanvas.value && !isLocked) {
lock();
} else if (!lockCanvas.value && isLocked) {
unlock();
}
if (CANVAS_MAP == null || !autoPlace.value) return;

ticksPassed++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public Button(String text, Runnable task, int x, int y, int width, int height) {
public void render(DrawContext drawContext, int mouseX, int mouseY, TextRenderer textRenderer) {
int fillColor = Color.DARK_GRAY.getRGB();
int borderColor = hovered(mouseX, mouseY) ? Color.WHITE.getRGB() : Color.BLACK.getRGB();
Renderer2D.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(), x, y, width - 4, 14, 2, fillColor);
Renderer2D.drawOutlineRoundedBox(drawContext.getMatrices().peek().getPositionMatrix(), x, y, width - 4, 14, 2, 0.7f, borderColor);
Renderer2D.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(), x, y, width, 14, 2, fillColor);
Renderer2D.drawOutlineRoundedBox(drawContext.getMatrices().peek().getPositionMatrix(), x, y, width, 14, 2, 0.7f, borderColor);

// Render button text
double textX = x + ((width / 2.0) - (Renderer2D.getFxStringWidth(text) / 2.0)) - 0.2;
double textX = x + ((width - Renderer2D.getFxStringWidth(text)) / 2.0);

float textHeight = Renderer2D.getFxStringHeight();
float textY = y + (14 - textHeight) / 2; // Center the text vertically
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public void unregister(String eventType, LuaValue listener) {
LuaFunction luaFunction = listener.checkfunction();
List<LuaFunction> eventListeners = listeners.get(eventType);
if (eventListeners != null) {
System.out.println(eventListeners);
System.out.println( eventListeners.remove(luaFunction));
eventListeners.remove(luaFunction);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/heliosclient/ui/clickgui/ConsoleScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public ConsoleScreen() {
consoleBox.displayLineNos = true;
consoleBox.autoScroll = true;

enterBox = new InputBox(33, 13, "", 256, InputBox.InputMode.ALL);
enterBox = new InputBox(29, 13, "", 256, InputBox.InputMode.ALL);
enterButton = new Button("Enter", () -> {
if (!enterBox.getValue().isEmpty()) {
HeliosClient.LOGGER.info(enterBox.getValue());
Expand Down Expand Up @@ -54,7 +54,7 @@ public void onDisplayed() {

private void resizeBoxes(){
consoleBox.setSize(HeliosClient.MC.getWindow().getScaledWidth() - 40, HeliosClient.MC.getWindow().getScaledHeight() - 55);
enterBox.setSize(HeliosClient.MC.getWindow().getScaledWidth() - 82, 13);
enterBox.setSize(HeliosClient.MC.getWindow().getScaledWidth() - 86, 13);
enterButton.setX(HeliosClient.MC.getWindow().getScaledWidth() - 58);
enterButton.setY(HeliosClient.MC.getWindow().getScaledHeight() - 33);
}
Expand Down
9 changes: 2 additions & 7 deletions src/main/java/dev/heliosclient/ui/clickgui/ModuleButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import dev.heliosclient.module.Module_;
import dev.heliosclient.module.modules.render.GUI;
import dev.heliosclient.module.settings.ParentScreenSetting;
import dev.heliosclient.module.settings.RGBASetting;
import dev.heliosclient.module.settings.Setting;
import dev.heliosclient.module.settings.lists.ListSetting;
import dev.heliosclient.module.sysmodules.ClickGUI;
import dev.heliosclient.ui.clickgui.gui.HudBox;
import dev.heliosclient.ui.clickgui.settings.SettingsScreen;
Expand Down Expand Up @@ -74,6 +72,8 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float x, int
this.x = x;
this.y = y;
this.shouldRender = shouldRender;
this.width = maxWidth;
hitBox.set(this.x, this.y, width, height);

if (!shouldRender) return;

Expand All @@ -85,10 +85,6 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float x, int
// Get the width and height of the module name
int moduleNameHeight = (int) Renderer2D.getFxStringHeight(module.name) - 1;

this.width = maxWidth;

hitBox.set(x, y, width, height);

Color fillColorStart = module.isActive() ? ColorManager.INSTANCE.primaryGradientStart : ColorUtils.changeAlpha(ModuleManager.get(GUI.class).buttonColor.getColor(), 100);
Color fillColorEnd = module.isActive() ? ColorManager.INSTANCE.primaryGradientEnd : ColorUtils.changeAlpha(ModuleManager.get(GUI.class).buttonColor.getColor(), 100);
Color blendedColor = ColorUtils.blend(fillColorStart, fillColorEnd, 1 / 2f);
Expand Down Expand Up @@ -135,7 +131,6 @@ private void drawGradientRectangleWithShadow(MatrixStack stack, float x, float y
}

public int renderSettings(DrawContext drawContext, int x, int y, int mouseX, int mouseY, TextRenderer textRenderer) {

if (!shouldRender){
updateScale(false);
return (int) (boxHeight * scale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import dev.heliosclient.managers.ColorManager;
import dev.heliosclient.module.modules.render.GUI;
import dev.heliosclient.module.settings.buttonsetting.Button;
import dev.heliosclient.scripting.LuaFile;
import dev.heliosclient.scripting.LuaScriptManager;
import dev.heliosclient.ui.clickgui.gui.PolygonMeshPatternRenderer;
Expand Down Expand Up @@ -325,7 +324,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {

@Override
public boolean shouldCloseOnEsc() {
return false;
return true;
}

@Override
Expand Down Expand Up @@ -387,9 +386,7 @@ public void setPosition(double x, double y) {
}

@Override
public void setWidth(double width) {

}
public void setWidth(double width) {}

public double getX() {
return x;
Expand All @@ -399,5 +396,4 @@ public double getY() {
return y - ScriptManagerScreen.this.scrollOffset;
}
}

}
7 changes: 2 additions & 5 deletions src/main/java/dev/heliosclient/util/KeyboardUtils.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package dev.heliosclient.util;

import dev.heliosclient.HeliosClient;
import net.minecraft.client.Keyboard;
import org.lwjgl.glfw.GLFW;

import static org.lwjgl.glfw.GLFW.GLFW_KEY_SPACE;

/**
* Utils for working with GLFW keycodes.
Expand Down Expand Up @@ -181,7 +178,7 @@ public static String translate(Integer keyCode) {
case GLFW.GLFW_KEY_NUM_LOCK -> {
return "NUM_LOCK";
}
case GLFW_KEY_SPACE -> {
case GLFW.GLFW_KEY_SPACE -> {
return "SPACE";
}
case GLFW.GLFW_KEY_ENTER -> {
Expand Down Expand Up @@ -371,7 +368,7 @@ public static String translateShort(Integer keyCode) {
case GLFW.GLFW_KEY_NUM_LOCK -> {
return "NUM";
}
case GLFW_KEY_SPACE -> {
case GLFW.GLFW_KEY_SPACE -> {
return "SPACE";
}
case GLFW.GLFW_KEY_ENTER -> {
Expand Down

0 comments on commit 9aefa64

Please sign in to comment.