aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/polyfrost/oneconfig/gui/elements/config
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-05-02 14:48:22 +0200
committerDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-05-02 14:48:22 +0200
commit63633b2286bd8717f078131014199c6ccaa6a8e3 (patch)
tree33e10d44380a26d1e8608bc5d4b2014f64df5fe0 /src/main/java/io/polyfrost/oneconfig/gui/elements/config
parent401ca42651010ea4a6349a60ddcac64632935510 (diff)
parent63192472f7a814725cbcdaf91eed1361bfc75c38 (diff)
downloadOneConfig-63633b2286bd8717f078131014199c6ccaa6a8e3.tar.gz
OneConfig-63633b2286bd8717f078131014199c6ccaa6a8e3.tar.bz2
OneConfig-63633b2286bd8717f078131014199c6ccaa6a8e3.zip
Merge branch 'master' of github.com:Polyfrost/OneConfig
Diffstat (limited to 'src/main/java/io/polyfrost/oneconfig/gui/elements/config')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java5
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java115
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java14
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java3
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java7
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java6
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java5
7 files changed, 138 insertions, 17 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java
index 93f4378..5f506f7 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java
@@ -4,6 +4,7 @@ import io.polyfrost.oneconfig.config.OneConfigConfig;
import io.polyfrost.oneconfig.config.interfaces.BasicOption;
import io.polyfrost.oneconfig.lwjgl.RenderManager;
import io.polyfrost.oneconfig.lwjgl.font.Fonts;
+import io.polyfrost.oneconfig.lwjgl.image.Images;
import io.polyfrost.oneconfig.utils.ColorUtils;
import io.polyfrost.oneconfig.utils.InputUtils;
import io.polyfrost.oneconfig.utils.MathUtils;
@@ -47,9 +48,9 @@ public class ConfigCheckbox extends BasicOption {
percentOn = MathUtils.clamp(MathUtils.easeOut(percentOn, toggled ? 1f : 0f, 5f));
if (percentOn == 0f) return;
if (percentOn != 1f) {
- RenderManager.drawImage(vg, "/assets/oneconfig/textures/check.png", x, y + 4, 24, 24, new Color(1f, 1f, 1f, percentOn).getRGB());
+ RenderManager.drawImage(vg, Images.CHECKMARK, x, y + 4, 24, 24, new Color(1f, 1f, 1f, percentOn).getRGB());
} else { // performance, that color could cause havoc am I right definitely
- RenderManager.drawImage(vg, "/assets/oneconfig/textures/check.png", x, y + 4, 24, 24);
+ RenderManager.drawImage(vg, Images.CHECKMARK, x, y + 4, 24, 24);
}
}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java
new file mode 100644
index 0000000..3525ab6
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java
@@ -0,0 +1,115 @@
+package io.polyfrost.oneconfig.gui.elements.config;
+
+import io.polyfrost.oneconfig.config.OneConfigConfig;
+import io.polyfrost.oneconfig.config.interfaces.BasicOption;
+import io.polyfrost.oneconfig.gui.OneConfigGui;
+import io.polyfrost.oneconfig.gui.elements.BasicElement;
+import io.polyfrost.oneconfig.gui.elements.ColorSelector;
+import io.polyfrost.oneconfig.gui.elements.TextInputField;
+import io.polyfrost.oneconfig.lwjgl.RenderManager;
+import io.polyfrost.oneconfig.lwjgl.font.Fonts;
+import io.polyfrost.oneconfig.lwjgl.image.Images;
+import io.polyfrost.oneconfig.utils.InputUtils;
+
+import java.awt.*;
+import java.lang.reflect.Field;
+
+public class ConfigColorElement extends BasicOption {
+ private float alpha;
+ private Color color = Color.BLUE;
+ private String hex;
+
+ private final TextInputField hexField = new TextInputField(104, 32, "", false, false);
+ private final TextInputField alphaField = new TextInputField(72, 32, "", false, false);
+ private final BasicElement element = new BasicElement(64, 32, false);
+
+ public ConfigColorElement(Field field, String name, int size) {
+ super(field, name, size);
+ hexField.setCentered(true);
+ alphaField.setCentered(true);
+ alphaField.onlyAcceptNumbers(true);
+ String buf = Integer.toHexString(color.getRGB());
+ hex = "#"+buf.substring(buf.length()-6);
+ }
+
+ @Override
+ public int getHeight() {
+ return 32;
+ }
+
+ @Override
+ public void draw(long vg, int x, int y) {
+ RenderManager.drawString(vg, name, x, y + 15, OneConfigConfig.WHITE_90, 18f, Fonts.INTER_MEDIUM);
+ hexField.draw(vg, x + 240, y);
+
+ if (!alphaField.isToggled()) alphaField.setInput(String.format("%.01f", alpha * 100f) + "%");
+ alphaField.setErrored(false);
+ if(alphaField.isToggled()) {
+ try {
+ float input = Float.parseFloat(alphaField.getInput());
+ if (input < 0f) {
+ alphaField.setErrored(true);
+ input = 100f;
+ }
+ if (input > 100f) {
+ alphaField.setErrored(true);
+ input = 100f;
+ }
+ alpha = input / 100f;
+ } catch (NumberFormatException e) {
+ alphaField.setErrored(true);
+ }
+ }
+ alphaField.draw(vg, x + 352, y);
+
+
+
+ if (!hexField.isToggled()) hexField.setInput(hex);
+ hexField.setErrored(false);
+ if(hexField.isToggled()) {
+ try {
+ color = HexToColor(hexField.getInput());
+ String buf = Integer.toHexString(color.getRGB());
+ hex = "#"+buf.substring(buf.length()-6);
+ } catch (NumberFormatException e) {
+ hexField.setErrored(true);
+ }
+ }
+ hexField.draw(vg, x + 352, y);
+
+ element.update(x + 432, y);
+ RenderManager.drawRoundedRect(vg, x + 432, y, 64, 32, OneConfigConfig.GRAY_300, 12f);
+ RenderManager.drawImage(vg, Images.COLOR_BASE, x + 948, y + 4, 56, 24, color.getRGB());
+ if(element.isClicked() && !element.isToggled()) {
+ OneConfigGui.INSTANCE.initColorSelector(new ColorSelector(color, InputUtils.mouseX(), InputUtils.mouseY()));
+ }
+ if(element.isToggled() && element.isClicked()) {
+ color = OneConfigGui.INSTANCE.closeColorSelector();
+ alpha = color.getAlpha() / 255f;
+ String buf = Integer.toHexString(color.getRGB());
+ hex = "#"+buf.substring(buf.length()-6);
+ }
+
+ }
+
+ // thanks stack overflow
+ public static Color HexToColor(String hex) throws NumberFormatException {
+ hex = hex.replace("#", "");
+ switch (hex.length()) {
+ case 6:
+ return new Color(
+ Integer.valueOf(hex.substring(0, 2), 16),
+ Integer.valueOf(hex.substring(2, 4), 16),
+ Integer.valueOf(hex.substring(4, 6), 16));
+ case 8:
+ return new Color(
+ Integer.valueOf(hex.substring(0, 2), 16),
+ Integer.valueOf(hex.substring(2, 4), 16),
+ Integer.valueOf(hex.substring(4, 6), 16),
+ Integer.valueOf(hex.substring(6, 8), 16));
+ }
+ throw new NumberFormatException("Invalid hex string: " + hex);
+ }
+
+
+}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java
index f4b5d0e..d80f242 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java
@@ -1,10 +1,10 @@
package io.polyfrost.oneconfig.gui.elements.config;
-import io.polyfrost.oneconfig.OneConfig;
import io.polyfrost.oneconfig.config.OneConfigConfig;
import io.polyfrost.oneconfig.config.interfaces.BasicOption;
import io.polyfrost.oneconfig.lwjgl.RenderManager;
import io.polyfrost.oneconfig.lwjgl.font.Fonts;
+import io.polyfrost.oneconfig.lwjgl.image.Images;
import io.polyfrost.oneconfig.utils.ColorUtils;
import io.polyfrost.oneconfig.utils.InputUtils;
import org.lwjgl.input.Mouse;
@@ -50,17 +50,17 @@ public class ConfigDropdown extends BasicOption { // TODO: chose where dividers
RenderManager.drawRoundedRect(vg, x + 224, y, 256, 32, backgroundColor, 12);
RenderManager.drawString(vg, options[selected], x + 236, y + 16, OneConfigConfig.WHITE_80, 14f, Fonts.INTER_MEDIUM);
RenderManager.drawRoundedRect(vg, x + 452, y + 4, 24, 24, OneConfigConfig.BLUE_600, 8);
- RenderManager.drawImage(vg, "/assets/oneconfig/textures/dropdown_arrow.png", x + 459, y + 8, 10, 6);
+ RenderManager.drawImage(vg, Images.DROPDOWN_ARROW, x + 459, y + 8, 10, 6);
NanoVG.nvgTranslate(vg, x + 469, y + 24);
} else {
RenderManager.drawRoundedRect(vg, x + 352, y, 640, 32, backgroundColor, 12);
RenderManager.drawString(vg, options[selected], x + 364, y + 16, OneConfigConfig.WHITE_80, 14f, Fonts.INTER_MEDIUM);
RenderManager.drawRoundedRect(vg, x + 964, y + 4, 24, 24, OneConfigConfig.BLUE_600, 8);
- RenderManager.drawImage(vg, "/assets/oneconfig/textures/dropdown_arrow.png", x + 971, y + 8, 10, 6);
+ RenderManager.drawImage(vg, Images.DROPDOWN_ARROW, x + 971, y + 8, 10, 6);
NanoVG.nvgTranslate(vg, x + 981, y + 24);
}
NanoVG.nvgRotate(vg, (float) Math.toRadians(180));
- RenderManager.drawImage(vg, "/assets/oneconfig/textures/dropdown_arrow.png", 0, 0, 10, 6);
+ RenderManager.drawImage(vg, Images.DROPDOWN_ARROW, 0, 0, 10, 6);
NanoVG.nvgResetTransform(vg);
NanoVG.nvgGlobalAlpha(vg, 1f);
}
@@ -114,7 +114,7 @@ public class ConfigDropdown extends BasicOption { // TODO: chose where dividers
if (hovered && Mouse.isButtonDown(0)) NanoVG.nvgGlobalAlpha(vg, 0.8f);
RenderManager.drawRoundedRect(vg, x + 452, y + 4, 24, 24, OneConfigConfig.BLUE_600, 8);
- RenderManager.drawImage(vg, "/assets/oneconfig/textures/dropdown_arrow.png", x + 459, y + 8, 10, 6);
+ RenderManager.drawImage(vg, Images.DROPDOWN_ARROW, x + 459, y + 8, 10, 6);
NanoVG.nvgTranslate(vg, x + 469, y + 24);
} else {
RenderManager.drawRoundedRect(vg, x + 352, y, 640, 32, backgroundColor, 12);
@@ -149,11 +149,11 @@ public class ConfigDropdown extends BasicOption { // TODO: chose where dividers
if (hovered && Mouse.isButtonDown(0)) NanoVG.nvgGlobalAlpha(vg, 0.8f);
RenderManager.drawRoundedRect(vg, x + 964, y + 4, 24, 24, OneConfigConfig.BLUE_600, 8);
- RenderManager.drawImage(vg, "/assets/oneconfig/textures/dropdown_arrow.png", x + 971, y + 8, 10, 6);
+ RenderManager.drawImage(vg, Images.DROPDOWN_ARROW, x + 971, y + 8, 10, 6);
NanoVG.nvgTranslate(vg, x + 981, y + 24);
}
NanoVG.nvgRotate(vg, (float) Math.toRadians(180));
- RenderManager.drawImage(vg, "/assets/oneconfig/textures/dropdown_arrow.png", 0, 0, 10, 6);
+ RenderManager.drawImage(vg, Images.DROPDOWN_ARROW, 0, 0, 10, 6);
NanoVG.nvgResetTransform(vg);
NanoVG.nvgGlobalAlpha(vg, 1f);
}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java
index c32b76e..fd46bc8 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java
@@ -7,6 +7,7 @@ import io.polyfrost.oneconfig.gui.OneConfigGui;
import io.polyfrost.oneconfig.gui.pages.ModConfigPage;
import io.polyfrost.oneconfig.lwjgl.RenderManager;
import io.polyfrost.oneconfig.lwjgl.font.Fonts;
+import io.polyfrost.oneconfig.lwjgl.image.Images;
import io.polyfrost.oneconfig.utils.ColorUtils;
import io.polyfrost.oneconfig.utils.InputUtils;
import org.lwjgl.input.Mouse;
@@ -38,7 +39,7 @@ public class ConfigPageButton extends BasicOption {
RenderManager.drawString(vg, name, x + 10, y + 32, OneConfigConfig.WHITE_90, 24, Fonts.INTER_MEDIUM);
if (!description.equals(""))
RenderManager.drawString(vg, name, x + 10, y + 70, OneConfigConfig.WHITE_90, 14, Fonts.INTER_MEDIUM);
- RenderManager.drawImage(vg, "/assets/oneconfig/textures/arrow.png", x + 981f, y + (description.equals("") ? 20f : 36f), 13, 22);
+ RenderManager.drawImage(vg, Images.CHEVRON_ARROW, x + 981f, y + (description.equals("") ? 20f : 36f), 13, 22);
if (clicked) OneConfigGui.INSTANCE.openPage(new ModConfigPage(page));
NanoVG.nvgGlobalAlpha(vg, 1f);
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java
index 25b3eab..47ce15c 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java
@@ -6,6 +6,7 @@ import io.polyfrost.oneconfig.gui.elements.BasicElement;
import io.polyfrost.oneconfig.gui.elements.TextInputField;
import io.polyfrost.oneconfig.lwjgl.RenderManager;
import io.polyfrost.oneconfig.lwjgl.font.Fonts;
+import io.polyfrost.oneconfig.lwjgl.image.Images;
import io.polyfrost.oneconfig.utils.ColorUtils;
import io.polyfrost.oneconfig.utils.InputUtils;
import io.polyfrost.oneconfig.utils.MathUtils;
@@ -24,7 +25,7 @@ public class ConfigSlider extends BasicOption {
private int colorTop, colorBottom;
private boolean isFloat = true;
private Float prevAsNum = null;
- private int step;
+ private final int step;
public ConfigSlider(Field field, String name, int size, float min, float max, int step) {
super(field, name, size);
@@ -128,14 +129,14 @@ public class ConfigSlider extends BasicOption {
}
if (current == 1f) NanoVG.nvgGlobalAlpha(vg, 0.3f);
RenderManager.drawRoundedRectVaried(vg, x + 980, y, 12, 14, colorTop, 6f, 6f, 0f, 0f);
- RenderManager.drawImage(vg, "/assets/oneconfig/textures/smallUpArrow.png", x + 981, y + 2, 10, 10);
+ RenderManager.drawImage(vg, Images.UP_ARROW, x + 981, y + 2, 10, 10);
if (current == 1f) NanoVG.nvgGlobalAlpha(vg, 1f);
if (current == 0f) NanoVG.nvgGlobalAlpha(vg, 0.3f);
RenderManager.drawRoundedRectVaried(vg, x + 980, y + 14, 12, 14, colorBottom, 0f, 0f, 6f, 6f);
NanoVG.nvgTranslate(vg, x + 991, y + 25);
NanoVG.nvgRotate(vg, (float) Math.toRadians(180));
- RenderManager.drawImage(vg, "/assets/oneconfig/textures/smallUpArrow.png", 0, 0, 10, 10);
+ RenderManager.drawImage(vg, Images.UP_ARROW, 0, 0, 10, 10);
NanoVG.nvgResetTransform(vg);
NanoVG.nvgGlobalAlpha(vg, 1f);
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java
index b999137..8cd7565 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java
@@ -5,6 +5,7 @@ import io.polyfrost.oneconfig.config.interfaces.BasicOption;
import io.polyfrost.oneconfig.gui.elements.TextInputField;
import io.polyfrost.oneconfig.lwjgl.RenderManager;
import io.polyfrost.oneconfig.lwjgl.font.Fonts;
+import io.polyfrost.oneconfig.lwjgl.image.Images;
import io.polyfrost.oneconfig.utils.InputUtils;
import java.awt.*;
@@ -28,13 +29,14 @@ public class ConfigTextBox extends BasicOption {
try {
String value = (String) get();
- textField.setInput(value == null ? "" : value);
+ textField.setInput(value == null ? "" : value);
} catch (IllegalAccessException ignored) {
}
textField.draw(vg, x + (size == 1 && hasHalfSize() ? 224 : 352), y);
- if (secure) RenderManager.drawImage(vg, "/assets/oneconfig/textures/eye.png", x + 967, y + 7, 18, 18, new Color(196,196,196).getRGB());
+ if (secure)
+ RenderManager.drawImage(vg, Images.HIDE_EYE, x + 967, y + 7, 18, 18, new Color(196, 196, 196).getRGB());
if (secure && InputUtils.isAreaClicked(x + 967, y + 7, 18, 18)) textField.setPassword(!textField.getPassword());
}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java
index 5acdae0..18bebbf 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java
@@ -4,6 +4,7 @@ import io.polyfrost.oneconfig.config.OneConfigConfig;
import io.polyfrost.oneconfig.config.interfaces.BasicOption;
import io.polyfrost.oneconfig.lwjgl.RenderManager;
import io.polyfrost.oneconfig.lwjgl.font.Fonts;
+import io.polyfrost.oneconfig.lwjgl.image.Images;
import io.polyfrost.oneconfig.utils.InputUtils;
import io.polyfrost.oneconfig.utils.MathUtils;
import org.lwjgl.nanovg.NanoVG;
@@ -49,9 +50,9 @@ public class ConfigUniSelector extends BasicOption {
// actual coordinates: 240, 7
NanoVG.nvgTranslate(vg, x + 248, y + 21);
NanoVG.nvgRotate(vg, (float) Math.toRadians(180));
- RenderManager.drawImage(vg, "/assets/oneconfig/textures/arrow.png", 0, 0, 8, 14, OneConfigConfig.BLUE_400);
+ RenderManager.drawImage(vg, Images.CHEVRON_ARROW, 0, 0, 8, 14, OneConfigConfig.BLUE_400);
NanoVG.nvgResetTransform(vg);
- RenderManager.drawImage(vg, "/assets/oneconfig/textures/arrow.png", x + 456, y + 7, 8, 14, OneConfigConfig.BLUE_400);
+ RenderManager.drawImage(vg, Images.CHEVRON_ARROW, x + 456, y + 7, 8, 14, OneConfigConfig.BLUE_400);
if (InputUtils.isAreaClicked(x + 235, y + 5, 18, 18) && selected > 0) {
previous = selected;