diff options
author | nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> | 2022-04-30 11:54:24 +0100 |
---|---|---|
committer | nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> | 2022-04-30 11:54:24 +0100 |
commit | 026aebb4748747f08d5088947056a75740550b17 (patch) | |
tree | 23583932e47825a91250ff60807d8a201b9557c3 /src/main | |
parent | 78fab84df48759e8968c477924b4bcc3b81e6cee (diff) | |
download | OneConfig-026aebb4748747f08d5088947056a75740550b17.tar.gz OneConfig-026aebb4748747f08d5088947056a75740550b17.tar.bz2 OneConfig-026aebb4748747f08d5088947056a75740550b17.zip |
config elements
Diffstat (limited to 'src/main')
8 files changed, 124 insertions, 17 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java b/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java index 955f7a4..d812f89 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java +++ b/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java @@ -11,6 +11,7 @@ import java.nio.file.Files; import java.nio.file.Paths; public class OneConfigConfig extends Config { + public static String currentProfile = "Default Profile"; // TODO i dont know how this works so this is just gonna be here for now @@ -33,6 +34,8 @@ public class OneConfigConfig extends Config { public static final int BLUE_600 = new Color(20, 82, 204, 255).getRGB(); // Blue 600 // button blue normal public static final int BLUE_600_80 = new Color(20, 82, 204, 204).getRGB(); // Blue 600 80% // button blue click public static final int BLUE_500 = new Color(25, 103, 255, 255).getRGB(); // Blue 500 // button blue hover + public static final int BLUE_400 = new Color(48, 129, 242, 255).getRGB(); + public static final int BLUE_400_80 = new Color(48, 129, 242, 204).getRGB(); public static final int WHITE_50 = new Color(255, 255, 255, 127).getRGB(); // White 60% public static final int WHITE_60 = new Color(255, 255, 255, 153).getRGB(); // White 60% public static final int WHITE_80 = new Color(255, 255, 255, 204).getRGB(); // White 80% 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 d9bdbb7..b7bcf4f 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/annotations/Option.java +++ b/src/main/java/io/polyfrost/oneconfig/config/annotations/Option.java @@ -36,6 +36,15 @@ public @interface Option { */ String subcategory(); + /** The name shown on the Left option of a DualOption slider. */ + String optionLeft() default "Option 1"; + + /** The name shown on the Right option of a DualOption slider. */ + String optionRight() default "Option 2"; + + /** A String array of all the possible values for the UniSelector, dropdownList, and ComboBox */ + String[] options() default {}; + /** * The width of the option (1 = half width, 2 = full width) */ 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 ef0a730..4378d34 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/data/OptionType.java +++ b/src/main/java/io/polyfrost/oneconfig/config/data/OptionType.java @@ -14,7 +14,7 @@ public enum OptionType { */ CHECKBOX, DUAL_OPTION, - ARROW_SELECTOR, + UNI_SELECTOR, /** * Type: String * Normal: 1x and 2x, Secure and Mutliline: 2x only 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 0cade35..ee72fee 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java +++ b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java @@ -6,10 +6,7 @@ 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.gui.elements.config.ConfigTextBox; +import io.polyfrost.oneconfig.gui.elements.config.*; import java.io.*; import java.lang.reflect.Field; @@ -99,6 +96,13 @@ public class Config { break; case TEXT: options.add(new ConfigTextBox(field, option.name(), option.size(), option.secure(), option.multiLine())); + break; + case DUAL_OPTION: + options.add(new ConfigDualOption(field, option.name(), option.size(), option.optionLeft(), option.optionRight())); + break; + case UNI_SELECTOR: + options.add(new ConfigUniSelector(field, option.name(), option.size(), option.options())); + break; } } } diff --git a/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java index ae8d796..0a4acd6 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java @@ -65,7 +65,7 @@ public class OneConfigGui extends GuiScreen { prevPage.draw(vg, (int) (x - pageProgress), y + 72); RenderManager.drawLine(vg, (int) (x - pageProgress + 1055), y + 72, (int) (x - pageProgress + 1057), y + 800, 2, OneConfigConfig.GRAY_700); // TODO might remove this currentPage.draw(vg, (int) (x - pageProgress + 1056), y + 72); - if (pageProgress > 828f) { + if (pageProgress > 830f) { // this number is the 'snap' point of the page prevPage = null; pageProgress = -224f; } diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java new file mode 100644 index 0000000..705ab1a --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java @@ -0,0 +1,53 @@ +package io.polyfrost.oneconfig.gui.elements.config; + +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.utils.InputUtils; +import io.polyfrost.oneconfig.utils.MathUtils; + +import java.lang.reflect.Field; + +public class ConfigDualOption extends BasicOption { + private float percentMove = 0f; + private final String left, right; + + public ConfigDualOption(Field field, String name, int size, String left, String right) { + super(field, name, size); + this.left = left; + this.right = right; + + } + + @Override + public int getHeight() { + return 32; + } + + @Override + public void draw(long vg, int x, int y) { + boolean toggled = false; + try { + toggled = (boolean) get(); + } catch (IllegalAccessException ignored) { + } + RenderManager.drawString(vg, name, x, y + 16, OneConfigConfig.WHITE_90, 18f, Fonts.INTER_MEDIUM); + RenderManager.drawRoundedRect(vg, x + 226, y, 256, 32, OneConfigConfig.GRAY_500, 12f); + int x1 = (int) (x + 228 + (percentMove * 128)); + RenderManager.drawRoundedRect(vg, x1, y + 2, 124, 28, OneConfigConfig.BLUE_600, 10f); + RenderManager.drawString(vg, left, x + 290 - RenderManager.getTextWidth(vg, left, 14f, Fonts.INTER_MEDIUM) / 2, y + 16, OneConfigConfig.WHITE_90, 14f, Fonts.INTER_MEDIUM); + RenderManager.drawString(vg, right, x + 418 - RenderManager.getTextWidth(vg, right, 14f, Fonts.INTER_MEDIUM) / 2, y + 16, OneConfigConfig.WHITE_90, 14f, Fonts.INTER_MEDIUM); + + if (InputUtils.isAreaClicked(x + 226, y, 256, 32)) { + toggled = !toggled; + try { + set(toggled); + } catch (IllegalAccessException e) { + System.err.println("failed to write config value: class=" + this + " fieldWatching=" + field + " valueWrite=" + toggled); + e.printStackTrace(); + } + } + percentMove = MathUtils.clamp(MathUtils.easeOut(percentMove, toggled ? 1f : 0f, 10)); + } +} diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java new file mode 100644 index 0000000..39f8cf9 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java @@ -0,0 +1,34 @@ +package io.polyfrost.oneconfig.gui.elements.config; + +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 java.lang.reflect.Field; + +public class ConfigUniSelector extends BasicOption { + String[] options; + + public ConfigUniSelector(Field field, String name, int size, String[] options) { + super(field, name, size); + this.options = options; + } + + @Override + public int getHeight() { + return 0; + } + + @Override + public void draw(long vg, int x, int y) { + int selected = 0; + try { + selected = (int) get(); + } catch (IllegalAccessException ignored) { + } + RenderManager.drawString(vg, name, x, y + 16, OneConfigConfig.WHITE_90, 18f, Fonts.INTER_MEDIUM); + RenderManager.drawString(vg, options[selected], x + 16, y + 16, OneConfigConfig.WHITE_90, 18f, Fonts.INTER_MEDIUM); + RenderManager.drawImage(vg, "/assets/oneconfig/textures/arrow.png", x + 230, y + 7, 13, 22, OneConfigConfig.BLUE_400); // TODO + } +} diff --git a/src/main/java/io/polyfrost/oneconfig/test/TestConfig.java b/src/main/java/io/polyfrost/oneconfig/test/TestConfig.java index fc8296d..a250318 100644 --- a/src/main/java/io/polyfrost/oneconfig/test/TestConfig.java +++ b/src/main/java/io/polyfrost/oneconfig/test/TestConfig.java @@ -9,37 +9,41 @@ import io.polyfrost.oneconfig.config.interfaces.Config; public class TestConfig extends Config { @Option( - name = "Test checkbox", + name = "Test dual thing", description = "Best description", subcategory = "Test", - type = OptionType.CHECKBOX + optionLeft = "FUNNY", optionRight = "not funny", + type = OptionType.DUAL_OPTION ) public static boolean switchTest; @Option( - name = "Test checkbox", + name = "Test string", description = "Best description", subcategory = "Test", - type = OptionType.CHECKBOX + optionLeft = "HI", optionRight = "BYE", + type = OptionType.DUAL_OPTION ) public static boolean switchTest1; @Option( - name = "Test checkbox", + name = "Test dual option", description = "Best description", subcategory = "Test", - type = OptionType.CHECKBOX, + optionRight = "cool", optionLeft = "not cool", + type = OptionType.DUAL_OPTION, size = 2 ) public static boolean switchTest2; @Option( - name = "Test checkbox", + name = "Test option", description = "Best description", subcategory = "Test", - type = OptionType.CHECKBOX + options = {"Hello", "World", "Fish", "Cat"}, + type = OptionType.UNI_SELECTOR ) - public static boolean switchTest3; + public static int switchTest3; @Option( name = "Test Page", @@ -65,10 +69,10 @@ public class TestConfig extends Config { public static boolean switchTest5; @Option( - name = "Test switch", + name = "Test check", description = "Best description", subcategory = "Other subcategory", - type = OptionType.SWITCH + type = OptionType.CHECKBOX ) public static boolean switchTest6; |