diff options
author | nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> | 2022-05-26 18:05:16 +0100 |
---|---|---|
committer | nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> | 2022-05-26 18:05:16 +0100 |
commit | c1010e9c2c6d82bd3f40c246e45cfe8e9b039d7b (patch) | |
tree | d634326c96182929c417225c1311005d5e195543 /src/main/java/cc/polyfrost/oneconfig/gui/elements | |
parent | 6160224ebc584194526f1f31b9a0d63c0ba017d4 (diff) | |
download | OneConfig-c1010e9c2c6d82bd3f40c246e45cfe8e9b039d7b.tar.gz OneConfig-c1010e9c2c6d82bd3f40c246e45cfe8e9b039d7b.tar.bz2 OneConfig-c1010e9c2c6d82bd3f40c246e45cfe8e9b039d7b.zip |
Color Utils fixes and more
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/gui/elements')
11 files changed, 66 insertions, 63 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 a4b8ecf..579841e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java @@ -1,7 +1,7 @@ package cc.polyfrost.oneconfig.gui.elements; -import cc.polyfrost.oneconfig.gui.OneConfigGui; 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; @@ -38,14 +38,14 @@ public class BasicButton extends BasicElement { public BasicButton(int width, int size, String text, SVGs icon1, SVGs icon2, int align, int colorPalette) { super(width, 32, colorPalette, true); - if(text != null) this.text = text; + if (text != null) this.text = text; if (icon1 != null) this.icon1 = icon1; if (icon2 != null) this.icon2 = icon2; this.colorPalette = colorPalette; this.alignment = align; this.cornerRadius = size == SIZE_48 ? 16f : 12f; this.xSpacing = size == SIZE_48 ? 12 : 8; - if(size == SIZE_36 || size == SIZE_40) { + if (size == SIZE_36 || size == SIZE_40) { this.xPadding = 16; } else this.xPadding = size == SIZE_48 ? 20 : 12; this.height = size; @@ -79,8 +79,8 @@ public class BasicButton extends BasicElement { final float middle = x + width / 2f; final float middleYIcon = y + height / 2f - iconSize / 2f; final float middleYText = y + height / 2f + fontSize / 8f; - if(this.text != null) { - if (this.colorPalette == -2) { + if (this.text != null) { + if (this.colorPalette == ColorUtils.TERTIARY) { textColor = OneConfigConfig.WHITE_80; if (hovered) textColor = OneConfigConfig.WHITE; if (clicked) textColor = OneConfigConfig.WHITE_80; @@ -88,67 +88,72 @@ public class BasicButton extends BasicElement { } contentWidth += RenderManager.getTextWidth(vg, text, fontSize, Fonts.MEDIUM); } - if(alignment == ALIGNMENT_CENTER) { - if (icon1 != null) { - contentWidth += iconSize + xSpacing; - } - if (icon2 != null) { - contentWidth += iconSize + xSpacing; - } - if(text != null) { - RenderManager.drawString(vg, text, middle - contentWidth / 2 + (icon1 == null ? 0 : iconSize + xSpacing), middleYText, textColor, fontSize, Fonts.MEDIUM); - } - if(icon1 != null) { - RenderManager.drawSvg(vg, icon1, middle - contentWidth / 2, middleYIcon, iconSize, iconSize); - } - if(icon2 != null) { - RenderManager.drawSvg(vg, icon2, middle + contentWidth / 2 - iconSize, middleYIcon, iconSize, iconSize); - } + if (alignment == ALIGNMENT_CENTER) { + if(icon1 != null && icon2 == null && text == null) { + RenderManager.drawSvg(vg, icon1, middle - iconSize / 2f, middleYIcon, iconSize, iconSize); + this.update(x, y); + return; + } + if (icon1 != null) { + contentWidth += iconSize + xSpacing; + } + if (icon2 != null) { + contentWidth += iconSize + xSpacing; + } + if (text != null) { + RenderManager.drawString(vg, text, middle - contentWidth / 2 + (icon1 == null ? 0 : iconSize + xSpacing), middleYText, textColor, fontSize, Fonts.MEDIUM); + } + if (icon1 != null) { + RenderManager.drawSvg(vg, icon1, middle - contentWidth / 2, middleYIcon, iconSize, iconSize); + } + if (icon2 != null) { + RenderManager.drawSvg(vg, icon2, middle + contentWidth / 2 - iconSize, middleYIcon, iconSize, iconSize); + } this.update(x, y); return; } - if(alignment == ALIGNMENT_JUSTIFIED) { - if(text != null) { + if (alignment == ALIGNMENT_JUSTIFIED) { + if (text != null) { RenderManager.drawString(vg, text, middle - contentWidth / 2, middleYText, textColor, fontSize, Fonts.MEDIUM); } - if(icon1 != null) { + if (icon1 != null) { RenderManager.drawSvg(vg, icon1, x + xSpacing, middleYIcon, iconSize, iconSize); } - if(icon2 != null) { + if (icon2 != null) { RenderManager.drawSvg(vg, icon2, x + width - xSpacing - iconSize, middleYIcon, iconSize, iconSize); } this.update(x, y); return; } - if(alignment == ALIGNMENT_LEFT) { + if (alignment == ALIGNMENT_LEFT) { contentWidth = xSpacing; - if(icon1 != null) { + if (icon1 != null) { RenderManager.drawSvg(vg, icon1, x + contentWidth, middleYIcon, iconSize, iconSize); contentWidth += iconSize + xSpacing; } - if(text != null) { + if (text != null) { RenderManager.drawString(vg, text, x + contentWidth, middleYText, textColor, fontSize, Fonts.MEDIUM); contentWidth += RenderManager.getTextWidth(vg, text, fontSize, Fonts.MEDIUM) + xSpacing; } - if(icon2 != null) { + if (icon2 != null) { RenderManager.drawSvg(vg, icon2, x + contentWidth, middleYIcon, iconSize, iconSize); } this.update(x, y); return; } - if(alignment == ALIGNMENT_RIGHT) { + if (alignment == ALIGNMENT_RIGHT) { contentWidth = width - xSpacing; - if(icon2 != null) { + if (icon2 != null) { contentWidth -= iconSize; RenderManager.drawSvg(vg, icon2, x + contentWidth, middleYIcon, iconSize, iconSize); contentWidth -= xSpacing; } - if(text != null) { + if (text != null) { contentWidth -= RenderManager.getTextWidth(vg, text, fontSize, Fonts.MEDIUM); RenderManager.drawString(vg, text, x + contentWidth, middleYText, textColor, fontSize, Fonts.MEDIUM); contentWidth -= xSpacing; } - if(icon1 != null) { + if (icon1 != null) { contentWidth -= iconSize; RenderManager.drawSvg(vg, icon1, x + contentWidth, middleYIcon, iconSize, iconSize); } @@ -171,7 +176,7 @@ public class BasicButton extends BasicElement { public void update(int x, int y) { super.update(x, y); if (hoverFx) { - if (colorPalette == -2) { + if (colorPalette == ColorUtils.TERTIARY) { currentColor = OneConfigConfig.TRANSPARENT; return; } 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 887d8d2..f6c9e35 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java @@ -31,7 +31,7 @@ public class BasicElement { } public BasicElement(int width, int height, boolean hoverFx) { - this(width, height, -1, hoverFx, 12f); + this(width, height, ColorUtils.TRANSPARENT, hoverFx, 12f); } 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 3607d24..e85e223 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java @@ -9,6 +9,7 @@ import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.Images; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; +import cc.polyfrost.oneconfig.utils.ColorUtils; import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.InternetUtils; import cc.polyfrost.oneconfig.utils.MathUtils; @@ -28,11 +29,11 @@ public class ColorSelector { private final ArrayList<BasicElement> buttons = new ArrayList<>(); private final BasicElement closeBtn = new BasicElement(32, 32, false); - private final BasicElement copyBtn = new BasicElement(32, 32, 2, true); - private final BasicElement pasteBtn = new BasicElement(32, 32, 2, true); - private final BasicButton guideBtn = new BasicButton(112, 32, "Guide", null, null, 0, BasicButton.ALIGNMENT_CENTER); - private final BasicElement faveBtn = new BasicElement(32, 32, 2, true); - private final BasicElement recentBtn = new BasicElement(32, 32, 2, true); + private final BasicButton copyBtn = new BasicButton(32, 32, SVGs.COPY, BasicButton.ALIGNMENT_CENTER, ColorUtils.SECONDARY); + private final BasicButton pasteBtn = new BasicButton(32, 32, SVGs.PASTE, BasicButton.ALIGNMENT_CENTER, ColorUtils.SECONDARY); + private final BasicButton guideBtn = new BasicButton(112, 32, "Guide", SVGs.HELP_CIRCLE, SVGs.POP_OUT, BasicButton.ALIGNMENT_CENTER, ColorUtils.SECONDARY); + private final BasicButton faveBtn = new BasicButton(32, 32, SVGs.HEART_OUTLINE, BasicButton.ALIGNMENT_CENTER, ColorUtils.SECONDARY); + private final BasicButton recentBtn = new BasicButton(32, 32, SVGs.HISTORY, BasicButton.ALIGNMENT_CENTER, ColorUtils.SECONDARY); private final NumberInputField hueInput = new NumberInputField(90, 32, 0, 0, 360, 1); private final NumberInputField saturationInput = new NumberInputField(90, 32, 100, 0, 100, 1); @@ -51,9 +52,9 @@ public class ColorSelector { public ColorSelector(OneColor color, int mouseX, int mouseY) { this.color = color; - buttons.add(new BasicElement(124, 28, 2, true, 10f)); - buttons.add(new BasicElement(124, 28, 2, true, 10f)); - buttons.add(new BasicElement(124, 28, 2, true, 10f)); + buttons.add(new BasicElement(124, 28, ColorUtils.SECONDARY, true, 10f)); + buttons.add(new BasicElement(124, 28, ColorUtils.SECONDARY, true, 10f)); + buttons.add(new BasicElement(124, 28, ColorUtils.SECONDARY, true, 10f)); hueInput.setCurrentValue(color.getHue()); saturationInput.setCurrentValue(color.getSaturation()); brightnessInput.setCurrentValue(color.getBrightness()); @@ -138,9 +139,7 @@ public class ColorSelector { // TODO favorite stuff faveBtn.draw(vg, x + 16, y + 672); - RenderManager.drawSvg(vg, SVGs.HEART_OUTLINE, x + 23, y + 679, 18, 18); recentBtn.draw(vg, x + 16, y + 720); - RenderManager.drawSvg(vg, SVGs.HISTORY, x + 23, y + 727, 18, 18); for(int i = 0; i < 7; i++) { favoriteColors.get(i).draw(vg, x + 104 + i * 44, y + 672); } @@ -188,12 +187,9 @@ public class ColorSelector { copyBtn.draw(vg, x + 204, y + 624); pasteBtn.draw(vg, x + 244, y + 624); - RenderManager.drawSvg(vg, SVGs.COPY, x + 211, y + 631, 18, 18); - RenderManager.drawSvg(vg, SVGs.PASTE, x + 251, y + 631, 18, 18); + guideBtn.draw(vg, x + 288, y + 624); - RenderManager.drawSvg(vg, SVGs.HELP_CIRCLE, x + 301, y + 631, 18, 18); - RenderManager.drawSvg(vg, SVGs.POP_OUT, x + 369, y + 631, 18, 18); boolean isMouseDown = Mouse.isButtonDown(0); 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 5853585..c60286d 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java @@ -63,12 +63,12 @@ public class ModCard extends BasicElement { super.update(x, y); isHoveredMain = InputUtils.isAreaHovered(x, y, width, 87); boolean isHoveredSecondary = InputUtils.isAreaHovered(x, y + 87, width - 32, 32) && !disabled; - colorGray = ColorUtils.getColor(colorGray, 0, isHoveredMain, clicked && isHoveredMain); + colorGray = ColorUtils.getColor(colorGray, ColorUtils.SECONDARY, isHoveredMain, clicked && isHoveredMain); if (active && !disabled) { - colorPrimary = ColorUtils.getColor(colorPrimary, 1, isHoveredSecondary, clicked && isHoveredSecondary); - } else - colorPrimary = ColorUtils.smoothColor(colorPrimary, OneConfigConfig.GRAY_500, OneConfigConfig.GRAY_400, isHoveredSecondary, 20f); - + colorPrimary = ColorUtils.getColor(colorPrimary, ColorUtils.PRIMARY, isHoveredSecondary, clicked && isHoveredSecondary); + } else { + colorPrimary = ColorUtils.getColor(colorPrimary, ColorUtils.SECONDARY, isHoveredSecondary, false); + } if (clicked && isHoveredMain) { if (!active) toggled = false; } 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 3caa51f..a0ba444 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 @@ -5,6 +5,7 @@ import cc.polyfrost.oneconfig.config.interfaces.BasicOption; import cc.polyfrost.oneconfig.gui.elements.BasicButton; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; +import cc.polyfrost.oneconfig.utils.ColorUtils; import java.lang.reflect.Field; @@ -13,13 +14,13 @@ public class ConfigButton extends BasicOption { public ConfigButton(Runnable runnable, Object parent, String name, int size, String text) { super(null, parent, name, size); - this.button = new BasicButton(size == 1 ? 128 : 256, 32, text, BasicButton.ALIGNMENT_CENTER, 1); + this.button = new BasicButton(size == 1 ? 128 : 256, 32, text, BasicButton.ALIGNMENT_CENTER, ColorUtils.PRIMARY); this.button.setClickAction(runnable); } public ConfigButton(Field field, Object parent, String name, int size, String text) { super(field, parent, name, size); - this.button = new BasicButton(size == 1 ? 128 : 256, 32, text, BasicButton.ALIGNMENT_CENTER, 1); + this.button = new BasicButton(size == 1 ? 128 : 256, 32, text, BasicButton.ALIGNMENT_CENTER, ColorUtils.PRIMARY); this.button.setClickAction(getRunnableFromField(field, parent)); } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java index 764edcf..91c3cff 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 @@ -40,7 +40,7 @@ public class ConfigCheckbox extends BasicOption { e.printStackTrace(); } } - color = ColorUtils.smoothColor(color, OneConfigConfig.GRAY_600, OneConfigConfig.GRAY_400, hover, 40f); + color = ColorUtils.getColor(color, ColorUtils.SECONDARY, hover, false); if (percentOn != 1f) { // performance RenderManager.drawRoundedRect(vg, x, y + 4, 24, 24, color, 6f); RenderManager.drawHollowRoundRect(vg, x, y + 4, 23.5f, 23.5f, OneConfigConfig.GRAY_300, 6f, 1f); // the 0.5f is to make it look better ok 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 51d43ea..a36a829 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 @@ -40,7 +40,7 @@ public class ConfigDropdown extends BasicOption { // TODO: remove dividers and f } if (opened) return; - backgroundColor = ColorUtils.smoothColor(backgroundColor, OneConfigConfig.GRAY_500, OneConfigConfig.GRAY_400, hovered, 100); + backgroundColor = ColorUtils.getColor(backgroundColor, ColorUtils.SECONDARY, hovered, false); int selected = 0; try { selected = (int) get(); 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 898d6d7..905aabf 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 @@ -9,6 +9,7 @@ import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; import cc.polyfrost.oneconfig.libs.universal.UKeyboard; +import cc.polyfrost.oneconfig.utils.ColorUtils; import java.lang.reflect.Field; @@ -18,7 +19,7 @@ public class ConfigKeyBind extends BasicOption { public ConfigKeyBind(Field field, Object parent, String name, int size) { super(field, parent, name, size); - button = new BasicButton(256, 32, "", SVGs.KEYSTROKE, null, BasicButton.ALIGNMENT_LEFT, 0); + button = new BasicButton(256, 32, "", SVGs.KEYSTROKE, null, BasicButton.ALIGNMENT_LEFT, ColorUtils.SECONDARY); button.setToggleable(true); } 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 edd44e1..61729b9 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 @@ -30,7 +30,7 @@ public class ConfigPageButton extends BasicOption { int height = description.equals("") ? 64 : 96; boolean hovered = InputUtils.isAreaHovered(x - 2, y, 1024, height) && isEnabled(); boolean clicked = hovered && InputUtils.isClicked(); - backgroundColor = ColorUtils.smoothColor(backgroundColor, OneConfigConfig.GRAY_500, OneConfigConfig.GRAY_400, hovered, 100); + backgroundColor = ColorUtils.getColor(backgroundColor, ColorUtils.SECONDARY, hovered, false); if (hovered && Mouse.isButtonDown(0)) RenderManager.setAlpha(vg, 0.8f); if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); 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 2fcf62e..f802680 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 @@ -28,7 +28,7 @@ public class ConfigSwitch extends BasicOption { } int x2 = x + 3 + (int) (percentOn * 18); boolean hovered = InputUtils.isAreaHovered(x, y, 42, 32); - colorDisabled = ColorUtils.smoothColor(colorDisabled, OneConfigConfig.GRAY_400, OneConfigConfig.GRAY_300, hovered, 40f); + colorDisabled = ColorUtils.getColor(colorDisabled, ColorUtils.SECONDARY, hovered, false); colorEnabled = ColorUtils.smoothColor(colorEnabled, OneConfigConfig.PRIMARY_600, OneConfigConfig.PRIMARY_500, hovered, 40f); if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); RenderManager.drawRoundedRect(vg, x, y + 4, 42, 24, colorDisabled, 12f); 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 3b6fa43..925f61d 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 @@ -47,8 +47,8 @@ public class NumberInputField extends TextInputField { if (current == max) colorTop = OneConfigConfig.GRAY_500_80; if (current == min) colorBottom = OneConfigConfig.GRAY_500_80; - colorTop = ColorUtils.getColor(colorTop, 2, upArrow.isHovered(), upArrow.isClicked()); - colorBottom = ColorUtils.getColor(colorBottom, 2, downArrow.isHovered(), downArrow.isClicked()); + colorTop = ColorUtils.getColor(colorTop, ColorUtils.SECONDARY, upArrow.isHovered(), upArrow.isClicked()); + colorBottom = ColorUtils.getColor(colorBottom, ColorUtils.SECONDARY, downArrow.isHovered(), downArrow.isClicked()); if (upArrow.isClicked()) { current += step; if (current > max) current = max; |