diff --git a/src/main/java/net/wurstclient/clickgui/ClickGui.java b/src/main/java/net/wurstclient/clickgui/ClickGui.java index ab505ef181..22a2603404 100644 --- a/src/main/java/net/wurstclient/clickgui/ClickGui.java +++ b/src/main/java/net/wurstclient/clickgui/ClickGui.java @@ -18,23 +18,15 @@ import java.util.Objects; import java.util.stream.Stream; -import org.joml.Matrix4f; -import org.lwjgl.opengl.GL11; +import org.lwjgl.glfw.GLFW; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gl.ShaderProgramKeys; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.render.BufferBuilder; -import net.minecraft.client.render.BufferRenderer; -import net.minecraft.client.render.Tessellator; -import net.minecraft.client.render.VertexFormat; -import net.minecraft.client.render.VertexFormats; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; import net.wurstclient.Category; @@ -107,12 +99,12 @@ public void init() int x = 5; int y = 5; - net.minecraft.client.util.Window sr = MC.getWindow(); + int scaledWidth = MC.getWindow().getScaledWidth(); for(Window window : windows) { window.pack(); - if(x + window.getWidth() + 5 > sr.getScaledWidth()) + if(x + window.getWidth() + 5 > scaledWidth) { x = 5; y += 18; @@ -201,7 +193,7 @@ private void saveWindows() public void handleMouseClick(int mouseX, int mouseY, int mouseButton) { - if(mouseButton == 0) + if(mouseButton == GLFW.GLFW_MOUSE_BUTTON_LEFT) leftMouseButtonPressed = true; boolean popupClicked = @@ -221,7 +213,7 @@ public void handleMouseClick(int mouseX, int mouseY, int mouseButton) public void handleMouseRelease(double mouseX, double mouseY, int mouseButton) { - if(mouseButton == 0) + if(mouseButton == GLFW.GLFW_MOUSE_BUTTON_LEFT) leftMouseButtonPressed = false; } @@ -275,7 +267,7 @@ public boolean handleNavigatorPopupClick(double mouseX, double mouseY, public void handleNavigatorMouseClick(double cMouseX, double cMouseY, int mouseButton, Window window) { - if(mouseButton == 0) + if(mouseButton == GLFW.GLFW_MOUSE_BUTTON_LEFT) leftMouseButtonPressed = true; handleComponentMouseClick(window, cMouseX, cMouseY, mouseButton); @@ -423,7 +415,7 @@ private void handleTitleBarMouseClick(Window window, int mouseX, int mouseY, private void handleScrollbarMouseClick(Window window, int mouseX, int mouseY, int mouseButton) { - if(mouseButton != 0) + if(mouseButton != GLFW.GLFW_MOUSE_BUTTON_LEFT) return; if(mouseX >= window.getWidth() - 1) @@ -466,11 +458,6 @@ public void render(DrawContext context, int mouseX, int mouseY, { updateColors(); - GL11.glDisable(GL11.GL_CULL_FACE); - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - // GL11.glShadeModel(GL11.GL_SMOOTH); - RenderSystem.lineWidth(1); MatrixStack matrixStack = context.getMatrices(); matrixStack.push(); @@ -505,8 +492,6 @@ public void render(DrawContext context, int mouseX, int mouseY, renderTooltip(context, mouseX, mouseY); matrixStack.pop(); - GL11.glEnable(GL11.GL_CULL_FACE); - GL11.glDisable(GL11.GL_BLEND); } public void renderPopups(DrawContext context, int mouseX, int mouseY) @@ -535,19 +520,18 @@ public void renderPopups(DrawContext context, int mouseX, int mouseY) public void renderTooltip(DrawContext context, int mouseX, int mouseY) { MatrixStack matrixStack = context.getMatrices(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); if(tooltip.isEmpty()) return; String[] lines = tooltip.split("\n"); - TextRenderer fr = MC.textRenderer; + TextRenderer tr = MC.textRenderer; int tw = 0; - int th = lines.length * fr.fontHeight; + int th = lines.length * tr.fontHeight; for(String line : lines) { - int lw = fr.getWidth(line); + int lw = tr.getWidth(line); if(lw > tw) tw = lw; } @@ -561,47 +545,25 @@ public void renderTooltip(DrawContext context, int mouseX, int mouseY) matrixStack.push(); matrixStack.translate(0, 0, 300); - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - - RenderSystem.setShader(ShaderProgramKeys.POSITION); // background - RenderUtils.setShaderColor(bgColor, ttOpacity); - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xt1, yt1, 0); - bufferBuilder.vertex(matrix, xt1, yt2, 0); - bufferBuilder.vertex(matrix, xt2, yt2, 0); - bufferBuilder.vertex(matrix, xt2, yt1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + context.fill(xt1, yt1, xt2, yt2, + RenderUtils.toIntColor(bgColor, ttOpacity)); // outline - RenderUtils.setShaderColor(acColor, 0.5F); - bufferBuilder = tessellator.begin( - VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xt1, yt1, 0); - bufferBuilder.vertex(matrix, xt1, yt2, 0); - bufferBuilder.vertex(matrix, xt2, yt2, 0); - bufferBuilder.vertex(matrix, xt2, yt1, 0); - bufferBuilder.vertex(matrix, xt1, yt1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + RenderUtils.drawBorder2D(context, xt1, yt1, xt2, yt2, + RenderUtils.toIntColor(acColor, 0.5F)); // text - RenderSystem.setShaderColor(1, 1, 1, 1); for(int i = 0; i < lines.length; i++) - context.drawText(fr, lines[i], xt1 + 2, yt1 + 2 + i * fr.fontHeight, + context.drawText(tr, lines[i], xt1 + 2, yt1 + 2 + i * tr.fontHeight, txtColor, false); - GL11.glEnable(GL11.GL_BLEND); matrixStack.pop(); } public void renderPinnedWindows(DrawContext context, float partialTicks) { - GL11.glDisable(GL11.GL_CULL_FACE); - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - RenderSystem.lineWidth(1); MatrixStack matrixStack = context.getMatrices(); matrixStack.push(); @@ -614,8 +576,6 @@ public void renderPinnedWindows(DrawContext context, float partialTicks) } matrixStack.pop(); - GL11.glEnable(GL11.GL_CULL_FACE); - GL11.glDisable(GL11.GL_BLEND); } public void updateColors() @@ -644,10 +604,10 @@ private void renderWindow(DrawContext context, Window window, int mouseX, int y2 = y1 + window.getHeight(); int y3 = y1 + 13; + int windowBgColor = RenderUtils.toIntColor(bgColor, opacity); + int outlineColor = RenderUtils.toIntColor(acColor, 0.5F); + MatrixStack matrixStack = context.getMatrices(); - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - RenderSystem.setShader(ShaderProgramKeys.POSITION); if(window.isMinimized()) y2 = y3; @@ -682,51 +642,21 @@ private void renderWindow(DrawContext context, Window window, int mouseX, int ys4 = ys3 + (int)scrollbarHeight; // window background - RenderUtils.setShaderColor(bgColor, opacity); - - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xs2, ys1, 0); - bufferBuilder.vertex(matrix, xs2, ys2, 0); - bufferBuilder.vertex(matrix, xs3, ys2, 0); - bufferBuilder.vertex(matrix, xs3, ys1, 0); - bufferBuilder.vertex(matrix, xs1, ys1, 0); - bufferBuilder.vertex(matrix, xs1, ys3, 0); - bufferBuilder.vertex(matrix, xs2, ys3, 0); - bufferBuilder.vertex(matrix, xs2, ys1, 0); - bufferBuilder.vertex(matrix, xs1, ys4, 0); - bufferBuilder.vertex(matrix, xs1, ys2, 0); - bufferBuilder.vertex(matrix, xs2, ys2, 0); - bufferBuilder.vertex(matrix, xs2, ys4, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + context.fill(xs2, ys1, xs3, ys2, windowBgColor); + context.fill(xs1, ys1, xs2, ys3, windowBgColor); + context.fill(xs1, ys4, xs2, ys2, windowBgColor); boolean hovering = mouseX >= xs1 && mouseY >= ys3 && mouseX < xs2 && mouseY < ys4; // scrollbar - RenderUtils.setShaderColor(acColor, + int scrollbarColor = RenderUtils.toIntColor(acColor, hovering ? opacity * 1.5F : opacity); - - bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, - VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xs1, ys3, 0); - bufferBuilder.vertex(matrix, xs1, ys4, 0); - bufferBuilder.vertex(matrix, xs2, ys4, 0); - bufferBuilder.vertex(matrix, xs2, ys3, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + context.fill(xs1, ys3, xs2, ys4, scrollbarColor); // outline - RenderUtils.setShaderColor(acColor, 0.5F); - - bufferBuilder = - tessellator.begin(VertexFormat.DrawMode.DEBUG_LINE_STRIP, - VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xs1, ys3, 0); - bufferBuilder.vertex(matrix, xs1, ys4, 0); - bufferBuilder.vertex(matrix, xs2, ys4, 0); - bufferBuilder.vertex(matrix, xs2, ys3, 0); - bufferBuilder.vertex(matrix, xs1, ys3, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + RenderUtils.drawBorder2D(context, xs1, ys3, xs2, ys4, + outlineColor); } int x3 = x1 + 2; @@ -736,29 +666,13 @@ private void renderWindow(DrawContext context, Window window, int mouseX, // window background // left & right - RenderUtils.setShaderColor(bgColor, opacity); - - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x1, y3, 0); - bufferBuilder.vertex(matrix, x1, y2, 0); - bufferBuilder.vertex(matrix, x3, y2, 0); - bufferBuilder.vertex(matrix, x3, y3, 0); - bufferBuilder.vertex(matrix, x5, y3, 0); - bufferBuilder.vertex(matrix, x5, y2, 0); - bufferBuilder.vertex(matrix, x4, y2, 0); - bufferBuilder.vertex(matrix, x4, y3, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + context.fill(x1, y3, x3, y2, windowBgColor); + context.fill(x5, y3, x4, y2, windowBgColor); - RenderUtils.enableScissor(context, x1, y3, x2, y2); + context.enableScissor(x1, y3, x2, y2); matrixStack.push(); matrixStack.translate(x1, y4, 0); - matrix = matrixStack.peek().getPositionMatrix(); - - RenderUtils.setShaderColor(bgColor, opacity); - bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, - VertexFormats.POSITION); // window background // between children @@ -768,10 +682,7 @@ private void renderWindow(DrawContext context, Window window, int mouseX, { int yc1 = window.getChild(i).getY(); int yc2 = yc1 - 2; - bufferBuilder.vertex(matrix, xc1, yc2, 0); - bufferBuilder.vertex(matrix, xc1, yc1, 0); - bufferBuilder.vertex(matrix, xc2, yc1, 0); - bufferBuilder.vertex(matrix, xc2, yc2, 0); + context.fill(xc1, yc2, xc2, yc1, windowBgColor); } // window background @@ -786,12 +697,7 @@ private void renderWindow(DrawContext context, Window window, int mouseX, yc1 = lastChild.getY() + lastChild.getHeight(); } int yc2 = yc1 + 2; - bufferBuilder.vertex(matrix, xc1, yc2, 0); - bufferBuilder.vertex(matrix, xc1, yc1, 0); - bufferBuilder.vertex(matrix, xc2, yc1, 0); - bufferBuilder.vertex(matrix, xc2, yc2, 0); - - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + context.fill(xc1, yc2, xc2, yc1, windowBgColor); // render children int cMouseX = mouseX - x1; @@ -801,34 +707,15 @@ private void renderWindow(DrawContext context, Window window, int mouseX, partialTicks); matrixStack.pop(); - matrix = matrixStack.peek().getPositionMatrix(); - RenderUtils.disableScissor(context); + context.disableScissor(); } - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - // window outline - RenderUtils.setShaderColor(acColor, 0.5F); - - BufferBuilder bufferBuilder = tessellator.begin( - VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x1, y1, 0); - bufferBuilder.vertex(matrix, x1, y2, 0); - bufferBuilder.vertex(matrix, x2, y2, 0); - bufferBuilder.vertex(matrix, x2, y1, 0); - bufferBuilder.vertex(matrix, x1, y1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + RenderUtils.drawBorder2D(context, x1, y1, x2, y2, outlineColor); + // title bar separator line if(!window.isMinimized()) - { - // title bar outline - bufferBuilder = tessellator.begin(VertexFormat.DrawMode.DEBUG_LINES, - VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x1, y3, 0); - bufferBuilder.vertex(matrix, x2, y3, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - } + RenderUtils.drawLine2D(context, x1, y3, x2, y3, outlineColor); // title bar buttons int x3 = x2; @@ -840,7 +727,8 @@ private void renderWindow(DrawContext context, Window window, int mouseX, x3 -= 11; int x4 = x3 + 9; boolean hovering = hoveringY && mouseX >= x3 && mouseX < x4; - renderCloseButton(matrixStack, x3, y4, x4, y5, hovering); + renderTitleBarButton(context, x3, y4, x4, y5, hovering); + ClickGuiIcons.drawCross(context, x3, y4, x4, y5, hovering); } if(window.isPinnable()) @@ -848,7 +736,8 @@ private void renderWindow(DrawContext context, Window window, int mouseX, x3 -= 11; int x4 = x3 + 9; boolean hovering = hoveringY && mouseX >= x3 && mouseX < x4; - renderPinButton(matrixStack, x3, y4, x4, y5, hovering, + renderTitleBarButton(context, x3, y4, x4, y5, hovering); + ClickGuiIcons.drawPin(context, x3, y4, x4, y5, hovering, window.isPinned()); } @@ -857,341 +746,45 @@ private void renderWindow(DrawContext context, Window window, int mouseX, x3 -= 11; int x4 = x3 + 9; boolean hovering = hoveringY && mouseX >= x3 && mouseX < x4; - renderMinimizeButton(matrixStack, x3, y4, x4, y5, hovering, + renderTitleBarButton(context, x3, y4, x4, y5, hovering); + ClickGuiIcons.drawMinimizeArrow(context, x3, y4, x4, y5, hovering, window.isMinimized()); } // title bar background // above & below buttons - RenderUtils.setShaderColor(acColor, opacity); - - bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, - VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x3, y1, 0); - bufferBuilder.vertex(matrix, x3, y4, 0); - bufferBuilder.vertex(matrix, x2, y4, 0); - bufferBuilder.vertex(matrix, x2, y1, 0); - bufferBuilder.vertex(matrix, x3, y5, 0); - bufferBuilder.vertex(matrix, x3, y3, 0); - bufferBuilder.vertex(matrix, x2, y3, 0); - bufferBuilder.vertex(matrix, x2, y5, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + int titleBgColor = RenderUtils.toIntColor(acColor, opacity); + context.fill(x3, y1, x2, y4, titleBgColor); + context.fill(x3, y5, x2, y3, titleBgColor); // title bar background // behind title - bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, - VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x1, y1, 0); - bufferBuilder.vertex(matrix, x1, y3, 0); - bufferBuilder.vertex(matrix, x3, y3, 0); - bufferBuilder.vertex(matrix, x3, y1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + context.fill(x1, y1, x3, y3, titleBgColor); // window title - RenderSystem.setShaderColor(1, 1, 1, 1); - TextRenderer fr = MC.textRenderer; - String title = fr.trimToWidth(Text.literal(window.getTitle()), x3 - x1) + TextRenderer tr = MC.textRenderer; + String title = tr.trimToWidth(Text.literal(window.getTitle()), x3 - x1) .getString(); - context.drawText(fr, title, x1 + 2, y1 + 3, txtColor, false); - GL11.glEnable(GL11.GL_BLEND); + context.drawText(tr, title, x1 + 2, y1 + 3, txtColor, false); } - private void renderTitleBarButton(MatrixStack matrixStack, int x1, int y1, + private void renderTitleBarButton(DrawContext context, int x1, int y1, int x2, int y2, boolean hovering) { int x3 = x2 + 2; - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - RenderSystem.setShader(ShaderProgramKeys.POSITION); - // button background - RenderUtils.setShaderColor(bgColor, + int buttonBgColor = RenderUtils.toIntColor(bgColor, hovering ? opacity * 1.5F : opacity); - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x1, y1, 0); - bufferBuilder.vertex(matrix, x1, y2, 0); - bufferBuilder.vertex(matrix, x2, y2, 0); - bufferBuilder.vertex(matrix, x2, y1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + context.fill(x1, y1, x2, y2, buttonBgColor); // background between buttons - RenderUtils.setShaderColor(acColor, opacity); - bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, - VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x2, y1, 0); - bufferBuilder.vertex(matrix, x2, y2, 0); - bufferBuilder.vertex(matrix, x3, y2, 0); - bufferBuilder.vertex(matrix, x3, y1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + int windowBgColor = RenderUtils.toIntColor(acColor, opacity); + context.fill(x2, y1, x3, y2, windowBgColor); // button outline - RenderUtils.setShaderColor(acColor, 0.5F); - bufferBuilder = tessellator.begin( - VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x1, y1, 0); - bufferBuilder.vertex(matrix, x1, y2, 0); - bufferBuilder.vertex(matrix, x2, y2, 0); - bufferBuilder.vertex(matrix, x2, y1, 0); - bufferBuilder.vertex(matrix, x1, y1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - } - - private void renderMinimizeButton(MatrixStack matrixStack, int x1, int y1, - int x2, int y2, boolean hovering, boolean minimized) - { - renderTitleBarButton(matrixStack, x1, y1, x2, y2, hovering); - - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - - float xa1 = x1 + 1; - float xa2 = (x1 + x2) / 2.0F; - float xa3 = x2 - 1; - float ya1; - float ya2; - - if(minimized) - { - ya1 = y1 + 3; - ya2 = y2 - 2.5F; - RenderSystem.setShaderColor(0, hovering ? 1 : 0.85F, 0, 1); - - }else - { - ya1 = y2 - 3; - ya2 = y1 + 2.5F; - RenderSystem.setShaderColor(hovering ? 1 : 0.85F, 0, 0, 1); - } - - // arrow - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xa1, ya1, 0); - bufferBuilder.vertex(matrix, xa3, ya1, 0); - bufferBuilder.vertex(matrix, xa2, ya2, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - - // outline - RenderSystem.setShaderColor(0.0625F, 0.0625F, 0.0625F, 0.5F); - bufferBuilder = tessellator.begin( - VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xa1, ya1, 0); - bufferBuilder.vertex(matrix, xa3, ya1, 0); - bufferBuilder.vertex(matrix, xa2, ya2, 0); - bufferBuilder.vertex(matrix, xa1, ya1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - } - - private void renderPinButton(MatrixStack matrixStack, int x1, int y1, - int x2, int y2, boolean hovering, boolean pinned) - { - renderTitleBarButton(matrixStack, x1, y1, x2, y2, hovering); - float h = hovering ? 1 : 0.85F; - - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - - if(pinned) - { - float xk1 = x1 + 2; - float xk2 = x2 - 2; - float xk3 = x1 + 1; - float xk4 = x2 - 1; - float yk1 = y1 + 2; - float yk2 = y2 - 2; - float yk3 = y2 - 0.5F; - - // knob - RenderSystem.setShaderColor(h, 0, 0, 0.5F); - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xk1, yk1, 0); - bufferBuilder.vertex(matrix, xk2, yk1, 0); - bufferBuilder.vertex(matrix, xk2, yk2, 0); - bufferBuilder.vertex(matrix, xk1, yk2, 0); - bufferBuilder.vertex(matrix, xk3, yk2, 0); - bufferBuilder.vertex(matrix, xk4, yk2, 0); - bufferBuilder.vertex(matrix, xk4, yk3, 0); - bufferBuilder.vertex(matrix, xk3, yk3, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - - float xn1 = x1 + 3.5F; - float xn2 = x2 - 3.5F; - float yn1 = y2 - 0.5F; - float yn2 = y2; - - // needle - RenderSystem.setShaderColor(h, h, h, 1); - bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, - VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xn1, yn1, 0); - bufferBuilder.vertex(matrix, xn2, yn1, 0); - bufferBuilder.vertex(matrix, xn2, yn2, 0); - bufferBuilder.vertex(matrix, xn1, yn2, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - - // outlines - RenderSystem.setShaderColor(0.0625F, 0.0625F, 0.0625F, 0.5F); - bufferBuilder = tessellator.begin( - VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xk1, yk1, 0); - bufferBuilder.vertex(matrix, xk2, yk1, 0); - bufferBuilder.vertex(matrix, xk2, yk2, 0); - bufferBuilder.vertex(matrix, xk1, yk2, 0); - bufferBuilder.vertex(matrix, xk1, yk1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - bufferBuilder = tessellator.begin( - VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xk3, yk2, 0); - bufferBuilder.vertex(matrix, xk4, yk2, 0); - bufferBuilder.vertex(matrix, xk4, yk3, 0); - bufferBuilder.vertex(matrix, xk3, yk3, 0); - bufferBuilder.vertex(matrix, xk3, yk2, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - bufferBuilder = tessellator.begin( - VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xn1, yn1, 0); - bufferBuilder.vertex(matrix, xn2, yn1, 0); - bufferBuilder.vertex(matrix, xn2, yn2, 0); - bufferBuilder.vertex(matrix, xn1, yn2, 0); - bufferBuilder.vertex(matrix, xn1, yn1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - - }else - { - float xk1 = x2 - 3.5F; - float xk2 = x2 - 0.5F; - float xk3 = x2 - 3; - float xk4 = x1 + 3; - float xk5 = x1 + 2; - float xk6 = x2 - 2; - float xk7 = x1 + 1; - float yk1 = y1 + 0.5F; - float yk2 = y1 + 3.5F; - float yk3 = y2 - 3; - float yk4 = y1 + 3; - float yk5 = y1 + 2; - float yk6 = y2 - 2; - float yk7 = y2 - 1; - - // knob - RenderSystem.setShaderColor(0, h, 0, 1); - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xk1, yk1, 0); - bufferBuilder.vertex(matrix, xk2, yk2, 0); - bufferBuilder.vertex(matrix, xk3, yk3, 0); - bufferBuilder.vertex(matrix, xk4, yk4, 0); - bufferBuilder.vertex(matrix, xk5, yk5, 0); - bufferBuilder.vertex(matrix, xk6, yk6, 0); - bufferBuilder.vertex(matrix, xk3, yk7, 0); - bufferBuilder.vertex(matrix, xk7, yk4, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - - float xn1 = x1 + 3; - float xn2 = x1 + 4; - float xn3 = x1 + 1; - float yn1 = y2 - 4; - float yn2 = y2 - 3; - float yn3 = y2 - 1; - - // needle - RenderSystem.setShaderColor(h, h, h, 1); - bufferBuilder = tessellator.begin(VertexFormat.DrawMode.TRIANGLES, - VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xn1, yn1, 0); - bufferBuilder.vertex(matrix, xn2, yn2, 0); - bufferBuilder.vertex(matrix, xn3, yn3, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - - // outlines - RenderSystem.setShaderColor(0.0625F, 0.0625F, 0.0625F, 0.5F); - bufferBuilder = tessellator.begin( - VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xk1, yk1, 0); - bufferBuilder.vertex(matrix, xk2, yk2, 0); - bufferBuilder.vertex(matrix, xk3, yk3, 0); - bufferBuilder.vertex(matrix, xk4, yk4, 0); - bufferBuilder.vertex(matrix, xk1, yk1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - bufferBuilder = tessellator.begin( - VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xk5, yk5, 0); - bufferBuilder.vertex(matrix, xk6, yk6, 0); - bufferBuilder.vertex(matrix, xk3, yk7, 0); - bufferBuilder.vertex(matrix, xk7, yk4, 0); - bufferBuilder.vertex(matrix, xk5, yk5, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - bufferBuilder = tessellator.begin( - VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xn1, yn1, 0); - bufferBuilder.vertex(matrix, xn2, yn2, 0); - bufferBuilder.vertex(matrix, xn3, yn3, 0); - bufferBuilder.vertex(matrix, xn1, yn1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - } - } - - private void renderCloseButton(MatrixStack matrixStack, int x1, int y1, - int x2, int y2, boolean hovering) - { - renderTitleBarButton(matrixStack, x1, y1, x2, y2, hovering); - - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - - float xc1 = x1 + 2; - float xc2 = x1 + 3; - float xc3 = x2 - 2; - float xc4 = x2 - 3; - float xc5 = x1 + 3.5F; - float xc6 = (x1 + x2) / 2.0F; - float xc7 = x2 - 3.5F; - float yc1 = y1 + 3; - float yc2 = y1 + 2; - float yc3 = y2 - 3; - float yc4 = y2 - 2; - float yc5 = y1 + 3.5F; - float yc6 = (y1 + y2) / 2.0F; - float yc7 = y2 - 3.5F; - - // cross - RenderSystem.setShaderColor(hovering ? 1 : 0.85F, 0, 0, 1); - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xc1, yc1, 0); - bufferBuilder.vertex(matrix, xc2, yc2, 0); - bufferBuilder.vertex(matrix, xc3, yc3, 0); - bufferBuilder.vertex(matrix, xc4, yc4, 0); - bufferBuilder.vertex(matrix, xc3, yc1, 0); - bufferBuilder.vertex(matrix, xc4, yc2, 0); - bufferBuilder.vertex(matrix, xc6, yc5, 0); - bufferBuilder.vertex(matrix, xc7, yc6, 0); - bufferBuilder.vertex(matrix, xc6, yc7, 0); - bufferBuilder.vertex(matrix, xc5, yc6, 0); - bufferBuilder.vertex(matrix, xc1, yc3, 0); - bufferBuilder.vertex(matrix, xc2, yc4, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - - // outline - RenderSystem.setShaderColor(0.0625F, 0.0625F, 0.0625F, 0.5F); - bufferBuilder = tessellator.begin(VertexFormat.DrawMode.DEBUG_LINES, - VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xc1, yc1, 0); - bufferBuilder.vertex(matrix, xc2, yc2, 0); - bufferBuilder.vertex(matrix, xc6, yc5, 0); - bufferBuilder.vertex(matrix, xc4, yc2, 0); - bufferBuilder.vertex(matrix, xc3, yc1, 0); - bufferBuilder.vertex(matrix, xc7, yc6, 0); - bufferBuilder.vertex(matrix, xc3, yc3, 0); - bufferBuilder.vertex(matrix, xc4, yc4, 0); - bufferBuilder.vertex(matrix, xc6, yc7, 0); - bufferBuilder.vertex(matrix, xc2, yc4, 0); - bufferBuilder.vertex(matrix, xc1, yc3, 0); - bufferBuilder.vertex(matrix, xc5, yc6, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + int outlineColor = RenderUtils.toIntColor(acColor, 0.5F); + RenderUtils.drawBorder2D(context, x1, y1, x2, y2, outlineColor); } public float[] getBgColor() diff --git a/src/main/java/net/wurstclient/clickgui/ClickGuiIcons.java b/src/main/java/net/wurstclient/clickgui/ClickGuiIcons.java new file mode 100644 index 0000000000..b853406d5b --- /dev/null +++ b/src/main/java/net/wurstclient/clickgui/ClickGuiIcons.java @@ -0,0 +1,209 @@ +/* + * Copyright (c) 2014-2025 Wurst-Imperium and contributors. + * + * This source code is subject to the terms of the GNU General Public + * License, version 3. If a copy of the GPL was not distributed with this + * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt + */ +package net.wurstclient.clickgui; + +import net.minecraft.client.gui.DrawContext; +import net.wurstclient.WurstClient; +import net.wurstclient.util.RenderUtils; + +public enum ClickGuiIcons +{ + ; + + public static void drawMinimizeArrow(DrawContext context, float x1, + float y1, float x2, float y2, boolean hovering, boolean minimized) + { + float xa1 = x1 + 1; + float xa2 = (x1 + x2) / 2; + float xa3 = x2 - 1; + float ya1; + float ya2; + + // arrow + int arrowColor; + float[][] arrowVertices; + if(minimized) + { + ya1 = y1 + 3; + ya2 = y2 - 2.5F; + arrowColor = hovering ? 0xFF00FF00 : 0xFF00D900; + arrowVertices = new float[][]{{xa1, ya1}, {xa2, ya2}, {xa3, ya1}}; + + }else + { + ya1 = y2 - 3; + ya2 = y1 + 2.5F; + arrowColor = hovering ? 0xFFFF0000 : 0xFFD90000; + arrowVertices = new float[][]{{xa1, ya1}, {xa3, ya1}, {xa2, ya2}}; + } + RenderUtils.fillTriangle2D(context, arrowVertices, arrowColor); + + // outline + int outlineColor = 0x80101010; + RenderUtils.drawLineStrip2D(context, arrowVertices, outlineColor); + } + + public static void drawRadarArrow(DrawContext context, float x1, float y1, + float x2, float y2) + { + float x3 = x1 + (x2 - x1) / 2; + float y3 = y1 + (y2 - y1) * 0.75F; + + // arrow + ClickGui gui = WurstClient.INSTANCE.getGui(); + int arrowColor = + RenderUtils.toIntColor(gui.getAcColor(), gui.getOpacity()); + float[][] arrowVertices = {{x3, y1}, {x1, y2}, {x3, y3}, {x2, y2}}; + RenderUtils.fillQuads2D(context, arrowVertices, arrowColor); + + // outline + int outlineColor = 0x80101010; + RenderUtils.drawLineStrip2D(context, arrowVertices, outlineColor); + } + + public static void drawPin(DrawContext context, float x1, float y1, + float x2, float y2, boolean hovering, boolean pinned) + { + int needleColor = hovering ? 0xFFFFFFFF : 0xFFD9D9D9; + int outlineColor = 0x80101010; + + if(pinned) + { + float xk1 = x1 + 2; + float xk2 = x2 - 2; + float xk3 = x1 + 1; + float xk4 = x2 - 1; + float yk1 = y1 + 2; + float yk2 = y2 - 2; + float yk3 = y2 - 0.5F; + + // knob + int knobColor = hovering ? 0xFFFF0000 : 0xFFD90000; + RenderUtils.fill2D(context, xk1, yk1, xk2, yk2, knobColor); + RenderUtils.fill2D(context, xk3, yk2, xk4, yk3, knobColor); + + float xn1 = x1 + 3.5F; + float xn2 = x2 - 3.5F; + float yn1 = y2 - 0.5F; + float yn2 = y2; + + // needle + RenderUtils.fill2D(context, xn1, yn1, xn2, yn2, needleColor); + + // outlines + RenderUtils.drawBorder2D(context, xk1, yk1, xk2, yk2, outlineColor); + RenderUtils.drawBorder2D(context, xk3, yk2, xk4, yk3, outlineColor); + RenderUtils.drawBorder2D(context, xn1, yn1, xn2, yn2, outlineColor); + + }else + { + float xk1 = x2 - 3.5F; + float xk2 = x2 - 0.5F; + float xk3 = x2 - 3; + float xk4 = x1 + 3; + float xk5 = x1 + 2; + float xk6 = x2 - 2; + float xk7 = x1 + 1; + float yk1 = y1 + 0.5F; + float yk2 = y1 + 3.5F; + float yk3 = y2 - 3; + float yk4 = y1 + 3; + float yk5 = y1 + 2; + float yk6 = y2 - 2; + float yk7 = y2 - 1; + + // knob + int knobColor = hovering ? 0xFF00FF00 : 0xFF00D900; + float[][] knobVertices = {{xk4, yk4}, {xk3, yk3}, {xk2, yk2}, + {xk1, yk1}, {xk5, yk5}, {xk7, yk4}, {xk3, yk7}, {xk6, yk6}}; + RenderUtils.fillQuads2D(context, knobVertices, knobColor); + + float xn1 = x1 + 3; + float xn2 = x1 + 4; + float xn3 = x1 + 1; + float yn1 = y2 - 4; + float yn2 = y2 - 3; + float yn3 = y2 - 1; + + // needle + float[][] needleVertices = {{xn3, yn3}, {xn2, yn2}, {xn1, yn1}}; + RenderUtils.fillTriangle2D(context, needleVertices, needleColor); + + // outlines + float[][] knobPart1 = new float[4][2]; + System.arraycopy(knobVertices, 0, knobPart1, 0, 4); + RenderUtils.drawLineStrip2D(context, knobPart1, outlineColor); + float[][] knobPart2 = new float[4][2]; + System.arraycopy(knobVertices, 4, knobPart2, 0, 4); + RenderUtils.drawLineStrip2D(context, knobPart2, outlineColor); + RenderUtils.drawLineStrip2D(context, needleVertices, outlineColor); + } + } + + public static void drawCheck(DrawContext context, float x1, float y1, + float x2, float y2, boolean hovering, boolean grayedOut) + { + float xc1 = x1 + 2.5F; + float xc2 = x1 + 3.5F; + float xc3 = (x1 + x2) / 2 - 1; + float xc4 = x2 - 3.5F; + float xc5 = x2 - 2.5F; + float yc1 = y1 + 2.5F; + float yc2 = y1 + 3.5F; + float yc3 = (y1 + y2) / 2; + float yc4 = yc3 + 1; + float yc5 = y2 - 4.5F; + float yc6 = y2 - 2.5F; + + // check + int checkColor = + grayedOut ? 0xC0808080 : hovering ? 0xFF00FF00 : 0xFF00D900; + float[][] checkVertices = {{xc2, yc3}, {xc1, yc4}, {xc3, yc6}, + {xc3, yc5}, {xc3, yc5}, {xc3, yc6}, {xc5, yc2}, {xc4, yc1}}; + RenderUtils.fillQuads2D(context, checkVertices, checkColor); + + // outline + int outlineColor = 0x80101010; + float[][] outlineVertices = {{xc2, yc3}, {xc3, yc5}, {xc4, yc1}, + {xc5, yc2}, {xc3, yc6}, {xc1, yc4}, {xc2, yc3}}; + RenderUtils.drawLineStrip2D(context, outlineVertices, outlineColor); + } + + public static void drawCross(DrawContext context, float x1, float y1, + float x2, float y2, boolean hovering) + { + float xc1 = x1 + 2; + float xc2 = x1 + 3; + float xc3 = x2 - 2; + float xc4 = x2 - 3; + float xc5 = x1 + 3.5F; + float xc6 = (x1 + x2) / 2; + float xc7 = x2 - 3.5F; + float yc1 = y1 + 3; + float yc2 = y1 + 2; + float yc3 = y2 - 3; + float yc4 = y2 - 2; + float yc5 = y1 + 3.5F; + float yc6 = (y1 + y2) / 2; + float yc7 = y2 - 3.5F; + + // cross + int crossColor = hovering ? 0xFFFF0000 : 0xFFD90000; + float[][] crossVertices = {{xc2, yc2}, {xc1, yc1}, {xc4, yc4}, + {xc3, yc3}, {xc3, yc1}, {xc4, yc2}, {xc6, yc5}, {xc7, yc6}, + {xc6, yc7}, {xc5, yc6}, {xc1, yc3}, {xc2, yc4}}; + RenderUtils.fillQuads2D(context, crossVertices, crossColor); + + // outline + int outlineColor = 0x80101010; + float[][] outlineVertices = {{xc1, yc1}, {xc2, yc2}, {xc6, yc5}, + {xc4, yc2}, {xc3, yc1}, {xc7, yc6}, {xc3, yc3}, {xc4, yc4}, + {xc6, yc7}, {xc2, yc4}, {xc1, yc3}, {xc5, yc6}}; + RenderUtils.drawLineStrip2D(context, outlineVertices, outlineColor); + } +} diff --git a/src/main/java/net/wurstclient/clickgui/ComboBoxPopup.java b/src/main/java/net/wurstclient/clickgui/ComboBoxPopup.java index fc02bbe789..4b847ee9b6 100644 --- a/src/main/java/net/wurstclient/clickgui/ComboBoxPopup.java +++ b/src/main/java/net/wurstclient/clickgui/ComboBoxPopup.java @@ -7,28 +7,18 @@ */ package net.wurstclient.clickgui; -import org.joml.Matrix4f; -import org.lwjgl.opengl.GL11; - -import com.mojang.blaze3d.systems.RenderSystem; +import org.lwjgl.glfw.GLFW; import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gl.ShaderProgramKeys; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.render.BufferBuilder; -import net.minecraft.client.render.BufferRenderer; -import net.minecraft.client.render.Tessellator; -import net.minecraft.client.render.VertexFormat; -import net.minecraft.client.render.VertexFormats; -import net.minecraft.client.util.math.MatrixStack; import net.wurstclient.WurstClient; import net.wurstclient.settings.EnumSetting; import net.wurstclient.util.RenderUtils; public final class ComboBoxPopup> extends Popup { - private final ClickGui gui = WurstClient.INSTANCE.getGui(); - private final TextRenderer tr = WurstClient.MC.textRenderer; + private static final ClickGui GUI = WurstClient.INSTANCE.getGui(); + private static final TextRenderer TR = WurstClient.MC.textRenderer; private final EnumSetting setting; private final int popupWidth; @@ -50,7 +40,7 @@ public ComboBoxPopup(Component owner, EnumSetting setting, @Override public void handleMouseClick(int mouseX, int mouseY, int mouseButton) { - if(mouseButton != 0) + if(mouseButton != GLFW.GLFW_MOUSE_BUTTON_LEFT) return; int yi1 = getY() - 11; @@ -74,7 +64,6 @@ public void handleMouseClick(int mouseX, int mouseY, int mouseButton) @Override public void render(DrawContext context, int mouseX, int mouseY) { - MatrixStack matrixStack = context.getMatrices(); int x1 = getX(); int x2 = x1 + getWidth(); int y1 = getY(); @@ -83,9 +72,10 @@ public void render(DrawContext context, int mouseX, int mouseY) boolean hovering = isHovering(mouseX, mouseY, x1, x2, y1, y2); if(hovering) - gui.setTooltip(""); + GUI.setTooltip(""); - drawOutline(matrixStack, x1, x2, y1, y2); + RenderUtils.drawBorder2D(context, x1, y1, x2, y2, + RenderUtils.toIntColor(GUI.getAcColor(), 0.5F)); int yi1 = y1 - 11; for(T value : setting.getValues()) @@ -93,15 +83,15 @@ public void render(DrawContext context, int mouseX, int mouseY) if(value == setting.getSelected()) continue; - RenderSystem.setShader(ShaderProgramKeys.POSITION); - yi1 += 11; int yi2 = yi1 + 11; boolean hValue = hovering && mouseY >= yi1 && mouseY < yi2; - drawValueBackground(matrixStack, x1, x2, yi1, yi2, hValue); + context.fill(x1, yi1, x2, yi2, RenderUtils.toIntColor( + GUI.getBgColor(), GUI.getOpacity() * (hValue ? 1.5F : 1))); - drawValueName(context, x1, yi1, value); + context.drawText(TR, value.toString(), x1 + 2, yi1 + 2, + GUI.getTxtColor(), false); } } @@ -111,57 +101,6 @@ private boolean isHovering(int mouseX, int mouseY, int x1, int x2, int y1, return mouseX >= x1 && mouseY >= y1 && mouseX < x2 && mouseY < y2; } - private void drawOutline(MatrixStack matrixStack, int x1, int x2, int y1, - int y2) - { - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - - float[] acColor = gui.getAcColor(); - RenderUtils.setShaderColor(acColor, 0.5F); - - BufferBuilder bufferBuilder = tessellator.begin( - VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x1, y1, 0); - bufferBuilder.vertex(matrix, x1, y2, 0); - bufferBuilder.vertex(matrix, x2, y2, 0); - bufferBuilder.vertex(matrix, x2, y1, 0); - bufferBuilder.vertex(matrix, x1, y1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - } - - private void drawValueBackground(MatrixStack matrixStack, int x1, int x2, - int yi1, int yi2, boolean hValue) - { - float[] bgColor = gui.getBgColor(); - float alpha = gui.getOpacity() * (hValue ? 1.5F : 1); - - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - - RenderUtils.setShaderColor(bgColor, alpha); - - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x1, yi1, 0); - bufferBuilder.vertex(matrix, x1, yi2, 0); - bufferBuilder.vertex(matrix, x2, yi2, 0); - bufferBuilder.vertex(matrix, x2, yi1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - } - - private void drawValueName(DrawContext context, int x1, int yi1, - Enum value) - { - ClickGui gui = WurstClient.INSTANCE.getGui(); - int txtColor = gui.getTxtColor(); - - RenderSystem.setShaderColor(1, 1, 1, 1); - context.drawText(tr, value.toString(), x1 + 2, yi1 + 2, txtColor, - false); - GL11.glEnable(GL11.GL_BLEND); - } - @Override public int getDefaultWidth() { diff --git a/src/main/java/net/wurstclient/clickgui/Component.java b/src/main/java/net/wurstclient/clickgui/Component.java index 89f42f138b..16eacb1c72 100644 --- a/src/main/java/net/wurstclient/clickgui/Component.java +++ b/src/main/java/net/wurstclient/clickgui/Component.java @@ -7,10 +7,15 @@ */ package net.wurstclient.clickgui; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; +import net.wurstclient.WurstClient; public abstract class Component { + protected static final MinecraftClient MC = WurstClient.MC; + protected static final WurstClient WURST = WurstClient.INSTANCE; + private int x; private int y; private int width; @@ -97,4 +102,19 @@ private void invalidateParent() if(parent != null) parent.invalidate(); } + + protected boolean isHovering(int mouseX, int mouseY) + { + int x1 = getX(); + int x2 = x1 + getWidth(); + int y1 = getY(); + int y2 = y1 + getHeight(); + + Window parent = getParent(); + boolean scrollEnabled = parent.isScrollingEnabled(); + int scroll = scrollEnabled ? parent.getScrollOffset() : 0; + + return mouseX >= x1 && mouseY >= y1 && mouseX < x2 && mouseY < y2 + && mouseY >= -scroll && mouseY < parent.getHeight() - 13 - scroll; + } } diff --git a/src/main/java/net/wurstclient/clickgui/Window.java b/src/main/java/net/wurstclient/clickgui/Window.java index 5f761435d1..9d20734aed 100644 --- a/src/main/java/net/wurstclient/clickgui/Window.java +++ b/src/main/java/net/wurstclient/clickgui/Window.java @@ -10,6 +10,7 @@ import java.util.ArrayList; import net.minecraft.client.font.TextRenderer; +import net.minecraft.util.math.MathHelper; import net.wurstclient.WurstClient; public class Window @@ -67,16 +68,8 @@ public final void setTitle(String title) */ public final int getX() { - // prevent window from going off the right side of the screen - net.minecraft.client.util.Window mcWindow = WurstClient.MC.getWindow(); - if(x > mcWindow.getScaledWidth() - 1) - return mcWindow.getScaledWidth() - 1; - - // prevent window from going off the left side of the screen - if(x <= -width) - return -width + 1; - - return x; + int scaledWidth = WurstClient.MC.getWindow().getScaledWidth(); + return MathHelper.clamp(x, -width + 1, scaledWidth - 1); } /** @@ -99,16 +92,8 @@ public final void setX(int x) */ public final int getY() { - // prevent window from going off the bottom of the screen - net.minecraft.client.util.Window mcWindow = WurstClient.MC.getWindow(); - if(y > mcWindow.getScaledHeight() - 1) - return mcWindow.getScaledHeight() - 1; - - // prevent window from going off the top of the screen - if(y <= -12) - return -12; - - return y; + int scaledHeight = WurstClient.MC.getWindow().getScaledHeight(); + return MathHelper.clamp(y, -12, scaledHeight - 1); } /** diff --git a/src/main/java/net/wurstclient/clickgui/components/AbstractListEditButton.java b/src/main/java/net/wurstclient/clickgui/components/AbstractListEditButton.java index 5a493fe09e..71107e0968 100644 --- a/src/main/java/net/wurstclient/clickgui/components/AbstractListEditButton.java +++ b/src/main/java/net/wurstclient/clickgui/components/AbstractListEditButton.java @@ -7,22 +7,10 @@ */ package net.wurstclient.clickgui.components; -import org.joml.Matrix4f; -import org.lwjgl.opengl.GL11; +import org.lwjgl.glfw.GLFW; -import com.mojang.blaze3d.systems.RenderSystem; - -import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gl.ShaderProgramKeys; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.render.BufferBuilder; -import net.minecraft.client.render.BufferRenderer; -import net.minecraft.client.render.Tessellator; -import net.minecraft.client.render.VertexFormat; -import net.minecraft.client.render.VertexFormats; -import net.minecraft.client.util.math.MatrixStack; -import net.wurstclient.WurstClient; import net.wurstclient.clickgui.ClickGui; import net.wurstclient.clickgui.Component; import net.wurstclient.settings.Setting; @@ -30,15 +18,11 @@ public abstract class AbstractListEditButton extends Component { - protected static final MinecraftClient MC = WurstClient.MC; + private static final ClickGui GUI = WURST.getGui(); + private static final TextRenderer TR = MC.textRenderer; private final String buttonText = "Edit..."; - private final int buttonWidth; - - public AbstractListEditButton() - { - buttonWidth = MC.textRenderer.getWidth(buttonText); - } + private final int buttonWidth = TR.getWidth(buttonText); protected abstract void openScreen(); @@ -49,7 +33,7 @@ public AbstractListEditButton() @Override public void handleMouseClick(double mouseX, double mouseY, int mouseButton) { - if(mouseButton != 0) + if(mouseButton != GLFW.GLFW_MOUSE_BUTTON_LEFT) return; if(mouseX < getX() + getWidth() - buttonWidth - 4) @@ -62,77 +46,43 @@ public void handleMouseClick(double mouseX, double mouseY, int mouseButton) public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) { - ClickGui gui = WurstClient.INSTANCE.getGui(); - float[] bgColor = gui.getBgColor(); - float[] acColor = gui.getAcColor(); - int txtColor = gui.getTxtColor(); - float opacity = gui.getOpacity(); - int x1 = getX(); int x2 = x1 + getWidth(); int x3 = x2 - buttonWidth - 4; int y1 = getY(); int y2 = y1 + getHeight(); - int scroll = getParent().isScrollingEnabled() - ? getParent().getScrollOffset() : 0; - boolean hovering = mouseX >= x1 && mouseY >= y1 && mouseX < x2 - && mouseY < y2 && mouseY >= -scroll - && mouseY < getParent().getHeight() - 13 - scroll; + boolean hovering = isHovering(mouseX, mouseY); boolean hText = hovering && mouseX < x3; boolean hBox = hovering && mouseX >= x3; - MatrixStack matrixStack = context.getMatrices(); - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - RenderSystem.setShader(ShaderProgramKeys.POSITION); - - // tooltip if(hText) - gui.setTooltip(getSetting().getWrappedDescription(200)); + GUI.setTooltip(getSetting().getWrappedDescription(200)); // background - RenderUtils.setShaderColor(bgColor, opacity); - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x1, y1, 0); - bufferBuilder.vertex(matrix, x1, y2, 0); - bufferBuilder.vertex(matrix, x3, y2, 0); - bufferBuilder.vertex(matrix, x3, y1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + context.fill(x1, y1, x3, y2, getFillColor(false)); - // box - RenderUtils.setShaderColor(bgColor, hBox ? opacity * 1.5F : opacity); - bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, - VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x3, y1, 0); - bufferBuilder.vertex(matrix, x3, y2, 0); - bufferBuilder.vertex(matrix, x2, y2, 0); - bufferBuilder.vertex(matrix, x2, y1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - RenderUtils.setShaderColor(acColor, 0.5F); - bufferBuilder = tessellator.begin( - VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x3, y1, 0); - bufferBuilder.vertex(matrix, x3, y2, 0); - bufferBuilder.vertex(matrix, x2, y2, 0); - bufferBuilder.vertex(matrix, x2, y1, 0); - bufferBuilder.vertex(matrix, x3, y1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + // button + context.fill(x3, y1, x2, y2, getFillColor(hBox)); + int outlineColor = RenderUtils.toIntColor(GUI.getAcColor(), 0.5F); + RenderUtils.drawBorder2D(context, x3, y1, x2, y2, outlineColor); - // setting name - RenderSystem.setShaderColor(1, 1, 1, 1); - TextRenderer tr = MC.textRenderer; - context.drawText(tr, getText(), x1, y1 + 2, txtColor, false); - context.drawText(tr, buttonText, x3 + 2, y1 + 2, txtColor, false); - GL11.glEnable(GL11.GL_BLEND); + // text + int txtColor = GUI.getTxtColor(); + context.drawText(TR, getText(), x1, y1 + 2, txtColor, false); + context.drawText(TR, buttonText, x3 + 2, y1 + 2, txtColor, false); + } + + private int getFillColor(boolean hovering) + { + float opacity = GUI.getOpacity() * (hovering ? 1.5F : 1); + return RenderUtils.toIntColor(GUI.getBgColor(), opacity); } @Override public int getDefaultWidth() { - TextRenderer fr = MC.textRenderer; - return fr.getWidth(getText()) + buttonWidth + 6; + return TR.getWidth(getText()) + buttonWidth + 6; } @Override diff --git a/src/main/java/net/wurstclient/clickgui/components/BlockComponent.java b/src/main/java/net/wurstclient/clickgui/components/BlockComponent.java index 02aba042a1..6216db6f91 100644 --- a/src/main/java/net/wurstclient/clickgui/components/BlockComponent.java +++ b/src/main/java/net/wurstclient/clickgui/components/BlockComponent.java @@ -7,39 +7,31 @@ */ package net.wurstclient.clickgui.components; -import org.joml.Matrix4f; -import org.lwjgl.opengl.GL11; - -import com.mojang.blaze3d.systems.RenderSystem; +import org.lwjgl.glfw.GLFW; import net.minecraft.block.Block; +import net.minecraft.block.BlockState; import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gl.ShaderProgramKeys; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.render.BufferBuilder; -import net.minecraft.client.render.BufferRenderer; -import net.minecraft.client.render.Tessellator; -import net.minecraft.client.render.VertexFormat; -import net.minecraft.client.render.VertexFormats; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.ItemStack; -import net.wurstclient.WurstClient; import net.wurstclient.clickgui.ClickGui; import net.wurstclient.clickgui.Component; +import net.wurstclient.clickgui.Window; import net.wurstclient.clickgui.screens.EditBlockScreen; import net.wurstclient.settings.BlockSetting; import net.wurstclient.util.RenderUtils; public final class BlockComponent extends Component { + private static final ClickGui GUI = WURST.getGui(); + private static final TextRenderer TR = MC.textRenderer; private static final int BLOCK_WITDH = 24; + private final BlockSetting setting; public BlockComponent(BlockSetting setting) { this.setting = setting; - setWidth(getDefaultWidth()); setHeight(getDefaultHeight()); } @@ -50,88 +42,89 @@ public void handleMouseClick(double mouseX, double mouseY, int mouseButton) if(mouseX < getX() + getWidth() - BLOCK_WITDH) return; - if(mouseButton == 0) + switch(mouseButton) { - Screen currentScreen = WurstClient.MC.currentScreen; - EditBlockScreen editScreen = - new EditBlockScreen(currentScreen, setting); - WurstClient.MC.setScreen(editScreen); + case GLFW.GLFW_MOUSE_BUTTON_LEFT: + MC.setScreen(new EditBlockScreen(MC.currentScreen, setting)); + break; - }else if(mouseButton == 1) + case GLFW.GLFW_MOUSE_BUTTON_RIGHT: setting.resetToDefault(); + break; + } } @Override public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) { - ClickGui gui = WurstClient.INSTANCE.getGui(); - float[] bgColor = gui.getBgColor(); - int txtColor = gui.getTxtColor(); - float opacity = gui.getOpacity(); - int x1 = getX(); int x2 = x1 + getWidth(); int x3 = x2 - BLOCK_WITDH; int y1 = getY(); int y2 = y1 + getHeight(); - int scroll = getParent().isScrollingEnabled() - ? getParent().getScrollOffset() : 0; - boolean hovering = mouseX >= x1 && mouseY >= y1 && mouseX < x2 - && mouseY < y2 && mouseY >= -scroll - && mouseY < getParent().getHeight() - 13 - scroll; + boolean hovering = isHovering(mouseX, mouseY, x1, y1, x2, y2); boolean hText = hovering && mouseX < x3; boolean hBlock = hovering && mouseX >= x3; - ItemStack stack = new ItemStack(setting.getBlock()); - - MatrixStack matrixStack = context.getMatrices(); - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - RenderSystem.setShader(ShaderProgramKeys.POSITION); - // tooltip if(hText) - gui.setTooltip(setting.getWrappedDescription(200)); + GUI.setTooltip(setting.getWrappedDescription(200)); else if(hBlock) - { - String tooltip = "\u00a76Name:\u00a7r " + getBlockName(stack); - tooltip += "\n\u00a76ID:\u00a7r " + setting.getBlockName(); - tooltip += "\n\u00a76Block #:\u00a7r " - + Block.getRawIdFromState(setting.getBlock().getDefaultState()); - tooltip += "\n\n\u00a7e[left-click]\u00a7r to edit"; - tooltip += "\n\u00a7e[right-click]\u00a7r to reset"; - gui.setTooltip(tooltip); - } + GUI.setTooltip(getBlockTooltip()); // background - RenderUtils.setShaderColor(bgColor, opacity); - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x1, y1, 0); - bufferBuilder.vertex(matrix, x1, y2, 0); - bufferBuilder.vertex(matrix, x2, y2, 0); - bufferBuilder.vertex(matrix, x2, y1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + int bgColor = + RenderUtils.toIntColor(GUI.getBgColor(), GUI.getOpacity()); + context.fill(x1, y1, x2, y2, bgColor); - // setting name - RenderSystem.setShaderColor(1, 1, 1, 1); - TextRenderer tr = WurstClient.MC.textRenderer; - String text = setting.getName() + ":"; - context.drawText(tr, text, x1, y1 + 2, txtColor, false); + // text + String name = setting.getName() + ":"; + context.drawText(TR, name, x1, y1 + 2, GUI.getTxtColor(), false); + // block + ItemStack stack = new ItemStack(setting.getBlock()); RenderUtils.drawItem(context, stack, x3, y1, true); + } + + private boolean isHovering(int mouseX, int mouseY, int x1, int y1, int x2, + int y2) + { + Window parent = getParent(); + boolean scrollEnabled = parent.isScrollingEnabled(); + int scroll = scrollEnabled ? parent.getScrollOffset() : 0; + + return mouseX >= x1 && mouseY >= y1 && mouseX < x2 && mouseY < y2 + && mouseY >= -scroll && mouseY < parent.getHeight() - 13 - scroll; + } + + private String getBlockTooltip() + { + Block block = setting.getBlock(); + BlockState state = block.getDefaultState(); + ItemStack stack = new ItemStack(block); + + String translatedName = stack.isEmpty() ? "\u00a7ounknown block\u00a7r" + : stack.getName().getString(); + String tooltip = "\u00a76Name:\u00a7r " + translatedName; - GL11.glEnable(GL11.GL_BLEND); + String blockId = setting.getBlockName(); + tooltip += "\n\u00a76ID:\u00a7r " + blockId; + + int blockNumber = Block.getRawIdFromState(state); + tooltip += "\n\u00a76Block #:\u00a7r " + blockNumber; + + tooltip += "\n\n\u00a7e[left-click]\u00a7r to edit"; + tooltip += "\n\u00a7e[right-click]\u00a7r to reset"; + + return tooltip; } @Override public int getDefaultWidth() { - TextRenderer tr = WurstClient.MC.textRenderer; - String text = setting.getName() + ":"; - return tr.getWidth(text) + BLOCK_WITDH + 4; + return TR.getWidth(setting.getName() + ":") + BLOCK_WITDH + 4; } @Override @@ -139,11 +132,4 @@ public int getDefaultHeight() { return BLOCK_WITDH; } - - private String getBlockName(ItemStack stack) - { - if(stack.isEmpty()) - return "\u00a7ounknown block\u00a7r"; - return stack.getName().getString(); - } } diff --git a/src/main/java/net/wurstclient/clickgui/components/CheckboxComponent.java b/src/main/java/net/wurstclient/clickgui/components/CheckboxComponent.java index 6d0554e81a..056333df2b 100644 --- a/src/main/java/net/wurstclient/clickgui/components/CheckboxComponent.java +++ b/src/main/java/net/wurstclient/clickgui/components/CheckboxComponent.java @@ -7,31 +7,21 @@ */ package net.wurstclient.clickgui.components; -import org.joml.Matrix4f; -import org.lwjgl.opengl.GL11; +import org.lwjgl.glfw.GLFW; -import com.mojang.blaze3d.systems.RenderSystem; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gl.ShaderProgramKeys; +import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.render.BufferBuilder; -import net.minecraft.client.render.BufferRenderer; -import net.minecraft.client.render.Tessellator; -import net.minecraft.client.render.VertexFormat; -import net.minecraft.client.render.VertexFormats; -import net.minecraft.client.util.math.MatrixStack; -import net.wurstclient.WurstClient; import net.wurstclient.clickgui.ClickGui; +import net.wurstclient.clickgui.ClickGuiIcons; import net.wurstclient.clickgui.Component; -import net.wurstclient.clickgui.Window; import net.wurstclient.settings.CheckboxSetting; import net.wurstclient.util.RenderUtils; public final class CheckboxComponent extends Component { - private final MinecraftClient MC = WurstClient.MC; - private final ClickGui GUI = WurstClient.INSTANCE.getGui(); + private static final ClickGui GUI = WURST.getGui(); + private static final TextRenderer TR = MC.textRenderer; + private static final int BOX_SIZE = 11; private final CheckboxSetting setting; @@ -47,11 +37,11 @@ public void handleMouseClick(double mouseX, double mouseY, int mouseButton) { switch(mouseButton) { - case 0: + case GLFW.GLFW_MOUSE_BUTTON_LEFT: setting.setChecked(!setting.isChecked()); break; - case 1: + case GLFW.GLFW_MOUSE_BUTTON_RIGHT: setting.setChecked(setting.isCheckedByDefault()); break; } @@ -61,178 +51,66 @@ public void handleMouseClick(double mouseX, double mouseY, int mouseButton) public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) { - MatrixStack matrixStack = context.getMatrices(); int x1 = getX(); int x2 = x1 + getWidth(); - int x3 = x1 + 11; + int x3 = x1 + BOX_SIZE; int y1 = getY(); int y2 = y1 + getHeight(); - boolean hovering = isHovering(mouseX, mouseY, x1, x2, y1, y2); - - RenderSystem.setShader(ShaderProgramKeys.POSITION); + boolean hovering = isHovering(mouseX, mouseY); + boolean hText = hovering && mouseX >= x3; - if(hovering && mouseX >= x3) - setTooltip(); + if(hText) + GUI.setTooltip(getTooltip()); if(setting.isLocked()) hovering = false; - drawBackground(matrixStack, x2, x3, y1, y2); - drawBox(matrixStack, x1, x3, y1, y2, hovering); + // background + context.fill(x3, y1, x2, y2, getFillColor(false)); + + // box + context.fill(x1, y1, x3, y2, getFillColor(hovering)); + int outlineColor = RenderUtils.toIntColor(GUI.getAcColor(), 0.5F); + RenderUtils.drawBorder2D(context, x1, y1, x3, y2, outlineColor); + // check if(setting.isChecked()) - drawCheck(matrixStack, x1, y1, hovering); + ClickGuiIcons.drawCheck(context, x1, y1, x3, y2, hovering, + setting.isLocked()); - drawName(context, x3, y1); + // text + String name = setting.getName(); + context.drawText(TR, name, x3 + 2, y1 + 2, GUI.getTxtColor(), false); } - private boolean isHovering(int mouseX, int mouseY, int x1, int x2, int y1, - int y2) + private int getFillColor(boolean hovering) { - Window parent = getParent(); - boolean scrollEnabled = parent.isScrollingEnabled(); - int scroll = scrollEnabled ? parent.getScrollOffset() : 0; - - return mouseX >= x1 && mouseY >= y1 && mouseX < x2 && mouseY < y2 - && mouseY >= -scroll && mouseY < parent.getHeight() - 13 - scroll; + float opacity = GUI.getOpacity() * (hovering ? 1.5F : 1); + return RenderUtils.toIntColor(GUI.getBgColor(), opacity); } - private void setTooltip() + private String getTooltip() { String tooltip = setting.getWrappedDescription(200); - if(setting.isLocked()) { tooltip += "\n\nThis checkbox is locked to "; tooltip += setting.isChecked() + "."; } - GUI.setTooltip(tooltip); - } - - private void drawBackground(MatrixStack matrixStack, int x2, int x3, int y1, - int y2) - { - float[] bgColor = GUI.getBgColor(); - float opacity = GUI.getOpacity(); - - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - - RenderUtils.setShaderColor(bgColor, opacity); - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x3, y1, 0); - bufferBuilder.vertex(matrix, x3, y2, 0); - bufferBuilder.vertex(matrix, x2, y2, 0); - bufferBuilder.vertex(matrix, x2, y1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - } - - private void drawBox(MatrixStack matrixStack, int x1, int x3, int y1, - int y2, boolean hovering) - { - float[] bgColor = GUI.getBgColor(); - float[] acColor = GUI.getAcColor(); - float opacity = GUI.getOpacity(); - - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - - RenderUtils.setShaderColor(bgColor, - hovering ? opacity * 1.5F : opacity); - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x1, y1, 0); - bufferBuilder.vertex(matrix, x1, y2, 0); - bufferBuilder.vertex(matrix, x3, y2, 0); - bufferBuilder.vertex(matrix, x3, y1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - - RenderUtils.setShaderColor(acColor, 0.5F); - bufferBuilder = tessellator.begin( - VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x1, y1, 0); - bufferBuilder.vertex(matrix, x1, y2, 0); - bufferBuilder.vertex(matrix, x3, y2, 0); - bufferBuilder.vertex(matrix, x3, y1, 0); - bufferBuilder.vertex(matrix, x1, y1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - } - - private void drawCheck(MatrixStack matrixStack, int x1, int y1, - boolean hovering) - { - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - - float xc1 = x1 + 2.5F; - float xc2 = x1 + 3.5F; - float xc3 = x1 + 4.5F; - float xc4 = x1 + 7.5F; - float xc5 = x1 + 8.5F; - float yc1 = y1 + 2.5F; - float yc2 = y1 + 3.5F; - float yc3 = y1 + 5.5F; - float yc4 = y1 + 6.5F; - float yc5 = y1 + 8.5F; - - // check - if(setting.isLocked()) - RenderSystem.setShaderColor(0.5F, 0.5F, 0.5F, 0.75F); - else - RenderSystem.setShaderColor(0, hovering ? 1 : 0.85F, 0, 1); - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xc2, yc3, 0); - bufferBuilder.vertex(matrix, xc3, yc4, 0); - bufferBuilder.vertex(matrix, xc3, yc5, 0); - bufferBuilder.vertex(matrix, xc1, yc4, 0); - bufferBuilder.vertex(matrix, xc4, yc1, 0); - bufferBuilder.vertex(matrix, xc5, yc2, 0); - bufferBuilder.vertex(matrix, xc3, yc5, 0); - bufferBuilder.vertex(matrix, xc3, yc4, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - - // outline - RenderSystem.setShaderColor(0.0625F, 0.0625F, 0.0625F, 0.5F); - bufferBuilder = tessellator.begin( - VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xc2, yc3, 0); - bufferBuilder.vertex(matrix, xc3, yc4, 0); - bufferBuilder.vertex(matrix, xc4, yc1, 0); - bufferBuilder.vertex(matrix, xc5, yc2, 0); - bufferBuilder.vertex(matrix, xc3, yc5, 0); - bufferBuilder.vertex(matrix, xc1, yc4, 0); - bufferBuilder.vertex(matrix, xc2, yc3, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - } - - private void drawName(DrawContext context, int x3, int y1) - { - ClickGui gui = WurstClient.INSTANCE.getGui(); - int txtColor = gui.getTxtColor(); - - RenderSystem.setShaderColor(1, 1, 1, 1); - - String name = setting.getName(); - int tx = x3 + 2; - int ty = y1 + 2; - context.drawText(MC.textRenderer, name, tx, ty, txtColor, false); - - GL11.glEnable(GL11.GL_BLEND); + return tooltip; } @Override public int getDefaultWidth() { - return MC.textRenderer.getWidth(setting.getName()) + 13; + return BOX_SIZE + TR.getWidth(setting.getName()) + 2; } @Override public int getDefaultHeight() { - return 11; + return BOX_SIZE; } } diff --git a/src/main/java/net/wurstclient/clickgui/components/ColorComponent.java b/src/main/java/net/wurstclient/clickgui/components/ColorComponent.java index 964079dffd..93d87a3dd4 100644 --- a/src/main/java/net/wurstclient/clickgui/components/ColorComponent.java +++ b/src/main/java/net/wurstclient/clickgui/components/ColorComponent.java @@ -7,25 +7,12 @@ */ package net.wurstclient.clickgui.components; -import org.joml.Matrix4f; -import org.lwjgl.opengl.GL11; +import org.lwjgl.glfw.GLFW; -import com.mojang.blaze3d.systems.RenderSystem; - -import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gl.ShaderProgramKeys; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.render.BufferBuilder; -import net.minecraft.client.render.BufferRenderer; -import net.minecraft.client.render.Tessellator; -import net.minecraft.client.render.VertexFormat; -import net.minecraft.client.render.VertexFormats; -import net.minecraft.client.util.math.MatrixStack; -import net.wurstclient.WurstClient; import net.wurstclient.clickgui.ClickGui; import net.wurstclient.clickgui.Component; -import net.wurstclient.clickgui.Window; import net.wurstclient.clickgui.screens.EditColorScreen; import net.wurstclient.settings.ColorSetting; import net.wurstclient.util.ColorUtils; @@ -33,8 +20,9 @@ public final class ColorComponent extends Component { - private final MinecraftClient MC = WurstClient.MC; - private final ClickGui GUI = WurstClient.INSTANCE.getGui(); + private static final ClickGui GUI = WURST.getGui(); + private static final TextRenderer TR = MC.textRenderer; + private static final int TEXT_HEIGHT = 11; private final ColorSetting setting; @@ -48,139 +36,79 @@ public ColorComponent(ColorSetting setting) @Override public void handleMouseClick(double mouseX, double mouseY, int mouseButton) { - if(mouseY < getY() + 11) + if(mouseY < getY() + TEXT_HEIGHT) return; - if(mouseButton == 0) + switch(mouseButton) + { + case GLFW.GLFW_MOUSE_BUTTON_LEFT: MC.setScreen(new EditColorScreen(MC.currentScreen, setting)); - else if(mouseButton == 1) + break; + + case GLFW.GLFW_MOUSE_BUTTON_RIGHT: setting.setColor(setting.getDefaultColor()); + break; + } } @Override public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) { - MatrixStack matrixStack = context.getMatrices(); int x1 = getX(); int x2 = x1 + getWidth(); int y1 = getY(); int y2 = y1 + getHeight(); - int y3 = y1 + 11; - - boolean hovering = isHovering(mouseX, mouseY, x1, x2, y1, y2); - - RenderSystem.setShader(ShaderProgramKeys.POSITION); - - if(hovering) - if(mouseY < y3) - GUI.setTooltip(setting.getWrappedDescription(200)); - else - { - String tooltip = "\u00a7cR:\u00a7r" + setting.getRed(); - tooltip += " \u00a7aG:\u00a7r" + setting.getGreen(); - tooltip += " \u00a79B:\u00a7r" + setting.getBlue(); - tooltip += "\n\n\u00a7e[left-click]\u00a7r to edit"; - tooltip += "\n\u00a7e[right-click]\u00a7r to reset"; - GUI.setTooltip(tooltip); - } + int y3 = y1 + TEXT_HEIGHT; - drawBackground(matrixStack, x1, x2, y1, y3); - drawBox(matrixStack, x1, x2, y2, y3, hovering && mouseY >= y3); + boolean hovering = isHovering(mouseX, mouseY); + boolean hText = hovering && mouseY < y3; + boolean hColor = hovering && mouseY >= y3; - drawNameAndValue(context, x1, x2, y1 + 2); - } - - private boolean isHovering(int mouseX, int mouseY, int x1, int x2, int y1, - int y2) - { - Window parent = getParent(); - boolean scrollEnabled = parent.isScrollingEnabled(); - int scroll = scrollEnabled ? parent.getScrollOffset() : 0; + if(hText) + GUI.setTooltip(setting.getWrappedDescription(200)); + else if(hColor) + GUI.setTooltip(getColorTooltip()); - return mouseX >= x1 && mouseY >= y1 && mouseX < x2 && mouseY < y2 - && mouseY >= -scroll && mouseY < parent.getHeight() - 13 - scroll; - } - - private void drawBackground(MatrixStack matrixStack, int x1, int x2, int y1, - int y2) - { - float[] bgColor = GUI.getBgColor(); + // background float opacity = GUI.getOpacity(); + int bgColor = RenderUtils.toIntColor(GUI.getBgColor(), opacity); + context.fill(x1, y1, x2, y3, bgColor); - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - - RenderUtils.setShaderColor(bgColor, opacity); + // box + context.fill(x1, y3, x2, y2, + setting.getColorI(hovering ? 1F : opacity)); + int outlineColor = RenderUtils.toIntColor(GUI.getAcColor(), 0.5F); + RenderUtils.drawBorder2D(context, x1, y3, x2, y2, outlineColor); - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x2, y1, 0); - bufferBuilder.vertex(matrix, x2, y2, 0); - bufferBuilder.vertex(matrix, x1, y2, 0); - bufferBuilder.vertex(matrix, x1, y1, 0); - - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - } - - private void drawBox(MatrixStack matrixStack, int x1, int x2, int y2, - int y3, boolean hovering) - { - float[] color = setting.getColorF(); - float[] acColor = GUI.getAcColor(); - float opacity = GUI.getOpacity(); - - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - - RenderUtils.setShaderColor(color, hovering ? 1F : opacity); - - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x1, y2, 0); - bufferBuilder.vertex(matrix, x1, y3, 0); - bufferBuilder.vertex(matrix, x2, y3, 0); - bufferBuilder.vertex(matrix, x2, y2, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - - RenderUtils.setShaderColor(acColor, 0.5F); - - bufferBuilder = tessellator.begin( - VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x1, y2, 0); - bufferBuilder.vertex(matrix, x1, y3, 0); - bufferBuilder.vertex(matrix, x2, y3, 0); - bufferBuilder.vertex(matrix, x2, y2, 0); - bufferBuilder.vertex(matrix, x1, y2, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + // text + String name = setting.getName(); + String value = ColorUtils.toHex(setting.getColor()); + int valueWidth = TR.getWidth(value); + int txtColor = GUI.getTxtColor(); + context.drawText(TR, name, x1, y1 + 2, txtColor, false); + context.drawText(TR, value, x2 - valueWidth, y1 + 2, txtColor, false); } - private void drawNameAndValue(DrawContext context, int x1, int x2, int y1) + private String getColorTooltip() { - ClickGui gui = WurstClient.INSTANCE.getGui(); - int txtColor = gui.getTxtColor(); - - RenderSystem.setShaderColor(1, 1, 1, 1); - TextRenderer tr = MC.textRenderer; - - context.drawText(tr, setting.getName(), x1, y1, txtColor, false); - - String value = ColorUtils.toHex(setting.getColor()); - int valueWidth = tr.getWidth(value); - context.drawText(tr, value, x2 - valueWidth, y1, txtColor, false); - - GL11.glEnable(GL11.GL_BLEND); + String tooltip = "\u00a7cR:\u00a7r" + setting.getRed(); + tooltip += " \u00a7aG:\u00a7r" + setting.getGreen(); + tooltip += " \u00a79B:\u00a7r" + setting.getBlue(); + tooltip += "\n\n\u00a7e[left-click]\u00a7r to edit"; + tooltip += "\n\u00a7e[right-click]\u00a7r to reset"; + return tooltip; } @Override public int getDefaultWidth() { - return MC.textRenderer.getWidth(setting.getName() + "#FFFFFF") + 6; + return TR.getWidth(setting.getName() + "#FFFFFF") + 6; } @Override public int getDefaultHeight() { - return 22; + return TEXT_HEIGHT * 2; } } diff --git a/src/main/java/net/wurstclient/clickgui/components/ComboBoxComponent.java b/src/main/java/net/wurstclient/clickgui/components/ComboBoxComponent.java index 837dfe22d8..7e63aa262e 100644 --- a/src/main/java/net/wurstclient/clickgui/components/ComboBoxComponent.java +++ b/src/main/java/net/wurstclient/clickgui/components/ComboBoxComponent.java @@ -8,70 +8,52 @@ package net.wurstclient.clickgui.components; import java.util.Arrays; -import java.util.stream.IntStream; -import java.util.stream.Stream; -import org.joml.Matrix4f; -import org.lwjgl.opengl.GL11; - -import com.mojang.blaze3d.systems.RenderSystem; +import org.lwjgl.glfw.GLFW; import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gl.ShaderProgramKeys; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.render.BufferBuilder; -import net.minecraft.client.render.BufferRenderer; -import net.minecraft.client.render.Tessellator; -import net.minecraft.client.render.VertexFormat; -import net.minecraft.client.render.VertexFormats; -import net.minecraft.client.util.math.MatrixStack; -import net.wurstclient.WurstClient; import net.wurstclient.clickgui.ClickGui; +import net.wurstclient.clickgui.ClickGuiIcons; import net.wurstclient.clickgui.ComboBoxPopup; import net.wurstclient.clickgui.Component; -import net.wurstclient.clickgui.Window; import net.wurstclient.settings.EnumSetting; import net.wurstclient.util.RenderUtils; public final class ComboBoxComponent> extends Component { - private final ClickGui gui = WurstClient.INSTANCE.getGui(); - private final TextRenderer tr = WurstClient.MC.textRenderer; + private static final ClickGui GUI = WURST.getGui(); + private static final TextRenderer TR = MC.textRenderer; + private static final int ARROW_SIZE = 11; private final EnumSetting setting; private final int popupWidth; + private ComboBoxPopup popup; public ComboBoxComponent(EnumSetting setting) { this.setting = setting; - popupWidth = calculatePopupWitdh(); + popupWidth = Arrays.stream(setting.getValues()).map(T::toString) + .mapToInt(s -> TR.getWidth(s)).max().getAsInt(); setWidth(getDefaultWidth()); setHeight(getDefaultHeight()); } - private int calculatePopupWitdh() - { - Stream values = Arrays.stream(setting.getValues()); - Stream vNames = values.map(T::toString); - IntStream vWidths = vNames.mapToInt(s -> tr.getWidth(s)); - return vWidths.max().getAsInt(); - } - @Override public void handleMouseClick(double mouseX, double mouseY, int mouseButton) { - if(mouseX < getX() + getWidth() - popupWidth - 15) + if(mouseX < getX() + getWidth() - popupWidth - ARROW_SIZE - 4) return; switch(mouseButton) { - case 0: + case GLFW.GLFW_MOUSE_BUTTON_LEFT: handleLeftClick(); break; - case 1: + case GLFW.GLFW_MOUSE_BUTTON_RIGHT: handleRightClick(); break; } @@ -87,7 +69,7 @@ private void handleLeftClick() } popup = new ComboBoxPopup<>(this, setting, popupWidth); - gui.addPopup(popup); + GUI.addPopup(popup); } private void handleRightClick() @@ -95,8 +77,7 @@ private void handleRightClick() if(isPopupOpen()) return; - T defaultSelected = setting.getDefaultSelected(); - setting.setSelected(defaultSelected); + setting.setSelected(setting.getDefaultSelected()); } private boolean isPopupOpen() @@ -108,178 +89,59 @@ private boolean isPopupOpen() public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) { - MatrixStack matrixStack = context.getMatrices(); int x1 = getX(); int x2 = x1 + getWidth(); - int x3 = x2 - 11; + int x3 = x2 - ARROW_SIZE; int x4 = x3 - popupWidth - 4; int y1 = getY(); int y2 = y1 + getHeight(); - boolean hovering = isHovering(mouseX, mouseY, x1, x2, y1, y2); + boolean hovering = isHovering(mouseX, mouseY); boolean hText = hovering && mouseX < x4; boolean hBox = hovering && mouseX >= x4; - RenderSystem.setShader(ShaderProgramKeys.POSITION); - // tooltip if(hText) - gui.setTooltip(setting.getWrappedDescription(200)); - - drawBackground(matrixStack, x1, x4, y1, y2); - drawBox(matrixStack, x2, x4, y1, y2, hBox); - - drawSeparator(matrixStack, x3, y1, y2); - drawArrow(matrixStack, x2, x3, y1, y2, hBox); - - drawNameAndValue(context, x1, x4, y1); - } - - private boolean isHovering(int mouseX, int mouseY, int x1, int x2, int y1, - int y2) - { - Window parent = getParent(); - boolean scrollEnabled = parent.isScrollingEnabled(); - int scroll = scrollEnabled ? parent.getScrollOffset() : 0; - - return mouseX >= x1 && mouseY >= y1 && mouseX < x2 && mouseY < y2 - && mouseY >= -scroll && mouseY < parent.getHeight() - 13 - scroll; - } - - private void drawBackground(MatrixStack matrixStack, int x1, int x4, int y1, - int y2) - { - float[] bgColor = gui.getBgColor(); - float opacity = gui.getOpacity(); - - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - - RenderUtils.setShaderColor(bgColor, opacity); - - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x1, y1, 0); - bufferBuilder.vertex(matrix, x1, y2, 0); - bufferBuilder.vertex(matrix, x4, y2, 0); - bufferBuilder.vertex(matrix, x4, y1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - } - - private void drawBox(MatrixStack matrixStack, int x2, int x4, int y1, - int y2, boolean hBox) - { - float[] bgColor = gui.getBgColor(); - float[] acColor = gui.getAcColor(); - float opacity = gui.getOpacity(); - - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); + GUI.setTooltip(setting.getWrappedDescription(200)); // background - float bgAlpha = hBox ? opacity * 1.5F : opacity; - RenderUtils.setShaderColor(bgColor, bgAlpha); - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x4, y1, 0); - bufferBuilder.vertex(matrix, x4, y2, 0); - bufferBuilder.vertex(matrix, x2, y2, 0); - bufferBuilder.vertex(matrix, x2, y1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + context.fill(x1, y1, x4, y2, getFillColor(false)); - // outline - RenderUtils.setShaderColor(acColor, 0.5F); - bufferBuilder = tessellator.begin( - VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x4, y1, 0); - bufferBuilder.vertex(matrix, x4, y2, 0); - bufferBuilder.vertex(matrix, x2, y2, 0); - bufferBuilder.vertex(matrix, x2, y1, 0); - bufferBuilder.vertex(matrix, x4, y1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - } - - private void drawSeparator(MatrixStack matrixStack, int x3, int y1, int y2) - { - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); + // box + context.fill(x4, y1, x2, y2, getFillColor(hBox)); - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x3, y1, 0); - bufferBuilder.vertex(matrix, x3, y2, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - } - - private void drawArrow(MatrixStack matrixStack, int x2, int x3, int y1, - int y2, boolean hBox) - { - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - - float xa1 = x3 + 1; - float xa2 = (x3 + x2) / 2.0F; - float xa3 = x2 - 1; - float ya1; - float ya2; - - if(isPopupOpen()) - { - ya1 = y2 - 3.5F; - ya2 = y1 + 3; - RenderSystem.setShaderColor(hBox ? 1 : 0.85F, 0, 0, 1); - - }else - { - ya1 = y1 + 3.5F; - ya2 = y2 - 3; - RenderSystem.setShaderColor(0, hBox ? 1 : 0.85F, 0, 1); - } + // outlines + int outlineColor = RenderUtils.toIntColor(GUI.getAcColor(), 0.5F); + RenderUtils.drawBorder2D(context, x4, y1, x2, y2, outlineColor); + RenderUtils.drawLine2D(context, x3, y1, x3, y2, outlineColor); // arrow - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xa1, ya1, 0); - bufferBuilder.vertex(matrix, xa3, ya1, 0); - bufferBuilder.vertex(matrix, xa2, ya2, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + ClickGuiIcons.drawMinimizeArrow(context, x3, y1 + 0.5F, x2, y2 - 0.5F, + hBox, !isPopupOpen()); - // outline - RenderSystem.setShaderColor(0.0625F, 0.0625F, 0.0625F, 0.5F); - bufferBuilder = tessellator.begin( - VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xa1, ya1, 0); - bufferBuilder.vertex(matrix, xa3, ya1, 0); - bufferBuilder.vertex(matrix, xa2, ya2, 0); - bufferBuilder.vertex(matrix, xa1, ya1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + // text + String name = setting.getName(); + String value = "" + setting.getSelected(); + int txtColor = GUI.getTxtColor(); + context.drawText(TR, name, x1, y1 + 2, txtColor, false); + context.drawText(TR, value, x4 + 2, y1 + 2, txtColor, false); } - private void drawNameAndValue(DrawContext context, int x1, int x4, int y1) + private int getFillColor(boolean hovering) { - ClickGui gui = WurstClient.INSTANCE.getGui(); - int txtColor = gui.getTxtColor(); - - RenderSystem.setShaderColor(1, 1, 1, 1); - - String name = setting.getName(); - String value = "" + setting.getSelected(); - - context.drawText(tr, name, x1, y1 + 2, txtColor, false); - context.drawText(tr, value, x4 + 2, y1 + 2, txtColor, false); - - GL11.glEnable(GL11.GL_BLEND); + float opacity = GUI.getOpacity() * (hovering ? 1.5F : 1); + return RenderUtils.toIntColor(GUI.getBgColor(), opacity); } @Override public int getDefaultWidth() { - return tr.getWidth(setting.getName()) + popupWidth + 17; + return TR.getWidth(setting.getName()) + popupWidth + ARROW_SIZE + 6; } @Override public int getDefaultHeight() { - return 11; + return ARROW_SIZE; } } diff --git a/src/main/java/net/wurstclient/clickgui/components/FeatureButton.java b/src/main/java/net/wurstclient/clickgui/components/FeatureButton.java index e9eb019088..9845a45647 100644 --- a/src/main/java/net/wurstclient/clickgui/components/FeatureButton.java +++ b/src/main/java/net/wurstclient/clickgui/components/FeatureButton.java @@ -9,24 +9,11 @@ import java.util.Objects; -import org.joml.Matrix4f; -import org.lwjgl.opengl.GL11; - -import com.mojang.blaze3d.systems.RenderSystem; - -import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gl.ShaderProgramKeys; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.render.BufferBuilder; -import net.minecraft.client.render.BufferRenderer; -import net.minecraft.client.render.Tessellator; -import net.minecraft.client.render.VertexFormat; -import net.minecraft.client.render.VertexFormats; -import net.minecraft.client.util.math.MatrixStack; import net.wurstclient.Feature; -import net.wurstclient.WurstClient; import net.wurstclient.clickgui.ClickGui; +import net.wurstclient.clickgui.ClickGuiIcons; import net.wurstclient.clickgui.Component; import net.wurstclient.clickgui.SettingsWindow; import net.wurstclient.clickgui.Window; @@ -36,8 +23,8 @@ public final class FeatureButton extends Component { - private final MinecraftClient MC = WurstClient.MC; - private final ClickGui GUI = WurstClient.INSTANCE.getGui(); + private static final ClickGui GUI = WURST.getGui(); + private static final TextRenderer TR = MC.textRenderer; private final Feature feature; private final boolean hasSettings; @@ -61,16 +48,11 @@ public void handleMouseClick(double mouseX, double mouseY, int mouseButton) if(hasSettings && (mouseX > getX() + getWidth() - 12 || feature.getPrimaryAction().isEmpty())) { - if(isSettingsWindowOpen()) - closeSettingsWindow(); - else - openSettingsWindow(); - + toggleSettingsWindow(); return; } - TooManyHaxHack tooManyHax = - WurstClient.INSTANCE.getHax().tooManyHaxHack; + TooManyHaxHack tooManyHax = WURST.getHax().tooManyHaxHack; if(tooManyHax.isEnabled() && tooManyHax.isBlocked(feature)) { ChatUtils.error(feature.getName() + " is blocked by TooManyHax."); @@ -85,235 +67,73 @@ private boolean isSettingsWindowOpen() return settingsWindow != null && !settingsWindow.isClosing(); } - private void openSettingsWindow() + private void toggleSettingsWindow() { - settingsWindow = new SettingsWindow(feature, getParent(), getY()); - GUI.addWindow(settingsWindow); - } - - private void closeSettingsWindow() - { - settingsWindow.close(); - settingsWindow = null; + if(!isSettingsWindowOpen()) + { + settingsWindow = new SettingsWindow(feature, getParent(), getY()); + GUI.addWindow(settingsWindow); + + }else + { + settingsWindow.close(); + settingsWindow = null; + } } @Override public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) { - MatrixStack matrixStack = context.getMatrices(); int x1 = getX(); int x2 = x1 + getWidth(); int x3 = hasSettings ? x2 - 11 : x2; int y1 = getY(); int y2 = y1 + getHeight(); - boolean hovering = isHovering(mouseX, mouseY, x1, x2, y1, y2); - boolean hHack = hovering && mouseX < x3; + boolean hovering = isHovering(mouseX, mouseY); + boolean hFeature = hovering && mouseX < x3; boolean hSettings = hovering && mouseX >= x3; - RenderSystem.setShader(ShaderProgramKeys.POSITION); - - if(hHack) - setTooltip(); - - drawButtonBackground(matrixStack, x1, x3, y1, y2, hHack); + if(hFeature) + GUI.setTooltip(feature.getWrappedDescription(200)); + // buttons + context.fill(x1, y1, x3, y2, + getButtonColor(feature.isEnabled(), hFeature)); if(hasSettings) - drawSettingsBackground(matrixStack, x2, x3, y1, y2, hSettings); - - drawOutline(matrixStack, x1, x2, y1, y2); + context.fill(x3, y1, x2, y2, getButtonColor(false, hSettings)); + // outlines + int outlineColor = RenderUtils.toIntColor(GUI.getAcColor(), 0.5F); + RenderUtils.drawBorder2D(context, x1, y1, x2, y2, outlineColor); if(hasSettings) - { - drawSeparator(matrixStack, x3, y1, y2); - drawSettingsArrow(matrixStack, x2, x3, y1, y2, hSettings); - } - - drawName(context, x1, x3, y1); - } - - private boolean isHovering(int mouseX, int mouseY, int x1, int x2, int y1, - int y2) - { - Window parent = getParent(); - boolean scrollEnabled = parent.isScrollingEnabled(); - int scroll = scrollEnabled ? parent.getScrollOffset() : 0; - - return mouseX >= x1 && mouseY >= y1 && mouseX < x2 && mouseY < y2 - && mouseY >= -scroll && mouseY < parent.getHeight() - 13 - scroll; - } - - private void setTooltip() - { - String tooltip = feature.getWrappedDescription(200); - - // if(feature.isBlocked()) - // { - // if(tooltip == null) - // tooltip = ""; - // else - // tooltip += "\n\n"; - // tooltip += - // "Your current YesCheat+ profile is blocking this feature."; - // } - - GUI.setTooltip(tooltip); - } - - private void drawButtonBackground(MatrixStack matrixStack, int x1, int x3, - int y1, int y2, boolean hHack) - { - float[] bgColor = GUI.getBgColor(); - float opacity = GUI.getOpacity(); - - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - - if(feature.isEnabled()) - // if(feature.isBlocked()) - // glColor4f(1, 0, 0, hHack ? opacity * 1.5F : opacity); - // else - RenderSystem.setShaderColor(0, 1, 0, - hHack ? opacity * 1.5F : opacity); - else - RenderUtils.setShaderColor(bgColor, - hHack ? opacity * 1.5F : opacity); - - bufferBuilder.vertex(matrix, x1, y1, 0); - bufferBuilder.vertex(matrix, x1, y2, 0); - bufferBuilder.vertex(matrix, x3, y2, 0); - bufferBuilder.vertex(matrix, x3, y1, 0); - - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - } - - private void drawSettingsBackground(MatrixStack matrixStack, int x2, int x3, - int y1, int y2, boolean hSettings) - { - float[] bgColor = GUI.getBgColor(); - float opacity = GUI.getOpacity(); - - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - RenderUtils.setShaderColor(bgColor, - hSettings ? opacity * 1.5F : opacity); - bufferBuilder.vertex(matrix, x3, y1, 0); - bufferBuilder.vertex(matrix, x3, y2, 0); - bufferBuilder.vertex(matrix, x2, y2, 0); - bufferBuilder.vertex(matrix, x2, y1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - } - - private void drawOutline(MatrixStack matrixStack, int x1, int x2, int y1, - int y2) - { - float[] acColor = GUI.getAcColor(); - - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - - BufferBuilder bufferBuilder = tessellator.begin( - VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION); - RenderUtils.setShaderColor(acColor, 0.5F); - bufferBuilder.vertex(matrix, x1, y1, 0); - bufferBuilder.vertex(matrix, x1, y2, 0); - bufferBuilder.vertex(matrix, x2, y2, 0); - bufferBuilder.vertex(matrix, x2, y1, 0); - bufferBuilder.vertex(matrix, x1, y1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - } - - private void drawSeparator(MatrixStack matrixStack, int x3, int y1, int y2) - { - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - - // separator - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x3, y1, 0); - bufferBuilder.vertex(matrix, x3, y2, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - } - - private void drawSettingsArrow(MatrixStack matrixStack, int x2, int x3, - int y1, int y2, boolean hSettings) - { - float xa1 = x3 + 1; - float xa2 = (x3 + x2) / 2.0F; - float xa3 = x2 - 1; - float ya1; - float ya2; - - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - - if(isSettingsWindowOpen()) - { - ya1 = y2 - 3.5F; - ya2 = y1 + 3; - RenderSystem.setShaderColor(hSettings ? 1 : 0.85F, 0, 0, 1); - - }else - { - ya1 = y1 + 3.5F; - ya2 = y2 - 3; - RenderSystem.setShaderColor(0, hSettings ? 1 : 0.85F, 0, 1); - } + RenderUtils.drawLine2D(context, x3, y1, x3, y2, outlineColor); // arrow - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xa1, ya1, 0); - bufferBuilder.vertex(matrix, xa3, ya1, 0); - bufferBuilder.vertex(matrix, xa2, ya2, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + if(hasSettings) + ClickGuiIcons.drawMinimizeArrow(context, x3, y1 + 0.5F, x2, + y2 - 0.5F, hSettings, !isSettingsWindowOpen()); - // outline - RenderSystem.setShaderColor(0.0625F, 0.0625F, 0.0625F, 0.5F); - bufferBuilder = tessellator.begin( - VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xa1, ya1, 0); - bufferBuilder.vertex(matrix, xa3, ya1, 0); - bufferBuilder.vertex(matrix, xa2, ya2, 0); - bufferBuilder.vertex(matrix, xa1, ya1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + // text + String name = feature.getName(); + int tx = x1 + (x3 - x1 - TR.getWidth(name)) / 2; + int ty = y1 + 2; + context.drawText(TR, name, tx, ty, GUI.getTxtColor(), false); } - private void drawName(DrawContext context, int x1, int x3, int y1) + private int getButtonColor(boolean enabled, boolean hovering) { - ClickGui gui = WurstClient.INSTANCE.getGui(); - int txtColor = gui.getTxtColor(); - - RenderSystem.setShaderColor(1, 1, 1, 1); - - TextRenderer tr = MC.textRenderer; - String name = feature.getName(); - int nameWidth = tr.getWidth(name); - int tx = x1 + (x3 - x1 - nameWidth) / 2; - int ty = y1 + 2; - - context.drawText(tr, name, tx, ty, txtColor, false); - - GL11.glEnable(GL11.GL_BLEND); + float[] rgb = enabled ? new float[]{0, 1, 0} : GUI.getBgColor(); + float opacity = GUI.getOpacity() * (hovering ? 1.5F : 1); + return RenderUtils.toIntColor(rgb, opacity); } @Override public int getDefaultWidth() { - String name = feature.getName(); - TextRenderer tr = MC.textRenderer; - int width = tr.getWidth(name) + 4; - if(hasSettings) - width += 11; - + int width = TR.getWidth(feature.getName()); + width += hasSettings ? 15 : 4; return width; } diff --git a/src/main/java/net/wurstclient/clickgui/components/FileComponent.java b/src/main/java/net/wurstclient/clickgui/components/FileComponent.java index ea699b1282..0eef34cb0a 100644 --- a/src/main/java/net/wurstclient/clickgui/components/FileComponent.java +++ b/src/main/java/net/wurstclient/clickgui/components/FileComponent.java @@ -7,21 +7,10 @@ */ package net.wurstclient.clickgui.components; -import org.joml.Matrix4f; -import org.lwjgl.opengl.GL11; - -import com.mojang.blaze3d.systems.RenderSystem; +import org.lwjgl.glfw.GLFW; import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gl.ShaderProgramKeys; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.render.BufferBuilder; -import net.minecraft.client.render.BufferRenderer; -import net.minecraft.client.render.Tessellator; -import net.minecraft.client.render.VertexFormat; -import net.minecraft.client.render.VertexFormats; -import net.minecraft.client.util.math.MatrixStack; -import net.wurstclient.WurstClient; import net.wurstclient.clickgui.ClickGui; import net.wurstclient.clickgui.Component; import net.wurstclient.clickgui.screens.SelectFileScreen; @@ -30,12 +19,14 @@ public final class FileComponent extends Component { + private static final ClickGui GUI = WURST.getGui(); + private static final TextRenderer TR = MC.textRenderer; + private final FileSetting setting; public FileComponent(FileSetting setting) { this.setting = setting; - setWidth(getDefaultWidth()); setHeight(getDefaultHeight()); } @@ -43,107 +34,67 @@ public FileComponent(FileSetting setting) @Override public void handleMouseClick(double mouseX, double mouseY, int mouseButton) { - if(mouseButton != 0) + if(mouseButton != GLFW.GLFW_MOUSE_BUTTON_LEFT) return; - TextRenderer fr = WurstClient.MC.textRenderer; - int buttonWidth = fr.getWidth(setting.getSelectedFileName()); - - if(mouseX < getX() + getWidth() - buttonWidth - 4) + if(mouseX < getX() + getWidth() - getButtonWidth() - 4) return; - WurstClient.MC.setScreen( - new SelectFileScreen(WurstClient.MC.currentScreen, setting)); + MC.setScreen(new SelectFileScreen(MC.currentScreen, setting)); } @Override public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) { - ClickGui gui = WurstClient.INSTANCE.getGui(); - float[] bgColor = gui.getBgColor(); - float[] acColor = gui.getAcColor(); - int txtColor = gui.getTxtColor(); - float opacity = gui.getOpacity(); - - TextRenderer tr = WurstClient.MC.textRenderer; - int buttonWidth = tr.getWidth(setting.getSelectedFileName()); - int x1 = getX(); int x2 = x1 + getWidth(); - int x3 = x2 - buttonWidth - 4; + int x3 = x2 - getButtonWidth() - 4; int y1 = getY(); int y2 = y1 + getHeight(); - int scroll = getParent().isScrollingEnabled() - ? getParent().getScrollOffset() : 0; - boolean hovering = mouseX >= x1 && mouseY >= y1 && mouseX < x2 - && mouseY < y2 && mouseY >= -scroll - && mouseY < getParent().getHeight() - 13 - scroll; + boolean hovering = isHovering(mouseX, mouseY); boolean hText = hovering && mouseX < x3; boolean hBox = hovering && mouseX >= x3; - MatrixStack matrixStack = context.getMatrices(); - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - RenderSystem.setShader(ShaderProgramKeys.POSITION); - // tooltip if(hText) - gui.setTooltip(setting.getWrappedDescription(200)); + GUI.setTooltip(setting.getWrappedDescription(200)); else if(hBox) - { - String tooltip = "\u00a7e[left-click]\u00a7r to select file"; - gui.setTooltip(tooltip); - } + GUI.setTooltip("\u00a7e[left-click]\u00a7r to select file"); // background - RenderUtils.setShaderColor(bgColor, opacity); - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x1, y1, 0); - bufferBuilder.vertex(matrix, x1, y2, 0); - bufferBuilder.vertex(matrix, x3, y2, 0); - bufferBuilder.vertex(matrix, x3, y1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + context.fill(x1, y1, x3, y2, getFillColor(false)); - // box - RenderUtils.setShaderColor(bgColor, hBox ? opacity * 1.5F : opacity); - bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, - VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x3, y1, 0); - bufferBuilder.vertex(matrix, x3, y2, 0); - bufferBuilder.vertex(matrix, x2, y2, 0); - bufferBuilder.vertex(matrix, x2, y1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - RenderUtils.setShaderColor(acColor, 0.5F); - bufferBuilder = tessellator.begin( - VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x3, y1, 0); - bufferBuilder.vertex(matrix, x3, y2, 0); - bufferBuilder.vertex(matrix, x2, y2, 0); - bufferBuilder.vertex(matrix, x2, y1, 0); - bufferBuilder.vertex(matrix, x3, y1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + // button + context.fill(x3, y1, x2, y2, getFillColor(hBox)); + int outlineColor = RenderUtils.toIntColor(GUI.getAcColor(), 0.5F); + RenderUtils.drawBorder2D(context, x3, y1, x2, y2, outlineColor); - // setting name - RenderSystem.setShaderColor(1, 1, 1, 1); - String text = setting.getName() + ": "; - context.drawText(tr, text, x1, y1 + 2, txtColor, false); - context.drawText(tr, setting.getSelectedFileName(), x3 + 2, y1 + 2, - txtColor, false); - GL11.glEnable(GL11.GL_BLEND); + // text + int txtColor = GUI.getTxtColor(); + String labelText = setting.getName() + ":"; + String buttonText = setting.getSelectedFileName(); + context.drawText(TR, labelText, x1, y1 + 2, txtColor, false); + context.drawText(TR, buttonText, x3 + 2, y1 + 2, txtColor, false); + } + + private int getFillColor(boolean hovering) + { + float opacity = GUI.getOpacity() * (hovering ? 1.5F : 1); + return RenderUtils.toIntColor(GUI.getBgColor(), opacity); + } + + private int getButtonWidth() + { + return TR.getWidth(setting.getSelectedFileName()); } @Override public int getDefaultWidth() { - TextRenderer fr = WurstClient.MC.textRenderer; - - String text = setting.getName() + ": "; - int buttonWidth = fr.getWidth(setting.getSelectedFileName()); - - return fr.getWidth(text) + buttonWidth + 6; + String text = setting.getName() + ":"; + return TR.getWidth(text) + getButtonWidth() + 6; } @Override diff --git a/src/main/java/net/wurstclient/clickgui/components/RadarComponent.java b/src/main/java/net/wurstclient/clickgui/components/RadarComponent.java index bd38975cd3..d4cd46464f 100644 --- a/src/main/java/net/wurstclient/clickgui/components/RadarComponent.java +++ b/src/main/java/net/wurstclient/clickgui/components/RadarComponent.java @@ -7,20 +7,10 @@ */ package net.wurstclient.clickgui.components; -import org.joml.Matrix4f; import org.joml.Quaternionf; -import com.mojang.blaze3d.systems.RenderSystem; - -import net.minecraft.client.gl.ShaderProgramKeys; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.client.render.BufferBuilder; -import net.minecraft.client.render.BufferRenderer; -import net.minecraft.client.render.BuiltBuffer; -import net.minecraft.client.render.Tessellator; -import net.minecraft.client.render.VertexFormat; -import net.minecraft.client.render.VertexFormats; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.Entity; import net.minecraft.entity.mob.AmbientEntity; @@ -30,8 +20,8 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; -import net.wurstclient.WurstClient; import net.wurstclient.clickgui.ClickGui; +import net.wurstclient.clickgui.ClickGuiIcons; import net.wurstclient.clickgui.Component; import net.wurstclient.hacks.RadarHack; import net.wurstclient.util.EntityUtils; @@ -52,90 +42,41 @@ public RadarComponent(RadarHack hack) public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) { - ClickGui gui = WurstClient.INSTANCE.getGui(); - float[] bgColor = gui.getBgColor(); - float[] acColor = gui.getAcColor(); - float opacity = gui.getOpacity(); + // Can't make this a field because RadarComponent is initialized earlier + // than ClickGui. + ClickGui gui = WURST.getGui(); int x1 = getX(); int x2 = x1 + getWidth(); int y1 = getY(); int y2 = y1 + getHeight(); - - int scroll = getParent().isScrollingEnabled() - ? getParent().getScrollOffset() : 0; - boolean hovering = mouseX >= x1 && mouseY >= y1 && mouseX < x2 - && mouseY < y2 && mouseY >= -scroll - && mouseY < getParent().getHeight() - 13 - scroll; - - MatrixStack matrixStack = context.getMatrices(); - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - RenderSystem.setShader(ShaderProgramKeys.POSITION); + float middleX = (x1 + x2) / 2F; + float middleY = (y1 + y2) / 2F; // tooltip - if(hovering) + if(isHovering(mouseX, mouseY)) gui.setTooltip(""); // background - RenderUtils.setShaderColor(bgColor, opacity); - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x1, y1, 0); - bufferBuilder.vertex(matrix, x1, y2, 0); - bufferBuilder.vertex(matrix, x2, y2, 0); - bufferBuilder.vertex(matrix, x2, y1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - - float middleX = (x1 + x2) / 2.0F; - float middleY = (y1 + y2) / 2.0F; + context.fill(x1, y1, x2, y2, + RenderUtils.toIntColor(gui.getBgColor(), gui.getOpacity())); + MatrixStack matrixStack = context.getMatrices(); matrixStack.push(); matrixStack.translate(middleX, middleY, 0); - matrix = matrixStack.peek().getPositionMatrix(); - ClientPlayerEntity player = WurstClient.MC.player; + ClientPlayerEntity player = MC.player; if(!hack.isRotateEnabled()) matrixStack.multiply(new Quaternionf().rotationZ( (180 + player.getYaw()) * MathHelper.RADIANS_PER_DEGREE)); - float xa1 = 0; - float xa2 = 2; - float xa3 = -2; - float ya1 = -2; - float ya2 = 2; - float ya3 = 1; - // arrow - RenderUtils.setShaderColor(acColor, opacity); - bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, - VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xa1, ya1, 0); - bufferBuilder.vertex(matrix, xa2, ya2, 0); - bufferBuilder.vertex(matrix, xa1, ya3, 0); - bufferBuilder.vertex(matrix, xa3, ya2, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - - // outline - RenderSystem.setShaderColor(0.0625F, 0.0625F, 0.0625F, 0.5F); - bufferBuilder = tessellator.begin( - VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xa1, ya1, 0); - bufferBuilder.vertex(matrix, xa2, ya2, 0); - bufferBuilder.vertex(matrix, xa1, ya3, 0); - bufferBuilder.vertex(matrix, xa3, ya2, 0); - bufferBuilder.vertex(matrix, xa1, ya1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + ClickGuiIcons.drawRadarArrow(context, -2, -2, 2, 2); matrixStack.pop(); - matrix = matrixStack.peek().getPositionMatrix(); Vec3d lerpedPlayerPos = EntityUtils.getLerpedPos(player, partialTicks); // points - RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR); - RenderSystem.setShaderColor(1, 1, 1, 1); - bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, - VertexFormats.POSITION_COLOR); for(Entity e : hack.getEntities()) { Vec3d lerpedEntityPos = EntityUtils.getLerpedPos(e, partialTicks); @@ -156,43 +97,26 @@ public void render(DrawContext context, int mouseX, int mouseY, || Math.abs(renderY) > getHeight() / 2.0) continue; - int color; - if(WurstClient.INSTANCE.getFriends().isFriend(e)) - color = 0x0000FF; - else if(e instanceof PlayerEntity) - color = 0xFF0000; - else if(e instanceof Monster) - color = 0xFF8000; - else if(e instanceof AnimalEntity || e instanceof AmbientEntity - || e instanceof WaterCreatureEntity) - color = 0x00FF00; - else - color = 0x808080; - - float red = (color >> 16 & 255) / 255F; - float green = (color >> 8 & 255) / 255F; - float blue = (color & 255) / 255F; - float alpha = 1; - bufferBuilder - .vertex(matrix, middleX + (float)renderX - 0.5F, - middleY + (float)renderY - 0.5F, 0) - .color(red, green, blue, alpha); - bufferBuilder - .vertex(matrix, middleX + (float)renderX + 0.5F, - middleY + (float)renderY - 0.5F, 0) - .color(red, green, blue, alpha); - bufferBuilder - .vertex(matrix, middleX + (float)renderX + 0.5F, - middleY + (float)renderY + 0.5F, 0) - .color(red, green, blue, alpha); - bufferBuilder - .vertex(matrix, middleX + (float)renderX - 0.5F, - middleY + (float)renderY + 0.5F, 0) - .color(red, green, blue, alpha); + float ex1 = middleX + (float)renderX - 0.5F; + float ex2 = middleX + (float)renderX + 0.5F; + float ey1 = middleY + (float)renderY - 0.5F; + float ey2 = middleY + (float)renderY + 0.5F; + RenderUtils.fill2D(context, ex1, ey1, ex2, ey2, getEntityColor(e)); } - BuiltBuffer buffer = bufferBuilder.endNullable(); - if(buffer != null) - BufferRenderer.drawWithGlobalProgram(buffer); + } + + private int getEntityColor(Entity e) + { + if(WURST.getFriends().isFriend(e)) + return 0xFF0000FF; + if(e instanceof PlayerEntity) + return 0xFFFF0000; + if(e instanceof Monster) + return 0xFFFF8000; + if(e instanceof AnimalEntity || e instanceof AmbientEntity + || e instanceof WaterCreatureEntity) + return 0xFF00FF00; + return 0xFF808080; } @Override diff --git a/src/main/java/net/wurstclient/clickgui/components/SliderComponent.java b/src/main/java/net/wurstclient/clickgui/components/SliderComponent.java index 04f98d212f..dc0290a883 100644 --- a/src/main/java/net/wurstclient/clickgui/components/SliderComponent.java +++ b/src/main/java/net/wurstclient/clickgui/components/SliderComponent.java @@ -7,34 +7,23 @@ */ package net.wurstclient.clickgui.components; -import org.joml.Matrix4f; -import org.lwjgl.opengl.GL11; +import org.lwjgl.glfw.GLFW; -import com.mojang.blaze3d.systems.RenderSystem; - -import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gl.ShaderProgramKeys; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.render.BufferBuilder; -import net.minecraft.client.render.BufferRenderer; -import net.minecraft.client.render.Tessellator; -import net.minecraft.client.render.VertexFormat; -import net.minecraft.client.render.VertexFormats; import net.minecraft.client.util.math.MatrixStack; -import net.wurstclient.WurstClient; import net.wurstclient.clickgui.ClickGui; import net.wurstclient.clickgui.Component; -import net.wurstclient.clickgui.Window; import net.wurstclient.clickgui.screens.EditSliderScreen; import net.wurstclient.settings.SliderSetting; import net.wurstclient.util.RenderUtils; public final class SliderComponent extends Component { - private final MinecraftClient MC = WurstClient.MC; - private final ClickGui GUI = WurstClient.INSTANCE.getGui(); + private static final ClickGui GUI = WURST.getGui(); + private static final TextRenderer TR = MC.textRenderer; + private static final int TEXT_HEIGHT = 11; private final SliderSetting setting; private boolean dragging; @@ -54,71 +43,19 @@ public void handleMouseClick(double mouseX, double mouseY, int mouseButton) switch(mouseButton) { - case 0: - handleLeftClick(); + case GLFW.GLFW_MOUSE_BUTTON_LEFT: + if(Screen.hasControlDown()) + MC.setScreen(new EditSliderScreen(MC.currentScreen, setting)); + else + dragging = true; break; - case 1: - handleRightClick(); + case GLFW.GLFW_MOUSE_BUTTON_RIGHT: + setting.setValue(setting.getDefaultValue()); break; } } - private void handleLeftClick() - { - if(Screen.hasControlDown()) - MC.setScreen(new EditSliderScreen(MC.currentScreen, setting)); - else - dragging = true; - } - - private void handleRightClick() - { - setting.setValue(setting.getDefaultValue()); - } - - @Override - public void render(DrawContext context, int mouseX, int mouseY, - float partialTicks) - { - MatrixStack matrixStack = context.getMatrices(); - int x1 = getX(); - int x2 = x1 + getWidth(); - int x3 = x1 + 2; - int x4 = x2 - 2; - int y1 = getY(); - int y2 = y1 + getHeight(); - int y3 = y1 + 11; - int y4 = y3 + 4; - int y5 = y2 - 4; - - handleDragging(mouseX, x3, x4); - - boolean hovering = isHovering(mouseX, mouseY, x1, x2, y1, y2); - boolean hSlider = hovering && mouseY >= y3 || dragging; - boolean renderAsDisabled = setting.isDisabled() || setting.isLocked(); - - RenderSystem.setShader(ShaderProgramKeys.POSITION); - - if(hovering && mouseY < y3) - setTooltip(); - else if(hSlider && !dragging) - GUI.setTooltip( - "\u00a7e[ctrl]\u00a7r+\u00a7e[left-click]\u00a7r for precise input\n" - + "\u00a7e[right-click]\u00a7r to reset"); - - if(renderAsDisabled) - { - hovering = false; - hSlider = false; - } - - drawBackground(matrixStack, x1, x2, x3, x4, y1, y2, y4, y5); - drawRail(matrixStack, x3, x4, y4, y5, hSlider, renderAsDisabled); - drawKnob(matrixStack, x1, x2, y2, y3, hSlider, renderAsDisabled); - drawNameAndValue(context, x1, x2, y1, renderAsDisabled); - } - private void handleDragging(int mouseX, int x3, int x4) { if(!dragging) @@ -141,193 +78,129 @@ private void handleDragging(int mouseX, int x3, int x4) setting.setValue(value); } - private boolean isHovering(int mouseX, int mouseY, int x1, int x2, int y1, - int y2) + @Override + public void render(DrawContext context, int mouseX, int mouseY, + float partialTicks) { - Window parent = getParent(); - boolean scrollEnabled = parent.isScrollingEnabled(); - int scroll = scrollEnabled ? parent.getScrollOffset() : 0; + int x1 = getX(); + int x2 = x1 + getWidth(); + int x3 = x1 + 2; + int x4 = x2 - 2; + int y1 = getY(); + int y2 = y1 + getHeight(); + int y3 = y1 + TEXT_HEIGHT; + int y4 = y3 + 4; + int y5 = y2 - 4; - return mouseX >= x1 && mouseY >= y1 && mouseX < x2 && mouseY < y2 - && mouseY >= -scroll && mouseY < parent.getHeight() - 13 - scroll; - } - - private void setTooltip() - { - String tooltip = setting.getWrappedDescription(200); + handleDragging(mouseX, x3, x4); - if(setting.isLocked()) - { - tooltip += "\n\nThis slider is locked to "; - tooltip += setting.getValueString() + "."; - - }else if(setting.isDisabled()) - tooltip += "\n\nThis slider is disabled."; + boolean hovering = isHovering(mouseX, mouseY); + boolean hText = hovering && mouseY < y3; + boolean hSlider = hovering && mouseY >= y3 || dragging; - GUI.setTooltip(tooltip); - } - - private void drawBackground(MatrixStack matrixStack, int x1, int x2, int x3, - int x4, int y1, int y2, int y4, int y5) - { - float[] bgColor = GUI.getBgColor(); + boolean grayedOut = setting.isDisabled() || setting.isLocked(); float opacity = GUI.getOpacity(); + float railOpacity = opacity * (hSlider ? 1.5F : 1); - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - - RenderUtils.setShaderColor(bgColor, opacity); - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - - bufferBuilder.vertex(matrix, x1, y1, 0); - bufferBuilder.vertex(matrix, x1, y4, 0); - bufferBuilder.vertex(matrix, x2, y4, 0); - bufferBuilder.vertex(matrix, x2, y1, 0); - - bufferBuilder.vertex(matrix, x1, y5, 0); - bufferBuilder.vertex(matrix, x1, y2, 0); - bufferBuilder.vertex(matrix, x2, y2, 0); - bufferBuilder.vertex(matrix, x2, y5, 0); - - bufferBuilder.vertex(matrix, x1, y4, 0); - bufferBuilder.vertex(matrix, x1, y5, 0); - bufferBuilder.vertex(matrix, x3, y5, 0); - bufferBuilder.vertex(matrix, x3, y4, 0); - - bufferBuilder.vertex(matrix, x4, y4, 0); - bufferBuilder.vertex(matrix, x4, y5, 0); - bufferBuilder.vertex(matrix, x2, y5, 0); - bufferBuilder.vertex(matrix, x2, y4, 0); + if(hText) + GUI.setTooltip(getTextTooltip()); + else if(hSlider && !dragging) + GUI.setTooltip(getSliderTooltip()); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - } - - private void drawRail(MatrixStack matrixStack, int x3, int x4, int y4, - int y5, boolean hSlider, boolean renderAsDisabled) - { - float[] bgColor = GUI.getBgColor(); - float[] acColor = GUI.getAcColor(); - float opacity = GUI.getOpacity(); + if(grayedOut) + { + hovering = false; + hSlider = false; + } - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); + // background (around the rail) + int bgColor = RenderUtils.toIntColor(GUI.getBgColor(), opacity); + float[][] bgVertices = {{x1, y1}, {x1, y4}, {x2, y4}, {x2, y1}, + {x1, y5}, {x1, y2}, {x2, y2}, {x2, y5}, {x1, y4}, {x1, y5}, + {x3, y5}, {x3, y4}, {x4, y4}, {x4, y5}, {x2, y5}, {x2, y4}}; + RenderUtils.fillQuads2D(context, bgVertices, bgColor); + // limit float xl1 = x3; float xl2 = x4; - if(!renderAsDisabled && setting.isLimited()) + if(!grayedOut && setting.isLimited()) { double ratio = (x4 - x3) / setting.getRange(); xl1 += ratio * (setting.getUsableMin() - setting.getMinimum()); xl2 += ratio * (setting.getUsableMax() - setting.getMaximum()); + + int limitColor = + RenderUtils.toIntColor(new float[]{1, 0, 0}, railOpacity); + float[][] limitVertices = {{x3, y4}, {x3, y5}, {xl1, y5}, {xl1, y4}, + {xl2, y4}, {xl2, y5}, {x4, y5}, {x4, y4}}; + RenderUtils.fillQuads2D(context, limitVertices, limitColor); } - // limit - RenderSystem.setShaderColor(1, 0, 0, - hSlider ? opacity * 1.5F : opacity); - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x3, y4, 0); - bufferBuilder.vertex(matrix, x3, y5, 0); - bufferBuilder.vertex(matrix, xl1, y5, 0); - bufferBuilder.vertex(matrix, xl1, y4, 0); - bufferBuilder.vertex(matrix, xl2, y4, 0); - bufferBuilder.vertex(matrix, xl2, y5, 0); - bufferBuilder.vertex(matrix, x4, y5, 0); - bufferBuilder.vertex(matrix, x4, y4, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - - // background - RenderUtils.setShaderColor(bgColor, hSlider ? opacity * 1.5F : opacity); - bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, - VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xl1, y4, 0); - bufferBuilder.vertex(matrix, xl1, y5, 0); - bufferBuilder.vertex(matrix, xl2, y5, 0); - bufferBuilder.vertex(matrix, xl2, y4, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + // rail + RenderUtils.fill2D(context, xl1, y4, xl2, y5, + RenderUtils.toIntColor(GUI.getBgColor(), railOpacity)); + RenderUtils.drawBorder2D(context, xl1, y4, xl2, y5, + RenderUtils.toIntColor(GUI.getAcColor(), 0.5F)); - // outline - RenderUtils.setShaderColor(acColor, 0.5F); - bufferBuilder = tessellator.begin( - VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x3, y4, 0); - bufferBuilder.vertex(matrix, x3, y5, 0); - bufferBuilder.vertex(matrix, x4, y5, 0); - bufferBuilder.vertex(matrix, x4, y4, 0); - bufferBuilder.vertex(matrix, x3, y4, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - } - - private void drawKnob(MatrixStack matrixStack, int x1, int x2, int y2, - int y3, boolean hSlider, boolean renderAsDisabled) - { - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); + MatrixStack matrices = context.getMatrices(); + matrices.push(); + matrices.translate(0, 0, 2); - double percentage = setting.getPercentage(); - float xk1 = x1 + (x2 - x1 - 8) * (float)percentage; + // knob + float xk1 = x1 + (x2 - x1 - 8) * (float)setting.getPercentage(); float xk2 = xk1 + 8; float yk1 = y3 + 1.5F; float yk2 = y2 - 1.5F; + int knobColor = grayedOut ? 0xC0808080 : RenderUtils + .toIntColor(setting.getKnobColor(), hSlider ? 1 : 0.75F); + RenderUtils.fill2D(context, xk1, yk1, xk2, yk2, knobColor); + RenderUtils.drawBorder2D(context, xk1, yk1, xk2, yk2, 0x80101010); - // knob - if(renderAsDisabled) - RenderSystem.setShaderColor(0.5F, 0.5F, 0.5F, 0.75F); - else - RenderUtils.setShaderColor(setting.getKnobColor(), - hSlider ? 1 : 0.75F); - - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xk1, yk1, 0); - bufferBuilder.vertex(matrix, xk1, yk2, 0); - bufferBuilder.vertex(matrix, xk2, yk2, 0); - bufferBuilder.vertex(matrix, xk2, yk1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + matrices.pop(); - // outline - RenderSystem.setShaderColor(0.0625F, 0.0625F, 0.0625F, 0.5F); - bufferBuilder = tessellator.begin( - VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, xk1, yk1, 0); - bufferBuilder.vertex(matrix, xk1, yk2, 0); - bufferBuilder.vertex(matrix, xk2, yk2, 0); - bufferBuilder.vertex(matrix, xk2, yk1, 0); - bufferBuilder.vertex(matrix, xk1, yk1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + // text + String name = setting.getName(); + String value = setting.getValueString(); + int valueWidth = TR.getWidth(value); + int txtColor = GUI.getTxtColor(); + context.drawText(TR, name, x1, y1 + 2, txtColor, false); + context.drawText(TR, value, x2 - valueWidth, y1 + 2, txtColor, false); } - private void drawNameAndValue(DrawContext context, int x1, int x2, int y1, - boolean renderAsDisabled) + private String getTextTooltip() { - ClickGui gui = WurstClient.INSTANCE.getGui(); - int txtColor = gui.getTxtColor(); - - RenderSystem.setShaderColor(1, 1, 1, 1); + String tooltip = setting.getWrappedDescription(200); - TextRenderer tr = MC.textRenderer; - String name = setting.getName(); - String value = setting.getValueString(); - int valueWidth = tr.getWidth(value); - context.drawText(tr, name, x1, y1 + 2, txtColor, false); - context.drawText(tr, value, x2 - valueWidth, y1 + 2, txtColor, false); + if(setting.isDisabled()) + tooltip += "\n\nThis slider is disabled."; + else if(setting.isLocked()) + { + tooltip += "\n\nThis slider is locked to "; + tooltip += setting.getValueString() + "."; + } - GL11.glEnable(GL11.GL_BLEND); + return tooltip; + } + + private String getSliderTooltip() + { + String tooltip = + "\u00a7e[ctrl]\u00a7r+\u00a7e[left-click]\u00a7r for precise input\n"; + tooltip += "\u00a7e[right-click]\u00a7r to reset"; + return tooltip; } @Override public int getDefaultWidth() { - TextRenderer tr = MC.textRenderer; - int nameWitdh = tr.getWidth(setting.getName()); - int valueWidth = tr.getWidth(setting.getValueString()); + int nameWitdh = TR.getWidth(setting.getName()); + int valueWidth = TR.getWidth(setting.getValueString()); return nameWitdh + valueWidth + 6; } @Override public int getDefaultHeight() { - return 22; + return TEXT_HEIGHT * 2; } } diff --git a/src/main/java/net/wurstclient/clickgui/components/TextFieldEditButton.java b/src/main/java/net/wurstclient/clickgui/components/TextFieldEditButton.java index c4370c4a84..c974678395 100644 --- a/src/main/java/net/wurstclient/clickgui/components/TextFieldEditButton.java +++ b/src/main/java/net/wurstclient/clickgui/components/TextFieldEditButton.java @@ -9,23 +9,11 @@ import java.util.Objects; -import org.joml.Matrix4f; -import org.lwjgl.opengl.GL11; +import org.lwjgl.glfw.GLFW; -import com.mojang.blaze3d.systems.RenderSystem; - -import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gl.ShaderProgramKeys; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.render.BufferBuilder; -import net.minecraft.client.render.BufferRenderer; -import net.minecraft.client.render.Tessellator; -import net.minecraft.client.render.VertexFormat; -import net.minecraft.client.render.VertexFormats; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Style; -import net.wurstclient.WurstClient; import net.wurstclient.clickgui.ClickGui; import net.wurstclient.clickgui.Component; import net.wurstclient.clickgui.screens.EditTextFieldScreen; @@ -35,7 +23,10 @@ public final class TextFieldEditButton extends Component { - protected static final MinecraftClient MC = WurstClient.MC; + private static final ClickGui GUI = WURST.getGui(); + private static final TextRenderer TR = MC.textRenderer; + private static final int TEXT_HEIGHT = 11; + private final TextFieldSetting setting; public TextFieldEditButton(TextFieldSetting setting) @@ -48,16 +39,16 @@ public TextFieldEditButton(TextFieldSetting setting) @Override public void handleMouseClick(double mouseX, double mouseY, int mouseButton) { - if(mouseY < getY() + 11) + if(mouseY < getY() + TEXT_HEIGHT) return; switch(mouseButton) { - case 0: + case GLFW.GLFW_MOUSE_BUTTON_LEFT: MC.setScreen(new EditTextFieldScreen(MC.currentScreen, setting)); break; - case 1: + case GLFW.GLFW_MOUSE_BUTTON_RIGHT: setting.resetToDefault(); break; } @@ -67,90 +58,54 @@ public void handleMouseClick(double mouseX, double mouseY, int mouseButton) public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) { - ClickGui gui = WurstClient.INSTANCE.getGui(); - float[] bgColor = gui.getBgColor(); - float[] acColor = gui.getAcColor(); - int txtColor = gui.getTxtColor(); - float opacity = gui.getOpacity(); + float[] bgColor = GUI.getBgColor(); + float opacity = GUI.getOpacity(); int x1 = getX(); int x2 = x1 + getWidth(); int y1 = getY(); int y2 = y1 + getHeight(); - int y3 = y1 + 11; + int y3 = y1 + TEXT_HEIGHT; - int scroll = getParent().isScrollingEnabled() - ? getParent().getScrollOffset() : 0; - boolean hovering = mouseX >= x1 && mouseY >= y1 && mouseX < x2 - && mouseY < y2 && mouseY >= -scroll - && mouseY < getParent().getHeight() - 13 - scroll; + boolean hovering = isHovering(mouseX, mouseY); boolean hText = hovering && mouseY < y3; boolean hBox = hovering && mouseY >= y3; - TextRenderer tr = MC.textRenderer; - MatrixStack matrixStack = context.getMatrices(); - Matrix4f matrix = matrixStack.peek().getPositionMatrix(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - RenderSystem.setShader(ShaderProgramKeys.POSITION); - - // tooltip if(hText) - gui.setTooltip(ChatUtils.wrapText(setting.getDescription(), 200)); + GUI.setTooltip(ChatUtils.wrapText(setting.getDescription(), 200)); else if(hBox) - gui.setTooltip(ChatUtils.wrapText(setting.getValue(), 200)); + GUI.setTooltip(ChatUtils.wrapText(setting.getValue(), 200)); // background - RenderUtils.setShaderColor(bgColor, opacity); - BufferBuilder bufferBuilder = tessellator - .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x1, y1, 0); - bufferBuilder.vertex(matrix, x1, y2, 0); - bufferBuilder.vertex(matrix, x2, y2, 0); - bufferBuilder.vertex(matrix, x2, y1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + context.fill(x1, y1, x2, y3, RenderUtils.toIntColor(bgColor, opacity)); // box - RenderUtils.setShaderColor(bgColor, hBox ? opacity * 1.5F : opacity); - bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, - VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x1, y3, 0); - bufferBuilder.vertex(matrix, x1, y2, 0); - bufferBuilder.vertex(matrix, x2, y2, 0); - bufferBuilder.vertex(matrix, x2, y3, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - RenderUtils.setShaderColor(acColor, 0.5F); - bufferBuilder = tessellator.begin( - VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION); - bufferBuilder.vertex(matrix, x1, y3, 0); - bufferBuilder.vertex(matrix, x1, y2, 0); - bufferBuilder.vertex(matrix, x2, y2, 0); - bufferBuilder.vertex(matrix, x2, y3, 0); - bufferBuilder.vertex(matrix, x1, y3, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + context.fill(x1, y3, x2, y2, + RenderUtils.toIntColor(bgColor, opacity * (hBox ? 1.5F : 1))); + RenderUtils.drawBorder2D(context, x1, y3, x2, y2, + RenderUtils.toIntColor(GUI.getAcColor(), 0.5F)); - int maxLength = tr.getTextHandler().getLimitedStringLength( - setting.getValue(), getWidth() - 8, Style.EMPTY); + // text + int txtColor = GUI.getTxtColor(); + context.drawText(TR, setting.getName(), x1, y1 + 2, txtColor, false); String value = setting.getValue(); + int maxWidth = getWidth() - TR.getWidth("...") - 2; + int maxLength = TR.getTextHandler().getLimitedStringLength(value, + maxWidth, Style.EMPTY); if(maxLength < value.length()) value = value.substring(0, maxLength) + "..."; - - // setting name and value - RenderSystem.setShaderColor(1, 1, 1, 1); - context.drawText(tr, setting.getName(), x1, y1 + 2, txtColor, false); - context.drawText(tr, value, x1 + 2, y3 + 2, txtColor, false); - GL11.glEnable(GL11.GL_BLEND); + context.drawText(TR, value, x1 + 2, y3 + 2, txtColor, false); } @Override public int getDefaultWidth() { - TextRenderer tr = MC.textRenderer; - return tr.getWidth(setting.getName()) + 4; + return TR.getWidth(setting.getName()) + 4; } @Override public int getDefaultHeight() { - return 22; + return TEXT_HEIGHT * 2; } } diff --git a/src/main/java/net/wurstclient/settings/ColorSetting.java b/src/main/java/net/wurstclient/settings/ColorSetting.java index 870ae26029..cfad1a56f7 100644 --- a/src/main/java/net/wurstclient/settings/ColorSetting.java +++ b/src/main/java/net/wurstclient/settings/ColorSetting.java @@ -17,6 +17,7 @@ import com.google.gson.JsonPrimitive; import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.util.math.MathHelper; import net.wurstclient.WurstClient; import net.wurstclient.clickgui.Component; import net.wurstclient.clickgui.components.ColorComponent; @@ -77,6 +78,11 @@ public int getColorI(int alpha) return color.getRGB() & 0x00FFFFFF | alpha << 24; } + public int getColorI(float alpha) + { + return getColorI((int)(MathHelper.clamp(alpha, 0, 1) * 255)); + } + public int getRed() { return color.getRed(); diff --git a/src/main/java/net/wurstclient/util/RenderUtils.java b/src/main/java/net/wurstclient/util/RenderUtils.java index 27b7185549..6fb634bcee 100644 --- a/src/main/java/net/wurstclient/util/RenderUtils.java +++ b/src/main/java/net/wurstclient/util/RenderUtils.java @@ -7,6 +7,8 @@ */ package net.wurstclient.util; +import java.util.OptionalDouble; + import org.joml.Matrix4f; import org.joml.Vector3f; @@ -18,6 +20,7 @@ import net.minecraft.client.gl.VertexBuffer; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.render.*; +import net.minecraft.client.render.VertexFormat.DrawMode; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; @@ -33,6 +36,40 @@ public enum RenderUtils private static final Box DEFAULT_BOX = new Box(0, 0, 0, 1, 1, 1); + /** + * Similar to {@link RenderLayer#getDebugLineStrip(double)}, but as a + * non-srip version with support for transparency. + * + * @implNote Just like {@link RenderLayer#getDebugLineStrip(double)}, this + * layer doesn't support any other line width than 1px. Changing + * the line width number does nothing. + */ + public static final RenderLayer.MultiPhase ONE_PIXEL_LINES = + RenderLayer.of("wurst:1px_lines", VertexFormats.POSITION_COLOR, + DrawMode.DEBUG_LINES, 1536, false, true, + RenderLayer.MultiPhaseParameters.builder() + .program(RenderLayer.POSITION_COLOR_PROGRAM) + .lineWidth(new RenderPhase.LineWidth(OptionalDouble.of(1))) + .transparency(RenderLayer.TRANSLUCENT_TRANSPARENCY) + .cull(RenderLayer.DISABLE_CULLING).build(false)); + + /** + * Similar to {@link RenderLayer#getDebugLineStrip(double)}, but with + * support for transparency. + * + * @implNote Just like {@link RenderLayer#getDebugLineStrip(double)}, this + * layer doesn't support any other line width than 1px. Changing + * the line width number does nothing. + */ + public static final RenderLayer.MultiPhase ONE_PIXEL_LINE_STRIP = + RenderLayer.of("wurst:1px_line_strip", VertexFormats.POSITION_COLOR, + DrawMode.DEBUG_LINE_STRIP, 1536, false, true, + RenderLayer.MultiPhaseParameters.builder() + .program(RenderLayer.POSITION_COLOR_PROGRAM) + .lineWidth(new RenderPhase.LineWidth(OptionalDouble.of(1))) + .transparency(RenderLayer.TRANSLUCENT_TRANSPARENCY) + .cull(RenderLayer.DISABLE_CULLING).build(false)); + /** * Enables a new scissor box with the given coordinates, while avoiding the * strange side-effects of Minecraft's own enableScissor() method. @@ -127,6 +164,14 @@ public static void setShaderColor(float[] rgb, float opacity) RenderSystem.setShaderColor(rgb[0], rgb[1], rgb[2], opacity); } + public static int toIntColor(float[] rgb, float opacity) + { + return (int)(MathHelper.clamp(opacity, 0, 1) * 255) << 24 + | (int)(MathHelper.clamp(rgb[0], 0, 1) * 255) << 16 + | (int)(MathHelper.clamp(rgb[1], 0, 1) * 255) << 8 + | (int)(MathHelper.clamp(rgb[2], 0, 1) * 255); + } + public static void drawSolidBox(MatrixStack matrixStack) { drawSolidBox(DEFAULT_BOX, matrixStack); @@ -762,4 +807,111 @@ public static void drawItem(DrawContext context, ItemStack stack, int x, RenderSystem.setShaderColor(1, 1, 1, 1); } + + /** + * Similar to {@link DrawContext#fill(int, int, int, int, int)}, but uses + * floating-point coordinates instead of integers. + */ + public static void fill2D(DrawContext context, float x1, float y1, float x2, + float y2, int color) + { + Matrix4f matrix = context.getMatrices().peek().getPositionMatrix(); + context.draw(consumers -> { + VertexConsumer buffer = consumers.getBuffer(RenderLayer.getGui()); + buffer.vertex(matrix, x1, y1, 0).color(color); + buffer.vertex(matrix, x1, y2, 0).color(color); + buffer.vertex(matrix, x2, y2, 0).color(color); + buffer.vertex(matrix, x2, y1, 0).color(color); + }); + } + + /** + * Renders the given vertices in QUADS draw mode. + * + * @apiNote Due to back-face culling, quads will be invisible if their + * vertices are not supplied in counter-clockwise order. + */ + public static void fillQuads2D(DrawContext context, float[][] vertices, + int color) + { + Matrix4f matrix = context.getMatrices().peek().getPositionMatrix(); + context.draw(consumers -> { + VertexConsumer buffer = consumers.getBuffer(RenderLayer.getGui()); + for(float[] vertex : vertices) + buffer.vertex(matrix, vertex[0], vertex[1], 0).color(color); + }); + } + + /** + * Renders the given vertices in TRIANGLE_STRIP draw mode. + * + * @apiNote Due to back-face culling, triangles will be invisible if their + * vertices are not supplied in counter-clockwise order. + */ + public static void fillTriangle2D(DrawContext context, float[][] vertices, + int color) + { + Matrix4f matrix = context.getMatrices().peek().getPositionMatrix(); + context.draw(consumers -> { + VertexConsumer buffer = + consumers.getBuffer(RenderLayer.getDebugFilledBox()); + for(float[] vertex : vertices) + buffer.vertex(matrix, vertex[0], vertex[1], 0).color(color); + }); + } + + /** + * Similar to {@link DrawContext#drawHorizontalLine(int, int, int, int)} and + * {@link DrawContext#drawVerticalLine(int, int, int, int)}, but supports + * diagonal lines, uses floating-point coordinates instead of integers, is + * one actual pixel wide instead of one scaled pixel, uses fewer draw calls + * than the vanilla method, and uses a z value of 1 to ensure that lines + * show up above fills. + */ + public static void drawLine2D(DrawContext context, float x1, float y1, + float x2, float y2, int color) + { + Matrix4f matrix = context.getMatrices().peek().getPositionMatrix(); + context.draw(consumers -> { + VertexConsumer buffer = consumers.getBuffer(ONE_PIXEL_LINES); + buffer.vertex(matrix, x1, y1, 1).color(color); + buffer.vertex(matrix, x2, y2, 1).color(color); + }); + } + + /** + * Similar to {@link DrawContext#drawBorder(int, int, int, int, int)}, but + * uses floating-point coordinates instead of integers, is one actual pixel + * wide instead of one scaled pixel, uses fewer draw calls than the vanilla + * method, and uses a z value of 1 to ensure that lines show up above fills. + */ + public static void drawBorder2D(DrawContext context, float x1, float y1, + float x2, float y2, int color) + { + Matrix4f matrix = context.getMatrices().peek().getPositionMatrix(); + context.draw(consumers -> { + VertexConsumer buffer = consumers.getBuffer(ONE_PIXEL_LINE_STRIP); + buffer.vertex(matrix, x1, y1, 1).color(color); + buffer.vertex(matrix, x2, y1, 1).color(color); + buffer.vertex(matrix, x2, y2, 1).color(color); + buffer.vertex(matrix, x1, y2, 1).color(color); + buffer.vertex(matrix, x1, y1, 1).color(color); + }); + } + + /** + * Draws a 1px border around the given polygon. + */ + public static void drawLineStrip2D(DrawContext context, float[][] vertices, + int color) + { + Matrix4f matrix = context.getMatrices().peek().getPositionMatrix(); + context.draw(consumers -> { + VertexConsumer buffer = consumers.getBuffer(ONE_PIXEL_LINE_STRIP); + for(float[] vertex : vertices) + buffer.vertex(matrix, vertex[0], vertex[1], 1).color(color); + buffer.vertex(matrix, vertices[0][0], vertices[0][1], 1) + .color(color); + }); + } }