aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-05-08 11:31:50 +0200
committerDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-05-08 11:31:50 +0200
commite2ae63de1dc738a0c7b7137a29c8b42c3d0a2cdc (patch)
treec0417b6a833d3107134a15562ac20b256a54477f /src/main/java/cc/polyfrost/oneconfig
parent7babed2c38d56f2bcd90074deecd9fd555ef5c29 (diff)
downloadOneConfig-e2ae63de1dc738a0c7b7137a29c8b42c3d0a2cdc.tar.gz
OneConfig-e2ae63de1dc738a0c7b7137a29c8b42c3d0a2cdc.tar.bz2
OneConfig-e2ae63de1dc738a0c7b7137a29c8b42c3d0a2cdc.zip
fix color things
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/interfaces/BasicOption.java4
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java5
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java21
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java18
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java19
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java67
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java3
8 files changed, 83 insertions, 56 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/BasicOption.java b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/BasicOption.java
index 2bf2d13..38e0366 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/BasicOption.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/BasicOption.java
@@ -78,4 +78,8 @@ public abstract class BasicOption {
public boolean hasHalfSize() {
return true;
}
+
+ public String getName() {
+ return name;
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
index 75c3ae5..d084186 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
@@ -30,7 +30,7 @@ public class OneConfigGui extends GuiScreen {
protected Page currentPage;
protected Page prevPage;
private float pageProgress = -224f;
- private final TextInputField textInputField = new TextInputField(248, 40, "Search all of OneConfig...", false, false);
+ private final TextInputField textInputField = new TextInputField(248, 40, "Search...", false, false);
private final ArrayList<Page> previousPages = new ArrayList<>();
private final ArrayList<Page> nextPages = new ArrayList<>();
private final BasicElement backArrow = new BasicElement(40, 40, -1, false);
@@ -223,6 +223,9 @@ public class OneConfigGui extends GuiScreen {
return color;
}
+ public String getSearchValue() {
+ return textInputField.getInput();
+ }
@Override
public boolean doesGuiPauseGame() {
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 b972d40..25987db 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java
@@ -16,13 +16,13 @@ public class ColorSelector {
private final int y;
private Color color;
private float percentMove = 0f;
- private final BasicElement hsbBtn = new BasicElement(124, 28, 2,true);
- private final BasicElement rgbBtn = new BasicElement(124, 28, 2,true);
- private final BasicElement chromaBtn = new BasicElement(124, 28, 2,true);
+ private final BasicElement hsbBtn = new BasicElement(124, 28, 2, true);
+ private final BasicElement rgbBtn = new BasicElement(124, 28, 2, true);
+ private final BasicElement chromaBtn = new BasicElement(124, 28, 2, true);
private final BasicElement closeBtn = new BasicElement(32, 32, true);
- private final BasicElement copyBtn = new BasicElement(32, 32, 2,true);
- private final BasicElement pasteBtn = new BasicElement(32, 32, 2,true);
+ 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 NumberInputField hueInput = new NumberInputField(90, 32, 0, 0, 255, 1);
@@ -36,7 +36,6 @@ public class ColorSelector {
private final Slider speedSlider = new Slider(384, 1, 60, 20);
-
public ColorSelector(Color color, int mouseX, int mouseY) {
this.color = color;
this.x = mouseX - 208;
@@ -53,7 +52,7 @@ public class ColorSelector {
RenderManager.drawString(vg, "Color Selector", x + 16, y + 32, OneConfigConfig.WHITE_90, 18f, Fonts.SEMIBOLD);
closeBtn.draw(vg, x + 368, y + 16);
RenderManager.drawImage(vg, Images.CLOSE, x + 369, y + 17, 30, 30);
- if(closeBtn.isClicked()) {
+ if (closeBtn.isClicked()) {
OneConfigGui.INSTANCE.closeColorSelector();
}
@@ -85,9 +84,6 @@ public class ColorSelector {
RenderManager.drawImage(vg, Images.HELP, x + 301, y + 631, 18, 18);
RenderManager.drawImage(vg, Images.LAUNCH, x + 369, y + 631, 18, 18);
-
-
-
switch (mode) {
default:
case 0:
@@ -128,9 +124,6 @@ public class ColorSelector {
RenderManager.drawHollowRoundRect(vg, x + 15, y + 487, 384, 40, OneConfigConfig.GRAY_300, 12f, 2f);
RenderManager.drawImage(vg, Images.COLOR_BASE_LARGE, x + 20, y + 492, 376, 32);
RenderManager.drawRoundedRect(vg, x + 20, y + 492, 376, 32, color.getRGB(), 8f);
-
-
-
}
public Color getColor() {
@@ -146,8 +139,6 @@ public class ColorSelector {
}
-
-
private static class ColorSlider extends Slider {
protected Color gradColorStart, gradColorEnd;
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 ce683bf..627c0cc 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 {
alphaField.setCentered(true);
alphaField.onlyAcceptNumbers(true);
String buf = Integer.toHexString(color.getRGB());
- hex = "#"+buf.substring(buf.length()-6);
+ hex = "#" + buf.substring(buf.length() - 6);
}
@Override
@@ -44,7 +44,7 @@ public class ConfigColorElement extends BasicOption {
if (!alphaField.isToggled()) alphaField.setInput(String.format("%.01f", alpha * 100f) + "%");
alphaField.setErrored(false);
- if(alphaField.isToggled()) {
+ if (alphaField.isToggled()) {
try {
float input = Float.parseFloat(alphaField.getInput());
if (input < 0f) {
@@ -62,15 +62,13 @@ public class ConfigColorElement extends BasicOption {
}
alphaField.draw(vg, x + 352, y);
-
-
if (!hexField.isToggled()) hexField.setInput(hex);
hexField.setErrored(false);
- if(hexField.isToggled()) {
+ if (hexField.isToggled()) {
try {
color = HexToColor(hexField.getInput());
String buf = Integer.toHexString(color.getRGB());
- hex = "#"+buf.substring(buf.length()-6);
+ hex = "#" + buf.substring(buf.length() - 6);
} catch (NumberFormatException e) {
hexField.setErrored(true);
}
@@ -80,14 +78,14 @@ public class ConfigColorElement extends BasicOption {
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()) {
+ if (element.isClicked() && !element.isToggled()) {
OneConfigGui.INSTANCE.initColorSelector(new ColorSelector(color, InputUtils.mouseX(), InputUtils.mouseY()));
}
- if(element.isToggled() && element.isClicked()) {
+ 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);
+ hex = "#" + buf.substring(buf.length() - 6);
}
}
@@ -110,6 +108,4 @@ public class ConfigColorElement extends BasicOption {
}
throw new NumberFormatException("Invalid hex string: " + hex);
}
-
-
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java
index 531f18a..d44c33f 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java
@@ -23,7 +23,7 @@ public class ConfigSlider extends BasicOption {
this.min = min;
this.max = max;
this.step = step;
- inputField = new NumberInputField(84, 24, 0, min, max, step == 0 ? 1 : step);
+ inputField = new NumberInputField(84, 32, 0, min, max, step == 0 ? 1 : step);
}
@Override
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java
index fa40b12..8bd9771 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java
@@ -3,12 +3,16 @@ package cc.polyfrost.oneconfig.gui.pages;
import cc.polyfrost.oneconfig.config.OneConfigConfig;
import cc.polyfrost.oneconfig.config.data.OptionPage;
import cc.polyfrost.oneconfig.config.interfaces.BasicOption;
+import cc.polyfrost.oneconfig.gui.OneConfigGui;
import cc.polyfrost.oneconfig.gui.elements.BasicButton;
import cc.polyfrost.oneconfig.gui.elements.config.ConfigPageButton;
import cc.polyfrost.oneconfig.lwjgl.RenderManager;
import cc.polyfrost.oneconfig.lwjgl.font.Fonts;
+import java.awt.*;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
public class ModConfigPage extends Page {
private final OptionPage page;
@@ -35,11 +39,19 @@ public class ModConfigPage extends Page {
@Override
public void draw(long vg, int x, int y) {
if (page.categories.size() == 0) return;
+ String filter = OneConfigGui.INSTANCE.getSearchValue().toLowerCase().trim();
+ LinkedHashMap<String, ArrayList<BasicOption>> filteredSubcategories = page.categories.get(selectedCategory).subcategories;
+ if (!filter.equals("")) {
+
+ }
int optionX = x + 30;
int optionY = y + (page.categories.size() == 1 ? 16 : 64);
+ // if (!option.getName().toLowerCase().contains(filter)) continue;
// Top page buttons
for (ConfigPageButton page : page.categories.get(selectedCategory).topPages) {
+ if (!page.getName().toLowerCase().contains(filter) && !page.description.toLowerCase().contains(filter))
+ continue;
page.draw(vg, optionX, optionY);
optionY += page.getHeight() + 16;
}
@@ -92,6 +104,8 @@ public class ModConfigPage extends Page {
// Bottom page buttons
for (ConfigPageButton page : page.categories.get(selectedCategory).bottomPages) {
+ if (!page.getName().toLowerCase().contains(filter) && !page.description.toLowerCase().contains(filter))
+ continue;
page.draw(vg, optionX, optionY);
optionY += page.getHeight() + 16;
}
@@ -122,10 +136,11 @@ public class ModConfigPage extends Page {
@Override
public int drawStatic(long vg, int x, int y) {
// Category buttons
- if(categories.size() <= 1) return 0;
+ if (categories.size() <= 1) return 0;
int buttonX = x + 16;
for (BasicButton button : categories) {
- if (button.getWidth() == 0) button.setWidth((int) (Math.ceil(RenderManager.getTextWidth(vg, button.getText(), 12f, Fonts.MEDIUM) / 8f) * 8 + 16));
+ if (button.getWidth() == 0)
+ button.setWidth((int) (Math.ceil(RenderManager.getTextWidth(vg, button.getText(), 12f, Fonts.MEDIUM) / 8f) * 8 + 16));
button.draw(vg, buttonX, y + 16);
buttonX += button.getWidth() + 16;
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java
index eef0dc9..126d889 100644
--- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java
+++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java
@@ -3,6 +3,7 @@ package cc.polyfrost.oneconfig.lwjgl;
import org.jetbrains.annotations.NotNull;
import java.awt.*;
+import java.util.Arrays;
/**
* OneColor is a class for storing Colors in HSBA format. This format is used to allow the color selectors to work correctly.
@@ -16,45 +17,56 @@ import java.awt.*;
*/
@SuppressWarnings("unused")
public class OneColor {
- private int rgba;
+ transient private int rgba;
private final byte[] hsba;
private int chroma = -1;
-
// rgb constructors
- /** Create a new OneColor, converting the RGBA color to HSBA. */
+
+ /**
+ * Create a new OneColor, converting the RGBA color to HSBA.
+ */
public OneColor(int rgba) {
this.rgba = rgba;
this.hsba = RGBAtoHSBA(this.rgba);
}
- /** Create a new OneColor from the given RGBA values. */
+ /**
+ * Create a new OneColor from the given RGBA values.
+ */
public OneColor(int r, int g, int b, int a) {
- this.rgba = (a << 24) | (r << 16) | (g << 8) | b; // trusting copilot on this
+ this.rgba = ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | ((b & 0xFF));
this.hsba = RGBAtoHSBA(this.rgba);
}
- /** Create a new OneColor, converting the RGB color to HSBA. */
+ /**
+ * Create a new OneColor, converting the RGB color to HSBA.
+ */
public OneColor(int r, int g, int b) {
this(r, g, b, 255);
}
- /** Convert the java.awt.Color to an OneColor (HSBA format). */
+ /**
+ * Convert the java.awt.Color to an OneColor (HSBA format).
+ */
public OneColor(@NotNull Color c) {
this(c.getRGB());
}
-
-
// hsb constructors
- /** Create a new OneColor from the given HSBA values. */
+
+ /**
+ * Create a new OneColor from the given HSBA values.
+ */
public OneColor(float hue, float saturation, float brightness, float alpha) {
this.hsba = new byte[]{(byte) hue, (byte) saturation, (byte) brightness, (byte) alpha};
this.rgba = HSBAtoRGBA(this.hsba[0], this.hsba[1], this.hsba[2], this.hsba[3]);
}
- /** Create a new OneColor from the given HSB values. (alpha is set to max)*/
+ /**
+ * Create a new OneColor from the given HSB values. (alpha is set to max)
+ */
public OneColor(float hue, float saturation, float brightness) {
this(hue, saturation, brightness, 1.0f);
}
@@ -65,10 +77,9 @@ public class OneColor {
this.chroma = (int) chromaSpeed;
}
-
// internal constructor
public OneColor(int hue, int saturation, int brightness, int alpha, int chromaSpeed) {
- if(chromaSpeed == -1) {
+ if (chromaSpeed == -1) {
this.hsba = new byte[]{(byte) hue, (byte) saturation, (byte) brightness, (byte) alpha};
this.rgba = HSBAtoRGBA(this.hsba[0], this.hsba[1], this.hsba[2], this.hsba[3]);
} else {
@@ -78,30 +89,31 @@ public class OneColor {
}
-
-
-
// accessors
public int getRed() {
return rgba >> 16 & 255;
}
+
public int getGreen() {
return rgba >> 8 & 255;
}
+
public int getBlue() {
return rgba & 255;
}
-
public float getHue() {
return hsba[0];
}
+
public float getSaturation() {
return hsba[1];
}
+
public float getBrightness() {
return hsba[2];
}
+
public int getAlpha() {
return hsba[3];
}
@@ -110,31 +122,36 @@ public class OneColor {
* Return the current color in RGBA format. This is the format used by LWJGL and Minecraft.
* This method WILL return the color as a chroma, at the specified speed, if it is set.
* Otherwise, it will just return the current color.
+ *
* @return the current color in RGBA format (equivalent to getRGB of java.awt.Color)
*/
public int getRGB() {
- if(chroma == -1) {
+ if (chroma == -1) {
return rgba;
} else {
return HSBAtoRGBA(System.currentTimeMillis() % chroma / (float) chroma, hsba[1], hsba[2], hsba[3]);
}
}
- /** Get the RGBA color from the HSB color, and apply the alpha. */
+ /**
+ * Get the RGBA color from the HSB color, and apply the alpha.
+ */
public int HSBAtoRGBA(float hue, float saturation, float brightness, float alpha) {
- int temp = Color.HSBtoRGB(hue, saturation, brightness);
+ int temp = Color.HSBtoRGB(hue / 360f, saturation / 100f, brightness / 100f);
return temp | (int) (alpha * 255) << 24; // trusting copilot on this
}
- /** Get the HSBA color from the RGBA color. */
+ /**
+ * Get the HSBA color from the RGBA color.
+ */
public byte[] RGBAtoHSBA(int rgba) {
byte[] hsb = new byte[4];
float[] hsbArray = Color.RGBtoHSB((rgba >> 16 & 255), (rgba >> 8 & 255), (rgba & 255), null);
- hsb[0] = (byte) hsbArray[0];
- hsb[1] = (byte) hsbArray[1];
- hsb[2] = (byte) hsbArray[2];
+ System.out.println(Arrays.toString(hsbArray));
+ hsb[0] = (byte) (hsbArray[0] * 360);
+ hsb[1] = (byte) (hsbArray[1] * 100);
+ hsb[2] = (byte) (hsbArray[2] * 100);
hsb[3] = (byte) (rgba >> 24 & 255);
return hsb;
}
-
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java
index 5669681..3554782 100644
--- a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java
+++ b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java
@@ -4,6 +4,7 @@ import cc.polyfrost.oneconfig.config.annotations.ConfigPage;
import cc.polyfrost.oneconfig.config.annotations.Option;
import cc.polyfrost.oneconfig.config.data.*;
import cc.polyfrost.oneconfig.config.interfaces.Config;
+import cc.polyfrost.oneconfig.lwjgl.OneColor;
public class TestConfig extends Config {
@@ -22,7 +23,7 @@ public class TestConfig extends Config {
type = OptionType.COLOR,
size = 2
)
- public static int color;
+ public static OneColor colorTest = new OneColor(126, 137, 42);
@Option(
name = "Test dual thing",