Skip to content

Commit

Permalink
[+] KeyBindsHud, Fixed some left over bugs of HudElement. Fixed HudCa…
Browse files Browse the repository at this point in the history
…tegoryPane not loading from the config, and Copy-Paste of properties of hud elements.
  • Loading branch information
tanishisherewithhh committed Aug 27, 2024
1 parent d28ee08 commit b21169f
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/main/java/dev/heliosclient/hud/HudElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class HudElement implements ISettingChange, ISaveAndLoad, Listener {

//This variable is used to control the number of imaginary lines to use, to
//anchor the hud elements during resize, as stated in the class comment.
private static final int NUMBER_OF_LINES = 100;
public static final int NUMBER_OF_LINES = 100;

// Default settings
// This is a lot of complete customisation.
Expand Down
1 change: 1 addition & 0 deletions src/main/java/dev/heliosclient/hud/HudElementList.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public HudElementList() {
registerElement(PlayerModel.DATA);
registerElement(CoordinatesHud.DATA);
registerElement(ClockHud.DATA);
registerElement(KeyBindsHud.DATA);
registerElement(Fps.DATA);
registerElement(SpeedHud.DATA);
registerElement(Ping.DATA);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/dev/heliosclient/hud/hudelements/ClockHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {
text = getRealLifeTime();
}

this.width = (int) (Renderer2D.getStringWidth(text));
this.width = (int) Renderer2D.getStringWidth(text);
this.height = (int) Renderer2D.getStringHeight(text);

super.renderElement(drawContext, textRenderer);
Renderer2D.drawString(drawContext.getMatrices(), text, this.x, this.y, ColorManager.INSTANCE.hudColor);
Expand Down
29 changes: 26 additions & 3 deletions src/main/java/dev/heliosclient/hud/hudelements/DirectionHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ public class DirectionHud extends HudElement {
.onSettingChange(this)
.build()
);

public BooleanSetting shortDirection = sgGeneral.add(new BooleanSetting.Builder()
.name("Short Direction / Axis")
.description("The direction will be shown short as axis (like X+, Z-,etc.)")
.defaultValue(false)
.onSettingChange(this)
.shouldRender(()-> mode.isOption(Mode.Simple))
.build()
);
public BooleanSetting snapToCrosshair = sgGeneral.add(new BooleanSetting.Builder()
.name("Snap to crosshair")
.description("Snaps the compass to the crosshair")
Expand Down Expand Up @@ -74,7 +81,7 @@ public class DirectionHud extends HudElement {
.defaultValue(0.7d)
.shouldRender(()-> mode.isOption(Mode.Compass))
.onSettingChange(this)
.shouldRender(() -> renderEllipse.value)
.shouldRender(() -> renderEllipse.value && mode.isOption(Mode.Compass))
.build()
);
public RGBASetting compassColor = sgGeneral.add(new RGBASetting.Builder()
Expand Down Expand Up @@ -132,8 +139,10 @@ public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {
Renderer2D.drawString(drawContext.getMatrices(), text, x, y, ColorManager.INSTANCE.hudColor);
}
}else {
String text = ColorUtils.reset + "Direction: " + ColorUtils.white + (mc.player == null ? "North" : mc.player.getHorizontalFacing().getName());
String directionAppend = shortDirection.value ? translateToShortAxis() : (mc.player == null ? "North" : mc.player.getHorizontalFacing().getName());
String text = ColorUtils.reset + "Direction: " + ColorUtils.white + directionAppend;
this.width = Math.round(Renderer2D.getStringWidth(text));
this.height = Math.round(Renderer2D.getStringHeight(text));

super.renderElement(drawContext, textRenderer);
Renderer2D.drawString(drawContext.getMatrices(), text, this.x, this.y, ColorManager.INSTANCE.hudColor);
Expand All @@ -150,6 +159,20 @@ private String getCardinalDirection(int i) {
};
}

private String translateToShortAxis(){
if(mc.player == null){
return "Z-";
}
return switch (mc.player.getHorizontalFacing()){
case DOWN -> "Y-";
case UP -> "Y+";
case NORTH -> "Z-";
case SOUTH -> "Z+";
case EAST -> "X+";
case WEST -> "X-";
};
}

public static HudElementData<DirectionHud> DATA = new HudElementData<>("DirectionHUD", "Displays the direction you are facing", DirectionHud::new);

enum Mode{
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/dev/heliosclient/hud/hudelements/KeyBindsHud.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package dev.heliosclient.hud.hudelements;

import dev.heliosclient.hud.HudElement;
import dev.heliosclient.hud.HudElementData;
import dev.heliosclient.managers.ColorManager;
import dev.heliosclient.managers.ModuleManager;
import dev.heliosclient.module.Module_;
import dev.heliosclient.module.settings.KeyBind;
import dev.heliosclient.util.ColorUtils;
import dev.heliosclient.util.KeyboardUtils;
import dev.heliosclient.util.render.Renderer2D;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;

public class KeyBindsHud extends HudElement {
public static HudElementData<KeyBindsHud> DATA = new HudElementData<>("KeybindsHUD", "Shows the modules with keybinds", KeyBindsHud::new);

public KeyBindsHud() {
super(DATA);
this.width = 50;
this.height = Math.round(Renderer2D.getStringHeight());
}

@Override
public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {
super.renderElement(drawContext, textRenderer);

int width = 20, height = 0;
int y = this.y + 1;
for(Module_ module : ModuleManager.getModules()){
if(module.keyBind.value == KeyBind.none()) continue;

String text = module.name + (module.isActive()? ColorUtils.green : ColorUtils.darkRed) + " [" + KeyboardUtils.translateShort(module.keyBind.value) + "]";

width = Math.round(Math.max(width, Renderer2D.getStringWidth(text) + 5));

Renderer2D.drawString(drawContext.getMatrices(),text,x + 2,y, ColorManager.INSTANCE.hudColor);

y += (int) (Renderer2D.getStringHeight(text) + 3);
height += Math.round(Renderer2D.getStringHeight(text)) + 3;
}

this.width = width;
this.height = Math.max(10, height + 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public class WelcomeHud extends HudElement {
.onSettingChange(this)
.inputMode(InputBox.InputMode.ALL)
.characterLimit(1000)
.defaultValue("Good morning, %s!")
.value("Welcome %s!")
.defaultValue("Good day, %s!")
.build()
);
public WelcomeHud() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public class GUI extends Module_ {
);
public BooleanSetting coolVisuals = sgVisuals.add(new BooleanSetting.Builder()
.name("Render Cool Polygon mesh")
.description("Renders lines and connecting dots that look good but may drain performance like Abyss client")
.description("Renders lines and connecting dots that look good but may drain performance")
.value(false)
.onSettingChange(this)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ public void loadFromFile(Map<String, Object> MAP) {
value = defaultValue;
rainbow = defaultRainbow;
HeliosClient.LOGGER.error("{} is null, Setting loaded to default", this.getSaveName());
updateHandles();
return;
}

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/dev/heliosclient/system/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import dev.heliosclient.ui.clickgui.CategoryPane;
import dev.heliosclient.ui.clickgui.ClickGUIScreen;
import dev.heliosclient.ui.clickgui.hudeditor.HudCategoryPane;
import dev.heliosclient.util.MathUtils;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -206,6 +207,8 @@ public void writeHudConfig() {
}
pane.put("x", HudCategoryPane.INSTANCE == null ? 0 : HudCategoryPane.INSTANCE.x);
pane.put("y", HudCategoryPane.INSTANCE == null ? 0 : HudCategoryPane.INSTANCE.y);
pane.put("collapsed", HudCategoryPane.INSTANCE != null && HudCategoryPane.INSTANCE.collapsed);


pane.put("elements", hudElements.isEmpty() ? new HashMap<>() : hudElements);

Expand Down Expand Up @@ -245,14 +248,24 @@ public void loadHudElements() {
HudManager.INSTANCE.hudElements.clear();
Map<String, Object> hudElementsPaneMap = getHudElementsPaneMap();
if (hudElementsPaneMap != null) {
HudCategoryPane.INSTANCE.x = MathUtils.o2iSafe(hudElementsPaneMap.get("x"));
HudCategoryPane.INSTANCE.y = MathUtils.o2iSafe(hudElementsPaneMap.get("y"));
if(hudElementsPaneMap.containsKey("collapsed")) {
HudCategoryPane.INSTANCE.collapsed = (boolean) hudElementsPaneMap.get("collapsed");
}

Map<String, Object> hudElementsMap = cast(hudElementsPaneMap.get("elements"));
if (hudElementsMap != null) {
hudElementsMap.forEach(this::loadHudElement);
}
}



loadHudElementSettings();

HudCategoryPane.INSTANCE.updateAllCount();

LOGGER.info("Loading Hud Elements Complete");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public void render(DrawContext drawContext, TextRenderer textRenderer, int mouse
Renderer2D.drawCustomString(FontRenderers.Small_fxfontRenderer, drawContext.getMatrices(), "Hud elements", x + 4, y + 3, ColorManager.INSTANCE.clickGuiPaneText());
Renderer2D.drawCustomString(FontRenderers.Small_fxfontRenderer, drawContext.getMatrices(), collapsed ? "+" : "-", x + width - Renderer2D.getCustomStringWidth(collapsed ? "+" : "-", FontRenderers.Small_fxfontRenderer) - 2, y + 3, ColorManager.INSTANCE.clickGuiPaneText());
}
public void updateAllCount(){
for(HudElementButton elementButton: hudElementButtons){
elementButton.updateCount();
}
}

public void mouseClicked(double mouseX, double mouseY, int button) {
if (hovered(mouseX, mouseY) && button == 1) collapsed = !collapsed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (element.selected && isPaste(keyCode) && !copiedSettings.isEmpty()) {
for (SettingGroup settingGroup : element.settingGroups) {
for (Setting<?> setting : settingGroup.getSettings()) {
if (!setting.shouldSaveAndLoad()) continue;
if (!setting.shouldSaveAndLoad() || !copiedSettings.containsKey(setting.getSaveName())) continue;

setting.loadFromFile(copiedSettings);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ public <T extends HudElement> void addInstanceToList(Class<? extends T> clazz) {
HudManager.INSTANCE.addHudElement(instance);
HudElement lastHudElement = HudManager.INSTANCE.hudElements.get(HudManager.INSTANCE.hudElements.size() - 1);

lastHudElement.posX = 1;
lastHudElement.posY = 1;
lastHudElement.distanceX = 0;
lastHudElement.distanceY = 0;
lastHudElement.posX = HudElement.NUMBER_OF_LINES/2 - 1;
lastHudElement.posY = HudElement.NUMBER_OF_LINES/2 - 1;

} catch (Exception e) {
HeliosClient.LOGGER.error("Error adding hud element instance to list", e);
}
Expand Down

0 comments on commit b21169f

Please sign in to comment.