diff options
13 files changed, 185 insertions, 38 deletions
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 8abb303..4cda7d5 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/annotations/Option.java +++ b/src/main/java/io/polyfrost/oneconfig/config/annotations/Option.java @@ -1,5 +1,6 @@ package io.polyfrost.oneconfig.config.annotations; +import io.polyfrost.oneconfig.config.data.InfoType; import io.polyfrost.oneconfig.config.data.OptionType; import java.lang.annotation.ElementType; @@ -11,7 +12,7 @@ import java.lang.annotation.Target; @Target(ElementType.FIELD) public @interface Option { /** - * The name of the page that will be displayed to the user + * The name of the option that will be displayed to the user */ String name(); @@ -39,4 +40,29 @@ public @interface Option { * The width of the option (1 = half width, 2 = full width) */ int size() default 1; + + /** + * The placeholder for the text box if there is no text inside + */ + String placeholder() default ""; + + /** + * If the text field is secure or not + */ + boolean secure() default false; + + /** + * If the text field is multi line or not + */ + boolean multiLine() default false; + + /** + * Steps of slider (0 for no steps) + */ + int step() default 0; + + /** + * Option for info option type + */ + InfoType infoType() default InfoType.INFO; } diff --git a/src/main/java/io/polyfrost/oneconfig/config/data/InfoType.java b/src/main/java/io/polyfrost/oneconfig/config/data/InfoType.java new file mode 100644 index 0000000..1b96161 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/config/data/InfoType.java @@ -0,0 +1,8 @@ +package io.polyfrost.oneconfig.config.data; + +public enum InfoType { + INFO, + WARNING, + ERROR, + SUCCESS +} diff --git a/src/main/java/io/polyfrost/oneconfig/config/data/OptionType.java b/src/main/java/io/polyfrost/oneconfig/config/data/OptionType.java index 22c92c0..61bb516 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/data/OptionType.java +++ b/src/main/java/io/polyfrost/oneconfig/config/data/OptionType.java @@ -1,6 +1,24 @@ package io.polyfrost.oneconfig.config.data; public enum OptionType { + /** + * Type: class + */ PAGE, - SWITCH + /** + * Type: boolean + */ + SWITCH, + /** + * Type: boolean + */ + CHECKBOX, + DUAL_OPTION, + ARROW_SELECTOR, + TEXT, + SLIDER, + COLOR, + DROPDOWN, + MULTI_DROPDOWN, + INFO } 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 06e3e4e..37114cf 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java +++ b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java @@ -6,9 +6,10 @@ import io.polyfrost.oneconfig.config.core.ConfigCore; import io.polyfrost.oneconfig.config.data.Mod; import io.polyfrost.oneconfig.config.data.OptionPage; import io.polyfrost.oneconfig.config.profiles.Profiles; +import io.polyfrost.oneconfig.gui.elements.config.ConfigCheckbox; import io.polyfrost.oneconfig.gui.elements.config.ConfigPage; import io.polyfrost.oneconfig.gui.elements.config.ConfigSwitch; -import io.polyfrost.oneconfig.test.TestConfig; +import io.polyfrost.oneconfig.gui.elements.config.ConfigTextBox; import java.io.*; import java.lang.reflect.Field; @@ -93,6 +94,11 @@ public class Config { case SWITCH: options.add(new ConfigSwitch(field, option.name(), option.size())); break; + case CHECKBOX: + options.add(new ConfigCheckbox(field, option.name(), option.size())); + break; + case TEXT: + options.add(new ConfigTextBox(field, option.name(), option.size(), option.placeholder(), option.secure(), option.multiLine())); } } } diff --git a/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java index 67ddc21..22e8f71 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java @@ -11,6 +11,7 @@ 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 static org.lwjgl.nanovg.NanoVG.nvgResetScissor; import static org.lwjgl.nanovg.NanoVG.nvgScissor; @@ -30,6 +31,7 @@ public class OneConfigGui extends GuiScreen { private final TextInputField textInputField = new TextInputField(248, 40, "Search all of OneConfig...", false, false); + public boolean mouseDown; public OneConfigGui() { INSTANCE = this; @@ -47,8 +49,6 @@ public class OneConfigGui extends GuiScreen { RenderManager.drawRoundedRect(vg, 320, 140, 244, 800, OneConfigConfig.GRAY_900_80, OneConfigConfig.CORNER_RADIUS_WIN); RenderManager.drawRect(vg, 544, 140, 20, 800, OneConfigConfig.GRAY_800); //RenderManager.drawDropShadow(vg, 544, 140, 1056, 800, 20f, 32f, OneConfigConfig.GRAY_800); - } else { - // L; } RenderManager.drawLine(vg, 544, 212, 1600, 212, 1, OneConfigConfig.GRAY_700); @@ -78,15 +78,8 @@ public class OneConfigGui extends GuiScreen { String s = (" draw: " + end / 1000000f + "ms"); RenderManager.drawString(vg, currentPage.getTitle(), x + 336, y + 36, OneConfigConfig.WHITE_90, 32f, Fonts.INTER_SEMIBOLD); RenderManager.drawString(vg, s, x + 1170, y + 790, OneConfigConfig.GRAY_300, 10f, Fonts.INTER_MEDIUM); - - - //textInputField.draw(vg, 792, 548); - //btn.draw(vg, 976, 870); - - //RenderManager.drawGradientRoundedRect(vg, 100, 100, 500, 100, OneConfigConfig.BLUE_600, OneConfigConfig.BLUE_500, OneConfigConfig.CORNER_RADIUS_WIN); - }); - + mouseDown = Mouse.isButtonDown(0) && prevPage == null; } protected void keyTyped(char key, int keyCode) { @@ -112,4 +105,9 @@ public class OneConfigGui extends GuiScreen { public boolean doesGuiPauseGame() { return false; } + + @Override + public void onGuiClosed() { + currentPage.finishUpAndClose(); + } } 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 dd72217..c4bab72 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java @@ -41,13 +41,13 @@ public class BasicElement { public void update(int x, int y) { hovered = InputUtils.isAreaHovered(x - hitBoxX, y - hitBoxY, width + hitBoxX, height + hitBoxY); + clicked = InputUtils.isClicked(); if (hovered) { - if (Mouse.isButtonDown(0) && !clicked) { + if (clicked) { toggled = !toggled; onClick(); } - clicked = Mouse.isButtonDown(0); } } @@ -92,5 +92,4 @@ public class BasicElement { public boolean isToggled() { return toggled; } - } 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 new file mode 100644 index 0000000..a2c4510 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java @@ -0,0 +1,21 @@ +package io.polyfrost.oneconfig.gui.elements.config; + +import io.polyfrost.oneconfig.config.interfaces.BasicOption; + +import java.lang.reflect.Field; + +public class ConfigCheckbox extends BasicOption { + public ConfigCheckbox(Field field, String name, int size) { + super(field, name, size); + } + + @Override + public void draw(long vg, int x, int y) { + + } + + @Override + public int getHeight() { + return 0; + } +} diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPage.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPage.java index 8a718bb..5386fc9 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPage.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPage.java @@ -9,7 +9,6 @@ import io.polyfrost.oneconfig.lwjgl.RenderManager; import io.polyfrost.oneconfig.lwjgl.font.Fonts; import io.polyfrost.oneconfig.utils.ColorUtils; import io.polyfrost.oneconfig.utils.InputUtils; -import org.lwjgl.input.Mouse; import org.lwjgl.nanovg.NanoVG; import java.lang.reflect.Field; @@ -18,7 +17,6 @@ public class ConfigPage extends BasicOption { public final OptionPage page; public final String description; private int backgroundColor = OneConfigConfig.GRAY_500; - private boolean pressed = false; public ConfigPage(Field field, String name, String description, int size, OptionPage page) { super(field, name, size); @@ -28,22 +26,23 @@ public class ConfigPage extends BasicOption { @Override public void draw(long vg, int x, int y) { - boolean hovered = InputUtils.isAreaHovered(x - 2, y, 1023, description.equals("") ? 64 : 96); - boolean clicked = pressed && !Mouse.isButtonDown(0); - pressed = hovered && Mouse.isButtonDown(0); + int height = description.equals("") ? 64 : 96; + NanoVG.nvgScissor(vg, x - 2, y, 1024, height); + boolean hovered = InputUtils.isAreaHovered(x - 2, y, 1024, height); + boolean clicked = InputUtils.isAreaClicked(x - 2, y, 1024, height); backgroundColor = ColorUtils.smoothColor(backgroundColor, OneConfigConfig.GRAY_500, OneConfigConfig.GRAY_400, hovered, 100); if (clicked) NanoVG.nvgGlobalAlpha(vg, 0.8f); - RenderManager.drawRoundedRect(vg, x - 2, y, 1024, description.equals("") ? 64 : 96, backgroundColor, 20); + RenderManager.drawRoundedRect(vg, x - 2, y, 1024, height, backgroundColor, 20); RenderManager.drawString(vg, name, x + 24, y + 32, OneConfigConfig.WHITE, 24, Fonts.INTER_MEDIUM); if (!description.equals("")) RenderManager.drawString(vg, name, x + 24, y + 70, OneConfigConfig.WHITE, 14, Fonts.INTER_MEDIUM); RenderManager.drawImage(vg, "/assets/oneconfig/textures/arrow.png", x + 995f, y + (description.equals("") ? 20f : 36f), 13, 22); - if (clicked) OneConfigGui.INSTANCE.openPage(new ModConfigPage(page)); NanoVG.nvgGlobalAlpha(vg, 1f); + NanoVG.nvgResetScissor(vg); } @Override diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java index 89cc6f8..804fc62 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java @@ -7,10 +7,6 @@ import io.polyfrost.oneconfig.lwjgl.font.Fonts; import io.polyfrost.oneconfig.utils.ColorUtils; import io.polyfrost.oneconfig.utils.InputUtils; import io.polyfrost.oneconfig.utils.MathUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.util.ChatComponentText; -import org.lwjgl.input.Cursor; -import org.lwjgl.input.Mouse; import java.lang.reflect.Field; @@ -20,7 +16,6 @@ import static org.lwjgl.nanovg.NanoVG.nvgScissor; public class ConfigSwitch extends BasicOption { private int color; private float percentOn = 0f; - private boolean clicked = false; private boolean toggled ; public ConfigSwitch(Field field, String name, int size) { @@ -34,8 +29,7 @@ public class ConfigSwitch extends BasicOption { @Override public void draw(long vg, int x, int y) { - nvgScissor(vg, x, y, size == 0 ? 480 : 992, 32); - boolean hovered = InputUtils.isAreaHovered(x, y, size == 0 ? 480 : 992, 32); + nvgScissor(vg, x, y, size == 1 ? 480 : 992, 32); int x2 = x + 19 + (int) (percentOn * 18); color = ColorUtils.smoothColor(color, OneConfigConfig.GRAY_400, OneConfigConfig.BLUE_500, toggled, 20f); if(color == -15123643) { @@ -45,7 +39,7 @@ public class ConfigSwitch extends BasicOption { RenderManager.drawRoundedRect(vg, x2, y + 7, 18, 18, OneConfigConfig.WHITE, 9f); RenderManager.drawString(vg, name, x + 66, y + 17, OneConfigConfig.WHITE, 18f, Fonts.INTER_MEDIUM); - if (InputUtils.isClicked(x, y, size == 0 ? 480 : 992, 32) && !this.clicked && hovered) + if (InputUtils.isAreaClicked(x + 16, y, 42, 32)) { toggled = !toggled; try { @@ -55,12 +49,8 @@ public class ConfigSwitch extends BasicOption { e.printStackTrace(); } } - this.clicked = InputUtils.isClicked(x, y, size == 0 ? 480 : 992, 32) && hovered; percentOn = MathUtils.clamp(MathUtils.easeOut(percentOn, toggled ? 1f : 0f, 10)); nvgResetScissor(vg); - - - } @Override 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 new file mode 100644 index 0000000..e09ad77 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java @@ -0,0 +1,28 @@ +package io.polyfrost.oneconfig.gui.elements.config; + +import io.polyfrost.oneconfig.config.interfaces.BasicOption; + +import java.lang.reflect.Field; + +public class ConfigTextBox extends BasicOption { + private final String placeholder; + private final boolean secure; + private final boolean multiLine; + + public ConfigTextBox(Field field, String name, int size, String placeholder, boolean secure, boolean multiLine) { + super(field, name, size); + this.placeholder = placeholder; + this.secure = secure; + this.multiLine = multiLine; + } + + @Override + public void draw(long vg, int x, int y) { + + } + + @Override + public int getHeight() { + return 0; + } +} diff --git a/src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java b/src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java index 9d93205..7a02d73 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java @@ -1,7 +1,6 @@ package io.polyfrost.oneconfig.gui.pages; import io.polyfrost.oneconfig.config.OneConfigConfig; -import io.polyfrost.oneconfig.config.data.Mod; import io.polyfrost.oneconfig.config.data.OptionPage; import io.polyfrost.oneconfig.config.interfaces.BasicOption; import io.polyfrost.oneconfig.lwjgl.RenderManager; @@ -55,6 +54,7 @@ public class ModConfigPage extends Page { } optionY += option.getHeight() + 16; } + optionY += 8; } } diff --git a/src/main/java/io/polyfrost/oneconfig/test/TestConfig.java b/src/main/java/io/polyfrost/oneconfig/test/TestConfig.java index 6cb82da..a7b7b90 100644 --- a/src/main/java/io/polyfrost/oneconfig/test/TestConfig.java +++ b/src/main/java/io/polyfrost/oneconfig/test/TestConfig.java @@ -17,6 +17,31 @@ public class TestConfig extends Config { public static boolean switchTest; @Option( + name = "Test switch", + description = "Best description", + subcategory = "Test", + type = OptionType.SWITCH + ) + public static boolean switchTest1; + + @Option( + name = "Test switch", + description = "Best description", + subcategory = "Test", + type = OptionType.SWITCH, + size = 2 + ) + public static boolean switchTest2; + + @Option( + name = "Test switch", + description = "Best description", + subcategory = "Test", + type = OptionType.SWITCH + ) + public static boolean switchTest3; + + @Option( name = "Test Page", type = OptionType.PAGE, subcategory = "Test" @@ -31,6 +56,30 @@ public class TestConfig extends Config { ) public static TestPage testPage2 = new TestPage(); + @Option( + name = "Test switch", + description = "Best description", + subcategory = "Other subcategory", + type = OptionType.SWITCH + ) + public static boolean switchTest4; + + @Option( + name = "Test switch", + description = "Best description", + subcategory = "Other subcategory", + type = OptionType.SWITCH + ) + public static boolean switchTest5; + + @Option( + name = "Test switch", + description = "Best description", + subcategory = "Other subcategory", + type = OptionType.SWITCH + ) + public static boolean switchTest6; + public TestConfig() { super(new Mod("hacks", ModType.UTIL_QOL, "ShadyDev", "1.0"), "hacksConfig.json"); } diff --git a/src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java b/src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java index e030c29..ab8d708 100644 --- a/src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java +++ b/src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java @@ -1,5 +1,6 @@ package io.polyfrost.oneconfig.utils; +import io.polyfrost.oneconfig.gui.OneConfigGui; import net.minecraft.client.Minecraft; import org.lwjgl.input.Mouse; @@ -15,8 +16,12 @@ public class InputUtils { return mouseX > x && mouseY > y && mouseX < x + width && mouseY < y + height; // TODO add scaling info } - public static boolean isClicked(int x, int y, int width, int height) { - return isAreaHovered(x, y, width, height) && Mouse.isButtonDown(0); // TODO make actually do what its meant to do (only 1 event) + public static boolean isAreaClicked(int x, int y, int width, int height) { + return isAreaHovered(x, y, width, height) && isClicked(); + } + + public static boolean isClicked() { + return OneConfigGui.INSTANCE.mouseDown && !Mouse.isButtonDown(0); } public static int mouseX() { |