From 5417c7bd2d43c306863707bb91e7c88a651a696b Mon Sep 17 00:00:00 2001 From: nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> Date: Sun, 24 Apr 2022 13:32:23 +0100 Subject: mod cards, loading of mods, fixes, and some more stuff --- .../io/polyfrost/oneconfig/utils/ColorUtils.java | 25 ++++++++++++++++++++-- .../io/polyfrost/oneconfig/utils/InputUtils.java | 16 ++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java (limited to 'src/main/java/io/polyfrost/oneconfig/utils') diff --git a/src/main/java/io/polyfrost/oneconfig/utils/ColorUtils.java b/src/main/java/io/polyfrost/oneconfig/utils/ColorUtils.java index b8d56bd..dd9a78e 100644 --- a/src/main/java/io/polyfrost/oneconfig/utils/ColorUtils.java +++ b/src/main/java/io/polyfrost/oneconfig/utils/ColorUtils.java @@ -1,6 +1,8 @@ package io.polyfrost.oneconfig.utils; import io.polyfrost.oneconfig.config.OneConfigConfig; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; import java.awt.*; @@ -10,6 +12,8 @@ public class ColorUtils { float[] color = splitColor(currentColor); if(click) { switch (colorPalette) { + case -2: + return new Color(0.9f,0.9f,0.9f,0.2f).getRGB(); case -1: return OneConfigConfig.GRAY_500_80; default: @@ -21,11 +25,13 @@ public class ColorUtils { } switch (colorPalette) { + case -2: + return getColorComponents(color, splitColor(OneConfigConfig.TRANSPARENT), new float[]{0.9f,0.9f,0.9f,0.3f}, hover, 20f); case -1: return getColorComponents(color, splitColor(OneConfigConfig.TRANSPARENT), splitColor(OneConfigConfig.GRAY_500), hover, 10f); default: case 0: - return getColorComponents(color, splitColor(OneConfigConfig.GRAY_500), splitColor(OneConfigConfig.GRAY_400), hover, 130f); + return getColorComponents(color, splitColor(OneConfigConfig.GRAY_600), splitColor(OneConfigConfig.GRAY_300), hover, 25f); case 1: return getColorComponents(color, splitColor(OneConfigConfig.BLUE_600), splitColor(OneConfigConfig.BLUE_500), hover, 150f); @@ -33,7 +39,22 @@ public class ColorUtils { } - private static float[] splitColor(int color) { + /** + * Smooths the transition of a color between two colors. + * @param currentColor the current color (also the one you want to change) + * @param direction false to move towards initColor, true to move towards finalColor + * @param speed speed of the transition + * @return currentColor but with the new color + */ + public static int smoothColor(int currentColor, int initColor, int finalColor, boolean direction, float speed) { + float[] init = splitColor(initColor); + float[] finalC = splitColor(finalColor); + float[] current = splitColor(currentColor); + return getColorComponents(current, init, finalC, direction, speed); + } + + @Contract(value = "_ -> new", pure = true) + private static float @NotNull [] splitColor(int color) { return new float[] { (color >> 16 & 255) / 255f, (color >> 8 & 255) / 255f, (color & 255) / 255f, (color >> 24 & 255) /255f }; } diff --git a/src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java b/src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java new file mode 100644 index 0000000..d5ad44b --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java @@ -0,0 +1,16 @@ +package io.polyfrost.oneconfig.utils; + +import net.minecraft.client.Minecraft; +import org.lwjgl.input.Mouse; + +public class InputUtils { + /** + * function to determine weather the mouse is currently over a specific region. Uses the current nvgScale to fix to any scale. + * @return true if mouse is over region, false if not. + */ + public static boolean isAreaHovered(int x, int y, int width, int height) { + int mouseX = Mouse.getX(); + int mouseY = Minecraft.getMinecraft().displayHeight - Math.abs(Mouse.getY()); + return mouseX > x && mouseY > y && mouseX < x + width && mouseY < y + height; // TODO add scaling info + } +} -- cgit