aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/polyfrost/oneconfig/gui/elements
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io/polyfrost/oneconfig/gui/elements')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/BasicButton.java17
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java13
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/ColorSelector.java250
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java9
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/TextInputField.java67
-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
12 files changed, 452 insertions, 59 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicButton.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicButton.java
index 1a1dcf7..716ef1e 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicButton.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicButton.java
@@ -5,6 +5,7 @@ import io.polyfrost.oneconfig.gui.OneConfigGui;
import io.polyfrost.oneconfig.gui.pages.Page;
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 org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -12,7 +13,7 @@ import org.jetbrains.annotations.Nullable;
public class BasicButton extends BasicElement {
protected String text;
- protected String fileNameLeftIco, fileNameRightIco;
+ protected Images fileNameLeftIco, fileNameRightIco;
private final int thisAlignment;
private final float fontSize;
private final int colorPalette;
@@ -33,11 +34,11 @@ public class BasicButton extends BasicElement {
* @param colorPalette color palette to use. see {@link io.polyfrost.oneconfig.utils.ColorUtils} for more info. Can support color palette of -2, which is larger font and icons. Also supports -3, which is just the text changing color.
* @param alignment alignment of the button. ALIGNMENT_LEFT or ALIGNMENT_CENTER.
*/
- public BasicButton(int width, int height, @NotNull String text, @Nullable String fileNameLeftIco, @Nullable String fileNameRightIco, int colorPalette, int alignment) {
+ public BasicButton(int width, int height, @NotNull String text, @Nullable Images fileNameLeftIco, @Nullable Images fileNameRightIco, int colorPalette, int alignment) {
super(width, height, colorPalette, true);
this.text = text;
- this.fileNameLeftIco = fileNameLeftIco;
- this.fileNameRightIco = fileNameRightIco;
+ if (fileNameLeftIco != null) this.fileNameLeftIco = fileNameLeftIco;
+ if (fileNameRightIco != null) this.fileNameRightIco = fileNameRightIco;
this.thisAlignment = alignment;
if (colorPalette == -2) {
fontSize = 24f;
@@ -48,22 +49,22 @@ public class BasicButton extends BasicElement {
}
}
- public BasicButton(int width, int height, @NotNull String text, @Nullable String fileNameLeftIco, @Nullable String fileNameRightIco, int colorPalette, int alignment, Page page) {
+ public BasicButton(int width, int height, @NotNull String text, @Nullable Images fileNameLeftIco, @Nullable Images fileNameRightIco, int colorPalette, int alignment, Page page) {
this(width, height, text, fileNameLeftIco, fileNameRightIco, colorPalette, alignment);
this.page = page;
}
- public BasicButton(int width, int height, @NotNull String text, @Nullable String fileNameLeftIco, @Nullable String fileNameRightIco, int colorPalette, int alignment, boolean toggleable) {
+ public BasicButton(int width, int height, @NotNull String text, @Nullable Images fileNameLeftIco, @Nullable Images fileNameRightIco, int colorPalette, int alignment, boolean toggleable) {
this(width, height, text, fileNameLeftIco, fileNameRightIco, colorPalette, alignment);
this.toggleable = toggleable;
}
- public BasicButton(int width, int height, @NotNull String text, @Nullable String fileNameLeftIco, @Nullable String fileNameRightIco, int colorPalette, int alignment, Runnable runnable) {
+ public BasicButton(int width, int height, @NotNull String text, @Nullable Images fileNameLeftIco, @Nullable Images fileNameRightIco, int colorPalette, int alignment, Runnable runnable) {
this(width, height, text, fileNameLeftIco, fileNameRightIco, colorPalette, alignment);
this.runnable = runnable;
}
- public BasicButton(int width, int height, @NotNull String text, @Nullable String fileNameLeftIco, @Nullable String fileNameRightIco, int colorPalette, int alignment, boolean toggleable, Runnable runnable) {
+ public BasicButton(int width, int height, @NotNull String text, @Nullable Images fileNameLeftIco, @Nullable Images fileNameRightIco, int colorPalette, int alignment, boolean toggleable, Runnable runnable) {
this(width, height, text, fileNameLeftIco, fileNameRightIco, colorPalette, alignment, runnable);
this.toggleable = toggleable;
}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java
index f31a5ef..dd3956c 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java
@@ -12,6 +12,7 @@ public class BasicElement {
protected boolean hovered = false;
protected boolean clicked = false;
protected boolean toggled = false;
+ protected boolean disabled = false;
protected int currentColor;
public BasicElement(int width, int height, int colorPalette, boolean hoverFx) {
@@ -39,6 +40,11 @@ public class BasicElement {
}
public void update(int x, int y) {
+ if(disabled) {
+ hovered = false;
+ clicked = false;
+ return;
+ }
hovered = InputUtils.isAreaHovered(x - hitBoxX, y - hitBoxY, width + hitBoxX, height + hitBoxY);
clicked = InputUtils.isClicked() && hovered;
@@ -91,4 +97,11 @@ public class BasicElement {
public boolean isToggled() {
return toggled;
}
+
+ public boolean isDisabled() {
+ return disabled;
+ }
+ public void disable(boolean state) {
+ disabled = state;
+ }
}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/ColorSelector.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/ColorSelector.java
new file mode 100644
index 0000000..bcf4754
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/ColorSelector.java
@@ -0,0 +1,250 @@
+package io.polyfrost.oneconfig.gui.elements;
+
+import io.polyfrost.oneconfig.config.OneConfigConfig;
+import io.polyfrost.oneconfig.lwjgl.RenderManager;
+import io.polyfrost.oneconfig.utils.InputUtils;
+import org.lwjgl.input.Mouse;
+
+import java.awt.*;
+import java.util.ArrayList;
+
+public class ColorSelector {
+ private Color color;
+ private final int x, y;
+ private final int width = 416;
+ private final int height = 768;
+
+ private final BasicElement HSBButton = new BasicElement(128, 32, -1, true);
+ private final BasicElement RGBButton = new BasicElement(128, 32, -1, true);
+ private final BasicElement ChromaButton = new BasicElement(128, 32, -1, true);
+
+ private final ArrayList<BasicElement> faves = new ArrayList<>();
+ private final ArrayList<BasicElement> history = new ArrayList<>();
+ private final BasicElement closeButton = new BasicElement(32, 32, -1, true);
+
+
+ public ColorSelector(Color color, int mouseX, int mouseY) {
+ this.color = color;
+ this.y = mouseY - 768;
+ this.x = mouseX - 208;
+
+ }
+
+ public void draw(long vg) {
+ RenderManager.drawRoundedRect(vg, x, y, width, height, OneConfigConfig.GRAY_800, 20f);
+
+ }
+
+ public Color getColor() {
+ return color;
+ }
+
+
+
+ private class HSBSelector extends ColorSelectorBase {
+
+
+ public HSBSelector(Color color) {
+ super(color);
+ }
+
+ @Override
+ public void drawBox(long vg, int x, int y) {
+
+ }
+
+ @Override
+ public void setColor(Color color) {
+
+ }
+
+ @Override
+ public int[] drawTopSlider() {
+ return new int[0];
+ }
+
+ @Override
+ public int[] drawBottomSlider() {
+ return new int[0];
+ }
+
+ @Override
+ public float[] getColorAtPos(int clickX, int clickY) {
+ return new float[0];
+ }
+ }
+
+
+ private class RGBSelector extends ColorSelectorBase {
+
+ public RGBSelector(Color color) {
+ super(color);
+ }
+
+ @Override
+ public void drawBox(long vg, int x, int y) {
+
+ }
+
+ @Override
+ public void setColor(Color color) {
+
+ }
+
+ @Override
+ public int[] drawTopSlider() {
+ return new int[0];
+ }
+
+ @Override
+ public int[] drawBottomSlider() {
+ return new int[0];
+ }
+
+
+ @Override
+ public float[] getColorAtPos(int clickX, int clickY) {
+ return new float[0];
+ }
+ }
+
+
+
+ private abstract class ColorSelectorBase {
+
+ private int selectedX;
+ private int selectedY;
+ private float[] hsb = new float[3];
+ private float[] rgba;
+ private final TextInputFieldNumber hueField = new TextInputFieldNumber(72, 32, "", 0, 100);
+ private final TextInputFieldNumber saturationField = new TextInputFieldNumber(72, 32, "", 0, 100);
+ private final TextInputFieldNumber brightnessField = new TextInputFieldNumber(72, 32, "", 0, 100);
+ private final TextInputFieldNumber alphaField = new TextInputFieldNumber(72, 32, "", 0, 100);
+
+ private final TextInputField hexField = new TextInputField(107, 32, true, false, "");
+ private final TextInputFieldNumber redField = new TextInputFieldNumber(44, 32, "", 0, 255);
+ private final TextInputFieldNumber greenField = new TextInputFieldNumber(44, 32, "", 0, 255);
+ private final TextInputFieldNumber blueField = new TextInputFieldNumber(44, 32, "", 0, 255);
+
+ private final Slider sliderTop = new Slider(0);
+ private final Slider sliderBottom = new Slider(0);
+
+ public ColorSelectorBase(Color color) {
+ rgba = new float[]{color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f};
+ }
+
+ public void updateElements(float[] rgba) {
+ this.rgba = rgba;
+ hsb = Color.RGBtoHSB((int) (rgba[0] * 255), (int) (rgba[1] * 255), (int) (rgba[2] * 255), hsb);
+ hueField.setInput(String.valueOf(hsb[0]));
+ saturationField.setInput(String.valueOf(hsb[1]));
+ brightnessField.setInput(String.valueOf(hsb[2]));
+ alphaField.setInput(String.valueOf(rgba[3]));
+ redField.setInput(String.valueOf(rgba[0]));
+ greenField.setInput(String.valueOf(rgba[1]));
+ blueField.setInput(String.valueOf(rgba[2]));
+ }
+ public abstract void drawBox(long vg, int x, int y);
+
+ /** draw the color selector contents, including the box, and the input fields. If it is clicked, getColorAtPos is called. updateElements is also called to update all the input fields. */
+ public void draw(long vg, int x, int y) {
+ drawBox(vg, x + 16, y + 120);
+ if(InputUtils.isAreaHovered(x + 16, y + 120, 384, 288) && Mouse.isButtonDown(0)) {
+ selectedX = InputUtils.mouseX() - x - 16;
+ selectedY = InputUtils.mouseY() - y - 120;
+ rgba = getColorAtPos(selectedX, selectedY);
+ } // TODO all of this
+ hueField.draw(vg, x + 104, y + 544);
+ saturationField.draw(vg, x + 312, y + 544);
+ brightnessField.draw(vg, x + 103, y + 584);
+ alphaField.draw(vg, x + 103, y + 584);
+ hexField.draw(vg, x + 96, y + 624);
+ redField.draw(vg, x + 228, y + 624);
+ greenField.draw(vg, x + 292, y + 664);
+ blueField.draw(vg, x + 356, y + 664);
+ sliderTop.draw(vg, x + 16, y + 424, drawTopSlider()[0], drawTopSlider()[1]);
+ sliderBottom.draw(vg, x + 16, y + 576, drawBottomSlider()[0], drawBottomSlider()[1]);
+ updateElements(rgba);
+ Color color1 = new Color(rgba[0], rgba[1], rgba[2], rgba[3]);
+ setColor(color1);
+ RenderManager.drawRoundedRect(vg, x + 16, y + 488, 384, 40, color1.getRGB(), 12f);
+ }
+
+ /** called to set the color of the color selector box based on the values of the input fields. */
+ public abstract void setColor(Color color);
+
+ /** return an array of two ints of the start color of the gradient and the end color of the gradient. */
+ public abstract int[] drawTopSlider();
+ /** return an array of two ints of the start color of the gradient and the end color of the gradient. */
+ public abstract int[] drawBottomSlider();
+
+ /**
+ * This method is called when the color selector is clicked. It needs to return color at the clicked position.
+ * @return color at the clicked position as a <code>float[] rgba.</code>
+ */
+ public abstract float[] getColorAtPos(int clickX, int clickY);
+
+ public float getRed() {
+ return rgba[0];
+ }
+ public float getGreen(){
+ return rgba[1];
+ }
+ public float getBlue(){
+ return rgba[2];
+ }
+ public float getAlpha(){
+ return rgba[3];
+ }
+
+ public float getHue(){
+ return hsb[0];
+ }
+
+ public float getSaturation(){
+ return hsb[1];
+ }
+
+ public float getBrightness(){
+ return hsb[2];
+ }
+
+ public String getHex() {
+ return null;
+ };
+
+ public Color getColor() {
+ return new Color(rgba[0], rgba[1], rgba[2], rgba[3]);
+ }
+
+ }
+
+ private class TextInputFieldNumber extends TextInputField {
+ private final float min, max;
+ public TextInputFieldNumber(int width, int height, String defaultValue, float min, float max) {
+ super(width, height, true, true, defaultValue);
+ this.min = min;
+ this.max = max;
+ }
+
+ @Override
+ public void draw(long vg, int x, int y) {
+ super.draw(vg, x, y);
+
+ }
+ }
+
+ private class Slider {
+ private final int style;
+
+ public Slider(int style) {
+ this.style = style;
+ }
+
+ public void draw(long vg, int x, int y, int color1, int color2) {
+
+ }
+ }
+}
+
+
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java
index 1587a93..90a3910 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java
@@ -8,12 +8,11 @@ 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 net.minecraft.client.Minecraft;
-import net.minecraft.client.resources.I18n;
import net.minecraft.command.CommandException;
-import net.minecraft.command.ICommandSender;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.fml.common.ModMetadata;
import org.jetbrains.annotations.NotNull;
@@ -50,7 +49,7 @@ public class ModCard extends BasicElement {
if (iconPath != null) {
RenderManager.drawImage(vg, iconPath, x, y, width, 87);
} else {
- RenderManager.drawImage(vg, "/assets/oneconfig/textures/box.png", x + 98, y + 19, 48, 48);
+ RenderManager.drawImage(vg, Images.MOD_BOX, x + 98, y + 19, 48, 48);
}
favoriteHitbox.update(x + 212, y + 87);
favoriteHitbox.currentColor = ColorUtils.getColor(favoriteHitbox.currentColor, favoriteHitbox.colorPalette, favoriteHitbox.hovered, favoriteHitbox.clicked);
@@ -58,9 +57,9 @@ public class ModCard extends BasicElement {
favorite = favoriteHitbox.isToggled();
RenderManager.drawString(vg, modData.name, x + 12, y + 103, OneConfigConfig.WHITE, 14f, Fonts.INTER_MEDIUM);
if (favorite) {
- RenderManager.drawImage(vg, "/assets/oneconfig/textures/love.png", x + 220, y + 95, 16, 16);
+ RenderManager.drawImage(vg, Images.FAVORITE, x + 220, y + 95, 16, 16);
} else {
- RenderManager.drawImage(vg, "/assets/oneconfig/textures/love_empty.png", x + 220, y + 95, 16, 16);
+ RenderManager.drawImage(vg, Images.FAVORITE_OFF, x + 220, y + 95, 16, 16);
}
super.update(x, y);
isHoveredMain = InputUtils.isAreaHovered(x, y, width, 87);
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/TextInputField.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/TextInputField.java
index 081c99b..04e5676 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/TextInputField.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/TextInputField.java
@@ -40,6 +40,12 @@ public class TextInputField extends BasicElement {
this.input = "";
}
+ public TextInputField(int width, int height, boolean centered, boolean onlyNums, String defaultText) {
+ this(width, height, defaultText, false, false);
+ this.centered = centered;
+ this.onlyNums = onlyNums;
+ }
+
public void onlyAcceptNumbers(boolean state) {
onlyNums = state;
}
@@ -85,7 +91,7 @@ public class TextInputField extends BasicElement {
toggled = false;
}
int color = toggled ? OneConfigConfig.WHITE : OneConfigConfig.WHITE_60;
- if(!toggled) caretPos = input.length();
+ if (!toggled) caretPos = input.length();
float width;
StringBuilder s = new StringBuilder();
if (!password) {
@@ -96,7 +102,7 @@ public class TextInputField extends BasicElement {
}
width = RenderManager.getTextWidth(vg, s.substring(0, caretPos), 14f, Fonts.INTER_REGULAR);
}
- if(hovered) {
+ if (hovered) {
while (Mouse.next()) {
if (Mouse.getEventButtonState()) {
if (Mouse.getEventButton() == 0) {
@@ -127,17 +133,19 @@ public class TextInputField extends BasicElement {
if (start != 0f && end != 0f && toggled) {
RenderManager.drawRect(vg, start, y + height / 2f - 10, end, 20, OneConfigConfig.GRAY_300);
}
- if(hovered) {
+ if (hovered) {
if (Mouse.isButtonDown(0) && !isDoubleClick) {
caretPos = calculatePos(Mouse.getX());
if (caretPos > prevCaret) {
- if(!centered) start = x + 12 + this.getTextWidth(vg, input.substring(0, prevCaret));
- else start = x + this.width / 2f - halfTextWidth + this.getTextWidth(vg, input.substring(0, prevCaret));
+ if (!centered) start = x + 12 + this.getTextWidth(vg, input.substring(0, prevCaret));
+ else
+ start = x + this.width / 2f - halfTextWidth + this.getTextWidth(vg, input.substring(0, prevCaret));
end = this.getTextWidth(vg, input.substring(prevCaret, caretPos));
selectedText = input.substring(prevCaret, caretPos);
} else {
- if(!centered) start = x + 12 + this.getTextWidth(vg, input.substring(0, prevCaret));
- else start = x + this.width / 2f - halfTextWidth + this.getTextWidth(vg, input.substring(0, prevCaret));
+ if (!centered) start = x + 12 + this.getTextWidth(vg, input.substring(0, prevCaret));
+ else
+ start = x + this.width / 2f - halfTextWidth + this.getTextWidth(vg, input.substring(0, prevCaret));
end = -this.getTextWidth(vg, input.substring(caretPos, prevCaret));
selectedText = input.substring(caretPos, prevCaret);
}
@@ -146,7 +154,7 @@ public class TextInputField extends BasicElement {
if (toggled) {
- if(!centered) {
+ if (!centered) {
RenderManager.drawLine(vg, x + width + 12, (float) y + height / 2f - 10, x + width + 12, (float) y + height / 2f + 10, 1, OneConfigConfig.WHITE);
} else {
RenderManager.drawLine(vg, x + this.width / 2f - halfTextWidth + width, (float) y + height / 2f - 10, x + this.width / 2f - halfTextWidth + width, (float) y + height / 2f + 10, 1, OneConfigConfig.WHITE);
@@ -155,7 +163,7 @@ public class TextInputField extends BasicElement {
if (input.equals("")) {
- if(!centered) {
+ if (!centered) {
RenderManager.drawString(vg, defaultText, x + 12, y + height / 2f + 1, color, 14f, Fonts.INTER_REGULAR);
} else {
RenderManager.drawString(vg, defaultText, x + this.width / 2f - halfTextWidth, y + height / 2f + 1, color, 14f, Fonts.INTER_REGULAR);
@@ -163,7 +171,7 @@ public class TextInputField extends BasicElement {
}
if (!password) {
- if(!centered) {
+ if (!centered) {
RenderManager.drawString(vg, input, x + 12, y + height / 2f + 1, color, 14f, Fonts.INTER_REGULAR);
} else {
RenderManager.drawString(vg, input, x + this.width / 2f - halfTextWidth, y + height / 2f + 1, color, 14f, Fonts.INTER_REGULAR);
@@ -195,7 +203,7 @@ public class TextInputField extends BasicElement {
e.printStackTrace();
}
}
- if(key == Keyboard.KEY_DELETE) {
+ if (key == Keyboard.KEY_DELETE) {
input = "";
}
@@ -258,7 +266,7 @@ public class TextInputField extends BasicElement {
return;
}
if (key == Keyboard.KEY_TAB) {
- if(onlyNums) return;
+ if (onlyNums) return;
input += " ";
caretPos += 4;
return;
@@ -311,7 +319,7 @@ public class TextInputField extends BasicElement {
end = 0f;
}
}
- if(key == Keyboard.KEY_END) {
+ if (key == Keyboard.KEY_END) {
toggled = false;
}
@@ -319,24 +327,24 @@ public class TextInputField extends BasicElement {
if (key == Keyboard.KEY_LCONTROL || key == Keyboard.KEY_RCONTROL || key == Keyboard.KEY_LMENU || key == Keyboard.KEY_RMENU || key == Keyboard.KEY_LMETA || key == Keyboard.KEY_RMETA || key == Keyboard.KEY_LSHIFT || key == Keyboard.KEY_RSHIFT || key == Keyboard.KEY_RETURN || key == Keyboard.KEY_CAPITAL || key == 221 || key == Keyboard.KEY_HOME) {
return;
}
- if(onlyNums) {
- if(!Character.isDigit(c) && key != 52) return;
+ if (onlyNums) {
+ if (!Character.isDigit(c) && key != 52) return;
}
if (!Character.isDefined(key)) return;
if (!Character.isDefined(c)) return;
- if(GuiScreen.isCtrlKeyDown()) return;
- if(ChatAllowedCharacters.isAllowedCharacter(c)) {
- if(getTextWidth(vg, input) + 22 > width) { // over typing is banned
+ if (GuiScreen.isCtrlKeyDown()) return;
+ if (ChatAllowedCharacters.isAllowedCharacter(c)) {
+ if (getTextWidth(vg, input) + 22 > width) { // over typing is banned
return;
}
- if(selectedText != null) {
- if(caretPos > prevCaret) {
+ if (selectedText != null) {
+ if (caretPos > prevCaret) {
input = input.substring(0, prevCaret) + input.substring(prevCaret, caretPos);
caretPos = prevCaret;
} else {
input = input.substring(0, caretPos) + input.substring(caretPos, prevCaret);
}
- if(selectedText.equals(input)) {
+ if (selectedText.equals(input)) {
input = "";
}
selectedText = null;
@@ -365,17 +373,18 @@ public class TextInputField extends BasicElement {
}
private void onDoubleClick() {
- prevCaret = input.substring(0,caretPos).lastIndexOf(' ') + 1;
+ prevCaret = input.substring(0, caretPos).lastIndexOf(' ') + 1;
caretPos = input.indexOf(' ', caretPos);
- if(caretPos == -1) caretPos = input.length();
+ if (caretPos == -1) caretPos = input.length();
selectedText = input.substring(prevCaret, caretPos);
- if(!centered) start = x + 12 + this.getTextWidth(vg, input.substring(0, prevCaret));
- else start = x + this.width / 2f - this.getTextWidth(vg, input) / 2f + this.getTextWidth(vg, input.substring(0, prevCaret));
+ if (!centered) start = x + 12 + this.getTextWidth(vg, input.substring(0, prevCaret));
+ else
+ start = x + this.width / 2f - this.getTextWidth(vg, input) / 2f + this.getTextWidth(vg, input.substring(0, prevCaret));
end = this.getTextWidth(vg, input.substring(prevCaret, caretPos));
}
private int calculatePos(int pos) {
- if(centered) pos -= 12;
+ if (centered) pos -= 12;
String s1 = "";
int i;
for (char c : input.toCharArray()) {
@@ -393,11 +402,11 @@ public class TextInputField extends BasicElement {
}
return 0;
}
-
+
private float getTextWidth(long vg, String s) {
- if(password) {
+ if (password) {
StringBuilder s1 = new StringBuilder();
- while(s1.length() < s.length()) {
+ while (s1.length() < s.length()) {
s1.append('*');
}
return RenderManager.getTextWidth(vg, s1.toString(), 14.0f, Fonts.INTER_REGULAR);
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);