diff options
16 files changed, 800 insertions, 200 deletions
diff --git a/api/OneConfig.api b/api/OneConfig.api index 60c800f..7e007d6 100644 --- a/api/OneConfig.api +++ b/api/OneConfig.api @@ -560,10 +560,11 @@ public class cc/polyfrost/oneconfig/gui/OneConfigGui : cc/polyfrost/oneconfig/ut public fun doesGuiPauseGame ()Z public fun draw (JFLcc/polyfrost/oneconfig/utils/InputHandler;)V public fun getColor ()Lcc/polyfrost/oneconfig/config/core/OneColor; - public fun getScaleFactor ()F + public static fun getScaleFactor ()F public fun getSearchValue ()Ljava/lang/String; public fun hasBackgroundBlur ()Z public fun initColorSelector (Lcc/polyfrost/oneconfig/gui/elements/ColorSelector;)V + public static fun isOpen ()Z public fun onKeyPressed (ICLcc/polyfrost/oneconfig/libs/universal/UKeyboard$Modifiers;)V public fun onScreenClose ()V public fun openPage (Lcc/polyfrost/oneconfig/gui/pages/Page;)V @@ -578,14 +579,28 @@ public class cc/polyfrost/oneconfig/gui/SideBar { } public abstract class cc/polyfrost/oneconfig/gui/animations/Animation { + protected final field change F + protected final field duration F + protected final field reverse Z + protected final field start F + protected field timePassed F public fun <init> (FFFZ)V protected abstract fun animate (F)F public fun get ()F public fun get (F)F + public fun getEnd ()F + public fun getStart ()F public fun isFinished ()Z public fun isReversed ()Z } +public class cc/polyfrost/oneconfig/gui/animations/ChainedAnimation : cc/polyfrost/oneconfig/gui/animations/Animation { + public fun <init> ([Lcc/polyfrost/oneconfig/gui/animations/Animation;)V + protected fun animate (F)F + public fun get (F)F + public fun isFinished ()Z +} + public class cc/polyfrost/oneconfig/gui/animations/ColorAnimation { public fun <init> (Lcc/polyfrost/oneconfig/utils/color/ColorPalette;)V public fun <init> (Lcc/polyfrost/oneconfig/utils/color/ColorPalette;I)V @@ -607,10 +622,14 @@ public class cc/polyfrost/oneconfig/gui/animations/CubicBezier : cc/polyfrost/on } public class cc/polyfrost/oneconfig/gui/animations/DummyAnimation : cc/polyfrost/oneconfig/gui/animations/Animation { + protected field done Ljava/util/concurrent/Callable; protected final field value F public fun <init> (F)V + public fun <init> (FF)V + public fun <init> (FLjava/util/concurrent/Callable;)V protected fun animate (F)F public fun get (F)F + public fun isFinished ()Z } public class cc/polyfrost/oneconfig/gui/animations/EaseInOutCubic : cc/polyfrost/oneconfig/gui/animations/Animation { @@ -1200,6 +1219,25 @@ public final class cc/polyfrost/oneconfig/renderer/AssetLoader { public fun removeSVG (JLjava/lang/String;FF)V } +public class cc/polyfrost/oneconfig/renderer/Icon { + public final field type Lcc/polyfrost/oneconfig/renderer/Icon$Type; + public fun <init> (Lcc/polyfrost/oneconfig/renderer/Image;)V + public fun <init> (Lcc/polyfrost/oneconfig/renderer/SVG;)V + public fun <init> (Ljava/lang/String;)V + public fun draw (JFFFF)V + public fun draw (JFFFFI)V + public fun draw (JFFFFIF)V + public fun getImage ()Lcc/polyfrost/oneconfig/renderer/Image; + public fun getSVG ()Lcc/polyfrost/oneconfig/renderer/SVG; +} + +public final class cc/polyfrost/oneconfig/renderer/Icon$Type : java/lang/Enum { + public static final field IMAGE Lcc/polyfrost/oneconfig/renderer/Icon$Type; + public static final field SVG Lcc/polyfrost/oneconfig/renderer/Icon$Type; + public static fun valueOf (Ljava/lang/String;)Lcc/polyfrost/oneconfig/renderer/Icon$Type; + public static fun values ()[Lcc/polyfrost/oneconfig/renderer/Icon$Type; +} + public class cc/polyfrost/oneconfig/renderer/Image { public final field filePath Ljava/lang/String; public final field flags I @@ -1230,18 +1268,25 @@ public final class cc/polyfrost/oneconfig/renderer/RenderManager { public static fun drawRoundedRectVaried (JFFFFIFFFF)V public static fun drawScaledString (Ljava/lang/String;FFILcc/polyfrost/oneconfig/renderer/RenderManager$TextType;F)V public static fun drawSvg (JLcc/polyfrost/oneconfig/renderer/SVG;FFFF)V + public static fun drawSvg (JLcc/polyfrost/oneconfig/renderer/SVG;FFFFF)V public static fun drawSvg (JLcc/polyfrost/oneconfig/renderer/SVG;FFFFI)V + public static fun drawSvg (JLcc/polyfrost/oneconfig/renderer/SVG;FFFFIF)V public static fun drawSvg (JLjava/lang/String;FFFF)V + public static fun drawSvg (JLjava/lang/String;FFFFF)V public static fun drawSvg (JLjava/lang/String;FFFFI)V + public static fun drawSvg (JLjava/lang/String;FFFFIF)V public static fun drawText (JLjava/lang/String;FFIFLcc/polyfrost/oneconfig/renderer/font/Font;)V public static fun drawURL (JLjava/lang/String;FFFLcc/polyfrost/oneconfig/renderer/font/Font;Lcc/polyfrost/oneconfig/utils/InputHandler;)V - public static fun drawWrappedString (JLjava/lang/String;FFFIFLcc/polyfrost/oneconfig/renderer/font/Font;)V + public static fun drawWrappedString (JLjava/lang/String;FFFIFFLcc/polyfrost/oneconfig/renderer/font/Font;)V public static fun fillNVGColorWithRGBA (FFFFLorg/lwjgl/nanovg/NVGColor;)V public static fun getTextWidth (JLjava/lang/String;FLcc/polyfrost/oneconfig/renderer/font/Font;)F + public static fun getWrappedStringHeight (JLjava/lang/String;FFFLcc/polyfrost/oneconfig/renderer/font/Font;)F + public static fun resetTransform (J)V public static fun scale (JFF)V public static fun setAlpha (JF)V public static fun setupAndDraw (Ljava/util/function/LongConsumer;)V public static fun setupAndDraw (ZLjava/util/function/LongConsumer;)V + public static fun translate (JFF)V } public final class cc/polyfrost/oneconfig/renderer/RenderManager$TextType : java/lang/Enum { @@ -1337,6 +1382,8 @@ public class cc/polyfrost/oneconfig/utils/InputHandler { public fun isBlockingInput ()Z public fun isClicked ()Z public fun isClicked (Z)Z + public fun isMouseDown ()Z + public fun isMouseDown (I)Z public fun mouseX ()F public fun mouseY ()F public fun resetScale ()V @@ -1380,6 +1427,24 @@ public final class cc/polyfrost/oneconfig/utils/NetworkUtils { public static fun getString (Ljava/lang/String;Ljava/lang/String;IZ)Ljava/lang/String; } +public final class cc/polyfrost/oneconfig/utils/Notifications { + public static final field INSTANCE Lcc/polyfrost/oneconfig/utils/Notifications; + public fun send (Ljava/lang/String;Ljava/lang/String;)V + public fun send (Ljava/lang/String;Ljava/lang/String;F)V + public fun send (Ljava/lang/String;Ljava/lang/String;FLjava/lang/Runnable;)V + public fun send (Ljava/lang/String;Ljava/lang/String;FLjava/util/concurrent/Callable;)V + public fun send (Ljava/lang/String;Ljava/lang/String;FLjava/util/concurrent/Callable;Ljava/lang/Runnable;)V + public fun send (Ljava/lang/String;Ljava/lang/String;Lcc/polyfrost/oneconfig/renderer/Icon;)V + public fun send (Ljava/lang/String;Ljava/lang/String;Lcc/polyfrost/oneconfig/renderer/Icon;F)V + public fun send (Ljava/lang/String;Ljava/lang/String;Lcc/polyfrost/oneconfig/renderer/Icon;FLjava/lang/Runnable;)V + public fun send (Ljava/lang/String;Ljava/lang/String;Lcc/polyfrost/oneconfig/renderer/Icon;FLjava/util/concurrent/Callable;)V + public fun send (Ljava/lang/String;Ljava/lang/String;Lcc/polyfrost/oneconfig/renderer/Icon;FLjava/util/concurrent/Callable;Ljava/lang/Runnable;)V + public fun send (Ljava/lang/String;Ljava/lang/String;Lcc/polyfrost/oneconfig/renderer/Icon;Ljava/lang/Runnable;)V + public fun send (Ljava/lang/String;Ljava/lang/String;Lcc/polyfrost/oneconfig/renderer/Icon;Ljava/util/concurrent/Callable;)V + public fun send (Ljava/lang/String;Ljava/lang/String;Ljava/lang/Runnable;)V + public fun send (Ljava/lang/String;Ljava/lang/String;Ljava/util/concurrent/Callable;)V +} + public final class cc/polyfrost/oneconfig/utils/TextUtils { public fun <init> ()V public static fun wrapText (JLjava/lang/String;FFLcc/polyfrost/oneconfig/renderer/font/Font;)Ljava/util/ArrayList; @@ -1586,18 +1651,26 @@ public final class cc/polyfrost/oneconfig/utils/dsl/RenderManagerDSLKt { public static final fun drawRoundedRectVaried (Lcc/polyfrost/oneconfig/utils/dsl/VG;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;ILjava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;)V public static final fun drawSVG (JLcc/polyfrost/oneconfig/renderer/SVG;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;)V public static final fun drawSVG (JLcc/polyfrost/oneconfig/renderer/SVG;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;I)V + public static final fun drawSVG (JLcc/polyfrost/oneconfig/renderer/SVG;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;ILjava/lang/Number;)V + public static final fun drawSVG (JLcc/polyfrost/oneconfig/renderer/SVG;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;)V public static final fun drawSVG (JLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;)V public static final fun drawSVG (JLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;I)V + public static final fun drawSVG (JLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;ILjava/lang/Number;)V + public static final fun drawSVG (JLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;)V public static final fun drawSVG (Lcc/polyfrost/oneconfig/utils/dsl/VG;Lcc/polyfrost/oneconfig/renderer/SVG;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;)V public static final fun drawSVG (Lcc/polyfrost/oneconfig/utils/dsl/VG;Lcc/polyfrost/oneconfig/renderer/SVG;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;I)V + public static final fun drawSVG (Lcc/polyfrost/oneconfig/utils/dsl/VG;Lcc/polyfrost/oneconfig/renderer/SVG;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;ILjava/lang/Number;)V + public static final fun drawSVG (Lcc/polyfrost/oneconfig/utils/dsl/VG;Lcc/polyfrost/oneconfig/renderer/SVG;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;)V public static final fun drawSVG (Lcc/polyfrost/oneconfig/utils/dsl/VG;Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;)V public static final fun drawSVG (Lcc/polyfrost/oneconfig/utils/dsl/VG;Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;I)V + public static final fun drawSVG (Lcc/polyfrost/oneconfig/utils/dsl/VG;Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;ILjava/lang/Number;)V + public static final fun drawSVG (Lcc/polyfrost/oneconfig/utils/dsl/VG;Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;)V public static final fun drawText (JLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;ILjava/lang/Number;Lcc/polyfrost/oneconfig/renderer/font/Font;)V public static final fun drawText (Lcc/polyfrost/oneconfig/utils/dsl/VG;Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Number;ILjava/lang/Number;Lcc/polyfrost/oneconfig/renderer/font/Font;)V public static final fun drawURL (JLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Lcc/polyfrost/oneconfig/renderer/font/Font;Lcc/polyfrost/oneconfig/utils/InputHandler;)V public static final fun drawURL (Lcc/polyfrost/oneconfig/utils/dsl/VG;Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Lcc/polyfrost/oneconfig/renderer/font/Font;Lcc/polyfrost/oneconfig/utils/InputHandler;)V - public static final fun drawWrappedString (JLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;ILjava/lang/Number;Lcc/polyfrost/oneconfig/renderer/font/Font;)V - public static final fun drawWrappedString (Lcc/polyfrost/oneconfig/utils/dsl/VG;Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;ILjava/lang/Number;Lcc/polyfrost/oneconfig/renderer/font/Font;)V + public static final fun drawWrappedString (JLjava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;ILjava/lang/Number;Ljava/lang/Number;Lcc/polyfrost/oneconfig/renderer/font/Font;)V + public static final fun drawWrappedString (Lcc/polyfrost/oneconfig/utils/dsl/VG;Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;ILjava/lang/Number;Ljava/lang/Number;Lcc/polyfrost/oneconfig/renderer/font/Font;)V public static final fun fill (Lorg/lwjgl/nanovg/NVGColor;FFFF)V public static final fun fill (Lorg/lwjgl/nanovg/NVGColor;I)V public static final fun fill (Lorg/lwjgl/nanovg/NVGColor;IIII)V @@ -1610,10 +1683,14 @@ public final class cc/polyfrost/oneconfig/utils/dsl/RenderManagerDSLKt { public static final fun newColor (JIIII)Lorg/lwjgl/nanovg/NVGColor; public static final fun newColor (Lcc/polyfrost/oneconfig/utils/dsl/VG;I)Lorg/lwjgl/nanovg/NVGColor; public static final fun newColor (Lcc/polyfrost/oneconfig/utils/dsl/VG;IIII)Lorg/lwjgl/nanovg/NVGColor; + public static final fun resetTransform (J)V + public static final fun resetTransform (Lcc/polyfrost/oneconfig/utils/dsl/VG;)V public static final fun scale (JFF)V public static final fun scale (Lcc/polyfrost/oneconfig/utils/dsl/VG;FF)V public static final fun setAlpha (JF)V public static final fun setAlpha (Lcc/polyfrost/oneconfig/utils/dsl/VG;F)V + public static final fun translate (JFF)V + public static final fun translate (Lcc/polyfrost/oneconfig/utils/dsl/VG;FF)V } public final class cc/polyfrost/oneconfig/utils/dsl/TextUtilsDSLKt { @@ -1710,24 +1787,3 @@ public final class cc/polyfrost/oneconfig/utils/hypixel/LocrawInfo$GameType : ja public static fun values ()[Lcc/polyfrost/oneconfig/utils/hypixel/LocrawInfo$GameType; } -public final class cc/polyfrost/oneconfig/utils/notifications/Notification { - public fun getAction ()Ljava/lang/Runnable; - public fun getDuration ()F - public fun getMessage ()Ljava/lang/String; - public fun getOnClose ()Ljava/lang/Runnable; - public fun getTitle ()Ljava/lang/String; - public fun getX ()F - public fun getY ()F - public fun setMessage (Ljava/lang/String;)V - public fun setTitle (Ljava/lang/String;)V -} - -public final class cc/polyfrost/oneconfig/utils/notifications/Notifications { - public static final field INSTANCE Lcc/polyfrost/oneconfig/utils/notifications/Notifications; - public fun send (Ljava/lang/String;Ljava/lang/String;)V - public fun send (Ljava/lang/String;Ljava/lang/String;F)V - public fun send (Ljava/lang/String;Ljava/lang/String;FLjava/lang/Runnable;)V - public fun send (Ljava/lang/String;Ljava/lang/String;FLjava/lang/Runnable;Ljava/lang/Runnable;)V - public fun send (Ljava/lang/String;Ljava/lang/String;Ljava/lang/Runnable;)V -} - diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java index 9017230..db2ea8b 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java @@ -66,7 +66,6 @@ public class OneConfigGui extends OneUIScreen { public boolean allowClose = true; protected Page currentPage; protected Page prevPage; - private float scale = 1f; private Animation animation; public OneConfigGui() { @@ -93,10 +92,7 @@ public class OneConfigGui extends OneUIScreen { NanoVG.nvgTranslate(vg, UResolution.getWindowWidth(), UResolution.getWindowHeight()); NanoVG.nvgRotate(vg, (float) Math.toRadians(180)); } - scale = Preferences.enableCustomScale ? Preferences.customScale : Math.min(UResolution.getWindowWidth() / 1920f, UResolution.getWindowHeight() / 1080f); - if (scale < 1 && !Preferences.enableCustomScale) - scale = Math.min(Math.min(1f, UResolution.getWindowWidth() / 1280f), Math.min(1f, UResolution.getWindowHeight() / 800f)); - scale = (float) (Math.floor(scale / 0.05f) * 0.05f); + float scale = getScaleFactor(); int x = (int) ((UResolution.getWindowWidth() - 1280 * scale) / 2f / scale); int y = (int) ((UResolution.getWindowHeight() - 800 * scale) / 2f / scale); RenderManager.scale(vg, scale, scale); @@ -198,6 +194,7 @@ public class OneConfigGui extends OneUIScreen { if (currentColorSelector != null) { currentColorSelector.draw(vg); } + RenderManager.resetTransform(vg); } @Override @@ -280,8 +277,11 @@ public class OneConfigGui extends OneUIScreen { return currentColorSelector.getColor(); } - public float getScaleFactor() { - return scale; + public static float getScaleFactor() { + float scale = Preferences.enableCustomScale ? Preferences.customScale : Math.min(UResolution.getWindowWidth() / 1920f, UResolution.getWindowHeight() / 1080f); + if (scale < 1 && !Preferences.enableCustomScale) + scale = Math.min(Math.min(1f, UResolution.getWindowWidth() / 1280f), Math.min(1f, UResolution.getWindowHeight() / 800f)); + return (float) (Math.floor(scale / 0.05f) * 0.05f); } public String getSearchValue() { @@ -303,4 +303,8 @@ public class OneConfigGui extends OneUIScreen { public boolean hasBackgroundBlur() { return Preferences.enableBlur; } + + public static boolean isOpen() { + return Platform.getGuiPlatform().getCurrentScreen() instanceof OneConfigGui; + } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java index 4040164..f85132b 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java @@ -29,11 +29,11 @@ package cc.polyfrost.oneconfig.gui.animations; import cc.polyfrost.oneconfig.utils.gui.GuiUtils; public abstract class Animation { - private final boolean reverse; - private final float duration; - private final float start; - private final float change; - private float timePassed = 0; + protected final boolean reverse; + protected final float duration; + protected final float start; + protected final float change; + protected float timePassed = 0; /** * @param duration The duration of the animation @@ -84,5 +84,19 @@ public abstract class Animation { return reverse; } + /** + * @return The start position of the animation + */ + public float getStart() { + return start; + } + + /** + * @return The end position of the animation + */ + public float getEnd() { + return start + change; + } + protected abstract float animate(float x); } diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/notifications/Notifications.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/ChainedAnimation.java index 4038355..63be4a0 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/notifications/Notifications.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/ChainedAnimation.java @@ -24,35 +24,33 @@ * <https://polyfrost.cc/legal/oneconfig/additional-terms> */ -package cc.polyfrost.oneconfig.utils.notifications; +package cc.polyfrost.oneconfig.gui.animations; -/** - * @deprecated Reserved for future use, not implemented yet. - */ -@Deprecated -public final class Notifications { - public static final Notifications INSTANCE = new Notifications(); - private Notifications() { - - } - - public void send(String title, String message) { - - } - - public void send(String title, String message, Runnable action) { +public class ChainedAnimation extends Animation { + private final Animation[] animations; + private int currentAnimation = 0; + private float value; + public ChainedAnimation(Animation... animations) { + super(1, 0, 0, false); + this.animations = animations; } - public void send(String title, String message, float duration) { - + @Override + public float get(float deltaTime) { + if (currentAnimation >= animations.length) return value; + value = animations[currentAnimation].get(deltaTime); + if (animations[currentAnimation].isFinished()) currentAnimation++; + return value; } - public void send(String title, String message, float duration, Runnable action) { - + @Override + public boolean isFinished() { + return currentAnimation >= animations.length; } - public void send(String title, String message, float duration, Runnable action, Runnable onClose) { - + @Override + protected float animate(float x) { + return 0; } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/DummyAnimation.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/DummyAnimation.java index ca9bc17..62cbed7 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/DummyAnimation.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/DummyAnimation.java @@ -26,23 +26,56 @@ package cc.polyfrost.oneconfig.gui.animations; +import java.util.concurrent.Callable; + public class DummyAnimation extends Animation { protected final float value; + protected Callable<Boolean> done = null; /** * @param value The value that is returned + * @param done A callable that returns if the animation is finished */ - public DummyAnimation(float value) { - super(value, value, value, false); + public DummyAnimation(float value, Callable<Boolean> done) { + super(0, value, value, false); + this.value = value; + this.done = done; + } + + /** + * @param value The value that is returned + * @param duration The duration of the animation + */ + public DummyAnimation(float value, float duration) { + super(duration, value, value, false); this.value = value; } + /** + * @param value The value that is returned + */ + public DummyAnimation(float value) { + this(value, 0); + } + @Override public float get(float deltaTime) { + timePassed += deltaTime; return value; } @Override + public boolean isFinished() { + if (done != null) { + try { + return done.call(); + } catch (Exception ignored) { + } + } + return super.isFinished(); + } + + @Override protected float animate(float x) { return x; } diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java index 88f726e..bc0e3a9 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java @@ -26,10 +26,7 @@ package cc.polyfrost.oneconfig.internal.config; -import cc.polyfrost.oneconfig.config.annotations.Exclude; -import cc.polyfrost.oneconfig.config.annotations.KeyBind; -import cc.polyfrost.oneconfig.config.annotations.Slider; -import cc.polyfrost.oneconfig.config.annotations.Switch; +import cc.polyfrost.oneconfig.config.annotations.*; import cc.polyfrost.oneconfig.config.core.OneKeyBind; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.internal.gui.BlurHandler; @@ -49,6 +46,12 @@ public class Preferences extends InternalConfig { ) public static OneKeyBind oneConfigKeyBind = new OneKeyBind(UKeyboard.KEY_RSHIFT); + @Dropdown( + name = "Release Channel", + options = {"Releases", "Pre-Releases"}, + size = 2 + ) + public static int updateChannel = 0; @Switch( name = "Use custom GUI scale", @@ -73,6 +76,10 @@ public class Preferences extends InternalConfig { initialize(); addListener("enableBlur", () -> BlurHandler.INSTANCE.reloadBlur(Platform.getGuiPlatform().getCurrentScreen())); registerKeyBind(oneConfigKeyBind, () -> new TickDelay(() -> Platform.getGuiPlatform().setCurrentScreen(OneConfigGui.create()), 1)); + addListener("updateChannel", () -> { + OneConfigConfig.updateChannel = updateChannel; + OneConfigConfig.getInstance().save(); + }); INSTANCE = this; } diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/utils/Notification.java b/src/main/java/cc/polyfrost/oneconfig/internal/utils/Notification.java new file mode 100644 index 0000000..e2c0b05 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/utils/Notification.java @@ -0,0 +1,118 @@ +/* + * This file is part of OneConfig. + * OneConfig - Next Generation Config Library for Minecraft: Java Edition + * Copyright (C) 2021, 2022 Polyfrost. + * <https://polyfrost.cc> <https://github.com/Polyfrost/> + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * OneConfig is licensed under the terms of version 3 of the GNU Lesser + * General Public License as published by the Free Software Foundation, AND + * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, + * either version 1.0 of the Additional Terms, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License. If not, see <https://www.gnu.org/licenses/>. You should + * have also received a copy of the Additional Terms Applicable + * to OneConfig, as published by Polyfrost. If not, see + * <https://polyfrost.cc/legal/oneconfig/additional-terms> + */ + +package cc.polyfrost.oneconfig.internal.utils; + +import cc.polyfrost.oneconfig.gui.OneConfigGui; +import cc.polyfrost.oneconfig.gui.animations.*; +import cc.polyfrost.oneconfig.internal.assets.Colors; +import cc.polyfrost.oneconfig.libs.universal.UResolution; +import cc.polyfrost.oneconfig.renderer.Icon; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.renderer.scissor.Scissor; +import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager; +import cc.polyfrost.oneconfig.utils.InputHandler; +import cc.polyfrost.oneconfig.utils.MathUtils; +import cc.polyfrost.oneconfig.utils.color.ColorPalette; +import cc.polyfrost.oneconfig.utils.gui.GuiUtils; +import org.jetbrains.annotations.Nullable; + +import java.util.concurrent.Callable; + +public final class Notification { + private final String title; + private final String message; + private final Icon icon; + private final Animation animation; + private final Callable<Float> progressBar; + private final Runnable action; + private final InputHandler inputHandler = new InputHandler(); + private final ColorAnimation bgColor = new ColorAnimation(new ColorPalette(Colors.GRAY_800, Colors.GRAY_700, Colors.GRAY_900)); + private final ColorAnimation titleColor = new ColorAnimation(new ColorPalette(Colors.WHITE_80, Colors.WHITE, Colors.WHITE)); + private final ColorAnimation messageColor = new ColorAnimation(new ColorPalette(Colors.WHITE_60, Colors.WHITE_90, Colors.WHITE_90)); + private boolean hovered = false; + + public Notification(String title, String message, @Nullable Icon icon, float duration, @Nullable Callable<Float> progressBar, @Nullable Runnable action) { + this.title = title; + this.message = message; + this.icon = icon; + this.animation = new ChainedAnimation( + new EaseInOutQuad(250, 0, 330, false), + progressBar == null ? new DummyAnimation(330, duration) : new DummyAnimation(330, () -> progressBar.call() >= 1f), + new EaseInOutQuad(250, 330, 0, false) + ); + this.progressBar = progressBar; + this.action = action; + } + + public float draw(final long vg, float y, float scale) { + RenderManager.scale(vg, scale, scale); + inputHandler.scale(scale, scale); + float x = (UResolution.getWindowWidth() / scale - animation.get(hovered ? 0 : GuiUtils.getDeltaTime())); + float textX = icon == null ? x + 16 : x + 64; + float textMaxLength = icon == null ? 268 : 220; + float messageHeight = RenderManager.getWrappedStringHeight(vg, message, textMaxLength, 12f, 1.75f, Fonts.REGULAR); + float height = getHeight(messageHeight); + y -= height; + hovered = inputHandler.isAreaHovered(x, y, 314, height); + if (hovered && inputHandler.isClicked() && action != null) action.run(); + int bgColor = this.bgColor.getColor(hovered, hovered && inputHandler.isMouseDown()); + int titleColor = this.titleColor.getColor(hovered, hovered && inputHandler.isMouseDown()); + int messageColor = this.messageColor.getColor(hovered, hovered && inputHandler.isMouseDown()); + RenderManager.drawRoundedRect(vg, x, y, 314f, height, bgColor, 8f); + if (icon != null) + icon.draw(vg, x + 16f, y + (height - (progressBar == null ? 0f : 5f)) / 2f - 16f, 32f, 32f, titleColor, scale); + RenderManager.drawText(vg, title, textX, y + 30, titleColor, 16f, Fonts.SEMIBOLD); + RenderManager.drawWrappedString(vg, message, textX, y + 46, textMaxLength, messageColor, 12f, 1.75f, Fonts.REGULAR); + if (progressBar != null) { + try { + float progress = MathUtils.clamp(progressBar.call()); + Scissor scissor1 = ScissorManager.scissor(vg, x + 314f * progress, y + height - 5f, 314f * (1 - progress), 5f); + RenderManager.drawRoundedRect(vg, x, y, 314f, height, Colors.PRIMARY_800, 8f); + ScissorManager.resetScissor(vg, scissor1); + Scissor scissor2 = ScissorManager.scissor(vg, x, y + height - 5f, 314f * progress - (314f * progress < 2.5f || 311.5f * progress > 2.5f ? 0f : 2.5f), 5f); + RenderManager.drawRoundedRect(vg, x, y, 314f, height, Colors.PRIMARY_500, 8f); + ScissorManager.resetScissor(vg, scissor2); + if (314f * progress >= 2.5f && 311.5f * progress <= 2.5f) + RenderManager.drawRoundedRect(vg, x + 2.5f, y + height - 5f, Math.max(0, 314f * progress - 5f), 5f, Colors.PRIMARY_500, 2.5f); + } catch (Exception ignored) { + } + } + RenderManager.resetTransform(vg); + return height; + } + + private float getHeight(float messageHeight) { + float height = 68 + messageHeight; + if (progressBar != null) height += 5f; + return height; + } + + public boolean isFinished() { + return animation.isFinished(); + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/Icon.java b/src/main/java/cc/polyfrost/oneconfig/renderer/Icon.java new file mode 100644 index 0000000..a256b57 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/renderer/Icon.java @@ -0,0 +1,88 @@ +/* + * This file is part of OneConfig. + * OneConfig - Next Generation Config Library for Minecraft: Java Edition + * Copyright (C) 2021, 2022 Polyfrost. + * <https://polyfrost.cc> <https://github.com/Polyfrost/> + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * OneConfig is licensed under the terms of version 3 of the GNU Lesser + * General Public License as published by the Free Software Foundation, AND + * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, + * either version 1.0 of the Additional Terms, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License. If not, see <https://www.gnu.org/licenses/>. You should + * have also received a copy of the Additional Terms Applicable + * to OneConfig, as published by Polyfrost. If not, see + * <https://polyfrost.cc/legal/oneconfig/additional-terms> + */ + +package cc.polyfrost.oneconfig.renderer; + +import com.google.gson.annotations.SerializedName; + +public class Icon { + private final Object icon; + public final Type type; + + public Icon(String filePath) { + this.icon = filePath; + this.type = filePath.endsWith(".svg") ? Type.SVG : Type.IMAGE; + } + + public Icon(SVG svg) { + this.icon = svg; + this.type = Type.SVG; + } + + public Icon(Image image) { + this.icon = image; + this.type = Type.IMAGE; + } + + public SVG getSVG() { + return (SVG) icon; + } + + public Image getImage() { + return (Image) icon; + } + + public void draw(long vg, float x, float y, float width, float height, int color, float scale) { + if (type == Type.SVG) { + RenderManager.drawSvg(vg, getSVG(), x, y, width, height, color, scale); + } else if (type == Type.IMAGE) { + RenderManager.drawImage(vg, getImage(), x, y, width, height, color); + } + } + + public void draw(long vg, float x, float y, float width, float height, int color) { + if (type == Type.SVG) { + RenderManager.drawSvg(vg, getSVG(), x, y, width, height, color); + } else if (type == Type.IMAGE) { + RenderManager.drawImage(vg, getImage(), x, y, width, height, color); + } + } + + public void draw(long vg, float x, float y, float width, float height) { + if (type == Type.SVG) { + RenderManager.drawSvg(vg, getSVG(), x, y, width, height); + } else if (type == Type.IMAGE) { + RenderManager.drawImage(vg, getImage(), x, y, width, height); + } + } + + public enum Type { + @SerializedName("0") + SVG, + @SerializedName("1") + IMAGE + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java b/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java index cfdb4ad..4d54621 100644 --- a/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java @@ -42,6 +42,7 @@ import org.lwjgl.nanovg.NVGColor; import org.lwjgl.nanovg.NVGPaint; import org.lwjgl.opengl.GL11; +import java.util.Arrays; import java.util.function.LongConsumer; import java.util.regex.Pattern; @@ -320,17 +321,27 @@ public final class RenderManager { * @param size The size. * @param font The font. */ - public static void drawWrappedString(long vg, String text, float x, float y, float width, int color, float size, Font font) { + public static void drawWrappedString(long vg, String text, float x, float y, float width, int color, float size, float lineHeight, Font font) { nvgBeginPath(vg); nvgFontSize(vg, size); nvgFontFace(vg, font.getName()); - nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE); + nvgTextLineHeight(vg, lineHeight); + nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_TOP); // Align top because center is weird with wrapping NVGColor nvgColor = color(vg, color); nvgTextBox(vg, x, y, width, text); nvgFill(vg); nvgColor.free(); } + public static float getWrappedStringHeight(long vg, String text, float width, float fontSize, float lineHeight, Font font) { + float[] bounds = new float[4]; + nvgFontSize(vg, fontSize); + nvgFontFace(vg, font.getName()); + nvgTextLineHeight(vg, lineHeight); + nvgTextBoxBounds(vg, 0, 0, width, text, bounds); + return bounds[3] - bounds[1]; + } + /** * Draw a formatted URL (a string in blue with an underline) that when clicked, opens the given text. * @@ -567,6 +578,26 @@ public final class RenderManager { } /** + * Translate to a location + * + * @param vg The NanoVG context + * @param x The x scale + * @param y The y scale + */ + public static void translate(long vg, float x, float y) { + nvgTranslate(vg, x, y); + } + + /** + * Reset all transforms + * + * @param vg The NanoVG context + */ + public static void resetTransform(long vg) { + nvgResetTransform(vg); + } + + /** * Sets the global alpha value to render with. * * @param vg The NanoVG context. @@ -577,7 +608,7 @@ public final class RenderManager { } /** - * Draws a SVG with the provided file path and parameters. + * Draws an SVG with the provided file path and parameters. * * @param vg The NanoVG context. * @param filePath The file path. @@ -585,11 +616,12 @@ public final class RenderManager { * @param y The y position. * @param width The width. * @param height The height. + * @param scale The scale */ - public static void drawSvg(long vg, String filePath, float x, float y, float width, float height) { - float w = width; - float h = height; - if (OneConfigGui.INSTANCE != null) { + public static void drawSvg(long vg, String filePath, float x, float y, float width, float height, float scale) { + float w = width * scale; + float h = height * scale; + if (OneConfigGui.INSTANCE != null && OneConfigGui.isOpen()) { w *= OneConfigGui.INSTANCE.getScaleFactor(); h *= OneConfigGui.INSTANCE.getScaleFactor(); } @@ -606,7 +638,7 @@ public final class RenderManager { } /** - * Draws a SVG with the provided file path and parameters. + * Draws an SVG with the provided file path and parameters. * * @param vg The NanoVG context. * @param filePath The file path. @@ -614,15 +646,30 @@ public final class RenderManager { * @param y The y position. * @param width The width. * @param height The height. - * @param color The color. */ - public static void drawSvg(long vg, String filePath, float x, float y, float width, float height, int color) { - float w = width; - float h = height; - if (OneConfigGui.INSTANCE != null) { - w *= OneConfigGui.INSTANCE.getScaleFactor(); - h *= OneConfigGui.INSTANCE.getScaleFactor(); + public static void drawSvg(long vg, String filePath, float x, float y, float width, float height) { + float scale = 1; + if (OneConfigGui.isOpen()) { + scale = OneConfigGui.getScaleFactor(); } + drawSvg(vg, filePath, x, y, width, height, scale); + } + + /** + * Draws an SVG with the provided file path and parameters. + * + * @param vg The NanoVG context. + * @param filePath The file path. + * @param x The x position. + * @param y The y position. + * @param width The width. + * @param height The height. + * @param color The color. + * @param scale The scale + */ + public static void drawSvg(long vg, String filePath, float x, float y, float width, float height, int color, float scale) { + float w = width * scale; + float h = height * scale; if (AssetLoader.INSTANCE.loadSVG(vg, filePath, w, h)) { NVGPaint imagePaint = NVGPaint.calloc(); int image = AssetLoader.INSTANCE.getSVG(filePath, w, h); @@ -639,15 +686,30 @@ public final class RenderManager { /** * Draws an SVG with the provided file path and parameters. * - * @see RenderManager#drawSvg(long, String, float, float, float, float) + * @param vg The NanoVG context. + * @param filePath The file path. + * @param x The x position. + * @param y The y position. + * @param width The width. + * @param height The height. + * @param color The color. */ - public static void drawSvg(long vg, SVG svg, float x, float y, float width, float height) { - float w = width; - float h = height; - if (OneConfigGui.INSTANCE != null) { - w *= OneConfigGui.INSTANCE.getScaleFactor(); - h *= OneConfigGui.INSTANCE.getScaleFactor(); + public static void drawSvg(long vg, String filePath, float x, float y, float width, float height, int color) { + float scale = 1; + if (OneConfigGui.isOpen()) { + scale = OneConfigGui.getScaleFactor(); } + drawSvg(vg, filePath, x, y, width, height, color, scale); + } + + /** + * Draws an SVG with the provided file path and parameters. + * + * @see RenderManager#drawSvg(long, String, float, float, float, float) + */ + public static void drawSvg(long vg, SVG svg, float x, float y, float width, float height, float scale) { + float w = width * scale; + float h = height * scale; if (AssetLoader.INSTANCE.loadSVG(vg, svg, w, h)) { drawSvg(vg, svg.filePath, x, y, width, height); } @@ -656,21 +718,43 @@ public final class RenderManager { /** * Draws an SVG with the provided file path and parameters. * - * @see RenderManager#drawSvg(long, String, float, float, float, float, int) + * @see RenderManager#drawSvg(long, String, float, float, float, float) */ - public static void drawSvg(long vg, SVG svg, float x, float y, float width, float height, int color) { - float w = width; - float h = height; - if (OneConfigGui.INSTANCE != null) { - w *= OneConfigGui.INSTANCE.getScaleFactor(); - h *= OneConfigGui.INSTANCE.getScaleFactor(); + public static void drawSvg(long vg, SVG svg, float x, float y, float width, float height) { + float scale = 1; + if (OneConfigGui.isOpen()) { + scale = OneConfigGui.getScaleFactor(); } + drawSvg(vg, svg, x, y, width, height, scale); + } + + /** + * Draws an SVG with the provided file path and parameters. + * + * @see RenderManager#drawSvg(long, String, float, float, float, float, int) + */ + public static void drawSvg(long vg, SVG svg, float x, float y, float width, float height, int color, float scale) { + float w = width * scale; + float h = height * scale; if (AssetLoader.INSTANCE.loadSVG(vg, svg, w, h)) { drawSvg(vg, svg.filePath, x, y, width, height, color); } } /** + * Draws an SVG with the provided file path and parameters. + * + * @see RenderManager#drawSvg(long, String, float, float, float, float) + */ + public static void drawSvg(long vg, SVG svg, float x, float y, float width, float height, int color) { + float scale = 1; + if (OneConfigGui.isOpen()) { + scale = OneConfigGui.getScaleFactor(); + } + drawSvg(vg, svg, x, y, width, height, color, scale); + } + + /** * Draw a circle with an info icon inside of it * * @param vg The NanoVG context. diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/InputHandler.java b/src/main/java/cc/polyfrost/oneconfig/utils/InputHandler.java index 6bd8207..809e55c 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/InputHandler.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/InputHandler.java @@ -135,6 +135,21 @@ public class InputHandler { } /** + * @param button The button + * @return If the button is down + */ + public boolean isMouseDown(int button) { + return Platform.getMousePlatform().isButtonDown(button); + } + + /** + * @return If the left mouse button is down + */ + public boolean isMouseDown() { + return isMouseDown(0); + } + + /** * Gets the current mouse X position. * <p> * All values returned from this class are not scaled to Minecraft's GUI scale. diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/Notifications.java b/src/main/java/cc/polyfrost/oneconfig/utils/Notifications.java new file mode 100644 index 0000000..b1fb387 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/utils/Notifications.java @@ -0,0 +1,238 @@ +/* + * This file is part of OneConfig. + * OneConfig - Next Generation Config Library for Minecraft: Java Edition + * Copyright (C) 2021, 2022 Polyfrost. + * <https://polyfrost.cc> <https://github.com/Polyfrost/> + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * OneConfig is licensed under the terms of version 3 of the GNU Lesser + * General Public License as published by the Free Software Foundation, AND + * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, + * either version 1.0 of the Additional Terms, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License. If not, see <https://www.gnu.org/licenses/>. You should + * have also received a copy of the Additional Terms Applicable + * to OneConfig, as published by Polyfrost. If not, see + * <https://polyfrost.cc/legal/oneconfig/additional-terms> + */ + +package cc.polyfrost.oneconfig.utils; + +import cc.polyfrost.oneconfig.events.event.HudRenderEvent; +import cc.polyfrost.oneconfig.gui.OneConfigGui; +import cc.polyfrost.oneconfig.gui.animations.Animation; +import cc.polyfrost.oneconfig.gui.animations.DummyAnimation; +import cc.polyfrost.oneconfig.gui.animations.EaseInOutQuad; +import cc.polyfrost.oneconfig.internal.utils.Notification; +import cc.polyfrost.oneconfig.libs.eventbus.Subscribe; +import cc.polyfrost.oneconfig.libs.universal.UResolution; +import cc.polyfrost.oneconfig.renderer.Icon; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import org.jetbrains.annotations.Nullable; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.concurrent.Callable; + +public final class Notifications { + public static final Notifications INSTANCE = new Notifications(); + // animation stores the bottom y of the notification + private final LinkedHashMap<Notification, Animation> notifications = new LinkedHashMap<>(); + private final float DEFAULT_DURATION = 4000; + + private Notifications() { + } + + /** + * Send a notification to the user + * + * @param title The title of the notification + * @param message The message of the notification + * @param icon The icon of the notification, null for none + * @param duration The duration the notification is on screen in ms + * @param progressbar A callable that returns the progress from 0-1 + * @param action The action executed when the notification is pressed + */ + public void send(String title, String message, @Nullable Icon icon, float duration, @Nullable Callable<Float> progressbar, @Nullable Runnable action) { + Notification notification = new Notification(title, message, icon, duration, progressbar, action); + notifications.put(notification, new DummyAnimation(-1)); + } + + /** + * Send a notification to the user + * + * @param title The title of the notification + * @param message The message of the notification + * @param duration The duration the notification is on screen in ms + * @param progressbar A callable that returns the progress from 0-1 + * @param action The action executed when the notification is pressed + */ + public void send(String title, String message, float duration, @Nullable Callable<Float> progressbar, @Nullable Runnable action) { + send(title, message, null, duration, progressbar, action); + } + + /** + * Send a notification to the user + * + * @param title The title of the notification + * @param message The message of the notification + * @param icon The icon of the notification, null for none + * @param duration The duration the notification is on screen in ms + * @param progressbar A callable that returns the progress from 0-1 + */ + public void send(String title, String message, @Nullable Icon icon, float duration, @Nullable Callable<Float> progressbar) { + send(title, message, icon, duration, progressbar, null); + } + + /** + * Send a notification to the user + * + * @param title The title of the notification + * @param message The message of the notification + * @param icon The icon of the notification, null for none + * @param duration The duration the notification is on screen in ms + * @param action The action executed when the notification is pressed + */ + public void send(String title, String message, @Nullable Icon icon, float duration, @Nullable Runnable action) { + send(title, message, icon, duration, null, action); + } + + /** + * Send a notification to the user + * + * @param title The title of the notification + * @param message The message of the notification + * @param duration The duration the notification is on screen in ms + * @param progressbar A callable that returns the progress from 0-1 + */ + public void send(String title, String message, float duration, @Nullable Callable<Float> progressbar) { + send(title, message, duration, progressbar, null); + } + + /** + * Send a notification to the user + * + * @param title The title of the notification + * @param message The message of the notification + * @param duration The duration the notification is on screen in ms + * @param action The action executed when the notification is pressed + */ + public void send(String title, String message, float duration, @Nullable Runnable action) { + send(title, message, duration, null, action); + } + + /** + * Send a notification to the user + * + * @param title The title of the notification + * @param message The message of the notification + * @param icon The icon of the notification, null for none + * @param progressbar A callable that returns the progress from 0-1 + */ + public void send(String title, String message, @Nullable Icon icon, @Nullable Callable<Float> progressbar) { + send(title, message, icon, DEFAULT_DURATION, progressbar); + } + + /** + * Send a notification to the user + * + * @param title The title of the notification + * @param message The message of the notification + * @param icon The icon of the notification, null for none + * @param action The action executed when the notification is pressed + */ + public void send(String title, String message, @Nullable Icon icon, @Nullable Runnable action) { + send(title, message, icon, DEFAULT_DURATION, action); + } + + /** + * Send a notification to the user + * + * @param title The title of the notification + * @param message The message of the notification + * @param progressbar A callable that returns the progress from 0-1 + */ + public void send(String title, String message, @Nullable Callable<Float> progressbar) { + send(title, message, DEFAULT_DURATION, progressbar); + } + + /** + * Send a notification to the user + * + * @param title The title of the notification + * @param message The message of the notification + * @param icon The icon of the notification, null for none + * @param duration The duration the notification is on screen in ms + */ + public void send(String title, String message, @Nullable Icon icon, float duration) { + send(title, message, icon, duration, (Callable<Float>) null); + } + + /** + * Send a notification to the user + * + * @param title The title of the notification + * @param message The message of the notification + * @param action The action executed when the notification is pressed + */ + public void send(String title, String message, @Nullable Runnable action) { + send(title, message, DEFAULT_DURATION, action); + } + + /** + * Send a notification to the user + * + * @param title The title of the notification + * @param message The message of the notification + * @param duration The duration the notification is on screen in ms + */ + public void send(String title, String message, float duration) { + send(title, message, duration, (Callable<Float>) null); + } + + /** + * Send a notification to the user + * + * @param title The title of the notification + * @param message The message of the notification + * @param icon The icon of the notification, null for none + */ + public void send(String title, String message, @Nullable Icon icon) { + send(title, message, icon, (Callable<Float>) null); + } + + /** + * Send a notification to the user + * + * @param title The title of the notification + * @param message The message of the notification + */ + public void send(String title, String message) { + send(title, message, (Callable<Float>) null); + } + + @Subscribe + private void onHudRender(HudRenderEvent event) { + RenderManager.setupAndDraw((vg) -> { + float desiredPosition = -16f; + float scale = OneConfigGui.getScaleFactor(); + for (Map.Entry<Notification, Animation> entry : notifications.entrySet()) { + if (entry.getValue().getEnd() == -1f) + entry.setValue(new DummyAnimation(desiredPosition)); + else if (desiredPosition != entry.getValue().getEnd()) + entry.setValue(new EaseInOutQuad(250, entry.getValue().get(0), desiredPosition, false)); + float height = entry.getKey().draw(vg, UResolution.getWindowHeight() / scale + entry.getValue().get(), scale); + desiredPosition -= height + 16f; + } + notifications.entrySet().removeIf(entry -> entry.getKey().isFinished()); + }); + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java index 1fdd7e7..bc6e9c0 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java @@ -28,13 +28,13 @@ package cc.polyfrost.oneconfig.utils; import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.renderer.font.Font; -import cc.polyfrost.oneconfig.renderer.font.Fonts; import java.util.ArrayList; /** - * Simple text utility class for NanoVG text rendering. + * @deprecated Use RenderManager's functions for wrapping text and getting the height of it instead */ +@Deprecated public final class TextUtils { /** diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/notifications/Notification.java b/src/main/java/cc/polyfrost/oneconfig/utils/notifications/Notification.java deleted file mode 100644 index 2e28c2c..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/utils/notifications/Notification.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * This file is part of OneConfig. - * OneConfig - Next Generation Config Library for Minecraft: Java Edition - * Copyright (C) 2021, 2022 Polyfrost. - * <https://polyfrost.cc> <https://github.com/Polyfrost/> - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * OneConfig is licensed under the terms of version 3 of the GNU Lesser - * General Public License as published by the Free Software Foundation, AND - * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, - * either version 1.0 of the Additional Terms, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License. If not, see <https://www.gnu.org/licenses/>. You should - * have also received a copy of the Additional Terms Applicable - * to OneConfig, as published by Polyfrost. If not, see - * <https://polyfrost.cc/legal/oneconfig/additional-terms> - */ - -package cc.polyfrost.oneconfig.utils.notifications; - -/** - * @deprecated Reserved for future use, not implemented yet. - */ -@Deprecated -public final class Notification { - private String title; - private String message; - private final float duration; - private float x; - private float y; - - private final Runnable action; - private final Runnable onClose; - - Notification(String title, String message, float duration, float x, float y, Runnable action, Runnable onClose) { - this.title = title; - this.message = message; - this.duration = duration; - this.x = x; - this.y = y; - this.action = action; - this.onClose = onClose; - } - - void draw(final long vg) { - - } - - public String getTitle() { - return title; - } - - public String getMessage() { - return message; - } - - public float getDuration() { - return duration; - } - - public float getX() { - return x; - } - - public float getY() { - return y; - } - - public Runnable getAction() { - return action; - } - - public Runnable getOnClose() { - return onClose; - } - - public void setTitle(String title) { - this.title = title; - } - - public void setMessage(String message) { - this.message = message; - } - - void setX(float x) { - this.x = x; - } - - void setY(float y) { - this.y = y; - } -} diff --git a/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/RenderManagerDSL.kt b/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/RenderManagerDSL.kt index ac6ff9c..9015361 100644 --- a/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/RenderManagerDSL.kt +++ b/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/RenderManagerDSL.kt @@ -164,11 +164,11 @@ fun Long.drawText(text: String, x: Number, y: Number, color: Int, size: Number, fun VG.drawText(text: String, x: Number, y: Number, color: Int, size: Number, font: Font) = instance.drawText(text, x, y, color, size, font) -fun Long.drawWrappedString(text: String, x: Number, y: Number, width: Number, color: Int, size: Number, font: Font) = - RenderManager.drawWrappedString(this, text, x.toFloat(), y.toFloat(), width.toFloat(), color, size.toFloat(), font) +fun Long.drawWrappedString(text: String, x: Number, y: Number, width: Number, color: Int, size: Number, lineHeight: Number, font: Font) = + RenderManager.drawWrappedString(this, text, x.toFloat(), y.toFloat(), width.toFloat(), color, size.toFloat(), lineHeight.toFloat(), font) -fun VG.drawWrappedString(text: String, x: Number, y: Number, width: Number, color: Int, size: Number, font: Font) = - instance.drawWrappedString(text, x, y, width, color, size, font) +fun VG.drawWrappedString(text: String, x: Number, y: Number, width: Number, color: Int, size: Number, lineHeight: Number, font: Font) = + instance.drawWrappedString(text, x, y, width, color, size, lineHeight, font) fun Long.drawURL(url: String, x: Number, y: Number, size: Number, font: Font, inputHandler: InputHandler) = RenderManager.drawURL(this, url, x.toFloat(), y.toFloat(), size.toFloat(), font, inputHandler) @@ -259,10 +259,20 @@ fun NVGColor.fill(r: Float, g: Float, b: Float, a: Float) = RenderManager.fillNV fun Long.scale(x: Float, y: Float) = RenderManager.scale(this, x, y) fun VG.scale(x: Float, y: Float) = instance.scale(x, y) +fun Long.translate(x: Float, y: Float) = RenderManager.translate(this, x, y) +fun VG.translate(x: Float, y: Float) = instance.translate(x, y) + +fun Long.resetTransform() = RenderManager.resetTransform(this) +fun VG.resetTransform() = instance.resetTransform() fun Long.setAlpha(alpha: Float) = RenderManager.setAlpha(this, alpha) fun VG.setAlpha(alpha: Float) = instance.setAlpha(alpha) +fun Long.drawSVG(filePath: String, x: Number, y: Number, width: Number, height: Number, scale: Number) = + RenderManager.drawSvg(this, filePath, x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), scale.toFloat()) + +fun VG.drawSVG(filePath: String, x: Number, y: Number, width: Number, height: Number, scale: Number) = + instance.drawSVG(filePath, x, y, width, height, scale) fun Long.drawSVG(filePath: String, x: Number, y: Number, width: Number, height: Number) = RenderManager.drawSvg(this, filePath, x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat()) @@ -270,18 +280,36 @@ fun Long.drawSVG(filePath: String, x: Number, y: Number, width: Number, height: fun VG.drawSVG(filePath: String, x: Number, y: Number, width: Number, height: Number) = instance.drawSVG(filePath, x, y, width, height) +fun Long.drawSVG(filePath: String, x: Number, y: Number, width: Number, height: Number, color: Int, scale: Number) = + RenderManager.drawSvg(this, filePath, x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), color, scale.toFloat()) + +fun VG.drawSVG(filePath: String, x: Number, y: Number, width: Number, height: Number, color: Int, scale: Number) = + instance.drawSVG(filePath, x, y, width, height, color, scale.toFloat()) + fun Long.drawSVG(filePath: String, x: Number, y: Number, width: Number, height: Number, color: Int) = RenderManager.drawSvg(this, filePath, x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), color) fun VG.drawSVG(filePath: String, x: Number, y: Number, width: Number, height: Number, color: Int) = instance.drawSVG(filePath, x, y, width, height, color) +fun Long.drawSVG(svg: SVG, x: Number, y: Number, width: Number, height: Number, scale: Number) = + RenderManager.drawSvg(this, svg, x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), scale.toFloat()) + +fun VG.drawSVG(svg: SVG, x: Number, y: Number, width: Number, height: Number, scale: Number) = + instance.drawSVG(svg, x, y, width, height, scale) + fun Long.drawSVG(svg: SVG, x: Number, y: Number, width: Number, height: Number) = RenderManager.drawSvg(this, svg, x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat()) fun VG.drawSVG(svg: SVG, x: Number, y: Number, width: Number, height: Number) = instance.drawSVG(svg, x, y, width, height) +fun Long.drawSVG(svg: SVG, x: Number, y: Number, width: Number, height: Number, color: Int, scale: Number) = + RenderManager.drawSvg(this, svg, x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), color, scale.toFloat()) + +fun VG.drawSVG(svg: SVG, x: Number, y: Number, width: Number, height: Number, color: Int, scale: Number) = + instance.drawSVG(svg, x, y, width, height, color, scale) + fun Long.drawSVG(svg: SVG, x: Number, y: Number, width: Number, height: Number, color: Int) = RenderManager.drawSvg(this, svg, x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), color) diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java b/versions/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java index 1e0704e..c67bd90 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java @@ -42,6 +42,7 @@ import cc.polyfrost.oneconfig.libs.eventbus.Subscribe; import cc.polyfrost.oneconfig.utils.commands.CommandManager; import cc.polyfrost.oneconfig.utils.gui.GuiUtils; import cc.polyfrost.oneconfig.utils.hypixel.HypixelUtils; +import cc.polyfrost.oneconfig.utils.Notifications; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import org.apache.logging.log4j.LogManager; @@ -150,6 +151,7 @@ public class OneConfig { EventManager.INSTANCE.register(new HudCore()); HypixelUtils.INSTANCE.initialize(); EventManager.INSTANCE.register(KeyBindHandler.INSTANCE); + EventManager.INSTANCE.register(Notifications.INSTANCE); ConfigCore.sortMods(); initialized = true; diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/test/TestConfig_Test.java b/versions/src/main/java/cc/polyfrost/oneconfig/test/TestConfig_Test.java index 0b14d38..48d52cb 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/test/TestConfig_Test.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/test/TestConfig_Test.java @@ -33,9 +33,14 @@ import cc.polyfrost.oneconfig.config.data.*; import cc.polyfrost.oneconfig.config.Config; import cc.polyfrost.oneconfig.config.data.ModType; import cc.polyfrost.oneconfig.config.migration.VigilanceMigrator; +import cc.polyfrost.oneconfig.gui.animations.Animation; +import cc.polyfrost.oneconfig.gui.animations.EaseInOutQuart; import cc.polyfrost.oneconfig.gui.pages.HomePage; +import cc.polyfrost.oneconfig.internal.assets.SVGs; import cc.polyfrost.oneconfig.libs.universal.UChat; import cc.polyfrost.oneconfig.libs.universal.UKeyboard; +import cc.polyfrost.oneconfig.renderer.Icon; +import cc.polyfrost.oneconfig.utils.Notifications; public class TestConfig_Test extends Config { @@ -189,6 +194,16 @@ public class TestConfig_Test extends Config { super(new Mod("Test Mod", ModType.UTIL_QOL, new VigilanceMigrator("./config/testConfig.toml")), "hacksConfig.json"); initialize(); addDependency("testCheckBox", "testSwitch"); + + registerKeyBind(testKeyBind, () -> { + Animation barAnimation = new EaseInOutQuart(4000, 0f, 1f, false); + Notifications.INSTANCE.send( + "Title", + "Very epic long message that will need to wrap because yes.", + new Icon(SVGs.APERTURE_FILL), + () -> barAnimation.get() + ); + }); } } |