aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-04-29 17:27:45 +0200
committerDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-04-29 17:27:45 +0200
commit86f6f3e8c3ae91ddbc29985f73e1d4f29f0a4b17 (patch)
tree36a7e8aafc3d29a844f611211b3d1f06ee48e7e8 /src/main/java/io
parent117d80ff0e343eecf260fd363db896166d8061d7 (diff)
downloadOneConfig-86f6f3e8c3ae91ddbc29985f73e1d4f29f0a4b17.tar.gz
OneConfig-86f6f3e8c3ae91ddbc29985f73e1d4f29f0a4b17.tar.bz2
OneConfig-86f6f3e8c3ae91ddbc29985f73e1d4f29f0a4b17.zip
text box config done
Diffstat (limited to 'src/main/java/io')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/annotations/Option.java5
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/data/OptionType.java4
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/interfaces/BasicOption.java14
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java2
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java1
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java19
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java33
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java17
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/pages/Page.java3
-rw-r--r--src/main/java/io/polyfrost/oneconfig/test/TestPage.java38
10 files changed, 97 insertions, 39 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 4cda7d5..d9bdbb7 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/annotations/Option.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/annotations/Option.java
@@ -42,11 +42,6 @@ public @interface Option {
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;
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 61bb516..ef0a730 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/data/OptionType.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/data/OptionType.java
@@ -15,6 +15,10 @@ public enum OptionType {
CHECKBOX,
DUAL_OPTION,
ARROW_SELECTOR,
+ /**
+ * Type: String
+ * Normal: 1x and 2x, Secure and Mutliline: 2x only
+ */
TEXT,
SLIDER,
COLOR,
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 5b6e2c0..7c9771c 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/interfaces/BasicOption.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/interfaces/BasicOption.java
@@ -55,22 +55,12 @@ public abstract class BasicOption {
public abstract void draw(long vg, int x, int y);
/**
- * Function that gets called when mouse is clicked
- *
- * @param mouseX x position of mouse
- * @param mouseY y position of mouse
- * @param mouseButton button that got pressed
- */
- protected void onMouseClicked(int mouseX, int mouseY, int mouseButton) {
- }
-
- /**
* Function that gets called when a key is typed
*
- * @param typedChar char that has been typed
+ * @param key char that has been typed
* @param keyCode code of key
*/
- protected void keyTyped(char typedChar, int keyCode) {
+ 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 37114cf..0cade35 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java
@@ -98,7 +98,7 @@ public class Config {
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()));
+ options.add(new ConfigTextBox(field, option.name(), option.size(), 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 22e8f71..f078bc3 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java
@@ -87,6 +87,7 @@ public class OneConfigGui extends GuiScreen {
try {
super.keyTyped(key, keyCode);
textInputField.keyTyped(key, keyCode);
+ currentPage.keyTyped(key, keyCode);
} catch (Exception e) {
System.out.println("this should literally never happen");
}
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 804fc62..5a4288b 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
@@ -16,31 +16,30 @@ import static org.lwjgl.nanovg.NanoVG.nvgScissor;
public class ConfigSwitch extends BasicOption {
private int color;
private float percentOn = 0f;
- private boolean toggled ;
public ConfigSwitch(Field field, String name, int size) {
- super(field, name, size);
- try {
- toggled = (boolean) get();
- } catch (IllegalAccessException e) {
- System.err.println("failed to get config value: class=" + this + " fieldWatching=" + field);
- }
+ super(field, name, size);
+
}
@Override
public void draw(long vg, int x, int y) {
+ boolean toggled = false;
+ try {
+ toggled = (boolean) get();
+ } catch (IllegalAccessException ignored) {
+ }
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) {
+ if (color == -15123643) {
color = OneConfigConfig.GRAY_400;
}
RenderManager.drawRoundedRect(vg, x + 16, y + 4, 42, 24, color, 12f);
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.isAreaClicked(x + 16, y, 42, 32))
- {
+ if (InputUtils.isAreaClicked(x + 16, y, 42, 32)) {
toggled = !toggled;
try {
set(toggled);
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
index e09ad77..8b96df1 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java
@@ -1,28 +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.gui.elements.TextInputField;
+import io.polyfrost.oneconfig.lwjgl.RenderManager;
+import io.polyfrost.oneconfig.lwjgl.font.Fonts;
+import org.lwjgl.nanovg.NanoVG;
import java.lang.reflect.Field;
public class ConfigTextBox extends BasicOption {
- private final String placeholder;
private final boolean secure;
private final boolean multiLine;
+ private final TextInputField textField;
- public ConfigTextBox(Field field, String name, int size, String placeholder, boolean secure, boolean multiLine) {
+ public ConfigTextBox(Field field, String name, int size, boolean secure, boolean multiLine) {
super(field, name, size);
- this.placeholder = placeholder;
this.secure = secure;
this.multiLine = multiLine;
+ String value = null;
+ try {
+ value = (String) get();
+ } catch (IllegalAccessException ignored) {
+ }
+ if (value == null) value = "";
+ this.textField = new TextInputField(size == 1 && hasHalfSize() ? 216 : 640, multiLine ? 64 : 32, value, multiLine, secure);
}
@Override
public void draw(long vg, int x, int y) {
+ NanoVG.nvgScissor(vg, x, y, size == 1 && !secure && !multiLine ? 216 : 344, 32);
+ RenderManager.drawString(vg, name, x, y + 16, OneConfigConfig.WHITE, 14, Fonts.INTER_MEDIUM);
+ NanoVG.nvgResetScissor(vg);
+ textField.draw(vg, x + (size == 1 && hasHalfSize() ? 224 : 352), y);
+ }
+
+ @Override
+ public void keyTyped(char key, int keyCode) {
+ textField.keyTyped(key, keyCode);
}
@Override
public int getHeight() {
- return 0;
+ return multiLine ? 64 : 32;
+ }
+
+ @Override
+ public boolean hasHalfSize() {
+ return !secure && !multiLine;
}
}
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 7a02d73..3bae729 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java
@@ -18,7 +18,7 @@ public class ModConfigPage extends Page {
public void draw(long vg, int x, int y) {
if (page.categories.size() == 0) return;
String selectedCategory = page.categories.keySet().stream().findFirst().get();
- int optionX = x + 16;
+ int optionX = x + 30;
int optionY = y + (page.categories.size() == 1 ? 32 : 72);
for (String subCategory : page.categories.get(selectedCategory).keySet()) {
RenderManager.drawString(vg, subCategory, x + 18, optionY, OneConfigConfig.WHITE, 24f, Fonts.INTER_MEDIUM);
@@ -46,7 +46,7 @@ public class ModConfigPage extends Page {
if (i + 1 < page.categories.get(selectedCategory).get(subCategory).size()) {
BasicOption nextOption = page.categories.get(selectedCategory).get(subCategory).get(i + 1);
if (option.size == 1 && option.hasHalfSize() && nextOption.size == 1 && nextOption.hasHalfSize()) {
- nextOption.draw(vg, optionX + 464, optionY);
+ nextOption.draw(vg, optionX + 528, optionY);
optionY += Math.max(option.getHeight(), nextOption.getHeight()) + 16;
i++;
continue;
@@ -60,6 +60,17 @@ public class ModConfigPage extends Page {
@Override
public void finishUpAndClose() {
- page.mod.config.save(); // TODO
+ page.mod.config.save();
+ }
+
+ @Override
+ public void keyTyped(char key, int keyCode) {
+ if (page.categories.size() == 0) return;
+ String selectedCategory = page.categories.keySet().stream().findFirst().get();
+ for (String subCategory : page.categories.get(selectedCategory).keySet()) {
+ for (int i = 0; i < page.categories.get(selectedCategory).get(subCategory).size(); i++) {
+ page.categories.get(selectedCategory).get(subCategory).get(i).keyTyped(key, keyCode);
+ }
+ }
}
}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/pages/Page.java b/src/main/java/io/polyfrost/oneconfig/gui/pages/Page.java
index 58c181f..b98bc01 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/pages/Page.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/pages/Page.java
@@ -24,4 +24,7 @@ public abstract class Page {
public String getTitle() {
return title;
}
+
+ public void keyTyped(char key, int keyCode) {
+ }
}
diff --git a/src/main/java/io/polyfrost/oneconfig/test/TestPage.java b/src/main/java/io/polyfrost/oneconfig/test/TestPage.java
index 93fe201..66deed8 100644
--- a/src/main/java/io/polyfrost/oneconfig/test/TestPage.java
+++ b/src/main/java/io/polyfrost/oneconfig/test/TestPage.java
@@ -5,10 +5,40 @@ import io.polyfrost.oneconfig.config.data.OptionType;
public class TestPage {
@Option(
- name = "Other test switch",
- description = "Best description",
+ name = "Text field 1x",
subcategory = "Test",
- type = OptionType.SWITCH
+ type = OptionType.TEXT
)
- public static boolean switchTest;
+ public static String testDescription;
+
+ @Option(
+ name = "Text field 1x",
+ subcategory = "Test",
+ type = OptionType.TEXT
+ )
+ public static String testDescription2;
+
+ @Option(
+ name = "Text field 2x",
+ subcategory = "Test",
+ type = OptionType.TEXT,
+ size = 2
+ )
+ public static String testDescription3;
+
+ @Option(
+ name = "Secure text field",
+ subcategory = "Test",
+ type = OptionType.TEXT,
+ secure = true
+ )
+ public static String testDescription4;
+
+ @Option(
+ name = "Text box",
+ subcategory = "Test",
+ type = OptionType.TEXT,
+ multiLine = true
+ )
+ public static String testDescription5;
}