From 30df910cf3b2f5b0683ce01e391c35829d8a5850 Mon Sep 17 00:00:00 2001 From: nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> Date: Wed, 20 Apr 2022 13:46:50 +0100 Subject: hella gui stuff --- .../oneconfig/command/OneConfigCommand.java | 5 +- .../oneconfig/config/OneConfigConfig.java | 39 +++- .../java/io/polyfrost/oneconfig/gui/HudGui.java | 248 +++++++++++++++++++++ .../io/polyfrost/oneconfig/gui/OneConfigGui.java | 47 ++++ .../oneconfig/gui/elements/BasicElement.java | 94 ++++++++ .../io/polyfrost/oneconfig/hud/gui/HudGui.java | 248 --------------------- .../polyfrost/oneconfig/lwjgl/RenderManager.java | 44 ++++ .../oneconfig/lwjgl/font/FontManager.java | 2 + .../io/polyfrost/oneconfig/utils/ColorUtils.java | 58 +++++ .../io/polyfrost/oneconfig/utils/MathUtils.java | 4 +- 10 files changed, 536 insertions(+), 253 deletions(-) create mode 100644 src/main/java/io/polyfrost/oneconfig/gui/HudGui.java create mode 100644 src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java create mode 100644 src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java delete mode 100644 src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java create mode 100644 src/main/java/io/polyfrost/oneconfig/utils/ColorUtils.java (limited to 'src') diff --git a/src/main/java/io/polyfrost/oneconfig/command/OneConfigCommand.java b/src/main/java/io/polyfrost/oneconfig/command/OneConfigCommand.java index b210146..f792ee7 100644 --- a/src/main/java/io/polyfrost/oneconfig/command/OneConfigCommand.java +++ b/src/main/java/io/polyfrost/oneconfig/command/OneConfigCommand.java @@ -1,6 +1,7 @@ package io.polyfrost.oneconfig.command; -import io.polyfrost.oneconfig.hud.gui.HudGui; +import io.polyfrost.oneconfig.gui.HudGui; +import io.polyfrost.oneconfig.gui.OneConfigGui; import io.polyfrost.oneconfig.test.TestNanoVGGui; import io.polyfrost.oneconfig.utils.TickDelay; import net.minecraft.client.Minecraft; @@ -34,7 +35,7 @@ public class OneConfigCommand extends CommandBase { @Override public void processCommand(ICommandSender sender, String[] args) { - if (args.length == 0) ; //new TickDelay(() -> mc.displayGuiScreen(new Window()), 1); + if (args.length == 0) new TickDelay(() -> mc.displayGuiScreen(new OneConfigGui()), 1); else { switch (args[0]) { case "hud": diff --git a/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java b/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java index b46c65d..570d379 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java +++ b/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java @@ -4,12 +4,47 @@ import com.google.gson.JsonParser; import io.polyfrost.oneconfig.config.data.ModData; import io.polyfrost.oneconfig.config.interfaces.Config; +import java.awt.*; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; public class OneConfigConfig extends Config { public static String currentProfile = "Default Profile"; + // TODO i dont know how this works so this is just gonna be here for now + public static int TRANSPARENT = new Color(0,0,0,0).getRGB(); // Transparent // button sidebar normal + + public static int GRAY_900 = new Color(13, 14, 15, 255).getRGB(); // Gray 900 + public static int GRAY_900_80 = new Color(13, 14, 15, 204).getRGB(); // Gray 900 80% + // im waiting for u to say the gray button colors + public static int GRAY_800 = new Color(21, 22, 23, 255).getRGB(); // Gray 800 + public static int GRAY_700 = new Color(34, 35, 38, 255).getRGB(); // Gray 700 + public static int GRAY_600 = new Color(42, 44, 48, 255).getRGB(); // Gray 600 + public static int GRAY_500 = new Color(49, 51, 56, 255).getRGB(); // Gray 500 // button sidebar hover, button gray normal + public static int GRAY_500_80 = new Color(49, 51, 56, 204).getRGB(); // Gray 500 80% // button sidebar pressed + + public static int GRAY_400 = new Color(55, 59, 69, 255).getRGB(); // Gray 400 // button gray hover + public static int GRAY_400_80 = new Color(55, 59, 69, 204).getRGB(); // Gray 400 80% // button gray pressed + public static int BLUE_700 = new Color(18, 71, 178, 255).getRGB(); // Blue 700 // button blue normal + public static int BLUE_600 = new Color(20, 82, 204, 255).getRGB(); // Blue 600 + public static int BLUE_500 = new Color(25, 103, 255, 255).getRGB(); // Blue 500 + public static int WHITE_60 = new Color(255, 255, 255, 153).getRGB(); // White 60% + public static int WHITE_90 = new Color(255, 255, 255, 229).getRGB(); // White 90% + public static int WHITE = new Color(255, 255, 255, 255).getRGB(); // White 100% + + public static boolean ROUNDED_CORNERS = true; + public static float CORNER_RADIUS_WIN = 20f; + public static float CORNER_RADIUS = 12f; + + + + + + + + public OneConfigConfig() { super(null, "OneConfig.json"); } @@ -22,7 +57,7 @@ public class OneConfigConfig extends Config { @Override public void save() { - try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("OneConfig/" + configFile), StandardCharsets.UTF_8))) { + try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(Paths.get("OneConfig/" + configFile)), StandardCharsets.UTF_8))) { writer.write(gson.toJson(this.getClass())); } catch (IOException e) { e.printStackTrace(); @@ -31,7 +66,7 @@ public class OneConfigConfig extends Config { @Override public void load() { - try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("OneConfig/" + configFile), StandardCharsets.UTF_8))) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(Paths.get("OneConfig/" + configFile)), StandardCharsets.UTF_8))) { deserializePart(new JsonParser().parse(reader).getAsJsonObject(), this.getClass()); } catch (IOException e) { e.printStackTrace(); diff --git a/src/main/java/io/polyfrost/oneconfig/gui/HudGui.java b/src/main/java/io/polyfrost/oneconfig/gui/HudGui.java new file mode 100644 index 0000000..77521f9 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/gui/HudGui.java @@ -0,0 +1,248 @@ +package io.polyfrost.oneconfig.gui; + +import io.polyfrost.oneconfig.hud.HudCore; +import io.polyfrost.oneconfig.hud.interfaces.BasicHud; +import io.polyfrost.oneconfig.lwjgl.RenderManager; +import io.polyfrost.oneconfig.test.TestHud; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiScreen; +import org.lwjgl.input.Keyboard; + +import java.awt.*; +import java.io.IOException; +import java.util.ArrayList; + +public class HudGui extends GuiScreen { + private BasicHud editingHud; + private boolean isDragging; + private boolean isScaling; + private int xOffset; + private int yOffset; + + @Override + public void initGui() { + HudCore.editing = true; + Keyboard.enableRepeatEvents(true); + for (BasicHud hud : HudCore.huds) { + hud.childBottom = new TestHud(); + hud.childBottom.parent = hud; + hud.childRight = new TestHud(); + hud.childRight.parent = hud; + } + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + Gui.drawRect(0, 0, this.width, this.height, new Color(80, 80, 80, 50).getRGB()); + + if (isDragging) { + setPosition(mouseX - xOffset, mouseY - yOffset, true); + } + + for (BasicHud hud : HudCore.huds) { + if (hud == editingHud && isScaling) { + float xFloat = hud.getXScaled(this.width); + float yFloat = hud.getYScaled(this.height); + float pos = getXSnapping(mouseX, true); + float newWidth = pos - xFloat; + float newScale = newWidth / ((hud.getWidth(hud.scale) + hud.paddingX * hud.scale) / hud.scale); + if (newScale > 20) + newScale = 20; + else if (newScale < 0.3) + newScale = 0.3f; + hud.scale = newScale; + + if (xFloat / this.width > 0.5) + editingHud.xUnscaled = (xFloat + (hud.getWidth(hud.scale) + hud.paddingX * hud.scale)) / (double) this.width; + if (yFloat / this.height > 0.5) + editingHud.yUnscaled = (yFloat + (hud.getHeight(hud.scale) + hud.paddingY * hud.scale)) / (double) this.height; + } + + int width = (int) (hud.getWidth(hud.scale) + hud.paddingX * hud.scale); + int height = (int) (hud.getHeight(hud.scale) + hud.paddingY * hud.scale); + int x = (int) hud.getXScaled(this.width); + int y = (int) hud.getYScaled(this.height); + + hud.drawExampleAll(x, y, hud.scale, true); + int color = new Color(215, 224, 235).getRGB(); + if (editingHud == hud) { + color = new Color(43, 159, 235).getRGB(); + if (isDragging) + Gui.drawRect(x, y, x + width, y + height, new Color(108, 176, 255, 60).getRGB()); + } + int finalColor = color; + RenderManager.setupAndDraw(true, (vg) -> { + RenderManager.drawLine(vg, x - 2 / 4f, y, x + width + 2 / 4f, y, 1, finalColor); + RenderManager.drawLine(vg, x, y, x, y + height, 1, finalColor); + RenderManager.drawLine(vg, x + width, y, x + width, y + height, 1, finalColor); + RenderManager.drawLine(vg, x - 2 / 4f, y + height, x + width + 2 / 4f, y + height, 1, finalColor); + }); + + if (hud == editingHud && !isDragging) { + Gui.drawRect(x + width - 3, y + height - 3, x + width + 3, y + height + 3, new Color(43, 159, 235).getRGB()); + Gui.drawRect(x + width - 2, y + height - 2, x + width + 2, y + height + 2, new Color(252, 252, 252).getRGB()); + } + } + } + + private void setPosition(float newX, float newY, boolean snap) { + float width = editingHud.getWidth(editingHud.scale) + editingHud.paddingX * editingHud.scale; + float height = editingHud.getHeight(editingHud.scale) + editingHud.paddingY * editingHud.scale; + + if (newX < 0) + newX = 0; + else if (newX + width > this.width) + newX = this.width - width; + if (newY < 0) + newY = 0; + else if (newY + height > this.height) + newY = this.height - height; + + if (snap) { + newX = getXSnapping(newX, false); + newY = getYSnapping(newY); + } + + if (newX / this.width <= 0.5) + editingHud.xUnscaled = newX / (double) this.width; + else + editingHud.xUnscaled = (newX + width) / (double) this.width; + if (newY / this.height <= 0.5) + editingHud.yUnscaled = newY / (double) this.height; + else + editingHud.yUnscaled = (newY + height) / (double) this.height; + } + + private float getXSnapping(float pos, boolean rightOnly) { + float width = editingHud.getWidth(editingHud.scale) + editingHud.paddingX * editingHud.scale; + ArrayList verticalLines = new ArrayList<>(); + verticalLines.add(this.width / 2f); + for (BasicHud hud : HudCore.huds) { + if (hud == editingHud) continue; + int hudWidth = (int) (hud.getWidth(hud.scale) + hud.paddingX * hud.scale); + int hudX = (int) hud.getXScaled(this.width); + verticalLines.add((float) hudX); + verticalLines.add((float) (hudX + hudWidth)); + verticalLines.add(hudX + hudWidth / 2f); + } + float smallestDiff = -1; + float smallestLine = 0; + float smallestOffset = 0; + for (float lineX : verticalLines) { + for (float offset = 0; offset <= (rightOnly ? 0 : width); offset += width / 2f) { + if (Math.abs(lineX - pos - offset) < 5 && (Math.abs(lineX - pos - offset) < smallestDiff || smallestDiff == -1)) { + smallestDiff = Math.abs(lineX - pos); + smallestLine = lineX; + smallestOffset = offset; + } + } + } + if (smallestDiff != -1) { + RenderManager.drawDottedLine(smallestLine, 0, smallestLine, this.height, 2, 12, new Color(255, 255, 255).getRGB()); + return smallestLine - smallestOffset; + } + return pos; + } + + private float getYSnapping(float pos) { + float height = editingHud.getHeight(editingHud.scale) + editingHud.paddingY * editingHud.scale; + ArrayList horizontalLines = new ArrayList<>(); + horizontalLines.add(this.height / 2f); + for (BasicHud hud : HudCore.huds) { + if (hud == editingHud) continue; + int hudHeight = (int) (hud.getHeight(hud.scale) + hud.paddingY * hud.scale); + int hudY = (int) hud.getYScaled(this.height); + horizontalLines.add((float) hudY); + horizontalLines.add((float) (hudY + hudHeight)); + horizontalLines.add(hudY + hudHeight / 2f); + } + float smallestDiff = -1; + float smallestLine = 0; + float smallestOffset = 0; + for (float lineY : horizontalLines) { + for (float offset = 0; offset <= height; offset += height / 2f) { + if (Math.abs(lineY - pos - offset) < 5 && (Math.abs(lineY - pos - offset) < smallestDiff || smallestDiff == -1)) { + smallestDiff = Math.abs(lineY - pos); + smallestLine = lineY; + smallestOffset = offset; + } + } + } + if (smallestDiff != -1) { + RenderManager.drawDottedLine(0, smallestLine, this.width, smallestLine, 2, 12, new Color(255, 255, 255).getRGB()); + return smallestLine - smallestOffset; + } + return pos; + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) { + if (mouseButton == 0) { + if (editingHud != null) { + int width = (int) (editingHud.getWidth(editingHud.scale) + editingHud.paddingX * editingHud.scale); + int height = (int) (editingHud.getHeight(editingHud.scale) + editingHud.paddingY * editingHud.scale); + float x = editingHud.getXScaled(this.width); + float y = editingHud.getYScaled(this.height); + if (mouseX >= x + width - 3 && mouseX <= x + width + 3 && mouseY >= y + height - 3 && mouseY <= y + height + 3) { + isScaling = true; + return; + } + } + editingHud = null; + for (BasicHud hud : HudCore.huds) { + int width = (int) (hud.getWidth(hud.scale) + hud.paddingX * hud.scale); + int height = (int) (hud.getHeight(hud.scale) + hud.paddingY * hud.scale); + float x = hud.getXScaled(this.width); + float y = hud.getYScaled(this.height); + if (mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height) { + editingHud = hud; + xOffset = (int) (mouseX - x); + yOffset = (int) (mouseY - y); + isDragging = true; + break; + } + } + } + } + + @Override + protected void mouseReleased(int mouseX, int mouseY, int state) { + isDragging = false; + isScaling = false; + } + + @Override + protected void keyTyped(char typedChar, int keyCode) throws IOException { + if (editingHud != null) { + float x = editingHud.getXScaled(this.width); + float y = editingHud.getYScaled(this.height); + switch (keyCode) { + case Keyboard.KEY_UP: + setPosition(x, y - 1, false); + break; + case Keyboard.KEY_DOWN: + setPosition(x, y + 1, false); + break; + case Keyboard.KEY_LEFT: + setPosition(x - 1, y, false); + break; + case Keyboard.KEY_RIGHT: + setPosition(x + 1, y, false); + break; + } + } + super.keyTyped(typedChar, keyCode); + } + + @Override + public void onGuiClosed() { + HudCore.editing = false; + Keyboard.enableRepeatEvents(false); + } + + @Override + public boolean doesGuiPauseGame() { + return false; + } +} \ No newline at end of file diff --git a/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java new file mode 100644 index 0000000..cbe1c6a --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java @@ -0,0 +1,47 @@ +package io.polyfrost.oneconfig.gui; + +import io.polyfrost.oneconfig.OneConfig; +import io.polyfrost.oneconfig.config.OneConfigConfig; +import io.polyfrost.oneconfig.gui.elements.BasicElement; +import io.polyfrost.oneconfig.lwjgl.RenderManager; +import net.minecraft.client.gui.GuiScreen; + +import java.awt.*; + +public class OneConfigGui extends GuiScreen { + private final BasicElement element = new BasicElement(200, 200, 1, true); + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + super.drawScreen(mouseX, mouseY, partialTicks); + RenderManager.setupAndDraw((vg) -> { + if(OneConfigConfig.ROUNDED_CORNERS) { + RenderManager.drawRoundedRect(vg, 544, 140, 1056, 800, OneConfigConfig.GRAY_800, OneConfigConfig.CORNER_RADIUS_WIN); + RenderManager.drawRoundedRect(vg, 320, 140, 244, 800, OneConfigConfig.GRAY_900_80, OneConfigConfig.CORNER_RADIUS_WIN); + RenderManager.drawRect(vg, 544, 140, 20, 800, OneConfigConfig.GRAY_800); + } else { + // L; + } + + RenderManager.drawLine(vg, 544, 212, 1600, 212, 1, OneConfigConfig.GRAY_700); + RenderManager.drawLine(vg, 544, 140, 544, 940, 1, OneConfigConfig.GRAY_700); + + RenderManager.drawString(vg, "OneConfig", 389, 163, OneConfigConfig.WHITE, 18f, "inter-bold"); + RenderManager.drawString(vg, "By Polyfrost", 389, 183, OneConfigConfig.WHITE, 12f, "inter-regular"); + element.setColorPalette(0); + element.draw(vg, 0, 0); + + //RenderManager.drawGradientRoundedRect(vg, 100, 100, 500, 100, OneConfigConfig.BLUE_600, OneConfigConfig.BLUE_500, OneConfigConfig.CORNER_RADIUS_WIN); + + + + }); + } + + + @Override + public boolean doesGuiPauseGame() { + return false; + } + +} diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java new file mode 100644 index 0000000..0b7d604 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java @@ -0,0 +1,94 @@ +package io.polyfrost.oneconfig.gui.elements; + +import io.polyfrost.oneconfig.lwjgl.RenderManager; +import io.polyfrost.oneconfig.utils.ColorUtils; +import net.minecraft.client.Minecraft; +import org.lwjgl.input.Mouse; + +public class BasicElement { + private int width; + private int height; + private int colorPalette; + + private int hitBoxX, hitBoxY; + + private final boolean hoverFx; + + private boolean hovered = false; + private boolean clicked = false; + private boolean toggled = false; + + private int currentColor; + + public BasicElement(int width, int height, int colorPalette, boolean hoverFx) { + this.height = height; + this.width = width; + this.colorPalette = colorPalette; + this.hoverFx = hoverFx; + } + + public BasicElement(int width, int height, boolean hoverFx) { + this.height = height; + this.width = width; + this.colorPalette = -1; + this.hoverFx = hoverFx; + } + + + public void draw(long vg, int x, int y) { + RenderManager.drawRectangle(vg, x, y, width, height, currentColor); + int mouseX = Mouse.getX(); + int mouseY = Minecraft.getMinecraft().displayHeight - Math.abs(Mouse.getY()); + int buttonRight = x + width; + int buttonBottom = y + height; + + hovered = mouseX > x - hitBoxX && mouseY > y - hitBoxY && mouseX < buttonRight + hitBoxX && mouseY < buttonBottom + hitBoxY; + if (Mouse.isButtonDown(0) && clicked) { + toggled = !toggled; + } + clicked = Mouse.isButtonDown(0) && hovered; + + if (hoverFx) { + currentColor = ColorUtils.getColor(currentColor, colorPalette, hovered, clicked); + } + } + + + public void setCustomHitbox(int x, int y) { + hitBoxX = x; + hitBoxY = y; + } + + public void setWidth(int width) { + this.width = width; + } + + public void setHeight(int height) { + this.height = height; + } + + public void setColorPalette(int colorPalette) { + this.colorPalette = colorPalette; + } + + public int getWidth() { + return width; + } + + public int getHeight() { + return height; + } + + public boolean isHovered() { + return hovered; + } + + public boolean isClicked() { + return clicked; + } + + public boolean isToggled() { + return toggled; + } + +} diff --git a/src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java b/src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java deleted file mode 100644 index 22121b7..0000000 --- a/src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java +++ /dev/null @@ -1,248 +0,0 @@ -package io.polyfrost.oneconfig.hud.gui; - -import io.polyfrost.oneconfig.hud.HudCore; -import io.polyfrost.oneconfig.hud.interfaces.BasicHud; -import io.polyfrost.oneconfig.lwjgl.RenderManager; -import io.polyfrost.oneconfig.test.TestHud; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.GuiScreen; -import org.lwjgl.input.Keyboard; - -import java.awt.*; -import java.io.IOException; -import java.util.ArrayList; - -public class HudGui extends GuiScreen { - private BasicHud editingHud; - private boolean isDragging; - private boolean isScaling; - private int xOffset; - private int yOffset; - - @Override - public void initGui() { - HudCore.editing = true; - Keyboard.enableRepeatEvents(true); - for (BasicHud hud : HudCore.huds) { - hud.childBottom = new TestHud(); - hud.childBottom.parent = hud; - hud.childRight = new TestHud(); - hud.childRight.parent = hud; - } - } - - @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { - Gui.drawRect(0, 0, this.width, this.height, new Color(80, 80, 80, 50).getRGB()); - - if (isDragging) { - setPosition(mouseX - xOffset, mouseY - yOffset, true); - } - - for (BasicHud hud : HudCore.huds) { - if (hud == editingHud && isScaling) { - float xFloat = hud.getXScaled(this.width); - float yFloat = hud.getYScaled(this.height); - float pos = getXSnapping(mouseX, true); - float newWidth = pos - xFloat; - float newScale = newWidth / ((hud.getWidth(hud.scale) + hud.paddingX * hud.scale) / hud.scale); - if (newScale > 20) - newScale = 20; - else if (newScale < 0.3) - newScale = 0.3f; - hud.scale = newScale; - - if (xFloat / this.width > 0.5) - editingHud.xUnscaled = (xFloat + (hud.getWidth(hud.scale) + hud.paddingX * hud.scale)) / (double) this.width; - if (yFloat / this.height > 0.5) - editingHud.yUnscaled = (yFloat + (hud.getHeight(hud.scale) + hud.paddingY * hud.scale)) / (double) this.height; - } - - int width = (int) (hud.getWidth(hud.scale) + hud.paddingX * hud.scale); - int height = (int) (hud.getHeight(hud.scale) + hud.paddingY * hud.scale); - int x = (int) hud.getXScaled(this.width); - int y = (int) hud.getYScaled(this.height); - - hud.drawExampleAll(x, y, hud.scale, true); - int color = new Color(215, 224, 235).getRGB(); - if (editingHud == hud) { - color = new Color(43, 159, 235).getRGB(); - if (isDragging) - Gui.drawRect(x, y, x + width, y + height, new Color(108, 176, 255, 60).getRGB()); - } - int finalColor = color; - RenderManager.setupAndDraw(true, (vg) -> { - RenderManager.drawLine(vg, x - 2 / 4f, y, x + width + 2 / 4f, y, 1, finalColor); - RenderManager.drawLine(vg, x, y, x, y + height, 1, finalColor); - RenderManager.drawLine(vg, x + width, y, x + width, y + height, 1, finalColor); - RenderManager.drawLine(vg, x - 2 / 4f, y + height, x + width + 2 / 4f, y + height, 1, finalColor); - }); - - if (hud == editingHud && !isDragging) { - Gui.drawRect(x + width - 3, y + height - 3, x + width + 3, y + height + 3, new Color(43, 159, 235).getRGB()); - Gui.drawRect(x + width - 2, y + height - 2, x + width + 2, y + height + 2, new Color(252, 252, 252).getRGB()); - } - } - } - - private void setPosition(float newX, float newY, boolean snap) { - float width = editingHud.getWidth(editingHud.scale) + editingHud.paddingX * editingHud.scale; - float height = editingHud.getHeight(editingHud.scale) + editingHud.paddingY * editingHud.scale; - - if (newX < 0) - newX = 0; - else if (newX + width > this.width) - newX = this.width - width; - if (newY < 0) - newY = 0; - else if (newY + height > this.height) - newY = this.height - height; - - if (snap) { - newX = getXSnapping(newX, false); - newY = getYSnapping(newY); - } - - if (newX / this.width <= 0.5) - editingHud.xUnscaled = newX / (double) this.width; - else - editingHud.xUnscaled = (newX + width) / (double) this.width; - if (newY / this.height <= 0.5) - editingHud.yUnscaled = newY / (double) this.height; - else - editingHud.yUnscaled = (newY + height) / (double) this.height; - } - - private float getXSnapping(float pos, boolean rightOnly) { - float width = editingHud.getWidth(editingHud.scale) + editingHud.paddingX * editingHud.scale; - ArrayList verticalLines = new ArrayList<>(); - verticalLines.add(this.width / 2f); - for (BasicHud hud : HudCore.huds) { - if (hud == editingHud) continue; - int hudWidth = (int) (hud.getWidth(hud.scale) + hud.paddingX * hud.scale); - int hudX = (int) hud.getXScaled(this.width); - verticalLines.add((float) hudX); - verticalLines.add((float) (hudX + hudWidth)); - verticalLines.add(hudX + hudWidth / 2f); - } - float smallestDiff = -1; - float smallestLine = 0; - float smallestOffset = 0; - for (float lineX : verticalLines) { - for (float offset = 0; offset <= (rightOnly ? 0 : width); offset += width / 2f) { - if (Math.abs(lineX - pos - offset) < 5 && (Math.abs(lineX - pos - offset) < smallestDiff || smallestDiff == -1)) { - smallestDiff = Math.abs(lineX - pos); - smallestLine = lineX; - smallestOffset = offset; - } - } - } - if (smallestDiff != -1) { - RenderManager.drawDottedLine(smallestLine, 0, smallestLine, this.height, 2, 12, new Color(255, 255, 255).getRGB()); - return smallestLine - smallestOffset; - } - return pos; - } - - private float getYSnapping(float pos) { - float height = editingHud.getHeight(editingHud.scale) + editingHud.paddingY * editingHud.scale; - ArrayList horizontalLines = new ArrayList<>(); - horizontalLines.add(this.height / 2f); - for (BasicHud hud : HudCore.huds) { - if (hud == editingHud) continue; - int hudHeight = (int) (hud.getHeight(hud.scale) + hud.paddingY * hud.scale); - int hudY = (int) hud.getYScaled(this.height); - horizontalLines.add((float) hudY); - horizontalLines.add((float) (hudY + hudHeight)); - horizontalLines.add(hudY + hudHeight / 2f); - } - float smallestDiff = -1; - float smallestLine = 0; - float smallestOffset = 0; - for (float lineY : horizontalLines) { - for (float offset = 0; offset <= height; offset += height / 2f) { - if (Math.abs(lineY - pos - offset) < 5 && (Math.abs(lineY - pos - offset) < smallestDiff || smallestDiff == -1)) { - smallestDiff = Math.abs(lineY - pos); - smallestLine = lineY; - smallestOffset = offset; - } - } - } - if (smallestDiff != -1) { - RenderManager.drawDottedLine(0, smallestLine, this.width, smallestLine, 2, 12, new Color(255, 255, 255).getRGB()); - return smallestLine - smallestOffset; - } - return pos; - } - - @Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton) { - if (mouseButton == 0) { - if (editingHud != null) { - int width = (int) (editingHud.getWidth(editingHud.scale) + editingHud.paddingX * editingHud.scale); - int height = (int) (editingHud.getHeight(editingHud.scale) + editingHud.paddingY * editingHud.scale); - float x = editingHud.getXScaled(this.width); - float y = editingHud.getYScaled(this.height); - if (mouseX >= x + width - 3 && mouseX <= x + width + 3 && mouseY >= y + height - 3 && mouseY <= y + height + 3) { - isScaling = true; - return; - } - } - editingHud = null; - for (BasicHud hud : HudCore.huds) { - int width = (int) (hud.getWidth(hud.scale) + hud.paddingX * hud.scale); - int height = (int) (hud.getHeight(hud.scale) + hud.paddingY * hud.scale); - float x = hud.getXScaled(this.width); - float y = hud.getYScaled(this.height); - if (mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height) { - editingHud = hud; - xOffset = (int) (mouseX - x); - yOffset = (int) (mouseY - y); - isDragging = true; - break; - } - } - } - } - - @Override - protected void mouseReleased(int mouseX, int mouseY, int state) { - isDragging = false; - isScaling = false; - } - - @Override - protected void keyTyped(char typedChar, int keyCode) throws IOException { - if (editingHud != null) { - float x = editingHud.getXScaled(this.width); - float y = editingHud.getYScaled(this.height); - switch (keyCode) { - case Keyboard.KEY_UP: - setPosition(x, y - 1, false); - break; - case Keyboard.KEY_DOWN: - setPosition(x, y + 1, false); - break; - case Keyboard.KEY_LEFT: - setPosition(x - 1, y, false); - break; - case Keyboard.KEY_RIGHT: - setPosition(x + 1, y, false); - break; - } - } - super.keyTyped(typedChar, keyCode); - } - - @Override - public void onGuiClosed() { - HudCore.editing = false; - Keyboard.enableRepeatEvents(false); - } - - @Override - public boolean doesGuiPauseGame() { - return false; - } -} \ No newline at end of file diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java index dcfc348..d728670 100644 --- a/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java +++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java @@ -1,5 +1,6 @@ package io.polyfrost.oneconfig.lwjgl; +import io.polyfrost.oneconfig.config.OneConfigConfig; import io.polyfrost.oneconfig.lwjgl.font.Font; import io.polyfrost.oneconfig.lwjgl.font.FontManager; import io.polyfrost.oneconfig.lwjgl.image.Image; @@ -63,6 +64,48 @@ public final class RenderManager { GlStateManager.popAttrib(); } + public static void drawRectangle(long vg, float x, float y, float width, float height, int color) { + if(OneConfigConfig.ROUNDED_CORNERS) { + drawRoundedRect(vg, x, y, width, height, color, OneConfigConfig.CORNER_RADIUS); + } else { + drawRect(vg, x, y, width, height, color); + } + } + + public static void drawGradientRectangle(long vg, float x, float y, float width, float height, int color1, int color2) { + if(OneConfigConfig.ROUNDED_CORNERS) { + drawGradientRoundedRect(vg, x, y, width, height, color1, color2, OneConfigConfig.CORNER_RADIUS); + } else { + drawGradientRect(vg, x, y, width, height, color1, color2); + } + } + + public static void drawGradientRoundedRect(long vg, float x, float y, float width, float height, int color, int color2, float radius) { + NVGPaint bg = NVGPaint.create(); + nvgBeginPath(vg); + nvgRoundedRect(vg, x, y, width, height, radius); + NVGColor nvgColor = color(vg, color); + NVGColor nvgColor2 = color(vg, color2); + nvgFillPaint(vg, nvgLinearGradient(vg, x, y + height, x + width, y, nvgColor, nvgColor2, bg)); // like the gradient is blocky + nvgFillPaint(vg, bg); + nvgFill(vg); + nvgColor.free(); + nvgColor2.free(); + } + + public static void drawGradientRect(long vg, float x, float y, float width, float height, int color, int color2) { + NVGPaint bg = NVGPaint.create(); + nvgBeginPath(vg); + nvgRect(vg, x, y, width, height); + NVGColor nvgColor = color(vg, color); + NVGColor nvgColor2 = color(vg, color2); + nvgFillPaint(vg, nvgLinearGradient(vg, x, y + height, x + width, y, nvgColor, nvgColor2, bg)); // like the gradient is blocky + nvgFillPaint(vg, bg); + nvgFill(vg); + nvgColor.free(); + nvgColor2.free(); + } + public static void drawRect(long vg, float x, float y, float width, float height, int color) { nvgBeginPath(vg); nvgRect(vg, x, y, width, height); @@ -184,6 +227,7 @@ public final class RenderManager { nvgColor.free(); } + public static NVGColor color(long vg, int color) { NVGColor nvgColor = NVGColor.calloc(); nvgRGBA((byte) (color >> 16 & 0xFF), (byte) (color >> 8 & 0xFF), (byte) (color & 0xFF), (byte) (color >> 24 & 0xFF), nvgColor); diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/font/FontManager.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/font/FontManager.java index 20a8cc7..08d108b 100644 --- a/src/main/java/io/polyfrost/oneconfig/lwjgl/font/FontManager.java +++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/font/FontManager.java @@ -14,6 +14,8 @@ public class FontManager { public void initialize(long vg) { fonts.add(new Font("inter-bold", "/assets/oneconfig/font/Inter-Bold.ttf")); + fonts.add(new Font("inter-regular", "/assets/oneconfig/font/Inter-Regular.otf")); + fonts.add(new Font("inter-semibold", "/assets/oneconfig/font/Inter-SemiBold.otf")); fonts.add(new Font("mc-regular", "/assets/oneconfig/font/Minecraft-Regular.otf")); for (Font font : fonts) { int loaded = -1; diff --git a/src/main/java/io/polyfrost/oneconfig/utils/ColorUtils.java b/src/main/java/io/polyfrost/oneconfig/utils/ColorUtils.java new file mode 100644 index 0000000..f45f9a5 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/utils/ColorUtils.java @@ -0,0 +1,58 @@ +package io.polyfrost.oneconfig.utils; + +import io.polyfrost.oneconfig.config.OneConfigConfig; + +import java.awt.*; + +public class ColorUtils { + + public static int getColor(int currentColor, int colorPalette, boolean hover, boolean click) { + float[] color = splitColor(currentColor); + if(click) { + switch (colorPalette) { + case -1: + return OneConfigConfig.GRAY_500_80; + default: + case 0: + return OneConfigConfig.GRAY_400_80; + } + } + + switch (colorPalette) { + case -1: + return getColorComponents(color, splitColor(OneConfigConfig.TRANSPARENT), splitColor(OneConfigConfig.GRAY_500), hover); + default: + case 0: + return getColorComponents(color, splitColor(OneConfigConfig.GRAY_500), splitColor(OneConfigConfig.GRAY_400), hover); // OK hopefully this works + + } + + } + + private static float[] splitColor(int color) { + Color c = new Color(color, true); + return new float[] {c.getRed() / 255f, c.getGreen() / 255f, c.getBlue() / 255f, c.getAlpha() / 255f}; + } + + private static int getColorComponents(float[] currentColor, float[] initColor, float[] finalColor, boolean hover) { + currentColor[0] = smooth(currentColor[0], initColor[0], finalColor[0], hover); + currentColor[1] = smooth(currentColor[1], initColor[1], finalColor[1], hover); + currentColor[2] = smooth(currentColor[2], initColor[2], finalColor[2], hover); + currentColor[3] = smooth(currentColor[3], initColor[3], finalColor[3], hover); + + return new Color(currentColor[0], currentColor[1], currentColor[2], currentColor[3]).getRGB(); + + } + + private static float smooth(float current, float min, float max, boolean moveToFinal) { + current = MathUtils.easeOut(current, moveToFinal ? 1f : 0f); + if(current <= min) { + current = min; + } + + if(current >= max) { + current = max; + } + return current; + } +} diff --git a/src/main/java/io/polyfrost/oneconfig/utils/MathUtils.java b/src/main/java/io/polyfrost/oneconfig/utils/MathUtils.java index e2e5184..7d64170 100644 --- a/src/main/java/io/polyfrost/oneconfig/utils/MathUtils.java +++ b/src/main/java/io/polyfrost/oneconfig/utils/MathUtils.java @@ -7,9 +7,11 @@ public class MathUtils { public static float easeOut(float current, float goal) { if (Math.floor(Math.abs(goal - current) / (float) 0.01) > 0) { - return current + (goal - current) / (float) 20.0; + return current + (goal - current) / (float) 100.0; // this number here controls the speed uh oh } else { return goal; } } + + } -- cgit