diff options
Diffstat (limited to 'src/main/java/io')
-rw-r--r-- | src/main/java/io/polyfrost/oneconfig/command/OneConfigCommand.java | 5 | ||||
-rw-r--r-- | src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java | 39 | ||||
-rw-r--r-- | src/main/java/io/polyfrost/oneconfig/gui/HudGui.java (renamed from src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java) | 2 | ||||
-rw-r--r-- | src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java | 47 | ||||
-rw-r--r-- | src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java | 94 | ||||
-rw-r--r-- | src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java | 44 | ||||
-rw-r--r-- | src/main/java/io/polyfrost/oneconfig/lwjgl/font/FontManager.java | 2 | ||||
-rw-r--r-- | src/main/java/io/polyfrost/oneconfig/utils/ColorUtils.java | 58 | ||||
-rw-r--r-- | src/main/java/io/polyfrost/oneconfig/utils/MathUtils.java | 4 |
9 files changed, 289 insertions, 6 deletions
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/hud/gui/HudGui.java b/src/main/java/io/polyfrost/oneconfig/gui/HudGui.java index 22121b7..77521f9 100644 --- a/src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/HudGui.java @@ -1,4 +1,4 @@ -package io.polyfrost.oneconfig.hud.gui; +package io.polyfrost.oneconfig.gui; import io.polyfrost.oneconfig.hud.HudCore; import io.polyfrost.oneconfig.hud.interfaces.BasicHud; 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/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; } } + + } |