aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/utils')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/ColorUtils.java73
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java3
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java3
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java9
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/JsonUtils.java8
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java8
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/NetworkUtils.java22
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java3
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/TickDelay.java6
9 files changed, 71 insertions, 64 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/ColorUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/ColorUtils.java
index ee9fe3e..73fd629 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/ColorUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/ColorUtils.java
@@ -7,30 +7,46 @@ import java.awt.*;
/**
* A class to help with color manipulation.
*/
-public class ColorUtils {
- /** Always returns transparent. */
+public final class ColorUtils {
+ /**
+ * Always returns transparent.
+ */
public static final int TRANSPARENT = -10;
- /** <h1>Primary Color Scheme</h1> Normal: Primary 600,<br> Hover: Primary 700,<br> Clicked: Primary 700 (80%) */
+ /**
+ * <h1>Primary Color Scheme</h1> Normal: Primary 600,<br> Hover: Primary 700,<br> Clicked: Primary 700 (80%)
+ */
public static final int PRIMARY = 1;
- /** <h1>Secondary Color Scheme</h1> Normal: Gray 500,<br> Hover: Gray 400,<br> Clicked: Gray 400 (80%) */
+ /**
+ * <h1>Secondary Color Scheme</h1> Normal: Gray 500,<br> Hover: Gray 400,<br> Clicked: Gray 400 (80%)
+ */
public static final int SECONDARY = 2;
- /** <h1>Secondary (Transparent) Color Scheme</h1> Normal: Transparent,<br> Hover: Gray rgba(229, 229, 229, 77),<br> Clicked: Gray rgba(229, 229, 229, 51) */
+ /**
+ * <h1>Secondary (Transparent) Color Scheme</h1> Normal: Transparent,<br> Hover: Gray rgba(229, 229, 229, 77),<br> Clicked: Gray rgba(229, 229, 229, 51)
+ */
public static final int SECONDARY_TRANSPARENT = 0;
- /** <h1>Tertiary Color Scheme</h1> Normal: Transparent (Text=White 90%),<br> Hover: Transparent (Text=White 100%),<br> Clicked: Transparent (Text=White 80%)
- * <h2>NOTICE this returns the text colors as it is always transparent.</h2>*/
+ /**
+ * <h1>Tertiary Color Scheme</h1> Normal: Transparent (Text=White 90%),<br> Hover: Transparent (Text=White 100%),<br> Clicked: Transparent (Text=White 80%)
+ * <h2>NOTICE this returns the text colors as it is always transparent.</h2>
+ */
public static final int TERTIARY = 3;
- /** <h1>Primary Destructive Color Scheme</h1> Normal: Error 700,<br> Hover: Error 600,<br> Clicked: Error 600 (80%) */
+ /**
+ * <h1>Primary Destructive Color Scheme</h1> Normal: Error 700,<br> Hover: Error 600,<br> Clicked: Error 600 (80%)
+ */
public static final int PRIMARY_DESTRUCTIVE = -1;
- /** <h1>Secondary Destructive Color Scheme</h1> Normal: Gray 500,<br> Hover: Error 800,<br> Clicked: Error 800 (80%) */
+ /**
+ * <h1>Secondary Destructive Color Scheme</h1> Normal: Gray 500,<br> Hover: Error 800,<br> Clicked: Error 800 (80%)
+ */
public static final int SECONDARY_DESTRUCTIVE = -2;
- /** <h1>Tertiary Destructive Color Scheme</h1> Normal: Transparent (Text=White 90%),<br> Hover: Transparent (Text=Error 300),<br> Clicked: Transparent (Text=Error 300 80%)
- * <h2>NOTICE this returns the text colors as it is always transparent.</h2>*/
+ /**
+ * <h1>Tertiary Destructive Color Scheme</h1> Normal: Transparent (Text=White 90%),<br> Hover: Transparent (Text=Error 300),<br> Clicked: Transparent (Text=Error 300 80%)
+ * <h2>NOTICE this returns the text colors as it is always transparent.</h2>
+ */
public static final int TERTIARY_DESTRUCTIVE = -3;
public static int getColor(int currentColor, int colorPalette, boolean hover, boolean click) {
float[] color = splitColor(currentColor);
- if(colorPalette == TRANSPARENT) {
+ if (colorPalette == TRANSPARENT) {
return OneConfigConfig.TRANSPARENT;
}
if (click) {
@@ -55,10 +71,10 @@ public class ColorUtils {
switch (colorPalette) {
case SECONDARY_TRANSPARENT: // Formally -2
- return getColorComponents(color, new float[]{0f,0f,0f,0f}, new float[]{0.9f, 0.9f, 0.9f, 0.3f}, hover, 50f);
+ return getColorComponents(color, new float[]{0f, 0f, 0f, 0f}, new float[]{0.9f, 0.9f, 0.9f, 0.3f}, hover, 50f);
case PRIMARY: // Formally 1
return hover ? OneConfigConfig.PRIMARY_700 : OneConfigConfig.PRIMARY_600;
- //return getColorComponents(color, splitColor(OneConfigConfig.PRIMARY_600), splitColor(OneConfigConfig.PRIMARY_700), hover, 100f);
+ //return getColorComponents(color, splitColor(OneConfigConfig.PRIMARY_600), splitColor(OneConfigConfig.PRIMARY_700), hover, 100f);
default:
case SECONDARY: // Formally 0
return getColorComponents(color, splitColor(OneConfigConfig.GRAY_500), splitColor(OneConfigConfig.GRAY_400), hover, 100f);
@@ -100,7 +116,7 @@ public class ColorUtils {
return ((int) (currentColor[3] * 255) << 24) |
((int) (currentColor[0] * 255) << 16) |
- ((int) (currentColor[1] * 255) << 8) |
+ ((int) (currentColor[1] * 255) << 8) |
((int) (currentColor[2] * 255));
}
@@ -119,6 +135,7 @@ public class ColorUtils {
/**
* Get the red component of an RGB color.
+ *
* @param color the color.
* @return the red component.
*/
@@ -128,6 +145,7 @@ public class ColorUtils {
/**
* Get the green component of an RGB color.
+ *
* @param color the color.
* @return the green component.
*/
@@ -137,6 +155,7 @@ public class ColorUtils {
/**
* Get the blue component of an RGB color.
+ *
* @param color the color.
* @return the blue component.
*/
@@ -146,6 +165,7 @@ public class ColorUtils {
/**
* Get the alpha component of an ARGB color.
+ *
* @param color the color.
* @return the alpha component.
*/
@@ -155,9 +175,10 @@ public class ColorUtils {
/**
* Get the RGB color from the given color components.
- * @param red the red component.
+ *
+ * @param red the red component.
* @param green the green component.
- * @param blue the blue component.
+ * @param blue the blue component.
* @param alpha the alpha component.
* @return the RGB color.
*/
@@ -167,9 +188,10 @@ public class ColorUtils {
/**
* Get the RGB color from the given color components.
- * @param red the red component.
+ *
+ * @param red the red component.
* @param green the green component.
- * @param blue the blue component.
+ * @param blue the blue component.
* @return the RGB color.
*/
public static int getColor(int red, int green, int blue) {
@@ -178,9 +200,10 @@ public class ColorUtils {
/**
* Get the RGB color from the given color components.
- * @param red the red component.
+ *
+ * @param red the red component.
* @param green the green component.
- * @param blue the blue component.
+ * @param blue the blue component.
* @param alpha the alpha component.
* @return the RGB color.
*/
@@ -190,8 +213,9 @@ public class ColorUtils {
/**
* Return the color with the given red component.
+ *
* @param color the color.
- * @param red the red component.
+ * @param red the red component.
* @return the color with the given red component.
*/
public static int setRed(int color, int red) {
@@ -200,6 +224,7 @@ public class ColorUtils {
/**
* Return the color with the given green component.
+ *
* @param color the color.
* @param green the green component.
* @return the color with the given green component.
@@ -210,8 +235,9 @@ public class ColorUtils {
/**
* Return the color with the given blue component.
+ *
* @param color the color.
- * @param blue the blue component.
+ * @param blue the blue component.
* @return the color with the given blue component.
*/
public static int setBlue(int color, int blue) {
@@ -220,6 +246,7 @@ public class ColorUtils {
/**
* Return the color with the given alpha component.
+ *
* @param color the color.
* @param alpha the alpha component.
* @return the color with the given alpha component.
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java
index 53f8d54..3c710c3 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java
@@ -6,10 +6,11 @@ import net.minecraft.client.gui.GuiScreen;
/**
* A class containing utility methods for working with GuiScreens.
*/
-public class GuiUtils {
+public final class GuiUtils {
/**
* Displays a screen after a tick, preventing mouse sync issues.
+ *
* @param screen the screen to display.
*/
public static void displayScreen(GuiScreen screen) {
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java
index 7263a19..64cabfd 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java
@@ -12,9 +12,6 @@ import java.nio.file.Files;
public final class IOUtils {
- private IOUtils() {
- }
-
/**
* Taken from legui under MIT License
* <a href="https://github.com/SpinyOwl/legui/blob/develop/LICENSE">https://github.com/SpinyOwl/legui/blob/develop/LICENSE</a>
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java
index 922010d..86e6c86 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java
@@ -4,7 +4,14 @@ import cc.polyfrost.oneconfig.gui.OneConfigGui;
import cc.polyfrost.oneconfig.libs.universal.UResolution;
import org.lwjgl.input.Mouse;
-public class InputUtils {
+/**
+ * Various utility methods for input.
+ * <p>
+ * All values returned from this class are not scaled to Minecraft's GUI scale.
+ * For scaled values, see {@link cc.polyfrost.oneconfig.libs.universal.UMouse}.
+ * </p>
+ */
+public final class InputUtils {
private static boolean blockClicks = false;
/**
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/JsonUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/JsonUtils.java
index f450d3b..4ea9ce2 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/JsonUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/JsonUtils.java
@@ -3,12 +3,8 @@ package cc.polyfrost.oneconfig.utils;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
-public class JsonUtils {
- private static final JsonParser PARSER = new JsonParser();
-
- public static JsonParser getParser() {
- return PARSER;
- }
+public final class JsonUtils {
+ public static final JsonParser PARSER = new JsonParser();
public static JsonElement parseString(String string, boolean catchExceptions) {
try {
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java
index fcfca02..19d399f 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java
@@ -2,7 +2,7 @@ package cc.polyfrost.oneconfig.utils;
import cc.polyfrost.oneconfig.gui.OneConfigGui;
-public class MathUtils {
+public final class MathUtils {
public static float clamp(float number) {
return number < 0f ? 0f : Math.min(number, 1f);
}
@@ -36,10 +36,10 @@ public class MathUtils {
/**
* taken from <a href="https://github.com/jesusgollonet/processing-penner-easing">https://github.com/jesusgollonet/processing-penner-easing</a>
*/
- public static float easeInOutQuad(float t,float b , float c, float d) {
+ public static float easeInOutQuad(float t, float b, float c, float d) {
c *= OneConfigGui.INSTANCE == null ? 16 : OneConfigGui.INSTANCE.getDeltaTime();
- if ((t/=d/2) < 1) return c/2*t*t + b;
- return -c/2 * ((--t)*(t-2) - 1) + b;
+ if ((t /= d / 2) < 1) return c / 2 * t * t + b;
+ return -c / 2 * ((--t) * (t - 2) - 1) + b;
}
public static float map(float value, float start1, float stop1, float start2, float stop2) {
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/NetworkUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/NetworkUtils.java
index 3192a2e..34d4382 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/NetworkUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/NetworkUtils.java
@@ -1,9 +1,9 @@
package cc.polyfrost.oneconfig.utils;
+import cc.polyfrost.oneconfig.libs.universal.UDesktop;
import com.google.gson.JsonElement;
import org.apache.commons.io.IOUtils;
-import java.awt.*;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URI;
@@ -11,7 +11,7 @@ import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
-public class NetworkUtils {
+public final class NetworkUtils {
private static InputStream setupConnection(String url, String userAgent, int timeout, boolean useCaches) throws IOException {
HttpURLConnection connection = ((HttpURLConnection) new URL(url).openConnection());
connection.setRequestMethod("GET");
@@ -87,22 +87,6 @@ public class NetworkUtils {
}
public static void browseLink(String uri) {
- try {
- browseLink(new URI(uri));
- } catch (Exception e) {
- e.printStackTrace();
- System.err.println("Invalid URI: " + uri);
- }
- }
-
- public static void browseLink(URI uri) {
- if(Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
- try {
- Desktop.getDesktop().browse(uri);
- } catch (IOException e) {
- e.printStackTrace();
- System.err.println("Failed to open URL in browser: " + uri);
- }
- }
+ UDesktop.browse(URI.create(uri));
}
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java
index 22baee0..252a588 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java
@@ -5,8 +5,7 @@ import cc.polyfrost.oneconfig.lwjgl.font.Fonts;
import java.util.ArrayList;
-public class TextUtils {
-
+public final class TextUtils {
public static ArrayList<String> wrapText(long vg, String text, float maxWidth, float fontSize, Fonts font) {
ArrayList<String> wrappedText = new ArrayList<>();
text += " ";
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/TickDelay.java b/src/main/java/cc/polyfrost/oneconfig/utils/TickDelay.java
index f467976..08f5fce 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/TickDelay.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/TickDelay.java
@@ -19,7 +19,7 @@ public class TickDelay {
if (event.phase == TickEvent.Phase.START) {
// Delay expired
if (delay < 1) {
- run();
+ function.run();
destroy();
}
delay--;
@@ -33,8 +33,4 @@ public class TickDelay {
private void register() {
MinecraftForge.EVENT_BUS.register(this);
}
-
- private void run() {
- function.run();
- }
}