diff options
16 files changed, 77 insertions, 32 deletions
diff --git a/api/OneConfig.api b/api/OneConfig.api index a922b10..3e5688f 100644 --- a/api/OneConfig.api +++ b/api/OneConfig.api @@ -293,6 +293,7 @@ public abstract class cc/polyfrost/oneconfig/config/elements/BasicOption { public final field description Ljava/lang/String; protected final field field Ljava/lang/reflect/Field; public final field name Ljava/lang/String; + protected field nameColor I protected field parent Ljava/lang/Object; public final field size I public final field subcategory Ljava/lang/String; @@ -301,11 +302,12 @@ public abstract class cc/polyfrost/oneconfig/config/elements/BasicOption { 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 drawDescription (JIILcc/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; public abstract fun getHeight ()I + protected fun getNameX (I)F public fun getParent ()Ljava/lang/Object; public fun isEnabled ()Z public fun isHidden ()Z @@ -728,6 +730,7 @@ public class cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox : cc/poly 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 + protected fun getNameX (I)F } public class cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement : cc/polyfrost/oneconfig/config/elements/BasicOption { @@ -799,6 +802,7 @@ public class cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch : cc/polyfr 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 + protected fun getNameX (I)F } public class cc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox : cc/polyfrost/oneconfig/config/elements/BasicOption { @@ -1337,6 +1341,8 @@ public class cc/polyfrost/oneconfig/renderer/scissor/ScissorManager { public fun <init> ()V public static fun clearScissors (J)V public static fun resetScissor (JLcc/polyfrost/oneconfig/renderer/scissor/Scissor;)V + public static fun restore (J)V + public static fun save ()V public static fun scissor (JFFFF)Lcc/polyfrost/oneconfig/renderer/scissor/Scissor; } 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 701e095..7fff468 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java @@ -27,6 +27,7 @@ package cc.polyfrost.oneconfig.config.elements; import cc.polyfrost.oneconfig.gui.animations.Animation; +import cc.polyfrost.oneconfig.gui.animations.ColorAnimation; import cc.polyfrost.oneconfig.gui.animations.DummyAnimation; import cc.polyfrost.oneconfig.gui.animations.EaseOutQuad; import cc.polyfrost.oneconfig.internal.assets.Colors; @@ -34,6 +35,7 @@ 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.color.ColorPalette; import cc.polyfrost.oneconfig.utils.gui.GuiUtils; import java.lang.reflect.Field; @@ -49,13 +51,13 @@ public abstract class BasicOption { public final String description; public final String category; public final String subcategory; + private final ColorAnimation nameColorAnimation = new ColorAnimation(new ColorPalette(Colors.WHITE_90, Colors.WHITE, Colors.WHITE_90)); + protected int nameColor = Colors.WHITE_90; private final ArrayList<Supplier<Boolean>> dependencies = new ArrayList<>(); private final ArrayList<Runnable> listeners = new ArrayList<>(); private final ArrayList<Supplier<Boolean>> hideConditions = new ArrayList<>(); private Animation descriptionAnimation = new DummyAnimation(0f); - private float mouseStillTime = 0f; - private float prevMouseX = 0f; - private float prevMouseY = 0f; + private float hoverTime = 0f; /** * Initialize option @@ -130,15 +132,12 @@ public abstract class BasicOption { public void keyTyped(char key, int keyCode) { } - public void drawDescription(long vg, int x, int y, int height, InputHandler inputHandler) { + public void drawDescription(long vg, int x, int y, 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 hovered = inputHandler.isAreaHovered(getNameX(x), y, RenderManager.getTextWidth(vg, name, 14f, Fonts.MEDIUM), 32f); + nameColor = nameColorAnimation.getColor(hovered, false); + if (hovered) hoverTime += GuiUtils.getDeltaTime(); + else hoverTime = 0; boolean shouldDrawDescription = shouldDrawDescription(); if (descriptionAnimation.getEnd() != 1f && shouldDrawDescription) { descriptionAnimation = new EaseOutQuad(150, descriptionAnimation.get(0), 1f, false); @@ -159,7 +158,17 @@ public abstract class BasicOption { * @return If this option should draw its description */ protected boolean shouldDrawDescription() { - return mouseStillTime > 350; + return hoverTime > 350; + } + + /** + * Get the X of the name of the option, used to trigger the description + * + * @param x The x coordinate of the option + * @return The x coordinate of the option's name + */ + protected float getNameX(int x) { + return x; } /** 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 628e973..9e6f214 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java @@ -90,15 +90,13 @@ 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); + option.drawDescription(vg, x, optionY, 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); - nextOption.drawDescription(vg, x + 512, optionY, optionHeight, inputHandler); - int nextOptionHeight = nextOption.getHeight(); - optionY += Math.max(optionHeight, nextOptionHeight) + 16; + nextOption.drawDescription(vg, x + 512, optionY, inputHandler); + optionY += Math.max(option.getHeight(), nextOption.getHeight()) + 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 681db60..578fa35 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 @@ -94,7 +94,7 @@ public class ConfigButton extends BasicOption { public void draw(long vg, int x, int y, InputHandler inputHandler) { button.disable(!isEnabled()); if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); - RenderManager.drawText(vg, name, x, y + 17, Colors.WHITE, 14f, Fonts.MEDIUM); + RenderManager.drawText(vg, name, x, y + 17, nameColor, 14f, Fonts.MEDIUM); button.draw(vg, x + (size == 1 ? 352 : 736), y, inputHandler); RenderManager.setAlpha(vg, 1f); } 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 6f3be32..34241a4 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 @@ -81,7 +81,7 @@ public class ConfigCheckbox extends BasicOption { } float percentOn = animation.get(); - RenderManager.drawText(vg, name, x + 32, y + 17, Colors.WHITE_90, 14f, Fonts.MEDIUM); + RenderManager.drawText(vg, name, x + 32, y + 17, nameColor, 14f, Fonts.MEDIUM); RenderManager.drawRoundedRect(vg, x, y + 4, 24, 24, color.getColor(hover, hover && Platform.getMousePlatform().isButtonDown(0)), 6f); RenderManager.drawHollowRoundRect(vg, x, y + 4, 23.5f, 23.5f, Colors.GRAY_300, 6f, 1f); // the 0.5f is to make it look better ok @@ -95,6 +95,11 @@ public class ConfigCheckbox extends BasicOption { } @Override + protected float getNameX(int x) { + return x + 32; + } + + @Override public int getHeight() { return 32; } 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 5e92ddc..20b58b3 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 @@ -76,7 +76,7 @@ public class ConfigColorElement extends BasicOption { } catch (IllegalAccessException e) { return; } - RenderManager.drawText(vg, name, x, y + 16, Colors.WHITE_90, 14f, Fonts.MEDIUM); + RenderManager.drawText(vg, name, x, y + 16, nameColor, 14f, Fonts.MEDIUM); if (!hexField.isToggled()) hexField.setInput("#" + color.getHex()); hexField.setErrored(false); if (hexField.isToggled()) { 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 6dd463f..376817c 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 @@ -62,7 +62,7 @@ public class ConfigDropdown extends BasicOption { @Override public void draw(long vg, int x, int y, InputHandler inputHandler) { if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); - RenderManager.drawText(vg, name, x, y + 16, Colors.WHITE_90, 14f, Fonts.MEDIUM); + RenderManager.drawText(vg, name, x, y + 16, nameColor, 14f, Fonts.MEDIUM); boolean hovered; if (size == 1) hovered = inputHandler.isAreaHovered(x + 224, y, 256, 32) && isEnabled(); 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 eb1dece..102eab3 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 @@ -69,7 +69,7 @@ public class ConfigDualOption extends BasicOption { if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); boolean hoveredLeft = inputHandler.isAreaHovered(x + 226, y, 128, 32) && isEnabled(); boolean hoveredRight = inputHandler.isAreaHovered(x + 354, y, 128, 32) && isEnabled(); - RenderManager.drawText(vg, name, x, y + 16, Colors.WHITE_90, 14f, Fonts.MEDIUM); + RenderManager.drawText(vg, name, x, y + 16, nameColor, 14f, Fonts.MEDIUM); RenderManager.drawRoundedRect(vg, x + 226, y, 256, 32, Colors.GRAY_600, 12f); RenderManager.drawRoundedRect(vg, x + posAnimation.get(), y + 2, 124, 28, Colors.PRIMARY_600, 10f); if (!hoveredLeft && isEnabled()) RenderManager.setAlpha(vg, 0.8f); 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 5e9f27f..1f4d613 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 @@ -51,7 +51,7 @@ public class ConfigHeader extends BasicOption { @Override public void draw(long vg, int x, int y, InputHandler inputHandler) { Scissor scissor = ScissorManager.scissor(vg, x, y, size == 1 ? 480 : 992, 32); - RenderManager.drawText(vg, name, x, y + 17, Colors.WHITE_90, 24, Fonts.MEDIUM); + RenderManager.drawText(vg, name, x, y + 17, nameColor, 24, Fonts.MEDIUM); ScissorManager.resetScissor(vg, scissor); } 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 94afaec..6e77481 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 @@ -55,7 +55,7 @@ public class ConfigInfo extends BasicOption { public void draw(long vg, int x, int y, InputHandler inputHandler) { Scissor scissor = ScissorManager.scissor(vg, x, y, size == 1 ? 448 : 960, 32); RenderManager.drawInfo(vg, type, x, y + 4, 24); - RenderManager.drawText(vg, name, x + 32, y + 18, Colors.WHITE_90, 14, Fonts.MEDIUM); + RenderManager.drawText(vg, name, x + 32, y + 18, nameColor, 14, Fonts.MEDIUM); ScissorManager.resetScissor(vg, scissor); } 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 491a99c..1e94422 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 @@ -59,7 +59,7 @@ public class ConfigKeyBind extends BasicOption { @Override public void draw(long vg, int x, int y, InputHandler inputHandler) { if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); - RenderManager.drawText(vg, name, x, y + 17, Colors.WHITE, 14f, Fonts.MEDIUM); + RenderManager.drawText(vg, name, x, y + 17, nameColor, 14f, Fonts.MEDIUM); OneKeyBind keyBind = getKeyBind(); String text = keyBind.getDisplay(); button.disable(!isEnabled()); 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 a4088d9..56424bf 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 @@ -99,7 +99,7 @@ public class ConfigSlider extends BasicOption { } if (!inputField.isToggled()) inputField.setCurrentValue(value); - RenderManager.drawText(vg, name, x, y + 17, Colors.WHITE_90, 14f, Fonts.MEDIUM); + RenderManager.drawText(vg, name, x, y + 17, nameColor, 14f, Fonts.MEDIUM); RenderManager.drawRoundedRect(vg, x + 352, y + 13, 512, 6, Colors.GRAY_300, 4f); RenderManager.drawRoundedRect(vg, x + 352, y + 13, xCoordinate - x - 352, 6, Colors.PRIMARY_500, 4f); if (step > 0) { 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 4ecc42b..a62afb7 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 @@ -71,7 +71,7 @@ public class ConfigSwitch extends BasicOption { if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); RenderManager.drawRoundedRect(vg, x, y + 4, 42, 24, color.getColor(hovered, hovered && Platform.getMousePlatform().isButtonDown(0)), 12f); RenderManager.drawRoundedRect(vg, x2, y + 7, 18, 18, Colors.WHITE, 9f); - RenderManager.drawText(vg, name, x + 50, y + 17, Colors.WHITE, 14f, Fonts.MEDIUM); + RenderManager.drawText(vg, name, x + 50, y + 17, nameColor, 14f, Fonts.MEDIUM); if (inputHandler.isAreaClicked(x, y, 42, 32) && isEnabled()) { toggled = !toggled; @@ -88,6 +88,11 @@ public class ConfigSwitch extends BasicOption { } @Override + protected float getNameX(int x) { + return x + 50; + } + + @Override public int getHeight() { return 32; } 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 4dc497b..a922e11 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 @@ -45,7 +45,7 @@ public class ConfigTextBox extends BasicOption { private final TextInputField textField; 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); + super(field, parent, name, description, category, subcategory, size); this.secure = secure; this.multiLine = multiLine; this.textField = new TextInputField(size == 1 ? 256 : 640, multiLine ? 64 : 32, placeholder, multiLine, secure); @@ -60,7 +60,7 @@ public class ConfigTextBox extends BasicOption { public void draw(long vg, int x, int y, InputHandler inputHandler) { if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); textField.disable(!isEnabled()); - RenderManager.drawText(vg, name, x, y + 16, Colors.WHITE_90, 14, Fonts.MEDIUM); + RenderManager.drawText(vg, name, x, y + 16, nameColor, 14, Fonts.MEDIUM); try { String value = (String) get(); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java index ec1e4a1..4de3d49 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java @@ -32,6 +32,7 @@ import cc.polyfrost.oneconfig.config.elements.BasicOption; import cc.polyfrost.oneconfig.gui.elements.BasicButton; import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager; import cc.polyfrost.oneconfig.utils.InputHandler; import cc.polyfrost.oneconfig.utils.color.ColorPalette; @@ -76,9 +77,12 @@ public class ModConfigPage extends Page { for (OptionSubcategory subCategory : page.categories.get(selectedCategory).subcategories) { optionY += subCategory.draw(vg, x + 30, optionY, inputHandler); } + ScissorManager.save(); + ScissorManager.clearScissors(vg); for (OptionSubcategory subCategory : page.categories.get(selectedCategory).subcategories) { subCategory.drawLast(vg, x + 30, inputHandler); } + ScissorManager.restore(vg); totalSize = optionY - y; } diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/ScissorManager.java b/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/ScissorManager.java index 6b5ea3f..56d3f45 100644 --- a/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/ScissorManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/ScissorManager.java @@ -34,7 +34,8 @@ import java.util.ArrayList; * Provides an easy way to manage and group scissor rectangles. */ public class ScissorManager { - private static final ArrayList<Scissor> scissors = new ArrayList<>(); + private static final ArrayList<ArrayList<Scissor>> previousScissors = new ArrayList<>(); + private static ArrayList<Scissor> scissors = new ArrayList<>(); /** * Adds and applies a scissor rectangle to the list of scissor rectangles. @@ -77,9 +78,26 @@ public class ScissorManager { NanoVG.nvgResetScissor(vg); } + /** + * Save the current scissors + */ + public static void save() { + previousScissors.add(new ArrayList<>(scissors)); + } + + /** + * Restore the scissors from the last save + * + * @param vg The NanoVG context. + */ + public static void restore(long vg) { + scissors = previousScissors.remove(0); + applyScissors(vg); + } + private static void applyScissors(long vg) { NanoVG.nvgResetScissor(vg); - if (scissors.size() <= 0) return; + if (scissors.size() == 0) return; Scissor finalScissor = getFinalScissor(scissors); NanoVG.nvgScissor(vg, finalScissor.x, finalScissor.y, finalScissor.width, finalScissor.height); } |