From 7c077e278b7266950a968a7e7f2f28b9a140ed96 Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Wed, 7 Sep 2022 22:20:00 +0200 Subject: new: option descriptions (#127) --- api/OneConfig.api | 55 +++++++++++---- .../oneconfig/config/annotations/Button.java | 2 + .../oneconfig/config/annotations/Checkbox.java | 2 + .../oneconfig/config/annotations/Color.java | 2 + .../oneconfig/config/annotations/Dropdown.java | 2 + .../oneconfig/config/annotations/DualOption.java | 2 + .../oneconfig/config/annotations/KeyBind.java | 2 + .../oneconfig/config/annotations/Slider.java | 2 + .../oneconfig/config/annotations/Switch.java | 2 + .../oneconfig/config/annotations/Text.java | 2 + .../oneconfig/config/elements/BasicOption.java | 62 +++++++++++++++-- .../config/elements/OptionSubcategory.java | 6 +- .../gui/elements/config/ConfigButton.java | 16 ++--- .../gui/elements/config/ConfigCheckbox.java | 6 +- .../gui/elements/config/ConfigColorElement.java | 6 +- .../gui/elements/config/ConfigDropdown.java | 11 ++- .../gui/elements/config/ConfigDualOption.java | 6 +- .../gui/elements/config/ConfigHeader.java | 2 +- .../oneconfig/gui/elements/config/ConfigInfo.java | 2 +- .../gui/elements/config/ConfigKeyBind.java | 6 +- .../gui/elements/config/ConfigPageButton.java | 4 +- .../gui/elements/config/ConfigSlider.java | 6 +- .../gui/elements/config/ConfigSwitch.java | 6 +- .../gui/elements/config/ConfigTextBox.java | 11 ++- .../java/cc/polyfrost/oneconfig/hud/HUDUtils.java | 27 ++++---- .../polyfrost/oneconfig/internal/assets/SVGs.java | 1 + .../compatibility/vigilance/VigilanceConfig.java | 24 +++---- .../polyfrost/oneconfig/internal/gui/HudGui.java | 81 ++++++++++++++++++++-- .../polyfrost/oneconfig/internal/hud/HudCore.java | 1 + .../polyfrost/oneconfig/renderer/AssetLoader.java | 46 +++++++++--- .../cc/polyfrost/oneconfig/renderer/NVGAsset.java | 25 +++++++ .../java/cc/polyfrost/oneconfig/utils/IOUtils.java | 48 +++++++++++-- .../cc/polyfrost/oneconfig/utils/NetworkUtils.java | 34 +-------- .../cc/polyfrost/oneconfig/utils/dsl/IOUtilsDSL.kt | 12 ++++ .../oneconfig/utils/dsl/NetworkUtilsDSL.kt | 7 -- .../resources/assets/oneconfig/icons/InfoArrow.svg | 1 + 36 files changed, 383 insertions(+), 147 deletions(-) create mode 100644 src/main/java/cc/polyfrost/oneconfig/renderer/NVGAsset.java create mode 100644 src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/IOUtilsDSL.kt create mode 100644 src/main/resources/assets/oneconfig/icons/InfoArrow.svg diff --git a/api/OneConfig.api b/api/OneConfig.api index aafb10b..a922b10 100644 --- a/api/OneConfig.api +++ b/api/OneConfig.api @@ -28,6 +28,7 @@ public class cc/polyfrost/oneconfig/config/Config { public abstract interface annotation class cc/polyfrost/oneconfig/config/annotations/Button : java/lang/annotation/Annotation { public abstract fun category ()Ljava/lang/String; + public abstract fun description ()Ljava/lang/String; public abstract fun name ()Ljava/lang/String; public abstract fun size ()I public abstract fun subcategory ()Ljava/lang/String; @@ -36,6 +37,7 @@ public abstract interface annotation class cc/polyfrost/oneconfig/config/annotat public abstract interface annotation class cc/polyfrost/oneconfig/config/annotations/Checkbox : java/lang/annotation/Annotation { public abstract fun category ()Ljava/lang/String; + public abstract fun description ()Ljava/lang/String; public abstract fun name ()Ljava/lang/String; public abstract fun size ()I public abstract fun subcategory ()Ljava/lang/String; @@ -44,6 +46,7 @@ public abstract interface annotation class cc/polyfrost/oneconfig/config/annotat public abstract interface annotation class cc/polyfrost/oneconfig/config/annotations/Color : java/lang/annotation/Annotation { public abstract fun allowAlpha ()Z public abstract fun category ()Ljava/lang/String; + public abstract fun description ()Ljava/lang/String; public abstract fun name ()Ljava/lang/String; public abstract fun size ()I public abstract fun subcategory ()Ljava/lang/String; @@ -55,6 +58,7 @@ public abstract interface annotation class cc/polyfrost/oneconfig/config/annotat public abstract interface annotation class cc/polyfrost/oneconfig/config/annotations/Dropdown : java/lang/annotation/Annotation { public abstract fun category ()Ljava/lang/String; + public abstract fun description ()Ljava/lang/String; public abstract fun name ()Ljava/lang/String; public abstract fun options ()[Ljava/lang/String; public abstract fun size ()I @@ -63,6 +67,7 @@ public abstract interface annotation class cc/polyfrost/oneconfig/config/annotat public abstract interface annotation class cc/polyfrost/oneconfig/config/annotations/DualOption : java/lang/annotation/Annotation { public abstract fun category ()Ljava/lang/String; + public abstract fun description ()Ljava/lang/String; public abstract fun left ()Ljava/lang/String; public abstract fun name ()Ljava/lang/String; public abstract fun right ()Ljava/lang/String; @@ -96,6 +101,7 @@ public abstract interface annotation class cc/polyfrost/oneconfig/config/annotat public abstract interface annotation class cc/polyfrost/oneconfig/config/annotations/KeyBind : java/lang/annotation/Annotation { public abstract fun category ()Ljava/lang/String; + public abstract fun description ()Ljava/lang/String; public abstract fun name ()Ljava/lang/String; public abstract fun size ()I public abstract fun subcategory ()Ljava/lang/String; @@ -114,6 +120,7 @@ public abstract interface annotation class cc/polyfrost/oneconfig/config/annotat public abstract interface annotation class cc/polyfrost/oneconfig/config/annotations/Slider : java/lang/annotation/Annotation { public abstract fun category ()Ljava/lang/String; + public abstract fun description ()Ljava/lang/String; public abstract fun max ()F public abstract fun min ()F public abstract fun name ()Ljava/lang/String; @@ -123,6 +130,7 @@ public abstract interface annotation class cc/polyfrost/oneconfig/config/annotat public abstract interface annotation class cc/polyfrost/oneconfig/config/annotations/Switch : java/lang/annotation/Annotation { public abstract fun category ()Ljava/lang/String; + public abstract fun description ()Ljava/lang/String; public abstract fun name ()Ljava/lang/String; public abstract fun size ()I public abstract fun subcategory ()Ljava/lang/String; @@ -130,6 +138,7 @@ public abstract interface annotation class cc/polyfrost/oneconfig/config/annotat public abstract interface annotation class cc/polyfrost/oneconfig/config/annotations/Text : java/lang/annotation/Annotation { public abstract fun category ()Ljava/lang/String; + public abstract fun description ()Ljava/lang/String; public abstract fun multiline ()Z public abstract fun name ()Ljava/lang/String; public abstract fun placeholder ()Ljava/lang/String; @@ -281,16 +290,18 @@ public final class cc/polyfrost/oneconfig/config/data/PageLocation : java/lang/E public abstract class cc/polyfrost/oneconfig/config/elements/BasicOption { public final field category Ljava/lang/String; + public final field description Ljava/lang/String; protected final field field Ljava/lang/reflect/Field; public final field name Ljava/lang/String; protected field parent Ljava/lang/Object; public final field size I public final field subcategory Ljava/lang/String; - public fun (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V + public fun (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V public fun addDependency (Ljava/util/function/Supplier;)V public fun addHideCondition (Ljava/util/function/Supplier;)V public fun addListener (Ljava/lang/Runnable;)V public abstract fun draw (JIILcc/polyfrost/oneconfig/utils/InputHandler;)V + public fun drawDescription (JIIILcc/polyfrost/oneconfig/utils/InputHandler;)V public fun drawLast (JIILcc/polyfrost/oneconfig/utils/InputHandler;)V public fun get ()Ljava/lang/Object; public fun getField ()Ljava/lang/reflect/Field; @@ -301,6 +312,7 @@ public abstract class cc/polyfrost/oneconfig/config/elements/BasicOption { public fun keyTyped (CI)V protected fun set (Ljava/lang/Object;)V public fun setParent (Ljava/lang/Object;)V + protected fun shouldDrawDescription ()Z } public class cc/polyfrost/oneconfig/config/elements/OptionCategory { @@ -702,9 +714,9 @@ public class cc/polyfrost/oneconfig/gui/elements/Slider : cc/polyfrost/oneconfig } public class cc/polyfrost/oneconfig/gui/elements/config/ConfigButton : cc/polyfrost/oneconfig/config/elements/BasicOption { - public fun (Ljava/lang/Runnable;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;)V - public fun (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;)V - public fun (Ljava/lang/reflect/Method;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;)V + public fun (Ljava/lang/Runnable;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;)V + public fun (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;)V + public fun (Ljava/lang/reflect/Method;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;)V public static fun create (Ljava/lang/reflect/Field;Ljava/lang/Object;)Lcc/polyfrost/oneconfig/gui/elements/config/ConfigButton; public static fun create (Ljava/lang/reflect/Method;Ljava/lang/Object;)Lcc/polyfrost/oneconfig/gui/elements/config/ConfigButton; public fun draw (JIILcc/polyfrost/oneconfig/utils/InputHandler;)V @@ -712,14 +724,14 @@ public class cc/polyfrost/oneconfig/gui/elements/config/ConfigButton : cc/polyfr } public class cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox : cc/polyfrost/oneconfig/config/elements/BasicOption { - public fun (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V + public fun (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V public static fun create (Ljava/lang/reflect/Field;Ljava/lang/Object;)Lcc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox; public fun draw (JIILcc/polyfrost/oneconfig/utils/InputHandler;)V public fun getHeight ()I } public class cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement : cc/polyfrost/oneconfig/config/elements/BasicOption { - public fun (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZ)V + public fun (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZ)V public static fun create (Ljava/lang/reflect/Field;Ljava/lang/Object;)Lcc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement; public fun draw (JIILcc/polyfrost/oneconfig/utils/InputHandler;)V public fun getHeight ()I @@ -728,15 +740,16 @@ public class cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement : cc/ } public class cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown : cc/polyfrost/oneconfig/config/elements/BasicOption { - public fun (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I[Ljava/lang/String;)V + public fun (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I[Ljava/lang/String;)V public static fun create (Ljava/lang/reflect/Field;Ljava/lang/Object;)Lcc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown; public fun draw (JIILcc/polyfrost/oneconfig/utils/InputHandler;)V public fun drawLast (JIILcc/polyfrost/oneconfig/utils/InputHandler;)V public fun getHeight ()I + protected fun shouldDrawDescription ()Z } public class cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption : cc/polyfrost/oneconfig/config/elements/BasicOption { - public fun (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)V + public fun (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)V public static fun create (Ljava/lang/reflect/Field;Ljava/lang/Object;)Lcc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption; public fun draw (JIILcc/polyfrost/oneconfig/utils/InputHandler;)V public fun getHeight ()I @@ -757,7 +770,7 @@ public class cc/polyfrost/oneconfig/gui/elements/config/ConfigInfo : cc/polyfros } public class cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind : cc/polyfrost/oneconfig/config/elements/BasicOption { - public fun (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V + public fun (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V public static fun create (Ljava/lang/reflect/Field;Ljava/lang/Object;)Lcc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind; public fun draw (JIILcc/polyfrost/oneconfig/utils/InputHandler;)V public fun getHeight ()I @@ -774,7 +787,7 @@ public class cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton : cc/po } public class cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider : cc/polyfrost/oneconfig/config/elements/BasicOption { - public fun (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;FFI)V + public fun (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;FFI)V public static fun create (Ljava/lang/reflect/Field;Ljava/lang/Object;)Lcc/polyfrost/oneconfig/gui/elements/config/ConfigSlider; public fun draw (JIILcc/polyfrost/oneconfig/utils/InputHandler;)V public fun getHeight ()I @@ -782,18 +795,19 @@ public class cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider : cc/polyfr } public class cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch : cc/polyfrost/oneconfig/config/elements/BasicOption { - public fun (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V + public fun (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V public static fun create (Ljava/lang/reflect/Field;Ljava/lang/Object;)Lcc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch; public fun draw (JIILcc/polyfrost/oneconfig/utils/InputHandler;)V public fun getHeight ()I } public class cc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox : cc/polyfrost/oneconfig/config/elements/BasicOption { - public fun (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;ZZ)V + public fun (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;ZZ)V public static fun create (Ljava/lang/reflect/Field;Ljava/lang/Object;)Lcc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox; public fun draw (JIILcc/polyfrost/oneconfig/utils/InputHandler;)V public fun getHeight ()I public fun keyTyped (CI)V + protected fun shouldDrawDescription ()Z } public class cc/polyfrost/oneconfig/gui/elements/text/NumberInputField : cc/polyfrost/oneconfig/gui/elements/text/TextInputField { @@ -1163,6 +1177,8 @@ public final class cc/polyfrost/oneconfig/renderer/AssetLoader { public fun clearImages (J)V public fun clearSVGs (J)V public fun getImage (Ljava/lang/String;)I + public fun getNVGImage (Ljava/lang/String;)Lcc/polyfrost/oneconfig/renderer/NVGAsset; + public fun getNVGSVG (Ljava/lang/String;)Lcc/polyfrost/oneconfig/renderer/NVGAsset; public fun getSVG (Ljava/lang/String;FF)I public fun imageToIntBuffer (Ljava/lang/String;)Ljava/nio/IntBuffer; public fun loadImage (JLcc/polyfrost/oneconfig/renderer/Image;)Z @@ -1201,6 +1217,13 @@ public class cc/polyfrost/oneconfig/renderer/Image { public fun (Ljava/lang/String;I)V } +public class cc/polyfrost/oneconfig/renderer/NVGAsset { + protected fun (III)V + public fun getHeight ()I + public fun getImage ()I + public fun getWidth ()I +} + public final class cc/polyfrost/oneconfig/renderer/RenderManager { public static fun color (JI)Lorg/lwjgl/nanovg/NVGColor; public static fun drawBorderedText (Ljava/lang/String;FFII)I @@ -1321,6 +1344,7 @@ public final class cc/polyfrost/oneconfig/utils/IOUtils { public fun ()V public static fun copyImageToClipboard (Ljava/awt/Image;)V public static fun copyStringToClipboard (Ljava/lang/String;)V + public static fun getFileChecksum (Ljava/io/File;)Ljava/lang/String; public static fun getImageFromClipboard ()Ljava/awt/Image; public static fun getStringFromClipboard ()Ljava/lang/String; public static fun resourceToByteBuffer (Ljava/lang/String;)Ljava/nio/ByteBuffer; @@ -1383,11 +1407,11 @@ public final class cc/polyfrost/oneconfig/utils/NetworkUtils { public static fun browseLink (Ljava/lang/String;)V public static fun downloadFile (Ljava/lang/String;Ljava/io/File;)Z public static fun downloadFile (Ljava/lang/String;Ljava/io/File;Ljava/lang/String;IZ)Z - public static fun getFileChecksum (Ljava/io/File;)Ljava/lang/String; public static fun getJsonElement (Ljava/lang/String;)Lcom/google/gson/JsonElement; public static fun getJsonElement (Ljava/lang/String;Ljava/lang/String;IZ)Lcom/google/gson/JsonElement; public static fun getString (Ljava/lang/String;)Ljava/lang/String; public static fun getString (Ljava/lang/String;Ljava/lang/String;IZ)Ljava/lang/String; + public static fun setupConnection (Ljava/lang/String;Ljava/lang/String;IZ)Ljava/io/InputStream; } public final class cc/polyfrost/oneconfig/utils/Notifications { @@ -1555,6 +1579,10 @@ public final class cc/polyfrost/oneconfig/utils/dsl/ColorUtilsDSLKt { public static final fun toColor (I)Lcc/polyfrost/oneconfig/config/core/OneColor; } +public final class cc/polyfrost/oneconfig/utils/dsl/IOUtilsDSLKt { + public static final fun checksum (Ljava/io/File;)Ljava/lang/String; +} + public final class cc/polyfrost/oneconfig/utils/dsl/JsonUtilsDSLKt { public static final fun asJsonElement (Ljava/lang/String;Z)Lcom/google/gson/JsonElement; public static synthetic fun asJsonElement$default (Ljava/lang/String;ZILjava/lang/Object;)Lcom/google/gson/JsonElement; @@ -1572,7 +1600,6 @@ public final class cc/polyfrost/oneconfig/utils/dsl/MultithreadingDSLKt { public final class cc/polyfrost/oneconfig/utils/dsl/NetworkUtilsDSLKt { public static final fun browseLink (Lcc/polyfrost/oneconfig/libs/universal/UDesktop;Ljava/lang/String;)V - public static final fun checksum (Ljava/io/File;)Ljava/lang/String; public static final fun download (Ljava/io/File;Ljava/lang/String;Ljava/lang/String;IZ)Z public static synthetic fun download$default (Ljava/io/File;Ljava/lang/String;Ljava/lang/String;IZILjava/lang/Object;)Z } 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> dependencies = new ArrayList<>(); private final ArrayList listeners = new ArrayList<>(); private final ArrayList> 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 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 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() { + @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 : 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 imageHashMap = new HashMap<>(); - private final HashMap svgHashMap = new HashMap<>(); + private final HashMap imageHashMap = new HashMap<>(); + private final HashMap 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. + *

Requires the assets to have been loaded first.

+ * + * @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 temp = new HashMap<>(imageHashMap); + HashMap 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. + *

Requires the assets to have been loaded first.

+ * + * @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 temp = new HashMap<>(svgHashMap); + HashMap 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 @@ -130,29 +130,6 @@ public final class NetworkUtils { return downloadFile(url, file, "OneConfig/1.0.0", 5000, false); } - /** - * 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. * @@ -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(); - } } diff --git a/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/IOUtilsDSL.kt b/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/IOUtilsDSL.kt new file mode 100644 index 0000000..6b89fe6 --- /dev/null +++ b/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/IOUtilsDSL.kt @@ -0,0 +1,12 @@ +package cc.polyfrost.oneconfig.utils.dsl + +import cc.polyfrost.oneconfig.utils.IOUtils +import cc.polyfrost.oneconfig.utils.NetworkUtils +import java.io.File + +/** + * Returns the SHA-256 hash of the given [File]. + * + * @see NetworkUtils.getFileChecksum + */ +fun File.checksum() = IOUtils.getFileChecksum(this) \ No newline at end of file diff --git a/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/NetworkUtilsDSL.kt b/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/NetworkUtilsDSL.kt index 56fba21..a744a29 100644 --- a/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/NetworkUtilsDSL.kt +++ b/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/NetworkUtilsDSL.kt @@ -30,13 +30,6 @@ import cc.polyfrost.oneconfig.utils.NetworkUtils import cc.polyfrost.oneconfig.libs.universal.UDesktop import java.io.File -/** - * Returns the SHA-256 hash of the given [File]. - * - * @see NetworkUtils.getFileChecksum - */ -fun File.checksum() = NetworkUtils.getFileChecksum(this) - /** * Downloads the given [url] to the given [File]. * diff --git a/src/main/resources/assets/oneconfig/icons/InfoArrow.svg b/src/main/resources/assets/oneconfig/icons/InfoArrow.svg new file mode 100644 index 0000000..1685884 --- /dev/null +++ b/src/main/resources/assets/oneconfig/icons/InfoArrow.svg @@ -0,0 +1 @@ + \ No newline at end of file -- cgit