aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-09-07 22:20:00 +0200
committerGitHub <noreply@github.com>2022-09-07 16:20:00 -0400
commit7c077e278b7266950a968a7e7f2f28b9a140ed96 (patch)
tree56b351874c48126f70e4ef6cbcf914ea832bdcd9 /src/main/java
parent17cfe96255f1ec3ab5609aa153d4abed2075c435 (diff)
downloadOneConfig-7c077e278b7266950a968a7e7f2f28b9a140ed96.tar.gz
OneConfig-7c077e278b7266950a968a7e7f2f28b9a140ed96.tar.bz2
OneConfig-7c077e278b7266950a968a7e7f2f28b9a140ed96.zip
new: option descriptions (#127)
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/annotations/Button.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/annotations/Checkbox.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/annotations/Color.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/annotations/Dropdown.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/annotations/DualOption.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/annotations/KeyBind.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/annotations/Slider.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/annotations/Switch.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/annotations/Text.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java62
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java16
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java11
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigInfo.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java4
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java11
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java27
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/assets/SVGs.java1
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilanceConfig.java24
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/gui/HudGui.java81
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java1
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/renderer/AssetLoader.java46
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/renderer/NVGAsset.java25
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java48
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/NetworkUtils.java34
32 files changed, 329 insertions, 126 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Button.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Button.java
index 783832e..0a6b66f 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Button.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Button.java
@@ -42,6 +42,8 @@ public @interface Button {
String text();
+ String description() default "";
+
int size() default 1;
String category() default "General";
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Checkbox.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Checkbox.java
index daddfbd..825549d 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Checkbox.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Checkbox.java
@@ -40,6 +40,8 @@ import java.lang.annotation.Target;
public @interface Checkbox {
String name();
+ String description() default "";
+
int size() default 1;
String category() default "General";
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Color.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Color.java
index 09dfa68..caa69f3 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Color.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Color.java
@@ -40,6 +40,8 @@ import java.lang.annotation.Target;
public @interface Color {
String name();
+ String description() default "";
+
boolean allowAlpha() default true;
int size() default 1;
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Dropdown.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Dropdown.java
index c3ebc6c..02f2ff2 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Dropdown.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Dropdown.java
@@ -42,6 +42,8 @@ public @interface Dropdown {
String[] options();
+ String description() default "";
+
int size() default 1;
String category() default "General";
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/DualOption.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/DualOption.java
index 3bcef12..20b340b 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/annotations/DualOption.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/DualOption.java
@@ -44,6 +44,8 @@ public @interface DualOption {
String right();
+ String description() default "";
+
int size() default 1;
String category() default "General";
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/KeyBind.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/KeyBind.java
index d59a316..cab3a2f 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/annotations/KeyBind.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/KeyBind.java
@@ -40,6 +40,8 @@ import java.lang.annotation.Target;
public @interface KeyBind {
String name();
+ String description() default "";
+
int size() default 1;
String category() default "General";
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Slider.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Slider.java
index 8cdffc8..f01aaf6 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Slider.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Slider.java
@@ -46,6 +46,8 @@ public @interface Slider {
int step() default 0;
+ String description() default "";
+
String category() default "General";
String subcategory() default "";
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Switch.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Switch.java
index ba8f5d7..253d08d 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Switch.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Switch.java
@@ -40,6 +40,8 @@ import java.lang.annotation.Target;
public @interface Switch {
String name();
+ String description() default "";
+
int size() default 1;
String category() default "General";
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Text.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Text.java
index a2ced12..e68c2a9 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Text.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Text.java
@@ -46,6 +46,8 @@ public @interface Text {
boolean multiline() default false;
+ String description() default "";
+
int size() default 1;
String category() default "General";
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java b/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java
index 3394c52..a06002c 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java
@@ -26,8 +26,15 @@
package cc.polyfrost.oneconfig.config.elements;
-import cc.polyfrost.oneconfig.config.Config;
+import cc.polyfrost.oneconfig.gui.animations.Animation;
+import cc.polyfrost.oneconfig.gui.animations.DummyAnimation;
+import cc.polyfrost.oneconfig.gui.animations.EaseOutQuad;
+import cc.polyfrost.oneconfig.internal.assets.Colors;
+import cc.polyfrost.oneconfig.internal.assets.SVGs;
+import cc.polyfrost.oneconfig.renderer.RenderManager;
+import cc.polyfrost.oneconfig.renderer.font.Fonts;
import cc.polyfrost.oneconfig.utils.InputHandler;
+import cc.polyfrost.oneconfig.utils.gui.GuiUtils;
import java.lang.reflect.Field;
import java.util.ArrayList;
@@ -39,27 +46,36 @@ public abstract class BasicOption {
protected final Field field;
protected Object parent;
public final String name;
+ public final String description;
public final String category;
public final String subcategory;
private final ArrayList<Supplier<Boolean>> dependencies = new ArrayList<>();
private final ArrayList<Runnable> listeners = new ArrayList<>();
private final ArrayList<Supplier<Boolean>> hideConditions = new ArrayList<>();
+ private Animation descriptionAnimation = new DummyAnimation(0f);
+ private float mouseStillTime = 0f;
+ private float prevMouseX = 0f;
+ private float prevMouseY = 0f;
/**
* Initialize option
*
- * @param field variable attached to option (null for category)
- * @param parent the parent object of the field, used for getting and setting the variable
- * @param name name of option
- * @param size size of option, 0 for single column, 1 for double.
+ * @param field variable attached to option (null for category)
+ * @param parent the parent object of the field, used for getting and setting the variable
+ * @param name name of option
+ * @param description The description
+ * @param category The category
+ * @param subcategory The subcategory
+ * @param size size of option, 0 for single column, 1 for double.
*/
- public BasicOption(Field field, Object parent, String name, String category, String subcategory, int size) {
+ public BasicOption(Field field, Object parent, String name, String description, String category, String subcategory, int size) {
this.field = field;
this.parent = parent;
this.name = name;
- this.size = size;
+ this.description = description;
this.category = category;
this.subcategory = subcategory;
+ this.size = size;
if (field != null) field.setAccessible(true);
}
@@ -114,6 +130,38 @@ public abstract class BasicOption {
public void keyTyped(char key, int keyCode) {
}
+ public void drawDescription(long vg, int x, int y, int height, InputHandler inputHandler) {
+ if (description.trim().equals("")) return;
+ if (inputHandler.isAreaHovered(x - 16, y, size == 1 ? 512f : 1024f, height) && prevMouseX == inputHandler.mouseX() && prevMouseY == inputHandler.mouseY()) {
+ mouseStillTime += GuiUtils.getDeltaTime();
+ } else {
+ mouseStillTime = 0;
+ }
+ prevMouseX = inputHandler.mouseX();
+ prevMouseY = inputHandler.mouseY();
+ boolean shouldDrawDescription = shouldDrawDescription();
+ if (descriptionAnimation.getEnd() != 1f && shouldDrawDescription) {
+ descriptionAnimation = new EaseOutQuad(150, descriptionAnimation.get(0), 1f, false);
+ } else if (descriptionAnimation.getEnd() != 0f && !shouldDrawDescription) {
+ descriptionAnimation = new EaseOutQuad(150, descriptionAnimation.get(0), 0f, false);
+ }
+ if (!shouldDrawDescription && descriptionAnimation.isFinished()) return;
+ float textWidth = RenderManager.getTextWidth(vg, description, 16, Fonts.MEDIUM);
+ RenderManager.setAlpha(vg, descriptionAnimation.get());
+ RenderManager.drawRoundedRect(vg, x, y - 42f, textWidth + 68f, 44f, Colors.GRAY_700, 8f);
+ RenderManager.drawDropShadow(vg, x, y - 42f, textWidth + 68f, 44f, 32f, 0f, 8f);
+ RenderManager.drawSvg(vg, SVGs.INFO_ARROW, x + 16, y - 30f, 20f, 20f, Colors.WHITE_80);
+ RenderManager.drawText(vg, description, x + 52, y - 20, Colors.WHITE_80, 16, Fonts.MEDIUM);
+ RenderManager.setAlpha(vg, 1f);
+ }
+
+ /**
+ * @return If this option should draw its description
+ */
+ protected boolean shouldDrawDescription() {
+ return mouseStillTime > 350;
+ }
+
/**
* @return If the option is enabled, based on the dependencies
*/
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java
index 08c59b8..628e973 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java
@@ -90,11 +90,15 @@ public class OptionSubcategory {
for (int i = 0; i < filteredOptions.size(); i++) {
BasicOption option = filteredOptions.get(i);
option.draw(vg, x, optionY, inputHandler);
+ int optionHeight = option.getHeight();
+ option.drawDescription(vg, x, optionY, optionHeight, inputHandler);
if (i + 1 < filteredOptions.size()) {
BasicOption nextOption = filteredOptions.get(i + 1);
if (option.size == 1 && nextOption.size == 1) {
nextOption.draw(vg, x + 512, optionY, inputHandler);
- optionY += Math.max(option.getHeight(), nextOption.getHeight()) + 16;
+ nextOption.drawDescription(vg, x + 512, optionY, optionHeight, inputHandler);
+ int nextOptionHeight = nextOption.getHeight();
+ optionY += Math.max(optionHeight, nextOptionHeight) + 16;
i++;
continue;
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java
index fdd0c2f..681db60 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java
@@ -42,20 +42,20 @@ import java.util.Arrays;
public class ConfigButton extends BasicOption {
private final BasicButton button;
- public ConfigButton(Runnable runnable, Object parent, String name, String category, String subcategory, int size, String text) {
- super(null, parent, name, category, subcategory, size);
+ public ConfigButton(Runnable runnable, Object parent, String name, String description, String category, String subcategory, int size, String text) {
+ super(null, parent, name, description, category, subcategory, size);
this.button = new BasicButton(size == 1 ? 128 : 256, 32, text, BasicButton.ALIGNMENT_CENTER, ColorPalette.PRIMARY);
this.button.setClickAction(runnable);
}
- public ConfigButton(Field field, Object parent, String name, String category, String subcategory, int size, String text) {
- super(field, parent, name, category, subcategory, size);
+ public ConfigButton(Field field, Object parent, String name, String description, String category, String subcategory, int size, String text) {
+ super(field, parent, name, description, category, subcategory, size);
this.button = new BasicButton(size == 1 ? 128 : 256, 32, text, BasicButton.ALIGNMENT_CENTER, ColorPalette.PRIMARY);
this.button.setClickAction(getRunnableFromField(field, parent));
}
- public ConfigButton(Method method, Object parent, String name, String category, String subcategory, int size, String text) {
- super(null, parent, name, category, subcategory, size);
+ public ConfigButton(Method method, Object parent, String name, String description, String category, String subcategory, int size, String text) {
+ super(null, parent, name, description, category, subcategory, size);
this.button = new BasicButton(size == 1 ? 128 : 256, 32, text, BasicButton.ALIGNMENT_CENTER, ColorPalette.PRIMARY);
this.button.setClickAction(() -> {
try {
@@ -70,13 +70,13 @@ public class ConfigButton extends BasicOption {
public static ConfigButton create(Field field, Object parent) {
Button button = field.getAnnotation(Button.class);
- return new ConfigButton(field, parent, button.name(), button.category(), button.subcategory(), button.size(), button.text());
+ return new ConfigButton(field, parent, button.name(), button.description(), button.category(), button.subcategory(), button.size(), button.text());
}
public static ConfigButton create(Method method, Object parent) {
method.setAccessible(true);
Button button = method.getAnnotation(Button.class);
- return new ConfigButton(method, parent, button.name(), button.category(), button.subcategory(), button.size(), button.text());
+ return new ConfigButton(method, parent, button.name(), button.description(), button.category(), button.subcategory(), button.size(), button.text());
}
private static Runnable getRunnableFromField(Field field, Object parent) {
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java
index 9cc60c9..6f3be32 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java
@@ -48,13 +48,13 @@ public class ConfigCheckbox extends BasicOption {
private final ColorAnimation color = new ColorAnimation(ColorPalette.SECONDARY);
private Animation animation;
- public ConfigCheckbox(Field field, Object parent, String name, String category, String subcategory, int size) {
- super(field, parent, name, category, subcategory, size);
+ public ConfigCheckbox(Field field, Object parent, String name, String description, String category, String subcategory, int size) {
+ super(field, parent, name, description, category, subcategory, size);
}
public static ConfigCheckbox create(Field field, Object parent) {
Checkbox checkbox = field.getAnnotation(Checkbox.class);
- return new ConfigCheckbox(field, parent, checkbox.name(), checkbox.category(), checkbox.subcategory(), checkbox.size());
+ return new ConfigCheckbox(field, parent, checkbox.name(), checkbox.description(), checkbox.category(), checkbox.subcategory(), checkbox.size());
}
@Override
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java
index 39780a1..5e92ddc 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java
@@ -48,8 +48,8 @@ public class ConfigColorElement extends BasicOption {
private boolean open = false;
private final boolean allowAlpha;
- public ConfigColorElement(Field field, Object parent, String name, String category, String subcategory, int size, boolean allowAlpha) {
- super(field, parent, name, category, subcategory, size);
+ public ConfigColorElement(Field field, Object parent, String name, String description, String category, String subcategory, int size, boolean allowAlpha) {
+ super(field, parent, name, description, category, subcategory, size);
hexField.setCentered(true);
alphaField.setCentered(true);
alphaField.onlyAcceptNumbers(true);
@@ -58,7 +58,7 @@ public class ConfigColorElement extends BasicOption {
public static ConfigColorElement create(Field field, Object parent) {
Color color = field.getAnnotation(Color.class);
- return new ConfigColorElement(field, parent, color.name(), color.category(), color.subcategory(), color.size(), color.allowAlpha());
+ return new ConfigColorElement(field, parent, color.name(), color.description(), color.category(), color.subcategory(), color.size(), color.allowAlpha());
}
@Override
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java
index 2660266..6dd463f 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java
@@ -49,14 +49,14 @@ public class ConfigDropdown extends BasicOption {
private boolean opened = false;
private Scissor inputScissor = null;
- public ConfigDropdown(Field field, Object parent, String name, String category, String subcategory, int size, String[] options) {
- super(field, parent, name, category, subcategory, size);
+ public ConfigDropdown(Field field, Object parent, String name, String description, String category, String subcategory, int size, String[] options) {
+ super(field, parent, name, description, category, subcategory, size);
this.options = options;
}
public static ConfigDropdown create(Field field, Object parent) {
Dropdown dropdown = field.getAnnotation(Dropdown.class);
- return new ConfigDropdown(field, parent, dropdown.name(), dropdown.category(), dropdown.subcategory(), dropdown.size(), dropdown.options());
+ return new ConfigDropdown(field, parent, dropdown.name(), dropdown.description(), dropdown.category(), dropdown.subcategory(), dropdown.size(), dropdown.options());
}
@Override
@@ -189,4 +189,9 @@ public class ConfigDropdown extends BasicOption {
public int getHeight() {
return 32;
}
+
+ @Override
+ protected boolean shouldDrawDescription() {
+ return super.shouldDrawDescription() && !opened;
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java
index c8582d1..eb1dece 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java
@@ -42,15 +42,15 @@ public class ConfigDualOption extends BasicOption {
private final String left, right;
private Animation posAnimation;
- public ConfigDualOption(Field field, Object parent, String name, String category, String subcategory, int size, String left, String right) {
- super(field, parent, name, category, subcategory, size);
+ public ConfigDualOption(Field field, Object parent, String name, String description, String category, String subcategory, int size, String left, String right) {
+ super(field, parent, name, description, category, subcategory, size);
this.left = left;
this.right = right;
}
public static ConfigDualOption create(Field field, Object parent) {
DualOption dualOption = field.getAnnotation(DualOption.class);
- return new ConfigDualOption(field, parent, dualOption.name(), dualOption.category(), dualOption.subcategory(), dualOption.size(), dualOption.left(), dualOption.right());
+ return new ConfigDualOption(field, parent, dualOption.name(), dualOption.description(), dualOption.category(), dualOption.subcategory(), dualOption.size(), dualOption.left(), dualOption.right());
}
@Override
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java
index 45865fe..5e9f27f 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java
@@ -40,7 +40,7 @@ import java.lang.reflect.Field;
public class ConfigHeader extends BasicOption {
public ConfigHeader(Field field, Object parent, String name, String category, String subcategory, int size) {
- super(field, parent, name, category, subcategory, size);
+ super(field, parent, name, "", category, subcategory, size);
}
public static ConfigHeader create(Field field, Object parent) {
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigInfo.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigInfo.java
index c44c50d..94afaec 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigInfo.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigInfo.java
@@ -42,7 +42,7 @@ public class ConfigInfo extends BasicOption {
private final InfoType type;
public ConfigInfo(Field field, Object parent, String name, String category, String subcategory, int size, InfoType type) {
- super(field, parent, name, category, subcategory, size);
+ super(field, parent, name, "", category, subcategory, size);
this.type = type;
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java
index daa034f..491a99c 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java
@@ -45,15 +45,15 @@ public class ConfigKeyBind extends BasicOption {
private final BasicButton button;
private boolean clicked = false;
- public ConfigKeyBind(Field field, Object parent, String name, String category, String subcategory, int size) {
- super(field, parent, name, category, subcategory, size);
+ public ConfigKeyBind(Field field, Object parent, String name, String description, String category, String subcategory, int size) {
+ super(field, parent, name, description, category, subcategory, size);
button = new BasicButton(256, 32, "", SVGs.KEYSTROKE, null, BasicButton.ALIGNMENT_JUSTIFIED, ColorPalette.SECONDARY);
button.setToggleable(true);
}
public static ConfigKeyBind create(Field field, Object parent) {
KeyBind keyBind = field.getAnnotation(KeyBind.class);
- return new ConfigKeyBind(field, parent, keyBind.name(), keyBind.category(), keyBind.subcategory(), keyBind.size());
+ return new ConfigKeyBind(field, parent, keyBind.name(), keyBind.description(), keyBind.category(), keyBind.subcategory(), keyBind.size());
}
@Override
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java
index de10600..2d8c4f2 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java
@@ -48,13 +48,13 @@ public class ConfigPageButton extends BasicOption {
private final ColorAnimation backgroundColor = new ColorAnimation(ColorPalette.SECONDARY);
public ConfigPageButton(Field field, Object parent, String name, String description, String category, String subcategory, OptionPage page) {
- super(field, parent, name, category, subcategory, 2);
+ super(field, parent, name, "", category, subcategory, 2);
this.description = description;
this.page = new ModConfigPage(page);
}
public ConfigPageButton(Field field, Object parent, String name, String description, String category, String subcategory, Page page) {
- super(field, parent, name, category, subcategory, 2);
+ super(field, parent, name, "", category, subcategory, 2);
this.description = description;
this.page = page;
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java
index 4e2dda5..a4088d9 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java
@@ -46,8 +46,8 @@ public class ConfigSlider extends BasicOption {
private boolean dragging = false;
private boolean mouseWasDown = false;
- public ConfigSlider(Field field, Object parent, String name, String category, String subcategory, float min, float max, int step) {
- super(field, parent, name,category, subcategory, 2);
+ public ConfigSlider(Field field, Object parent, String name, String description, String category, String subcategory, float min, float max, int step) {
+ super(field, parent, name, description, category, subcategory, 2);
this.min = min;
this.max = max;
this.step = step;
@@ -56,7 +56,7 @@ public class ConfigSlider extends BasicOption {
public static ConfigSlider create(Field field, Object parent) {
Slider slider = field.getAnnotation(Slider.class);
- return new ConfigSlider(field, parent, slider.name(), slider.category(), slider.subcategory(), slider.min(), slider.max(), slider.step());
+ return new ConfigSlider(field, parent, slider.name(), slider.description(), slider.category(), slider.subcategory(), slider.min(), slider.max(), slider.step());
}
@Override
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java
index 9d13e3e..4ecc42b 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java
@@ -45,13 +45,13 @@ public class ConfigSwitch extends BasicOption {
private ColorAnimation color;
private Animation animation;
- public ConfigSwitch(Field field, Object parent, String name, String category, String subcategory, int size) {
- super(field, parent, name, category, subcategory, size);
+ public ConfigSwitch(Field field, Object parent, String name, String description, String category, String subcategory, int size) {
+ super(field, parent, name, description, category, subcategory, size);
}
public static ConfigSwitch create(Field field, Object parent) {
Switch options = field.getAnnotation(Switch.class);
- return new ConfigSwitch(field, parent, options.name(), options.category(), options.subcategory(), options.size());
+ return new ConfigSwitch(field, parent, options.name(), options.description(), options.category(), options.subcategory(), options.size());
}
@Override
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java
index adb9131..4dc497b 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java
@@ -44,8 +44,8 @@ public class ConfigTextBox extends BasicOption {
private final boolean multiLine;
private final TextInputField textField;
- public ConfigTextBox(Field field, Object parent, String name, String category, String subcategory, int size, String placeholder, boolean secure, boolean multiLine) {
- super(field, parent, name, category, subcategory, size);
+ public ConfigTextBox(Field field, Object parent, String name, String description, String category, String subcategory, int size, String placeholder, boolean secure, boolean multiLine) {
+ super(field, parent, name, category, description, subcategory, size);
this.secure = secure;
this.multiLine = multiLine;
this.textField = new TextInputField(size == 1 ? 256 : 640, multiLine ? 64 : 32, placeholder, multiLine, secure);
@@ -53,7 +53,7 @@ public class ConfigTextBox extends BasicOption {
public static ConfigTextBox create(Field field, Object parent) {
Text text = field.getAnnotation(Text.class);
- return new ConfigTextBox(field, parent, text.name(), text.category(), text.subcategory(), text.secure() || text.multiline() ? 2 : text.size(), text.placeholder(), text.secure(), text.multiline());
+ return new ConfigTextBox(field, parent, text.name(), text.description(), text.category(), text.subcategory(), text.secure() || text.multiline() ? 2 : text.size(), text.placeholder(), text.secure(), text.multiline());
}
@Override
@@ -97,4 +97,9 @@ public class ConfigTextBox extends BasicOption {
public int getHeight() {
return multiLine ? textField.getHeight() : 32;
}
+
+ @Override
+ protected boolean shouldDrawDescription() {
+ return super.shouldDrawDescription() && !textField.isToggled();
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java b/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java
index caff4a6..ef8dd8d 100644
--- a/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java
@@ -32,13 +32,10 @@ import cc.polyfrost.oneconfig.config.core.ConfigUtils;
import cc.polyfrost.oneconfig.config.elements.BasicOption;
import cc.polyfrost.oneconfig.config.elements.OptionPage;
import cc.polyfrost.oneconfig.gui.elements.config.*;
-import cc.polyfrost.oneconfig.hud.BasicHud;
-import cc.polyfrost.oneconfig.hud.Hud;
import cc.polyfrost.oneconfig.internal.hud.HudCore;
import java.lang.reflect.Field;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -73,27 +70,27 @@ public class HUDUtils {
HashMap<String, Field> fields = new HashMap<>();
for (Field f : fieldArrayList) fields.put(f.getName(), f);
options.add(new ConfigHeader(field, hud, hudAnnotation.name(), category, subcategory, 2));
- options.add(new ConfigSwitch(fields.get("enabled"), hud, "Enabled", category, subcategory, 2));
+ options.add(new ConfigSwitch(fields.get("enabled"), hud, "Enabled", "If the HUD is enabled", category, subcategory, 2));
options.addAll(ConfigUtils.getClassOptions(hud));
if (hud instanceof BasicHud) {
- options.add(new ConfigCheckbox(fields.get("background"), hud, "Background", category, subcategory, 1));
- options.add(new ConfigCheckbox(fields.get("rounded"), hud, "Rounded corners", category, subcategory, 1));
+ options.add(new ConfigCheckbox(fields.get("background"), hud, "Background", "If the background of the HUD is enabled.", category, subcategory, 1));
+ options.add(new ConfigCheckbox(fields.get("rounded"), hud, "Rounded corners", "If the background has rounded corners.", category, subcategory, 1));
options.get(options.size() - 1).addDependency(() -> ((BasicHud) hud).background || ((BasicHud) hud).border);
- options.add(new ConfigCheckbox(fields.get("border"), hud, "Outline/border", category, subcategory, 1));
- options.add(new ConfigColorElement(fields.get("bgColor"), hud, "Background color:", category, subcategory, 1, true));
+ options.add(new ConfigCheckbox(fields.get("border"), hud, "Outline/border", "If the hud has an outline.", category, subcategory, 1));
+ options.add(new ConfigColorElement(fields.get("bgColor"), hud, "Background color:", "The color of the background.", category, subcategory, 1, true));
options.get(options.size() - 1).addDependency(() -> ((BasicHud) hud).background);
- options.add(new ConfigColorElement(fields.get("borderColor"), hud, "Border color:", category, subcategory, 1, true));
+ options.add(new ConfigColorElement(fields.get("borderColor"), hud, "Border color:", "The color of the border.", category, subcategory, 1, true));
options.get(options.size() - 1).addDependency(() -> ((BasicHud) hud).border);
- options.add(new ConfigSlider(fields.get("cornerRadius"), hud, "Corner radius:", category, subcategory, 0, 10, 0));
+ options.add(new ConfigSlider(fields.get("cornerRadius"), hud, "Corner radius:", "The corner radius of the background.", category, subcategory, 0, 10, 0));
options.get(options.size() - 1).addDependency(() -> ((BasicHud) hud).rounded);
- options.add(new ConfigSlider(fields.get("borderSize"), hud, "Border thickness:", category, subcategory, 0, 10, 0));
+ options.add(new ConfigSlider(fields.get("borderSize"), hud, "Border thickness:", "The thickness of the outline.", category, subcategory, 0, 10, 0));
options.get(options.size() - 1).addDependency(() -> ((BasicHud) hud).border);
if (hud instanceof SingleTextHud) {
- options.add(new ConfigSlider(fields.get("paddingX"), hud, "Width", category, subcategory, 50, 72, 0));
- options.add(new ConfigSlider(fields.get("paddingY"), hud, "Height", category, subcategory, 10, 22, 0));
+ options.add(new ConfigSlider(fields.get("paddingX"), hud, "Width", "The width of the HUD.", category, subcategory, 50, 72, 0));
+ options.add(new ConfigSlider(fields.get("paddingY"), hud, "Height", "The height of the HUD.", category, subcategory, 10, 22, 0));
} else {
- options.add(new ConfigSlider(fields.get("paddingX"), hud, "X-Padding", category, subcategory, 0, 50, 0));
- options.add(new ConfigSlider(fields.get("paddingY"), hud, "Y-Padding", category, subcategory, 0, 50, 0));
+ options.add(new ConfigSlider(fields.get("paddingX"), hud, "X-Padding", "The horizontal padding of the HUD.", category, subcategory, 0, 50, 0));
+ options.add(new ConfigSlider(fields.get("paddingY"), hud, "Y-Padding", "The vertical padding of the HUD.", category, subcategory, 0, 50, 0));
}
options.get(options.size() - 2).addDependency(() -> ((BasicHud) hud).background || ((BasicHud) hud).border);
options.get(options.size() - 1).addDependency(() -> ((BasicHud) hud).background || ((BasicHud) hud).border);
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/assets/SVGs.java b/src/main/java/cc/polyfrost/oneconfig/internal/assets/SVGs.java
index cafedde..5ccf384 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/assets/SVGs.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/assets/SVGs.java
@@ -51,6 +51,7 @@ public class SVGs {
public static final SVG X_CIRCLE_BOLD = new SVG("/assets/oneconfig/icons/XCircleBold.svg");
public static final SVG CARET_LEFT = new SVG("/assets/oneconfig/icons/CaretLeftBold.svg");
public static final SVG CARET_RIGHT = new SVG("/assets/oneconfig/icons/CaretRightBold.svg");
+ public static final SVG INFO_ARROW = new SVG("/assets/oneconfig/icons/InfoArrow.svg");
// OLD ICONS
public static final SVG BOX = new SVG("/assets/oneconfig/old-icons/Box.svg");
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilanceConfig.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilanceConfig.java
index 66375cc..07c1e2a 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilanceConfig.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilanceConfig.java
@@ -85,35 +85,35 @@ public class VigilanceConfig extends Config {
ArrayList<BasicOption> options = ConfigUtils.getSubCategory(page, getCategory(attributes), getSubcategory(attributes)).options;
switch (attributes.getType()) {
case SWITCH:
- options.add(new ConfigSwitch(getFieldOfProperty(option), option.getInstance(), getName(attributes), getCategory(attributes), getSubcategory(attributes), 2));
+ options.add(new ConfigSwitch(getFieldOfProperty(option), option.getInstance(), getName(attributes), attributes.getDescription(), getCategory(attributes), getSubcategory(attributes), 2));
break;
case CHECKBOX:
- options.add(new ConfigCheckbox(getFieldOfProperty(option), option.getInstance(), getName(attributes),getCategory(attributes), getSubcategory(attributes), 2));
+ options.add(new ConfigCheckbox(getFieldOfProperty(option), option.getInstance(), getName(attributes), attributes.getDescription(), getCategory(attributes), getSubcategory(attributes), 2));
break;
case PARAGRAPH:
case TEXT:
- options.add(new ConfigTextBox(getFieldOfProperty(option), option.getInstance(), getName(attributes), getCategory(attributes), getSubcategory(attributes), 2, attributes.getPlaceholder(), attributes.getProtected(), attributes.getType() == PropertyType.PARAGRAPH));
+ options.add(new ConfigTextBox(getFieldOfProperty(option), option.getInstance(), getName(attributes), attributes.getDescription(), getCategory(attributes), getSubcategory(attributes), 2, attributes.getPlaceholder(), attributes.getProtected(), attributes.getType() == PropertyType.PARAGRAPH));
break;
case SELECTOR:
- options.add(new ConfigDropdown(getFieldOfProperty(option), option.getInstance(), getName(attributes), getCategory(attributes), getSubcategory(attributes), 2, attributes.getOptions().toArray(new String[0])));
+ options.add(new ConfigDropdown(getFieldOfProperty(option), option.getInstance(), getName(attributes), attributes.getDescription(), getCategory(attributes), getSubcategory(attributes), 2, attributes.getOptions().toArray(new String[0])));
break;
case PERCENT_SLIDER:
- options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), getName(attributes), getCategory(attributes), getSubcategory(attributes), 0, 1, 0));
+ options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), getName(attributes), attributes.getDescription(), getCategory(attributes), getSubcategory(attributes), 0, 1, 0));
break;
case DECIMAL_SLIDER:
- options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), getName(attributes), getCategory(attributes), getSubcategory(attributes), attributes.getMinF(), attributes.getMaxF(), 0));
+ options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), getName(attributes), attributes.getDescription(), getCategory(attributes), getSubcategory(attributes), attributes.getMinF(), attributes.getMaxF(), 0));
break;
case NUMBER:
- options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), getName(attributes), getCategory(attributes), getSubcategory(attributes), attributes.getMin(), attributes.getMax(), 1));
+ options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), getName(attributes), attributes.getDescription(), getCategory(attributes), getSubcategory(attributes), attributes.getMin(), attributes.getMax(), 1));
break;
case SLIDER:
- options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), getName(attributes), getCategory(attributes), getSubcategory(attributes), attributes.getMin(), attributes.getMax(), 0));
+ options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), getName(attributes), attributes.getDescription(), getCategory(attributes), getSubcategory(attributes), attributes.getMin(), attributes.getMax(), 0));
break;
case COLOR:
- options.add(new CompatConfigColorElement(getFieldOfProperty(option), option.getInstance(), getCategory(attributes), getSubcategory(attributes), getName(attributes), 2));
+ options.add(new CompatConfigColorElement(getFieldOfProperty(option), option.getInstance(), getCategory(attributes), attributes.getDescription(), getSubcategory(attributes), getName(attributes), 2));
break;
case BUTTON:
- options.add(new ConfigButton(() -> ((CallablePropertyValue) option.getValue()).invoke(option.getInstance()), option.getInstance(), getName(attributes), getCategory(attributes), getSubcategory(attributes), 2, attributes.getPlaceholder().isEmpty() ? "Activate" : attributes.getPlaceholder()));
+ options.add(new ConfigButton(() -> ((CallablePropertyValue) option.getValue()).invoke(option.getInstance()), option.getInstance(), getName(attributes), attributes.getDescription(), getCategory(attributes), getSubcategory(attributes), 2, attributes.getPlaceholder().isEmpty() ? "Activate" : attributes.getPlaceholder()));
break;
}
if (attributes.getType() == PropertyType.SWITCH || attributes.getType() == PropertyType.CHECKBOX) {
@@ -194,8 +194,8 @@ public class VigilanceConfig extends Config {
private Color prevColor = null;
private OneColor cachedColor = null;
- public CompatConfigColorElement(Field color, Vigilant parent, String name, String category, String subcategory, int size) {
- super(null, parent, name, category, subcategory, size, true);
+ public CompatConfigColorElement(Field color, Vigilant parent, String name, String description, String category, String subcategory, int size) {
+ super(null, parent, name, description, category, subcategory, size, true);
this.color = color;
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/gui/HudGui.java b/src/main/java/cc/polyfrost/oneconfig/internal/gui/HudGui.java
index 6169896..ef5a25a 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/gui/HudGui.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/gui/HudGui.java
@@ -30,14 +30,15 @@ import cc.polyfrost.oneconfig.gui.GuiPause;
import cc.polyfrost.oneconfig.gui.OneConfigGui;
import cc.polyfrost.oneconfig.hud.Hud;
import cc.polyfrost.oneconfig.hud.Position;
-import cc.polyfrost.oneconfig.internal.hud.utils.GrabOffset;
-import cc.polyfrost.oneconfig.internal.hud.utils.SnappingLine;
import cc.polyfrost.oneconfig.internal.config.core.ConfigCore;
import cc.polyfrost.oneconfig.internal.hud.HudCore;
+import cc.polyfrost.oneconfig.internal.hud.utils.GrabOffset;
+import cc.polyfrost.oneconfig.internal.hud.utils.SnappingLine;
import cc.polyfrost.oneconfig.libs.universal.UKeyboard;
import cc.polyfrost.oneconfig.libs.universal.UMatrixStack;
import cc.polyfrost.oneconfig.libs.universal.UResolution;
import cc.polyfrost.oneconfig.libs.universal.UScreen;
+import cc.polyfrost.oneconfig.renderer.AssetLoader;
import cc.polyfrost.oneconfig.renderer.RenderManager;
import cc.polyfrost.oneconfig.utils.MathUtils;
import cc.polyfrost.oneconfig.utils.gui.GuiUtils;
@@ -45,8 +46,10 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.awt.*;
-import java.util.ArrayList;
-import java.util.HashMap;
+import java.lang.reflect.Field;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Collectors;
public class HudGui extends UScreen implements GuiPause {
private static final int SNAPPING_DISTANCE = 10;
@@ -155,6 +158,7 @@ public class HudGui extends UScreen implements GuiPause {
} else if (keyCode == UKeyboard.KEY_RIGHT) {
setHudPositions(1f, 0f, false);
}
+ superSecretMethod(typedChar);
super.onKeyPressed(keyCode, typedChar, modifiers);
}
@@ -292,4 +296,73 @@ public class HudGui extends UScreen implements GuiPause {
}
return lines;
}
+
+ private String superSecretString = "";
+
+ private void superSecretMethod(char charTyped) {
+ superSecretString += charTyped;
+ superSecretString = superSecretString.toLowerCase();
+ if (!"blahaj".substring(0, superSecretString.length()).equals(superSecretString)
+ && !"blåhaj".substring(0, superSecretString.length()).equals(superSecretString)
+ && !"bigrat".substring(0, superSecretString.length()).equals(superSecretString)) {
+ superSecretString = "";
+ return;
+ } else if (!"blahaj".equals(superSecretString)
+ && !"blåhaj".equals(superSecretString)
+ && !"bigrat".equals(superSecretString)) {
+ return;
+ }
+ String url;
+ switch (superSecretString) {
+ case "blahaj":
+ case "blåhaj":
+ url = "https://blahaj.shop/api/random/image?" + UUID.randomUUID();
+ break;
+ case "bigrat":
+ url = "https://bigrat.monster/media/bigrat.png";
+ break;
+ default:
+ return;
+ }
+ superSecretString = "";
+ AtomicBoolean loaded = new AtomicBoolean();
+ RenderManager.setupAndDraw((vg) -> loaded.set(AssetLoader.INSTANCE.loadImage(vg, url)));
+ if (!loaded.get()) return;
+ int w = AssetLoader.INSTANCE.getNVGImage(url).getWidth();
+ int h = AssetLoader.INSTANCE.getNVGImage(url).getHeight();
+ float s = Math.min(300f / w, 300f / h);
+ float width = w * s;
+ float height = h * s;
+ HudCore.huds.put(new Map.Entry<Field, Object>() {
+ @Override
+ public Field getKey() {
+ return null;
+ }
+
+ @Override
+ public Object getValue() {
+ return null;
+ }
+
+ @Override
+ public Object setValue(Object o) {
+ return null;
+ }
+ }, new Hud(true) {
+ @Override
+ protected void draw(UMatrixStack matrices, float x, float y, float scale, boolean example) {
+ RenderManager.setupAndDraw(true, (vg) -> RenderManager.drawImage(vg, url, x, y, width * scale, height * scale));
+ }
+
+ @Override
+ protected float getWidth(float scale, boolean example) {
+ return width * scale;
+ }
+
+ @Override
+ protected float getHeight(float scale, boolean example) {
+ return height * scale;
+ }
+ });
+ }
} \ No newline at end of file
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java b/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java
index f557c8d..05fb6e6 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java
@@ -52,6 +52,7 @@ public class HudCore {
public static void reInitHuds() {
for (Map.Entry<Field, Object> field : huds.keySet()) {
+ if (field == null || field.getKey() == null || field.getValue() == null) continue;
try {
field.getKey().setAccessible(true);
Hud oldHud = huds.get(field);
diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/AssetLoader.java b/src/main/java/cc/polyfrost/oneconfig/renderer/AssetLoader.java
index 4fe8c0b..3e70ce1 100644
--- a/src/main/java/cc/polyfrost/oneconfig/renderer/AssetLoader.java
+++ b/src/main/java/cc/polyfrost/oneconfig/renderer/AssetLoader.java
@@ -59,8 +59,8 @@ public final class AssetLoader {
}
public static final int DEFAULT_FLAGS = NanoVG.NVG_IMAGE_REPEATX | NanoVG.NVG_IMAGE_REPEATY | NanoVG.NVG_IMAGE_GENERATE_MIPMAPS;
- private final HashMap<String, Integer> imageHashMap = new HashMap<>();
- private final HashMap<String, Integer> svgHashMap = new HashMap<>();
+ private final HashMap<String, NVGAsset> imageHashMap = new HashMap<>();
+ private final HashMap<String, NVGAsset> svgHashMap = new HashMap<>();
public static AssetLoader INSTANCE = new AssetLoader();
/**
@@ -87,7 +87,7 @@ public final class AssetLoader {
return false;
}
- imageHashMap.put(fileName, NanoVG.nvgCreateImageRGBA(vg, width[0], height[0], flags, buffer));
+ imageHashMap.put(fileName, new NVGAsset(NanoVG.nvgCreateImageRGBA(vg, width[0], height[0], flags, buffer), width[0], height[0]));
return true;
}
return true;
@@ -155,7 +155,7 @@ public final class AssetLoader {
NanoSVG.nsvgDeleteRasterizer(rasterizer);
NanoSVG.nsvgDelete(svg);
- svgHashMap.put(name, NanoVG.nvgCreateImageRGBA(vg, w, h, flags, image));
+ svgHashMap.put(name, new NVGAsset(NanoVG.nvgCreateImageRGBA(vg, w, h, flags, image), w, h));
return true;
} catch (Exception e) {
System.err.println("Failed to parse SVG file");
@@ -201,6 +201,18 @@ public final class AssetLoader {
* @see AssetLoader#loadImage(long, String)
*/
public int getImage(String fileName) {
+ return imageHashMap.get(fileName).getImage();
+ }
+
+ /**
+ * Get a loaded assets from the cache.
+ * <p><b>Requires the assets to have been loaded first.</b></p>
+ *
+ * @param fileName The name of the file to load.
+ * @return The image and its data
+ * @see AssetLoader#loadImage(long, String)
+ */
+ public NVGAsset getNVGImage(String fileName) {
return imageHashMap.get(fileName);
}
@@ -213,7 +225,7 @@ public final class AssetLoader {
* @see AssetLoader#loadImage(long, String)
*/
public void removeImage(long vg, String fileName) {
- NanoVG.nvgDeleteImage(vg, imageHashMap.get(fileName));
+ NanoVG.nvgDeleteImage(vg, imageHashMap.get(fileName).getImage());
imageHashMap.remove(fileName);
}
@@ -224,9 +236,9 @@ public final class AssetLoader {
* @param vg The NanoVG context.
*/
public void clearImages(long vg) {
- HashMap<String, Integer> temp = new HashMap<>(imageHashMap);
+ HashMap<String, NVGAsset> temp = new HashMap<>(imageHashMap);
for (String image : temp.keySet()) {
- NanoVG.nvgDeleteImage(vg, imageHashMap.get(image));
+ NanoVG.nvgDeleteImage(vg, imageHashMap.get(image).getImage());
imageHashMap.remove(image);
}
}
@@ -241,7 +253,19 @@ public final class AssetLoader {
*/
public int getSVG(String fileName, float width, float height) {
String name = fileName + "-" + width + "-" + height;
- return svgHashMap.get(name);
+ return svgHashMap.get(name).getImage();
+ }
+
+ /**
+ * Get a loaded assets from the cache.
+ * <p><b>Requires the assets to have been loaded first.</b></p>
+ *
+ * @param fileName The name of the file to load.
+ * @return The SVG and its data
+ * @see AssetLoader#loadImage(long, String)
+ */
+ public NVGAsset getNVGSVG(String fileName) {
+ return svgHashMap.get(fileName);
}
/**
@@ -254,7 +278,7 @@ public final class AssetLoader {
*/
public void removeSVG(long vg, String fileName, float width, float height) {
String name = fileName + "-" + width + "-" + height;
- NanoVG.nvgDeleteImage(vg, imageHashMap.get(name));
+ NanoVG.nvgDeleteImage(vg, imageHashMap.get(name).getImage());
svgHashMap.remove(name);
}
@@ -265,9 +289,9 @@ public final class AssetLoader {
* @param vg The NanoVG context.
*/
public void clearSVGs(long vg) {
- HashMap<String, Integer> temp = new HashMap<>(svgHashMap);
+ HashMap<String, NVGAsset> temp = new HashMap<>(svgHashMap);
for (String image : temp.keySet()) {
- NanoVG.nvgDeleteImage(vg, svgHashMap.get(image));
+ NanoVG.nvgDeleteImage(vg, svgHashMap.get(image).getImage());
svgHashMap.remove(image);
}
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/NVGAsset.java b/src/main/java/cc/polyfrost/oneconfig/renderer/NVGAsset.java
new file mode 100644
index 0000000..b5253e6
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/renderer/NVGAsset.java
@@ -0,0 +1,25 @@
+package cc.polyfrost.oneconfig.renderer;
+
+public class NVGAsset {
+ private final int image;
+ private final int width;
+ private final int height;
+
+ protected NVGAsset(int image, int width, int height) {
+ this.image = image;
+ this.width = width;
+ this.height = height;
+ }
+
+ public int getImage() {
+ return image;
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java
index 1e66701..48498fd 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java
@@ -30,15 +30,13 @@ import org.jetbrains.annotations.NotNull;
import java.awt.*;
import java.awt.datatransfer.*;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
import java.net.URL;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.file.Files;
+import java.security.MessageDigest;
/**
* Utility class for I/O operations.
@@ -54,7 +52,9 @@ public final class IOUtils {
byte[] bytes;
path = path.trim();
if (path.startsWith("http")) {
- bytes = org.apache.commons.io.IOUtils.toByteArray(new URL(path));
+ try (InputStream in = NetworkUtils.setupConnection(path, "OneConfig", 5000, true)) {
+ bytes = org.apache.commons.io.IOUtils.toByteArray(in);
+ }
} else {
InputStream stream;
File file = new File(path);
@@ -84,6 +84,7 @@ public final class IOUtils {
/**
* Copy the specified String to the System Clipboard.
+ *
* @param s the string to copy
*/
public static void copyStringToClipboard(String s) {
@@ -93,6 +94,7 @@ public final class IOUtils {
/**
* Return the String on the system clipboard.
+ *
* @return the string on the system clipboard, or null if there is no string on the clipboard or another error occurred.
*/
public static String getStringFromClipboard() {
@@ -105,6 +107,7 @@ public final class IOUtils {
/**
* Copy the given image to the System Clipboard.
+ *
* @param image the image to copy
*/
public static void copyImageToClipboard(Image image) {
@@ -114,6 +117,7 @@ public final class IOUtils {
/**
* Return the image on the system clipboard.
+ *
* @return the image on the system clipboard, or null if there is no image on the clipboard or another error occurred.
*/
public static Image getImageFromClipboard() {
@@ -124,19 +128,49 @@ public final class IOUtils {
}
}
+ /**
+ * Gets the SHA-256 hash of a file.
+ *
+ * @param file The file to hash.
+ * @return The SHA-256 hash of the file.
+ */
+ public static String getFileChecksum(File file) {
+ try (FileInputStream inputStream = new FileInputStream(file)) {
+ MessageDigest digest = MessageDigest.getInstance("SHA-256");
+ byte[] bytesBuffer = new byte[1024];
+ int bytesRead;
+
+ while ((bytesRead = inputStream.read(bytesBuffer)) != -1) {
+ digest.update(bytesBuffer, 0, bytesRead);
+ }
+ return convertByteArrayToHexString(digest.digest());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return "";
+ }
+ private static String convertByteArrayToHexString(byte[] arrayBytes) {
+ StringBuilder stringBuffer = new StringBuilder();
+ for (byte arrayByte : arrayBytes) {
+ stringBuffer.append(Integer.toString((arrayByte & 0xff) + 0x100, 16)
+ .substring(1));
+ }
+ return stringBuffer.toString();
+ }
private static class ImageSelection implements Transferable {
private final Image image;
+
public ImageSelection(Image image) {
this.image = image;
}
@Override
public DataFlavor[] getTransferDataFlavors() {
- return new DataFlavor[] {DataFlavor.imageFlavor};
+ return new DataFlavor[]{DataFlavor.imageFlavor};
}
@Override
@@ -147,7 +181,7 @@ public final class IOUtils {
@NotNull
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
- if(!DataFlavor.imageFlavor.equals(flavor)) {
+ if (!DataFlavor.imageFlavor.equals(flavor)) {
throw new UnsupportedFlavorException(flavor);
}
return image;
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/NetworkUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/NetworkUtils.java
index 5919be8..f527175 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/NetworkUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/NetworkUtils.java
@@ -131,29 +131,6 @@ public final class NetworkUtils {
}
/**
- * Gets the SHA-256 hash of a file.
- *
- * @param file The file to hash.
- * @return The SHA-256 hash of the file.
- */
- public static String getFileChecksum(File file) {
- try (FileInputStream inputStream = new FileInputStream(file)) {
- MessageDigest digest = MessageDigest.getInstance("SHA-256");
- byte[] bytesBuffer = new byte[1024];
- int bytesRead;
-
- while ((bytesRead = inputStream.read(bytesBuffer)) != -1) {
- digest.update(bytesBuffer, 0, bytesRead);
- }
-
- return convertByteArrayToHexString(digest.digest());
- } catch (Exception e) {
- e.printStackTrace();
- }
- return "";
- }
-
- /**
* Launches a URL in the default browser.
*
* @param uri The URI to launch.
@@ -164,7 +141,7 @@ public final class NetworkUtils {
UDesktop.browse(URI.create(uri));
}
- private static InputStream setupConnection(String url, String userAgent, int timeout, boolean useCaches) throws IOException {
+ public static InputStream setupConnection(String url, String userAgent, int timeout, boolean useCaches) throws IOException {
HttpURLConnection connection = ((HttpURLConnection) new URL(url).openConnection());
connection.setRequestMethod("GET");
connection.setUseCaches(useCaches);
@@ -174,13 +151,4 @@ public final class NetworkUtils {
connection.setDoOutput(true);
return connection.getInputStream();
}
-
- private static String convertByteArrayToHexString(byte[] arrayBytes) {
- StringBuilder stringBuffer = new StringBuilder();
- for (byte arrayByte : arrayBytes) {
- stringBuffer.append(Integer.toString((arrayByte & 0xff) + 0x100, 16)
- .substring(1));
- }
- return stringBuffer.toString();
- }
}