From e9b612948117560aace2fe09d1420eb7fad8d60e Mon Sep 17 00:00:00 2001 From: tanishisherewithhh <120117618+tanishisherewithhh@users.noreply.github.com> Date: Mon, 2 Sep 2024 20:34:25 +0530 Subject: [PATCH] LICENSE name change. RGBASetting rainbow with custom sat and brightness. HudElement documentation and resize logic change. ClientTag now shows client textures. And some optimisations. --- LICENSE | 2 +- .../java/dev/heliosclient/hud/HudElement.java | 55 +++++---------- .../hud/hudelements/ClientTag.java | 68 ++++++++++++++++--- .../module/settings/DoubleSetting.java | 19 ++++-- .../module/settings/RGBASetting.java | 35 +++++----- .../module/sysmodules/ClickGUI.java | 8 ++- .../ui/clickgui/CategoryPane.java | 7 +- .../ui/clickgui/ClickGUIScreen.java | 1 - .../clickgui/hudeditor/HudElementButton.java | 4 ++ .../settings/ClientSettingsScreen.java | 29 ++++++-- .../ui/clickgui/settings/SettingsScreen.java | 35 +++++++--- .../dev/heliosclient/util/ColorUtils.java | 33 +++------ .../heliosclient/util/render/Renderer2D.java | 10 ++- 13 files changed, 185 insertions(+), 121 deletions(-) diff --git a/LICENSE b/LICENSE index 111f5a19..20d76583 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/src/main/java/dev/heliosclient/hud/HudElement.java b/src/main/java/dev/heliosclient/hud/HudElement.java index 182e3b24..928d96cc 100644 --- a/src/main/java/dev/heliosclient/hud/HudElement.java +++ b/src/main/java/dev/heliosclient/hud/HudElement.java @@ -32,11 +32,16 @@ * Class for creating HudElements for HUD * *

Position is stored using this method:


- * 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.
- * 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.
- * 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.
+ * The HUD element stores on each axis to which section of the lines it lies to,
+ * (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]). + *
+ * 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.
+ * 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. * - *

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.

+ *

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.

