aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/polyfrost/oneconfig/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io/polyfrost/oneconfig/gui')
-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
5 files changed, 56 insertions, 17 deletions
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) {
+ }
}