diff options
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/gui')
17 files changed, 96 insertions, 34 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java index 5985d12..8db7640 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java @@ -9,14 +9,17 @@ import cc.polyfrost.oneconfig.gui.elements.ColorSelector; import cc.polyfrost.oneconfig.gui.elements.text.TextInputField; import cc.polyfrost.oneconfig.gui.pages.ModsPage; import cc.polyfrost.oneconfig.gui.pages.Page; -import cc.polyfrost.oneconfig.libs.universal.*; +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.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager; import cc.polyfrost.oneconfig.utils.GuiUtils; -import cc.polyfrost.oneconfig.utils.color.ColorPalette; import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.color.ColorPalette; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.lwjgl.input.Mouse; @@ -64,6 +67,7 @@ public class OneConfigGui extends UScreen { public void onDrawScreen(@NotNull UMatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { super.onDrawScreen(matrixStack, mouseX, mouseY, partialTicks); long start = System.nanoTime(); + RenderManager.drawScaledString("HELLO", 10, 10, -1, false, 1.5f); int x2 = 0; int y2 = 0; RenderManager.setupAndDraw((vg) -> { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/ColorAnimation.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/ColorAnimation.java index a9ef863..98b2377 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/ColorAnimation.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/ColorAnimation.java @@ -1,7 +1,6 @@ package cc.polyfrost.oneconfig.gui.animations; import cc.polyfrost.oneconfig.utils.color.ColorPalette; -import cc.polyfrost.oneconfig.utils.color.ColorUtils; public class ColorAnimation { private ColorPalette palette; @@ -25,6 +24,13 @@ public class ColorAnimation { alphaAnimation = new DummyAnimation(palette.getNormalColorf()[3]); } + /** + * Return the current color at the current time, according to a EaseInOut quadratic animation. + * + * @param hovered the hover state of the element + * @param pressed the pressed state of the element + * @return the current color + */ public int getColor(boolean hovered, boolean pressed) { int state = pressed ? 2 : hovered ? 1 : 0; if (state != prevState) { @@ -38,6 +44,13 @@ public class ColorAnimation { return ((int) (alphaAnimation.get() * 255) << 24) | ((int) (redAnimation.get() * 255) << 16) | ((int) (greenAnimation.get() * 255) << 8) | ((int) (blueAnimation.get() * 255)); } + /** + * Return the current alpha of the color. This method is used to get the alpha of pressed buttons that have text/icons on them, so they also darken accordingly. + */ + public float getAlpha() { + return alphaAnimation.get(0); + } + public ColorPalette getPalette() { return palette; } 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 bc97aca..dc5bc26 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/DummyAnimation.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/DummyAnimation.java @@ -1,6 +1,6 @@ package cc.polyfrost.oneconfig.gui.animations; -public class DummyAnimation extends Animation{ +public class DummyAnimation extends Animation { /** * @param value The value that is returned */ diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuad.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuad.java index 9af6557..7b4ba7f 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuad.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuad.java @@ -1,6 +1,6 @@ package cc.polyfrost.oneconfig.gui.animations; -public class EaseInOutQuad extends Animation{ +public class EaseInOutQuad extends Animation { /** * @param duration The duration of the animation @@ -17,7 +17,8 @@ public class EaseInOutQuad extends Animation{ */ @Override protected float animate(float timePassed, float duration, float start, float change) { - if ((timePassed /= duration / 2) < 1) return change / 2 * timePassed * timePassed + start;; + if ((timePassed /= duration / 2) < 1) return change / 2 * timePassed * timePassed + start; + ; return -change / 2 * ((--timePassed) * (timePassed - 2) - 1) + start; } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuart.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuart.java index a21aa73..9c3abe9 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuart.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuart.java @@ -1,6 +1,6 @@ package cc.polyfrost.oneconfig.gui.animations; -public class EaseInOutQuart extends Animation{ +public class EaseInOutQuart extends Animation { /** * @param duration The duration of the animation @@ -17,7 +17,8 @@ public class EaseInOutQuart extends Animation{ */ @Override protected float animate(float timePassed, float duration, float start, float change) { - if ((timePassed /= duration / 2) < 1) return change / 2 * timePassed * timePassed * timePassed * timePassed + start; + if ((timePassed /= duration / 2) < 1) + return change / 2 * timePassed * timePassed * timePassed * timePassed + start; return -change / 2 * ((timePassed -= 2) * timePassed * timePassed * timePassed - 2) + start; } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java index 6d9f88c..a55d931 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java @@ -1,12 +1,12 @@ package cc.polyfrost.oneconfig.gui.elements; -import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.pages.Page; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; import cc.polyfrost.oneconfig.utils.color.ColorPalette; +import cc.polyfrost.oneconfig.utils.color.ColorUtils; import org.jetbrains.annotations.NotNull; public class BasicButton extends BasicElement { @@ -15,6 +15,7 @@ public class BasicButton extends BasicElement { protected SVGs icon1, icon2; private final int alignment; private final float fontSize, cornerRadius; + private float alpha; private final int xSpacing, xPadding; private final int iconSize; public int x, y; @@ -26,8 +27,6 @@ public class BasicButton extends BasicElement { public static final int SIZE_36 = 36; public static final int SIZE_40 = 40; public static final int SIZE_48 = 48; - - public static final int CUSTOM_COLOR = -100; private boolean toggleable = false; private Page page; private Runnable runnable; @@ -65,11 +64,12 @@ public class BasicButton extends BasicElement { if (disabled) RenderManager.setAlpha(vg, 0.5f); float contentWidth = 0f; int color = -1; - if (colorPalette == ColorPalette.TERTIARY || colorPalette == ColorPalette.TERTIARY_DESTRUCTIVE) + if (colorPalette == ColorPalette.TERTIARY || colorPalette == ColorPalette.TERTIARY_DESTRUCTIVE) { color = currentColor; - else + } else { RenderManager.drawRoundedRect(vg, x, y, this.width, this.height, currentColor, this.cornerRadius); - + color = ColorUtils.getColor(1f, 1f, 1f, alpha); + } final float middle = x + width / 2f; final float middleYIcon = y + height / 2f - iconSize / 2f; final float middleYText = y + height / 2f + fontSize / 8f; @@ -106,7 +106,6 @@ public class BasicButton extends BasicElement { } if (text != null) { RenderManager.drawText(vg, text, x + contentWidth, middleYText, color, fontSize, Fonts.MEDIUM); - contentWidth += RenderManager.getTextWidth(vg, text, fontSize, Fonts.MEDIUM) + xSpacing; } if (icon2 != null) RenderManager.drawSvg(vg, icon2, x + width - xPadding - iconSize, middleYIcon, iconSize, iconSize, color); @@ -114,6 +113,11 @@ public class BasicButton extends BasicElement { if (disabled) RenderManager.setAlpha(vg, 1f); } + @Override + public void update(int x, int y) { + super.update(x, y); + this.alpha = colorAnimation.getAlpha(); + } @Override public void onClick() { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java index 0e3fe23..f0b930c 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java @@ -9,17 +9,47 @@ import org.lwjgl.input.Mouse; public class BasicElement { protected int width, height; + /** + * The color palette used for this element. + */ protected ColorPalette colorPalette; + /** + * hitBoxX and hitBoxY are integer variables to determine (in pixels) how far past the boundaries of this button it is still able to be interacted with. + */ protected int hitBoxX, hitBoxY; protected boolean hoverFx; + /** + * Whether the element is currently being hovered over + */ protected boolean hovered = false; + /** + * Whether the mouse is actively being held down on the element. + */ protected boolean pressed = false; + /** + * Whether the element is clicked. + */ protected boolean clicked = false; + /** + * The toggle state of the button. Its false, then if it is clicked, it becomes true, and if clicked again, it becomes false. + */ protected boolean toggled = false; + /** + * Whether the element is currently disabled. + */ protected boolean disabled = false; + /** + * The ARGB color of this element. + */ public int currentColor; protected final float radius; + /** + * Boolean to determine if this element is allowed to be clicked when {@link InputUtils#isBlockingClicks()} is true. + */ private boolean block = false; + /** + * The color animation used by this element. + */ protected ColorAnimation colorAnimation; public BasicElement(int width, int height, @NotNull ColorPalette colorPalette, boolean hoverFx) { @@ -40,11 +70,22 @@ public class BasicElement { } + /** + * Draw script for the element. + * <br> <b>Make sure to call {@link #update(int x, int y)} to update the elements states!</b> + * + * @param vg NanoVG context (see {@link RenderManager}) + * @param x x position of the element + * @param y y position of the element + */ public void draw(long vg, int x, int y) { this.update(x, y); RenderManager.drawRoundedRect(vg, x, y, width, height, currentColor, radius); } + /** + * Update this element's clicked, hovered, toggled, and pressed states, invoke any necessary methods, and update the color animation. + */ public void update(int x, int y) { if (disabled) { hovered = false; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java index 1a53564..e16b83e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java @@ -3,7 +3,10 @@ package cc.polyfrost.oneconfig.gui.elements; import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.config.core.OneColor; import cc.polyfrost.oneconfig.gui.OneConfigGui; -import cc.polyfrost.oneconfig.gui.animations.*; +import cc.polyfrost.oneconfig.gui.animations.Animation; +import cc.polyfrost.oneconfig.gui.animations.DummyAnimation; +import cc.polyfrost.oneconfig.gui.animations.EaseInOutCubic; +import cc.polyfrost.oneconfig.gui.animations.EaseInOutQuad; import cc.polyfrost.oneconfig.gui.elements.text.NumberInputField; import cc.polyfrost.oneconfig.gui.elements.text.TextInputField; import cc.polyfrost.oneconfig.lwjgl.RenderManager; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java index e8d4b2d..b7fbe9a 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java @@ -10,8 +10,8 @@ import cc.polyfrost.oneconfig.libs.universal.wrappers.UPlayer; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; -import cc.polyfrost.oneconfig.utils.color.ColorPalette; import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.color.ColorPalette; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.fml.common.ModMetadata; import org.jetbrains.annotations.NotNull; 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 16b1ea2..121416d 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 @@ -29,7 +29,7 @@ public class ConfigColorElement extends BasicOption { @Override public void draw(long vg, int x, int y) { - if(!isEnabled()) RenderManager.setAlpha(vg, 0.5f); + if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); hexField.disable(!isEnabled()); alphaField.disable(!isEnabled()); element.disable(!isEnabled()); @@ -81,7 +81,7 @@ public class ConfigColorElement extends BasicOption { open = !open; OneConfigGui.INSTANCE.initColorSelector(new ColorSelector(color, InputUtils.mouseX(), InputUtils.mouseY())); } - if(OneConfigGui.INSTANCE.currentColorSelector == null) open = false; + if (OneConfigGui.INSTANCE.currentColorSelector == null) open = false; if (OneConfigGui.INSTANCE.currentColorSelector != null && open) { color = (OneConfigGui.INSTANCE.getColor()); } 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 156f782..472f80e 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 @@ -6,9 +6,8 @@ import cc.polyfrost.oneconfig.gui.animations.ColorAnimation; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; -import cc.polyfrost.oneconfig.utils.color.ColorPalette; -import cc.polyfrost.oneconfig.utils.color.ColorUtils; import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.color.ColorPalette; import org.lwjgl.input.Mouse; import java.awt.*; @@ -18,7 +17,7 @@ import java.util.Arrays; public class ConfigDropdown extends BasicOption { private final String[] options; private final ColorAnimation backgroundColor = new ColorAnimation(ColorPalette.SECONDARY); - private final ColorAnimation atomColor = new ColorAnimation(new ColorPalette(OneConfigConfig.PRIMARY_600, OneConfigConfig.PRIMARY_500, OneConfigConfig.PRIMARY_500)); + private final ColorAnimation atomColor = new ColorAnimation(new ColorPalette(OneConfigConfig.PRIMARY_600, OneConfigConfig.PRIMARY_500, OneConfigConfig.PRIMARY_500)); private boolean opened = false; public ConfigDropdown(Field field, Object parent, String name, int size, String[] options) { 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 7a458c8..700d3dd 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 @@ -2,11 +2,12 @@ package cc.polyfrost.oneconfig.gui.elements.config; import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.config.interfaces.BasicOption; -import cc.polyfrost.oneconfig.gui.animations.*; +import cc.polyfrost.oneconfig.gui.animations.Animation; +import cc.polyfrost.oneconfig.gui.animations.DummyAnimation; +import cc.polyfrost.oneconfig.gui.animations.EaseInOutCubic; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.utils.InputUtils; -import cc.polyfrost.oneconfig.utils.MathUtils; import java.lang.reflect.Field; 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 b464423..24a512c 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 @@ -9,8 +9,8 @@ import cc.polyfrost.oneconfig.gui.pages.ModConfigPage; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; -import cc.polyfrost.oneconfig.utils.color.ColorPalette; import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.color.ColorPalette; import org.lwjgl.input.Mouse; import java.lang.reflect.Field; 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 cb54f9b..090f5a6 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 @@ -8,10 +8,8 @@ import cc.polyfrost.oneconfig.gui.animations.DummyAnimation; import cc.polyfrost.oneconfig.gui.animations.EaseInOutQuad; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; -import cc.polyfrost.oneconfig.utils.color.ColorPalette; -import cc.polyfrost.oneconfig.utils.color.ColorUtils; import cc.polyfrost.oneconfig.utils.InputUtils; -import cc.polyfrost.oneconfig.utils.MathUtils; +import cc.polyfrost.oneconfig.utils.color.ColorPalette; import org.lwjgl.input.Mouse; import java.lang.reflect.Field; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java index 69b1584..c3edb62 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java @@ -6,7 +6,6 @@ import cc.polyfrost.oneconfig.gui.elements.BasicElement; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; import cc.polyfrost.oneconfig.utils.color.ColorPalette; -import cc.polyfrost.oneconfig.utils.color.ColorUtils; public class NumberInputField extends TextInputField { private final BasicElement upArrow = new BasicElement(12, 14, false); @@ -15,7 +14,7 @@ public class NumberInputField extends TextInputField { private float max; private float step; private final ColorAnimation colorTop = new ColorAnimation(ColorPalette.SECONDARY); - private final ColorAnimation colorBottom = new ColorAnimation(ColorPalette.SECONDARY); + private final ColorAnimation colorBottom = new ColorAnimation(ColorPalette.SECONDARY); private float current; public NumberInputField(int width, int height, float defaultValue, float min, float max, float step) { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java index 2866008..3b8e172 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java @@ -67,9 +67,9 @@ public class ModsPage extends Page { for (BasicButton btn : modCategories) { btn.draw(vg, iXCat, y + 16); iXCat += btn.getWidth() + 8; - if(btn.isToggled()) selected = true; + if (btn.isToggled()) selected = true; } - if(!selected) modCategories.get(0).setToggled(true); + if (!selected) modCategories.get(0).setToggled(true); return 60; } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java index 4e85cf5..9c10841 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java @@ -1,11 +1,9 @@ package cc.polyfrost.oneconfig.gui.pages; import cc.polyfrost.oneconfig.gui.animations.Animation; -import cc.polyfrost.oneconfig.gui.animations.EaseInOutQuad; import cc.polyfrost.oneconfig.gui.animations.EaseOutQuad; import cc.polyfrost.oneconfig.lwjgl.scissor.Scissor; import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager; -import cc.polyfrost.oneconfig.utils.MathUtils; import org.lwjgl.input.Mouse; /** |