diff options
author | nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> | 2022-06-05 10:36:43 +0100 |
---|---|---|
committer | nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> | 2022-06-05 10:36:43 +0100 |
commit | 087f5404658a1543834f16a89e3436f8399297f6 (patch) | |
tree | 4b6d18abbc2e6f3083e664786dbbef98bb142a33 /src/main/java/cc/polyfrost/oneconfig/gui/elements | |
parent | 3e472ea407d128de61820fc167e08b8fe24186c9 (diff) | |
download | OneConfig-087f5404658a1543834f16a89e3436f8399297f6.tar.gz OneConfig-087f5404658a1543834f16a89e3436f8399297f6.tar.bz2 OneConfig-087f5404658a1543834f16a89e3436f8399297f6.zip |
Reformat code and OC-38
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/gui/elements')
10 files changed, 67 insertions, 22 deletions
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) { |