aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io
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
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')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/OneConfig.java3
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/annotations/Option.java7
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/interfaces/BasicOption.java24
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java5
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java69
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/SideBar.java29
-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
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/pages/HomePage.java3
-rw-r--r--src/main/java/io/polyfrost/oneconfig/lwjgl/IOUtil.java5
-rw-r--r--src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java100
-rw-r--r--src/main/java/io/polyfrost/oneconfig/lwjgl/image/ImageLoader.java37
-rw-r--r--src/main/java/io/polyfrost/oneconfig/lwjgl/image/Images.java48
-rw-r--r--src/main/java/io/polyfrost/oneconfig/test/TestNanoVGGui.java1
24 files changed, 644 insertions, 198 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/OneConfig.java b/src/main/java/io/polyfrost/oneconfig/OneConfig.java
index 5e25ee0..3c867b9 100644
--- a/src/main/java/io/polyfrost/oneconfig/OneConfig.java
+++ b/src/main/java/io/polyfrost/oneconfig/OneConfig.java
@@ -8,6 +8,7 @@ import io.polyfrost.oneconfig.config.data.ModType;
import io.polyfrost.oneconfig.hud.HudCore;
import io.polyfrost.oneconfig.lwjgl.RenderManager;
import io.polyfrost.oneconfig.lwjgl.font.Fonts;
+import io.polyfrost.oneconfig.lwjgl.image.Images;
import io.polyfrost.oneconfig.test.TestConfig;
import net.minecraft.client.Minecraft;
import net.minecraftforge.client.ClientCommandHandler;
@@ -52,7 +53,7 @@ public class OneConfig {
RenderManager.setupAndDraw((vg) -> {
RenderManager.drawRoundedRect(vg, -100, -100, 50, 50, -1, 12f);
RenderManager.drawString(vg, "OneConfig loading...", -100, -100, -1, 12f, Fonts.INTER_MEDIUM);
- RenderManager.drawImage(vg, "/assets/oneconfig/textures/icon.png", -100, -100, 50, 50);
+ RenderManager.drawImage(vg, Images.LOGO, -100, -100, 50, 50);
});
}
diff --git a/src/main/java/io/polyfrost/oneconfig/config/annotations/Option.java b/src/main/java/io/polyfrost/oneconfig/config/annotations/Option.java
index a4f4a67..77831db 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/annotations/Option.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/annotations/Option.java
@@ -32,10 +32,11 @@ public @interface Option {
String subcategory();
- /** A String array of all the possible values for the UniSelector, dropdownList, and ComboBox.
+ /**
+ * A String array of all the possible values for the UniSelector, dropdownList, and ComboBox.
* Also used in the DualOption slider, index 0 is the left, index 1 is the right; for example:
* {"Option 1", "Option 2"}
- * */
+ */
String[] options() default {};
/**
@@ -62,10 +63,12 @@ public @interface Option {
* Steps of slider (0 for no steps)
*/
int step() default 0;
+
/**
* Minimum value of slider
*/
float min() default 0;
+
/**
* The maximum value of the slider
*/
diff --git a/src/main/java/io/polyfrost/oneconfig/config/interfaces/BasicOption.java b/src/main/java/io/polyfrost/oneconfig/config/interfaces/BasicOption.java
index 8d19b55..3c02b69 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/interfaces/BasicOption.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/interfaces/BasicOption.java
@@ -1,7 +1,5 @@
package io.polyfrost.oneconfig.config.interfaces;
-import io.polyfrost.oneconfig.gui.elements.BasicElement;
-
import java.lang.reflect.Field;
@SuppressWarnings({"unused"})
@@ -13,9 +11,9 @@ public abstract class BasicOption {
/**
* Initialize option
*
- * @param field variable attached to option (null for category)
- * @param name name of option
- * @param size size of option, 0 for single column, 1 for double.
+ * @param field variable attached to option (null for category)
+ * @param name name of option
+ * @param size size of option, 0 for single column, 1 for double.
*/
public BasicOption(Field field, String name, int size) {
this.field = field;
@@ -48,9 +46,9 @@ public abstract class BasicOption {
/**
* Function that gets called when drawing option
*
- * @param vg NanoVG context
- * @param x x position
- * @param y y position
+ * @param vg NanoVG context
+ * @param x x position
+ * @param y y position
*/
public abstract void draw(long vg, int x, int y);
@@ -58,9 +56,9 @@ public abstract class BasicOption {
* Function that gets called last drawing option,
* should be used for things that draw above other options
*
- * @param vg NanoVG context
- * @param x x position
- * @param y y position
+ * @param vg NanoVG context
+ * @param x x position
+ * @param y y position
*/
public void drawLast(long vg, int x, int y) {
@@ -69,8 +67,8 @@ public abstract class BasicOption {
/**
* Function that gets called when a key is typed
*
- * @param key char that has been typed
- * @param keyCode code of key
+ * @param key char that has been typed
+ * @param keyCode code of key
*/
public void keyTyped(char key, int keyCode) {
}
diff --git a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java
index ca151db..b3c8c75 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java
@@ -18,7 +18,10 @@ import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Optional;
public class Config {
protected final String configFile;
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java
index 130df7f..930c8cd 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java
@@ -1,16 +1,23 @@
package io.polyfrost.oneconfig.gui;
import io.polyfrost.oneconfig.config.OneConfigConfig;
+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.gui.pages.HomePage;
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.MathUtils;
import net.minecraft.client.gui.GuiScreen;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
+import org.lwjgl.nanovg.NanoVG;
+
+import java.awt.*;
+import java.util.ArrayList;
import static org.lwjgl.nanovg.NanoVG.nvgResetScissor;
import static org.lwjgl.nanovg.NanoVG.nvgScissor;
@@ -28,6 +35,12 @@ public class OneConfigGui extends GuiScreen {
private float pageProgress = -224f;
private final TextInputField textInputField = new TextInputField(248, 40, "Search all of OneConfig...", false, false);
+ private final ArrayList<Page> pageHistory = new ArrayList<>();
+ private int currentPageIndex = 0;
+ private final BasicElement backArrow = new BasicElement(40, 40, -1, true);
+ private final BasicElement forwardArrow = new BasicElement(40, 40, -1, true);
+
+ private ColorSelector currentColorSelector;
public boolean mouseDown;
@@ -57,12 +70,43 @@ public class OneConfigGui extends GuiScreen {
RenderManager.drawLine(vg, 544, 212, 1600, 212, 1, OneConfigConfig.GRAY_700);
RenderManager.drawLine(vg, 544, 140, 544, 940, 1, OneConfigConfig.GRAY_700);
- RenderManager.drawImage(vg, "/assets/oneconfig/textures/icon.png", x + 19, y + 19, 42, 42);
+ RenderManager.drawImage(vg, Images.LOGO, x + 19, y + 19, 42, 42);
RenderManager.drawString(vg, "OneConfig", x + 69, y + 32, OneConfigConfig.WHITE, 18f, Fonts.INTER_BOLD); // added half line height to center text
RenderManager.drawString(vg, "By Polyfrost", x + 69, y + 51, OneConfigConfig.WHITE, 12f, Fonts.INTER_REGULAR);
textInputField.draw(vg, x + 1020, y + 16);
- //element.setColorPalette(0);
sideBar.draw(vg, x, y);
+ backArrow.draw(vg, x + 240, y + 16);
+ forwardArrow.draw(vg, x + 280, y + 16);
+
+ if (currentPageIndex <= 0) {
+ backArrow.disable(true);
+ NanoVG.nvgGlobalAlpha(vg, 0.5f);
+ } else backArrow.disable(false);
+ RenderManager.drawImage(vg, Images.ARROW_LEFT, x + 250, y + 26, 20, 20);
+ NanoVG.nvgGlobalAlpha(vg, 1f);
+ if (currentPageIndex > pageHistory.size() - 1) {
+ forwardArrow.disable(true);
+ NanoVG.nvgGlobalAlpha(vg, 0.5f);
+ } else forwardArrow.disable(false);
+ RenderManager.drawImage(vg, Images.ARROW_RIGHT, x + 290, y + 26, 20, 20);
+ NanoVG.nvgGlobalAlpha(vg, 1f);
+
+ /*if (backArrow.isClicked()) { // TODO
+ try {
+ openPage(pageHistory.get(currentPageIndex--));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ if (forwardArrow.isClicked()) {
+ try {
+ pageHistory.add(currentPage);
+ openPage(pageHistory.get(currentPageIndex++));
+ } catch (Exception ignored) {
+ }
+ }*/
+
+
nvgScissor(vg, x + 224, y + 72, 1056, 728);
if (prevPage != null) {
pageProgress = MathUtils.easeInOutCirc(50, pageProgress, 832 - pageProgress, 220);
@@ -77,6 +121,9 @@ public class OneConfigGui extends GuiScreen {
currentPage.draw(vg, (int) (x - pageProgress), y + 72);
}
nvgResetScissor(vg);
+ if(currentColorSelector != null) {
+ currentColorSelector.draw(vg);
+ }
long end = System.nanoTime() - start;
String s = (" draw: " + end / 1000000f + "ms");
RenderManager.drawString(vg, currentPage.getTitle(), x + 336, y + 36, OneConfigConfig.WHITE_90, 32f, Fonts.INTER_SEMIBOLD);
@@ -97,7 +144,7 @@ public class OneConfigGui extends GuiScreen {
}
public void openPage(@NotNull Page page) {
- if(page == currentPage) return;
+ if (page == currentPage) return;
currentPage.finishUpAndClose();
if (prevPage == null) {
prevPage = currentPage;
@@ -105,6 +152,22 @@ public class OneConfigGui extends GuiScreen {
currentPage = page;
}
+ /**
+ * initialize a new ColorSelector and add it to the draw script. This method is used to make sure it is always rendered on top.
+ * @implNote Correct usage: <code>OneConfigGui.INSTANCE.initColorSelector(new ColorSelector(color, InputUtils.mouseX(), InputUtils.mouseY()));</code>
+ */
+ public void initColorSelector(ColorSelector colorSelector) {
+ currentColorSelector = colorSelector;
+ }
+
+ /** Close the current color selector and return the color it had when it closed.
+ */
+ public Color closeColorSelector() {
+ Color color = currentColorSelector.getColor();
+ currentColorSelector = null;
+ return color;
+ }
+
@Override
public boolean doesGuiPauseGame() {
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/SideBar.java b/src/main/java/io/polyfrost/oneconfig/gui/SideBar.java
index dc136a7..195e398 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/SideBar.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/SideBar.java
@@ -3,11 +3,10 @@ package io.polyfrost.oneconfig.gui;
import io.polyfrost.oneconfig.config.OneConfigConfig;
import io.polyfrost.oneconfig.gui.elements.BasicButton;
import io.polyfrost.oneconfig.gui.pages.HomePage;
-import io.polyfrost.oneconfig.gui.pages.ModConfigPage;
import io.polyfrost.oneconfig.gui.pages.ModsPage;
-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.MathUtils;
import net.minecraft.client.Minecraft;
@@ -20,19 +19,19 @@ public class SideBar {
private float targetY = 0, currentY = 0;
public SideBar() {
- btnList.add(new BasicButton(192, 36, "Dashboard", "/assets/oneconfig/textures/Dashboard.png", null, -3, BasicButton.ALIGNMENT_LEFT, new HomePage()));
- btnList.add(new BasicButton(192, 36, "Global Search", "/assets/oneconfig/textures/search.png", null, -3, BasicButton.ALIGNMENT_LEFT));
- btnList.add(new BasicButton(192, 36, "Mods", "/assets/oneconfig/textures/Mods.png", null, -3, BasicButton.ALIGNMENT_LEFT, new ModsPage()));
- btnList.add(new BasicButton(192, 36, "Performance", "/assets/oneconfig/textures/Performance.png", null, -3, BasicButton.ALIGNMENT_LEFT));
- btnList.add(new BasicButton(192, 36, "Profiles", "/assets/oneconfig/textures/Profiles.png", null, -3, BasicButton.ALIGNMENT_LEFT));
- btnList.add(new BasicButton(192, 36, "Updates", "/assets/oneconfig/textures/Update.png", null, -3, BasicButton.ALIGNMENT_LEFT));
- btnList.add(new BasicButton(192, 36, "Theme", "/assets/oneconfig/textures/Theme.png", null, -3, BasicButton.ALIGNMENT_LEFT));
- btnList.add(new BasicButton(192, 36, "Screenshots", "/assets/oneconfig/textures/Image.png", null, -3, BasicButton.ALIGNMENT_LEFT));
- btnList.add(new BasicButton(192, 36, "HUD Settings", "/assets/oneconfig/textures/HUDSettings.png", null, -3, BasicButton.ALIGNMENT_LEFT));
- btnList.add(new BasicButton(192, 36, "Preferences", "/assets/oneconfig/textures/Settings.png", null, -3, BasicButton.ALIGNMENT_LEFT));
- btnList.add(new BasicButton(192, 36, "Close", "/assets/oneconfig/textures/XCircle.png", null, -1, BasicButton.ALIGNMENT_LEFT, () -> Minecraft.getMinecraft().displayGuiScreen(null)));
- btnList.add(new BasicButton(192, 36, "Minimize", "/assets/oneconfig/textures/Minimise.png", null, -1, BasicButton.ALIGNMENT_LEFT));
- btnList.add(new BasicButton(192, 36, "Edit HUD", "/assets/oneconfig/textures/HUD.png", null, 0, BasicButton.ALIGNMENT_LEFT, () -> Minecraft.getMinecraft().displayGuiScreen(new HudGui())));
+ btnList.add(new BasicButton(192, 36, "Dashboard", Images.DASHBOARD, null, -3, BasicButton.ALIGNMENT_LEFT, new HomePage()));
+ btnList.add(new BasicButton(192, 36, "Global Search", Images.SEARCH, null, -3, BasicButton.ALIGNMENT_LEFT));
+ btnList.add(new BasicButton(192, 36, "Mods", Images.MODS, null, -3, BasicButton.ALIGNMENT_LEFT, new ModsPage()));
+ btnList.add(new BasicButton(192, 36, "Performance", Images.PERFORMANCE, null, -3, BasicButton.ALIGNMENT_LEFT));
+ btnList.add(new BasicButton(192, 36, "Profiles", Images.PROFILES, null, -3, BasicButton.ALIGNMENT_LEFT));
+ btnList.add(new BasicButton(192, 36, "Updates", Images.UPDATES, null, -3, BasicButton.ALIGNMENT_LEFT));
+ btnList.add(new BasicButton(192, 36, "Theme", Images.THEMES, null, -3, BasicButton.ALIGNMENT_LEFT));
+ btnList.add(new BasicButton(192, 36, "Screenshots", Images.SCREENSHOT, null, -3, BasicButton.ALIGNMENT_LEFT));
+ btnList.add(new BasicButton(192, 36, "HUD Settings", Images.HUD_SETTINGS, null, -3, BasicButton.ALIGNMENT_LEFT));
+ btnList.add(new BasicButton(192, 36, "Preferences", Images.PREFERENCES, null, -3, BasicButton.ALIGNMENT_LEFT));
+ btnList.add(new BasicButton(192, 36, "Close", Images.CLOSE, null, -1, BasicButton.ALIGNMENT_LEFT, () -> Minecraft.getMinecraft().displayGuiScreen(null)));
+ btnList.add(new BasicButton(192, 36, "Minimize", Images.MINIMIZE, null, -1, BasicButton.ALIGNMENT_LEFT));
+ btnList.add(new BasicButton(192, 36, "Edit HUD", Images.HUD, null, 0, BasicButton.ALIGNMENT_LEFT, () -> Minecraft.getMinecraft().displayGuiScreen(new HudGui())));
}
public void draw(long vg, int x, int y) {
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