Skip to content

Commit

Permalink
LICENSE name change. RGBASetting rainbow with custom sat and brightne…
Browse files Browse the repository at this point in the history
…ss. HudElement documentation and resize logic change. ClientTag now shows client textures. And some optimisations.
  • Loading branch information
tanishisherewithhh committed Sep 2, 2024
1 parent c34c0f8 commit e9b6129
Show file tree
Hide file tree
Showing 13 changed files with 185 additions and 121 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023-present HeliosDevelopement
Copyright (c) 2023-present HeliosMinecraft

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
55 changes: 17 additions & 38 deletions src/main/java/dev/heliosclient/hud/HudElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,16 @@
* Class for creating HudElements for HUD
*
* <h4>Position is stored using this method:</h4><br>
* There are 3 imaginary lines on each axis. For y-axis, one is on top of the screen, center, bottom. Similarly, for x-axis they are placed on left, center and right.<br>
* The HUD element stores on each axis to which line it is closest to. This is stored in the posX and posY variable. Element also stores the distance to this line in pixels in the distanceX and distance Y variables. These are capped so the elements can`t go off the screen. These values aren't changed at all while not dragging ensuring no shifts happening.<br>
* This approach ensures that when resizing the elements on screen don't overlap much and don't shift around. unless they are touched in the editor.
* There are `[NUMBER_OF_LINES]` (imaginary lines) on each axis. The screen is divided on each axis (x,y) in the count of lines.<br>
* The HUD element stores on each axis to which section of the lines it lies to, <br>
* (For example if the 3rd line in x axis is present at 30 pixels and the second line is at 20 pixels,
* and the hud element is present at 25 pixels then the line chosen will be 3rd line [The spacing is controlled by number of lines]).
* <br>
* This is stored in the posX and posY variable. Element also stores the distance to this line in pixels in the distanceX and distance Y variables.
* These are capped so the elements can`t go off the screen. These values aren't changed at all while not dragging ensuring no shifts happening.<br>
* This approach ensures that when resizing the elements on screen don't overlap much and don't shift around, unless they are touched in the editor.
*
* <h4>Warning: Makes sure the element is centered along the x and y position. If this is not met they will go off-screen and hit-boxes will be broken.</h4>
* <h4>Warning: Makes sure the element is drawn with its top-left vertex as the element's x and y position. If this is not met they will go off-screen and hit-boxes will be broken.</h4>
*/
public class HudElement implements ISettingChange, ISaveAndLoad, Listener {
protected static final MinecraftClient mc = MinecraftClient.getInstance();
Expand Down Expand Up @@ -65,7 +70,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.
public static final int NUMBER_OF_LINES = 100;
public static final int NUMBER_OF_LINES = 120;

// Default settings
// This is a lot of complete customisation.
Expand Down Expand Up @@ -164,7 +169,6 @@ public HudElement(HudElementData<?> hudElementInfo) {
*/
public void renderEditor(DrawContext drawContext, TextRenderer textRenderer, int mouseX, int mouseY) {
// Get right line to align to

double posYInterval = (double) drawContext.getScaledWindowHeight() / (NUMBER_OF_LINES);
double posXInterval = (double) drawContext.getScaledWindowWidth() / (NUMBER_OF_LINES);

Expand All @@ -190,36 +194,11 @@ public void renderEditor(DrawContext drawContext, TextRenderer textRenderer, int
y = newY;


for (int i = 0; i < NUMBER_OF_LINES; i++) {
if (x < posXInterval * i) {
posX = i;
break;
}
}
posX = (int) (x / posXInterval);
posY = (int) (y / posYInterval);

for (int i = 0; i < NUMBER_OF_LINES; i++) {
if (y < posYInterval * i) {
posY = i;
break;
}
}

// Calculate and store distances from the lines
if (posX == 0) {
distanceX = Math.max(x, 0);
} else if (posX == NUMBER_OF_LINES) {
distanceX = Math.max(drawContext.getScaledWindowWidth() - x, this.width);
} else {
distanceX = (int) Math.min(x - posXInterval * posX, posXInterval - x % posXInterval);
}

if (posY == 0) {
distanceY = Math.max(y, 0);
} else if (posY == NUMBER_OF_LINES) {
distanceY = Math.max(drawContext.getScaledWindowHeight() - y, this.height);
} else {
distanceY = (int) Math.min(y - posYInterval * posY, posYInterval - y % posYInterval);
}
distanceX = (int) (x % posXInterval);
distanceY = (int) (y % posYInterval);
}

// Move to right position according to pos and distance variables
Expand Down Expand Up @@ -255,7 +234,7 @@ public void renderEditor(DrawContext drawContext, TextRenderer textRenderer, int
//Renders element
renderElement(drawContext, textRenderer);

// Set the hudBox values after the render element incase any change of width/height occurs
// Set the hudBox values after the render element in-case any change of width/height occurs
setHudBox();
}

Expand All @@ -274,8 +253,8 @@ public void render(DrawContext drawContext, TextRenderer textRenderer) {
//Skip if in F3 menu or hud is hidden
if (HeliosClient.MC.options.hudHidden || HeliosClient.MC.getDebugHud().shouldShowDebugHud()) return;

double posYInterval = (double) drawContext.getScaledWindowHeight() / (NUMBER_OF_LINES);
double posXInterval = (double) drawContext.getScaledWindowWidth() / (NUMBER_OF_LINES);
double posYInterval = (double) drawContext.getScaledWindowHeight() / NUMBER_OF_LINES;
double posXInterval = (double) drawContext.getScaledWindowWidth() / NUMBER_OF_LINES;

// Move to right position according to pos and distance variables
if (posX == 0) {
Expand Down
68 changes: 60 additions & 8 deletions src/main/java/dev/heliosclient/hud/hudelements/ClientTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,84 @@
import dev.heliosclient.hud.HudElement;
import dev.heliosclient.hud.HudElementData;
import dev.heliosclient.managers.ColorManager;
import dev.heliosclient.module.settings.CycleSetting;
import dev.heliosclient.module.settings.DoubleSetting;
import dev.heliosclient.module.settings.SettingGroup;
import dev.heliosclient.util.render.Renderer2D;
import dev.heliosclient.util.render.textures.Texture;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;

import java.util.List;

public class ClientTag extends HudElement {
public SettingGroup sgSettings = new SettingGroup("General");

static Texture LOGO = new Texture("icon.png");
static Texture FULL_SPLASH = new Texture("splashscreen/client_splash.png");

private final CycleSetting mode = sgSettings.add(new CycleSetting.Builder()
.name("Mode")
.description("Mode to show the client tag")
.defaultValue(List.of(Mode.values()))
.defaultListOption(Mode.Text)
.onSettingChange(this)
.build()
);
private final DoubleSetting scale = sgSettings.add(new DoubleSetting.Builder()
.name("Scale")
.description("Change the scale of the tag")
.min(0.3d)
.max(5d)
.value(1D)
.defaultValue(1D)
.onSettingChange(this)
.roundingPlace(2)
.shouldRender(()-> !mode.isOption(Mode.Text))
.build()
);

public ClientTag() {
super(DATA);
this.width = 20;
this.height = Math.round(Renderer2D.getStringHeight());
this.draggable = false;
this.renderOutLineBox = false;
addSettingGroup(sgSettings);
}

public static HudElementData<ClientTag> DATA = new HudElementData<>("Client Tag", "Shows client watermark", ClientTag::new);

@Override
public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {
String text = HeliosClient.clientTag + " " + HeliosClient.versionTag;
this.width = (int) (Renderer2D.getStringWidth(text));
this.x = HeliosClient.MC.getWindow().getScaledWidth() - this.width - 3;
this.y = HeliosClient.MC.getWindow().getScaledHeight() - this.height;

super.renderElement(drawContext, textRenderer);
Renderer2D.drawString(drawContext.getMatrices(), text, this.x, this.y, ColorManager.INSTANCE.hudColor);

switch ((Mode)mode.getOption()){
case Text -> {
String text = HeliosClient.clientTag + " " + HeliosClient.versionTag;
this.width = Math.round(Renderer2D.getStringWidth(text));
this.height = Math.round(Renderer2D.getStringHeight());

Renderer2D.drawString(drawContext.getMatrices(), text, this.x, this.y, ColorManager.INSTANCE.hudColor);
}
case FullSplash -> {
this.width = (int) Math.round(80 * scale.value);
this.height = (int) Math.round(24 * scale.value);

drawContext.drawTexture(FULL_SPLASH, this.x, (int) Math.round(this.y - (6 * scale.value)),0,0, this.width,(int) Math.round(36 * scale.value),this.width,(int) Math.round(36 * scale.value));
}
case Logo -> {
//Square 303x303 reduced by 8 times. (303/8 ~= 38)
this.width = this.height = (int) Math.round(38 * scale.value);

drawContext.drawTexture(LOGO, this.x, this.y,0,0, this.width,this.height, this.width,this.height);
}
}
}


enum Mode{
FullSplash,
Logo,
Text
}

}
19 changes: 12 additions & 7 deletions src/main/java/dev/heliosclient/module/settings/DoubleSetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
import java.util.function.BooleanSupplier;

public class DoubleSetting extends Setting<Double> {
private final double min, max;
public final double min, max;
private final int roundingPlace;
private final InputBox inputBox;
public double value;
boolean sliding = false;
static int lighterDarkGray = ColorUtils.changeAlpha(Color.DARK_GRAY, 105).getRGB();

public DoubleSetting(String name, String description, ISettingChange ISettingChange, double value, double min, double max, int roundingPlace, BooleanSupplier shouldRender, double defaultValue) {
super(shouldRender, defaultValue);
Expand All @@ -41,9 +42,9 @@ public DoubleSetting(String name, String description, ISettingChange ISettingCha
@Override
public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY, TextRenderer textRenderer) {
super.render(drawContext, x, y, mouseX, mouseY, textRenderer);
int defaultColor = ColorManager.INSTANCE.defaultTextColor();
int defaultTColor = ColorManager.INSTANCE.defaultTextColor();

Renderer2D.drawFixedString(drawContext.getMatrices(), name, x + 2, y + 2, defaultColor);
Renderer2D.drawFixedString(drawContext.getMatrices(), name, x + 2, y + 2, defaultTColor);
//I dont understand these calculations.
double diff = Math.min(100, Math.max(0, (mouseX - x) / 1.9));

Expand All @@ -65,11 +66,13 @@ public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY
Renderer2D.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(), x + 2, y + 16, 188, 2, 1, 0xFFAAAAAA);

int scaledValue = (int) ((value - min) / (max - min) * 188) + 2;
// Slider background
// Slider colored background
Renderer2D.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(), x + 2, y + 16, scaledValue, 2, 1, ColorManager.INSTANCE.clickGuiSecondary());
// Slider
Renderer2D.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(), x + scaledValue, y + 14f, 2, 6, 1, 0xFFFFFFFF);
Renderer2D.drawRectangle(drawContext.getMatrices().peek().getPositionMatrix(), x + scaledValue, y + 19f, 2, 1, ColorUtils.changeAlpha(Color.DARK_GRAY, 105).getRGB());


Renderer2D.drawRectangle(drawContext.getMatrices().peek().getPositionMatrix(), x + scaledValue, y + 19f, 2, 1, lighterDarkGray);

if (hovered(mouseX, mouseY)) {
hovertimer++;
Expand Down Expand Up @@ -115,7 +118,7 @@ public void renderCompact(DrawContext drawContext, int x, int y, int mouseX, int

//Slider Bar which moves and cartoony shadow
Renderer2D.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(), x + scaledValue, y + 14, 2, 6, 1, 0xFFFFFFFF);
Renderer2D.drawRectangle(drawContext.getMatrices().peek().getPositionMatrix(), x + scaledValue, y + 19, 2, 1, ColorUtils.changeAlpha(Color.DARK_GRAY, 155).getRGB());
Renderer2D.drawRectangle(drawContext.getMatrices().peek().getPositionMatrix(), x + scaledValue, y + 19, 2, 1, lighterDarkGray);
if (hovered(mouseX, mouseY)) {
hovertimer++;
} else {
Expand Down Expand Up @@ -144,8 +147,10 @@ public void mouseClicked(double mouseX, double mouseY, int button) {

@Override
public void mouseReleased(double mouseX, double mouseY, int button) {
if(sliding) {
postSettingChange();
}
sliding = false;
postSettingChange();
}

@Override
Expand Down
35 changes: 17 additions & 18 deletions src/main/java/dev/heliosclient/module/settings/RGBASetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public RGBASetting(String name, String description, Color defaultColor, boolean
this.brightnessSaturationBoxWidth = boxWidth;
this.brightnessSaturationBoxHeight = boxHeight;

updateHandles();
updateHandles(true);
alpha = defaultColor.getAlpha() / 255f;
alphaHandleY = Math.round((1.0f - alpha) * (float) boxHeight);

Expand All @@ -89,10 +89,6 @@ public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY
this.y = y;
Renderer2D.drawFixedString(drawContext.getMatrices(), name, x + 2, y + 4, -1);
Renderer2D.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(), x + 170, y + 2, 15, 15, 2, value.getRGB());

if (rainbow) {
value = ColorUtils.changeAlpha(ColorUtils.getRainbowColor(), value.getAlpha());
}
}

public void renderSetting(DrawContext drawContext, int x, int y, int mouseX, int mouseY, TextRenderer textRenderer) {
Expand All @@ -109,7 +105,7 @@ public void renderSetting(DrawContext drawContext, int x, int y, int mouseX, int
int value3 = hoveredOverBrightnessSaturationBox(mouseX, mouseY) ? Color.DARK_GRAY.getRGB() : Color.BLACK.brighter().getRGB();

if (rainbow) {
updateHandles();
updateHandles(false);
}
this.gradientBoxX = x + offsetX;
this.gradientBoxY = y + offsetY;
Expand Down Expand Up @@ -209,15 +205,18 @@ public void drawBrightnessSaturationBox(DrawContext drawContext, int x, int y, f
Renderer2D.drawOutlineRoundedBox(drawContext.getMatrices().peek().getPositionMatrix(), x - 1, y - 1, boxWidth + 2, boxHeight + 2, 3, 1, value3);
}

public void updateHandles() {
public void updateHandles(boolean brightAndSat) {
float[] hsbvals = Color.RGBtoHSB(value.getRed(), value.getGreen(), value.getBlue(), null);
hue = hsbvals[0];
saturation = hsbvals[1];
brightness = hsbvals[2];
handleX = Math.min((int) (hue * boxWidth), boxWidth);
handleY = Math.min((int) ((1 - saturation) * gradientBoxHeight), gradientBoxHeight);
shadeHandleX = Math.min((int) (brightness * boxWidth), boxWidth);
shadeHandleY = Math.min((int) ((1 - saturation) * boxHeight), boxHeight);

if(brightAndSat) {
saturation = hsbvals[1];
brightness = hsbvals[2];
shadeHandleX = Math.min((int) (brightness * boxWidth), boxWidth);
shadeHandleY = Math.min((int) ((1 - saturation) * boxHeight), boxHeight);
}
}


Expand Down Expand Up @@ -265,7 +264,7 @@ public void mouse(double mouseX, double mouseY, int button) {

value = new Color(red, green, blue, (int) (alpha * 255));
isPicking = !isPicking;
updateHandles();
updateHandles(true);
alpha = value.getAlpha() / 255f;
}

Expand All @@ -290,7 +289,7 @@ public void mouse(double mouseX, double mouseY, int button) {
alpha = 1.0f - alphaHandleY / (float) boxHeight;
}
if (rainbow) {
updateHandles();
updateHandles(false);
} else {
value = Color.getHSBColor(hue, saturation, brightness);
}
Expand All @@ -302,7 +301,7 @@ public void keyPress(int keyCode) {
if (ColorUtils.isHexColor(hexInput.getValue())) {
try {
value = ColorUtils.hexToColor(hexInput.getValue());
updateHandles();
updateHandles(true);
} catch (Exception e) {
e.printStackTrace();
// Something went wrong
Expand All @@ -316,7 +315,7 @@ public void mouseClicked(double mouseX, double mouseY, int button) {
if (hoveredSetting((int) mouseX, (int) mouseY) && hoveredOverReset(mouseX, mouseY)) {
value = defaultValue;
rainbow = defaultRainbow;
updateHandles();
updateHandles(true);
alphaHandleY = Math.round((1.0f - alpha) * (float) boxHeight);
alpha = value.getAlpha() / 255f;
}
Expand Down Expand Up @@ -367,7 +366,7 @@ public void setValue(Color value) {
@SubscribeEvent
public void onTick(TickEvent.CLIENT event) {
if (rainbow) {
value = ColorUtils.changeAlpha(ColorUtils.getRainbowColor(), value.getAlpha());
value = ColorUtils.changeAlpha(ColorUtils.getRainbowColor(saturation,brightness), value.getAlpha());
}
}

Expand All @@ -384,15 +383,15 @@ public void loadFromFile(Map<String, Object> MAP) {
value = defaultValue;
rainbow = defaultRainbow;
HeliosClient.LOGGER.error("{} is null, Setting loaded to default", this.getSaveName());
updateHandles();
updateHandles(true);
return;
}

List<?> list = (List<?>) MAP.get(this.getSaveName());

value = ColorUtils.intToColor(MathUtils.d2iSafe(list.get(0)));
rainbow = MathUtils.d2iSafe(list.get(1)) == 1;
updateHandles();
updateHandles(true);
}

public Color getWithAlpha(int alpha){
Expand Down
Loading

0 comments on commit e9b6129

Please sign in to comment.