*/ public class HudElement implements ISettingChange, ISaveAndLoad, Listener { protected static final MinecraftClient mc = MinecraftClient.getInstance(); @@ -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. @@ -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); @@ -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 @@ -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(); } @@ -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) { diff --git a/src/main/java/dev/heliosclient/hud/hudelements/ClientTag.java b/src/main/java/dev/heliosclient/hud/hudelements/ClientTag.java index 0f175399..7257902e 100644 --- a/src/main/java/dev/heliosclient/hud/hudelements/ClientTag.java +++ b/src/main/java/dev/heliosclient/hud/hudelements/ClientTag.java @@ -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 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 + } + } diff --git a/src/main/java/dev/heliosclient/module/settings/DoubleSetting.java b/src/main/java/dev/heliosclient/module/settings/DoubleSetting.java index 2fe25a93..a3706d49 100644 --- a/src/main/java/dev/heliosclient/module/settings/DoubleSetting.java +++ b/src/main/java/dev/heliosclient/module/settings/DoubleSetting.java @@ -19,11 +19,12 @@ import java.util.function.BooleanSupplier; public class DoubleSetting extends Setting { - 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); @@ -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)); @@ -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++; @@ -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 { @@ -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 diff --git a/src/main/java/dev/heliosclient/module/settings/RGBASetting.java b/src/main/java/dev/heliosclient/module/settings/RGBASetting.java index 5f4407ba..019a4a09 100644 --- a/src/main/java/dev/heliosclient/module/settings/RGBASetting.java +++ b/src/main/java/dev/heliosclient/module/settings/RGBASetting.java @@ -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); @@ -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) { @@ -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; @@ -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); + } } @@ -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; } @@ -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); } @@ -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 @@ -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; } @@ -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()); } } @@ -384,7 +383,7 @@ public void loadFromFile(Map MAP) { value = defaultValue; rainbow = defaultRainbow; HeliosClient.LOGGER.error("{} is null, Setting loaded to default", this.getSaveName()); - updateHandles(); + updateHandles(true); return; } @@ -392,7 +391,7 @@ public void loadFromFile(Map MAP) { value = ColorUtils.intToColor(MathUtils.d2iSafe(list.get(0))); rainbow = MathUtils.d2iSafe(list.get(1)) == 1; - updateHandles(); + updateHandles(true); } public Color getWithAlpha(int alpha){ diff --git a/src/main/java/dev/heliosclient/module/sysmodules/ClickGUI.java b/src/main/java/dev/heliosclient/module/sysmodules/ClickGUI.java index 35bd62a8..72a47076 100644 --- a/src/main/java/dev/heliosclient/module/sysmodules/ClickGUI.java +++ b/src/main/java/dev/heliosclient/module/sysmodules/ClickGUI.java @@ -147,10 +147,9 @@ public class ClickGUI extends Module_ { .name("Rainbow/Gradient speed") .description("Speed of the rainbow and gradients throughout the client") .onSettingChange(this) - .value(14.0) .max(20) .min(1) - .defaultValue(10.0) + .defaultValue(14.0) .roundingPlace(0) .build() ); @@ -443,6 +442,11 @@ public void onLoad() { FontManager.INSTANCE.registerFonts(); } + + public int getRainbowSpeed(){ + return (int) Math.max(RainbowSpeed.max - RainbowSpeed.getInt(),1); + } + public static boolean shouldGlowMousePointer(){ if(HeliosClient.CLICKGUI != null){ return HeliosClient.CLICKGUI.glowMousePointer.value; diff --git a/src/main/java/dev/heliosclient/ui/clickgui/CategoryPane.java b/src/main/java/dev/heliosclient/ui/clickgui/CategoryPane.java index cd258865..cce22cbf 100644 --- a/src/main/java/dev/heliosclient/ui/clickgui/CategoryPane.java +++ b/src/main/java/dev/heliosclient/ui/clickgui/CategoryPane.java @@ -177,14 +177,9 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float delta, if (gui.categoryBorder.value) { drawOutlineGradientBox(drawContext.getMatrices().peek().getPositionMatrix(), x, y, width); } - - // Calculate the scale factor from the MatrixStack - Matrix4f matrix = drawContext.getMatrices().peek().getPositionMatrix(); - float scaleY = matrix.m11(); - drawRectangle(drawContext.getMatrices().peek().getPositionMatrix(), x - 1, y + categoryNameHeight + 6, false, false, true, true, width + 2f, hudBox.getHeight(), HeliosClient.CLICKGUI.guiRoundness.getInt() + 1,ColorManager.INSTANCE.clickGuiPrimary); // Apply the scale factor to the scissor box dimensions - Renderer2D.enableScissor(x - 20, (int) ((y + categoryNameHeight + 6) * scaleY), width + 40, (int) ((hudBox.getHeight() - 1) * scaleY)); + Renderer2D.enableScissor(x - 20, (int) ((y + categoryNameHeight + 6)), width + 40, (int) ((hudBox.getHeight() - 1))); } if (collapsed) { diff --git a/src/main/java/dev/heliosclient/ui/clickgui/ClickGUIScreen.java b/src/main/java/dev/heliosclient/ui/clickgui/ClickGUIScreen.java index 14d15ef3..6331ae7e 100644 --- a/src/main/java/dev/heliosclient/ui/clickgui/ClickGUIScreen.java +++ b/src/main/java/dev/heliosclient/ui/clickgui/ClickGUIScreen.java @@ -148,7 +148,6 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) FontRenderers.Super_Small_fxfontRenderer.drawString(drawContext.getMatrices(), "Middle Click - Open QuickSettings", 2, drawContext.getScaledWindowHeight() - (2 * fontHeight) - 2 * 2, -1); FontRenderers.Super_Small_fxfontRenderer.drawString(drawContext.getMatrices(), "Right Click - Open Settings", 2, drawContext.getScaledWindowHeight() - (fontHeight) - 2, -1); } - Renderer2D.scaleAndPosition(drawContext.getMatrices(),0,0,width,height,scale); for (CategoryPane category : categoryPanes) { diff --git a/src/main/java/dev/heliosclient/ui/clickgui/hudeditor/HudElementButton.java b/src/main/java/dev/heliosclient/ui/clickgui/hudeditor/HudElementButton.java index 63cbf26a..cab7b03b 100644 --- a/src/main/java/dev/heliosclient/ui/clickgui/hudeditor/HudElementButton.java +++ b/src/main/java/dev/heliosclient/ui/clickgui/hudeditor/HudElementButton.java @@ -61,6 +61,10 @@ public void addInstanceToList(Class clazz) { lastHudElement.posX = HudElement.NUMBER_OF_LINES/2 - 1; lastHudElement.posY = HudElement.NUMBER_OF_LINES/2 - 1; + lastHudElement.distanceX = (HeliosClient.MC.getWindow().getScaledWidth() - lastHudElement.width)/2; + lastHudElement.distanceY = (HeliosClient.MC.getWindow().getScaledHeight() - lastHudElement.height)/2; + lastHudElement.x = (HeliosClient.MC.getWindow().getScaledWidth() - lastHudElement.width)/2; + lastHudElement.y = (HeliosClient.MC.getWindow().getScaledHeight() - lastHudElement.height)/2; } catch (Exception e) { HeliosClient.LOGGER.error("Error adding hud element instance to list", e); diff --git a/src/main/java/dev/heliosclient/ui/clickgui/settings/ClientSettingsScreen.java b/src/main/java/dev/heliosclient/ui/clickgui/settings/ClientSettingsScreen.java index 25716a1e..0319f0e0 100644 --- a/src/main/java/dev/heliosclient/ui/clickgui/settings/ClientSettingsScreen.java +++ b/src/main/java/dev/heliosclient/ui/clickgui/settings/ClientSettingsScreen.java @@ -51,17 +51,20 @@ public void updateSetting() { ); } + @Override + public void onDisplayed() { + super.onDisplayed(); + adjustWindowHeight(); + } @Override - public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) { - if (this.client.world == null) { - super.renderBackgroundTexture(drawContext); - } + public void resize(MinecraftClient client, int width, int height) { + super.resize(client, width, height); - if(GUI.coolVisuals()){ - PolygonMeshPatternRenderer.INSTANCE.render(drawContext.getMatrices(),mouseX,mouseY); - } + adjustWindowHeight(); + } + private void adjustWindowHeight(){ windowHeight = 50; for (SettingGroup settingGroup : module.settingGroups) { float groupNameHeight = settingGroup.getGroupNameHeight(); @@ -74,6 +77,18 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) } windowHeight += Math.round(groupNameHeight + 4); } + } + + + @Override + public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) { + if (this.client.world == null) { + super.renderBackgroundTexture(drawContext); + } + + if(GUI.coolVisuals()){ + PolygonMeshPatternRenderer.INSTANCE.render(drawContext.getMatrices(),mouseX,mouseY); + } window.setWindowHeight(windowHeight); window.setWindowWidth(windowWidth); diff --git a/src/main/java/dev/heliosclient/ui/clickgui/settings/SettingsScreen.java b/src/main/java/dev/heliosclient/ui/clickgui/settings/SettingsScreen.java index c22f5a4a..444ce8fb 100644 --- a/src/main/java/dev/heliosclient/ui/clickgui/settings/SettingsScreen.java +++ b/src/main/java/dev/heliosclient/ui/clickgui/settings/SettingsScreen.java @@ -11,6 +11,7 @@ import dev.heliosclient.ui.clickgui.gui.PolygonMeshPatternRenderer; import dev.heliosclient.ui.clickgui.gui.Window; import dev.heliosclient.util.interfaces.IWindowContentRenderer; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; import net.minecraft.text.Text; @@ -45,27 +46,43 @@ public void updateSetting() { })); } + @Override + public void onDisplayed() { + super.onDisplayed(); + adjustWindowHeight(); + } @Override - public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) { - if (this.client.world == null) { - super.renderBackgroundTexture(drawContext); - } + public void resize(MinecraftClient client, int width, int height) { + super.resize(client, width, height); - if(GUI.coolVisuals()){ - PolygonMeshPatternRenderer.INSTANCE.render(drawContext.getMatrices(),mouseX,mouseY); - } + adjustWindowHeight(); + } + private void adjustWindowHeight(){ windowHeight = 50; for (SettingGroup settingGroup : module.settingGroups) { - windowHeight += Math.round(settingGroup.getGroupNameHeight() + 13); + float groupNameHeight = settingGroup.getGroupNameHeight(); + windowHeight += Math.round(groupNameHeight + 12); if (!settingGroup.shouldRender()) continue; for (Setting setting : settingGroup.getSettings()) { if (!setting.shouldRender()) continue; setting.quickSettings = false; windowHeight += setting.getHeight() + 1; } - windowHeight += 8; + windowHeight += Math.round(groupNameHeight + 4); + } + } + + + @Override + public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) { + if (this.client.world == null) { + super.renderBackgroundTexture(drawContext); + } + + if(GUI.coolVisuals()){ + PolygonMeshPatternRenderer.INSTANCE.render(drawContext.getMatrices(),mouseX,mouseY); } window.setWindowHeight(windowHeight); diff --git a/src/main/java/dev/heliosclient/util/ColorUtils.java b/src/main/java/dev/heliosclient/util/ColorUtils.java index d2960b5a..eb78a8d5 100644 --- a/src/main/java/dev/heliosclient/util/ColorUtils.java +++ b/src/main/java/dev/heliosclient/util/ColorUtils.java @@ -1,13 +1,9 @@ package dev.heliosclient.util; import dev.heliosclient.HeliosClient; -import net.minecraft.client.gl.Framebuffer; -import net.minecraft.client.util.GlAllocationUtils; import net.minecraft.util.math.random.Random; -import org.lwjgl.opengl.GL11; import java.awt.*; -import java.nio.ByteBuffer; import java.util.Objects; /** @@ -137,8 +133,16 @@ public static Color getRainbowColor(int speed) { * @return Current rainbow color. */ public static Color getRainbowColor() { - float hue = (System.currentTimeMillis() % ((int) HeliosClient.CLICKGUI.RainbowSpeed.value * 1000)) / ((int) HeliosClient.CLICKGUI.RainbowSpeed.value * 1000.0f); - return Color.getHSBColor(hue, 1.0f, 1.0f); + return getRainbowColor(1.0f,1.0f); + } + /** + * Rainbow cycle with the provided brightness and saturation + * + * @return Current rainbow color. + */ + public static Color getRainbowColor(float saturation, float brightness) { + float hue = (System.currentTimeMillis() % (HeliosClient.CLICKGUI.getRainbowSpeed() * 1000)) / (HeliosClient.CLICKGUI.getRainbowSpeed() * 1000.0f); + return Color.getHSBColor(hue, saturation, brightness); } /** @@ -148,7 +152,7 @@ public static Color getRainbowColor() { */ public static Color getRainbowColor2() { float hueOffset = 0.1f; - float hue = ((System.currentTimeMillis() % ((int) HeliosClient.CLICKGUI.RainbowSpeed.value * 1000)) / ((int) HeliosClient.CLICKGUI.RainbowSpeed.value * 1000.0f)) + hueOffset; + float hue = (System.currentTimeMillis() % (HeliosClient.CLICKGUI.getRainbowSpeed() * 1000)) / (HeliosClient.CLICKGUI.getRainbowSpeed() * 1000.0f) + hueOffset; hue += (int) hue; return Color.getHSBColor(hue, 1.0f, 1.0f); } @@ -271,21 +275,6 @@ public static boolean isHexColor(String value) { } } - public static Color getColorAtPixel(double mouseX, double mouseY) { - Framebuffer framebuffer = HeliosClient.MC.getFramebuffer(); - int x = (int) (mouseX * framebuffer.textureWidth / HeliosClient.MC.getWindow().getScaledWidth()); - int y = (int) ((HeliosClient.MC.getWindow().getScaledHeight() - mouseY) * framebuffer.textureHeight / HeliosClient.MC.getWindow().getScaledHeight()); - - ByteBuffer buffer = GlAllocationUtils.allocateByteBuffer(4); - GL11.glReadPixels(x, y, 1, 1, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); - int red = buffer.get(0) & 0xFF; - int green = buffer.get(1) & 0xFF; - int blue = buffer.get(2) & 0xFF; - int alpha = buffer.get(3) & 0xFF; - - return new Color(red, green, blue, alpha); - } - public static float getSaturation(Color color) { float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null); return hsb[1]; diff --git a/src/main/java/dev/heliosclient/util/render/Renderer2D.java b/src/main/java/dev/heliosclient/util/render/Renderer2D.java index 7b74869f..e73c88fb 100644 --- a/src/main/java/dev/heliosclient/util/render/Renderer2D.java +++ b/src/main/java/dev/heliosclient/util/render/Renderer2D.java @@ -125,8 +125,10 @@ public static void drawGradient(Matrix4f matrix4f, float x, float y, float width } public static void enableScissor(int x, int y, int width, int height) { - double scaleFactor = HeliosClient.MC.getWindow().getScaleFactor(); + enableScissor(x,y,width,height,mc.getWindow().getScaleFactor()); + } + public static void enableScissor(int x, int y, int width, int height, double scaleFactor) { int scissorX = (int) (x * scaleFactor); int scissorY = (int) (HeliosClient.MC.getWindow().getHeight() - ((y + height) * scaleFactor)); int scissorWidth = (int) (width * scaleFactor); @@ -1067,6 +1069,11 @@ public static void scaledProjection() { RenderSystem.setProjectionMatrix(new Matrix4f().setOrtho(0, (float) (mc.getWindow().getFramebufferWidth() / mc.getWindow().getScaleFactor()), (float) (mc.getWindow().getFramebufferHeight() / mc.getWindow().getScaleFactor()), 0, 1000, 21000), vertexSorter); } + public static void customScaledProjection(float scale) { + vertexSorter = RenderSystem.getVertexSorting(); + RenderSystem.setProjectionMatrix(new Matrix4f().setOrtho(0, mc.getWindow().getFramebufferWidth() / scale, mc.getWindow().getFramebufferHeight() / scale, 0, 1000, 21000), VertexSorter.BY_Z); + } + /** * Draws a rounded rectangle with a shadow in a bad way * @@ -1185,7 +1192,6 @@ public static void drawRoundedGradientRectangle(Matrix4f matrix, Color color1, C RenderSystem.blendFunc(GL40C.GL_DST_ALPHA, GL40C.GL_ONE_MINUS_DST_ALPHA); - RenderSystem.enableBlend(); RenderSystem.setShaderColor(1f, 1f, 1f, 1f); BufferBuilder bufferBuilder = setupAndBegin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);