aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/polyfrost/oneconfig/gui/elements
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-04-30 17:05:10 +0200
committerDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-04-30 17:05:10 +0200
commit0283a6618360ed473da42c1144da5b44146155bb (patch)
tree7002057b340df87e20989473a7f370aa89f5ad44 /src/main/java/io/polyfrost/oneconfig/gui/elements
parent026aebb4748747f08d5088947056a75740550b17 (diff)
downloadOneConfig-0283a6618360ed473da42c1144da5b44146155bb.tar.gz
OneConfig-0283a6618360ed473da42c1144da5b44146155bb.tar.bz2
OneConfig-0283a6618360ed473da42c1144da5b44146155bb.zip
more config system stuff
Diffstat (limited to 'src/main/java/io/polyfrost/oneconfig/gui/elements')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java12
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java (renamed from src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPage.java)10
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java23
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java31
4 files changed, 56 insertions, 20 deletions
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
index e9ed4bf..6832236 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java
@@ -14,7 +14,6 @@ import java.lang.reflect.Field;
public class ConfigCheckbox extends BasicOption {
private int color;
private float percentOn = 0f;
- private boolean toggled = false;
public ConfigCheckbox(Field field, String name, int size) {
super(field, name, size);
@@ -22,11 +21,22 @@ public class ConfigCheckbox extends BasicOption {
@Override
public void draw(long vg, int x, int y) {
+ boolean toggled = false;
+ try {
+ toggled = (boolean) get();
+ } catch (IllegalAccessException ignored) {
+ }
boolean hover = InputUtils.isAreaHovered(x, y, 24, 24);
boolean clicked = InputUtils.isClicked() && hover;
if(clicked) {
toggled = !toggled;
+ try {
+ set(toggled);
+ } catch (IllegalAccessException e) {
+ System.err.println("failed to write config value: class=" + this + " fieldWatching=" + field + " valueWrite=" + toggled);
+ e.printStackTrace();
+ }
}
if(percentOn != 1f) { // performance
RenderManager.drawRoundedRect(vg, x, y, 24, 24, color, 6f);
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPage.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java
index 569d799..607c877 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPage.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java
@@ -13,13 +13,13 @@ import org.lwjgl.nanovg.NanoVG;
import java.lang.reflect.Field;
-public class ConfigPage extends BasicOption {
+public class ConfigPageButton extends BasicOption {
public final OptionPage page;
public final String description;
private int backgroundColor = OneConfigConfig.GRAY_500;
- public ConfigPage(Field field, String name, String description, int size, OptionPage page) {
- super(field, name, size);
+ public ConfigPageButton(Field field, String name, String description, OptionPage page) {
+ super(field, name, 2);
this.description = description;
this.page = page;
}
@@ -34,9 +34,9 @@ public class ConfigPage extends BasicOption {
if (clicked) NanoVG.nvgGlobalAlpha(vg, 0.8f);
RenderManager.drawRoundedRect(vg, x - 16, y, 1024, height, backgroundColor, 20);
- RenderManager.drawString(vg, name, x + 10, y + 32, OneConfigConfig.WHITE, 24, Fonts.INTER_MEDIUM);
+ RenderManager.drawString(vg, name, x + 10, y + 32, OneConfigConfig.WHITE_90, 24, Fonts.INTER_MEDIUM);
if (!description.equals(""))
- RenderManager.drawString(vg, name, x + 10, y + 70, OneConfigConfig.WHITE, 14, Fonts.INTER_MEDIUM);
+ RenderManager.drawString(vg, name, x + 10, y + 70, OneConfigConfig.WHITE_90, 14, Fonts.INTER_MEDIUM);
RenderManager.drawImage(vg, "/assets/oneconfig/textures/arrow.png", x + 981f, y + (description.equals("") ? 20f : 36f), 13, 22);
if (clicked) OneConfigGui.INSTANCE.openPage(new ModConfigPage(page));
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 8d6179c..b3f689c 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
@@ -6,8 +6,8 @@ import io.polyfrost.oneconfig.gui.elements.TextInputField;
import io.polyfrost.oneconfig.lwjgl.RenderManager;
import io.polyfrost.oneconfig.lwjgl.font.Fonts;
import io.polyfrost.oneconfig.utils.InputUtils;
-import org.lwjgl.nanovg.NanoVG;
+import java.awt.*;
import java.lang.reflect.Field;
public class ConfigTextBox extends BasicOption {
@@ -15,26 +15,27 @@ public class ConfigTextBox extends BasicOption {
private final boolean multiLine;
private final TextInputField textField;
- public ConfigTextBox(Field field, String name, int size, boolean secure, boolean multiLine) {
+ public ConfigTextBox(Field field, String name, int size, String placeholder, boolean secure, boolean multiLine) {
super(field, name, size);
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);
+ this.textField = new TextInputField(size == 1 && hasHalfSize() ? 256 : 640, multiLine ? 64 : 32, placeholder, multiLine, secure);
}
@Override
public void draw(long vg, int x, int y) {
- RenderManager.drawString(vg, name, x, y + 16, OneConfigConfig.WHITE, 14, Fonts.INTER_MEDIUM);
+ RenderManager.drawString(vg, name, x, y + 16, OneConfigConfig.WHITE_90, 14, Fonts.INTER_MEDIUM);
+
+ try {
+ String value = (String) get();
+ textField.setInput(value == null ? "" : value);
+ } catch (IllegalAccessException ignored) {
+ }
+
textField.draw(vg, x + (size == 1 && hasHalfSize() ? 224 : 352), y);
- if (secure) RenderManager.drawImage(vg, "/assets/oneconfig/textures/eye.png", x + 967, y + 7, 18, 18);
+ if (secure) RenderManager.drawImage(vg, "/assets/oneconfig/textures/eye.png", x + 967, y + 7, 18, 18, new Color(196,196,196).getRGB());
if (secure && InputUtils.isAreaClicked(x + 967, y + 7, 18, 18)) textField.setPassword(!textField.getPassword());
}
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
index 39f8cf9..b20e8bc 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java
@@ -4,6 +4,8 @@ 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 org.lwjgl.nanovg.NanoVG;
import java.lang.reflect.Field;
@@ -17,7 +19,7 @@ public class ConfigUniSelector extends BasicOption {
@Override
public int getHeight() {
- return 0;
+ return 32;
}
@Override
@@ -27,8 +29,31 @@ public class ConfigUniSelector extends BasicOption {
selected = (int) get();
} catch (IllegalAccessException ignored) {
}
+ String option = options[selected] + " " + (selected + 1) + "/" + options.length;
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
+ RenderManager.drawString(vg, option, x + 352 - RenderManager.getTextWidth(vg, option, 14f, Fonts.INTER_MEDIUM) / 2f, y + 15, OneConfigConfig.WHITE_90, 14f, Fonts.INTER_MEDIUM);
+
+ // actual coordinates: 240, 7
+ NanoVG.nvgTranslate(vg, x + 248, y + 21);
+ NanoVG.nvgRotate(vg, (float) Math.toRadians(180));
+ RenderManager.drawImage(vg, "/assets/oneconfig/textures/arrow.png", 0, 0, 8, 14, OneConfigConfig.BLUE_400);
+ NanoVG.nvgResetTransform(vg);
+ RenderManager.drawImage(vg, "/assets/oneconfig/textures/arrow.png", x + 456, y + 7, 8, 14, OneConfigConfig.BLUE_400);
+
+ if (InputUtils.isAreaClicked(x + 240, y + 7, 8, 14)) {
+ if (selected > 0) selected -= 1;
+ else selected = options.length - 1;
+ try {
+ set(selected);
+ } catch (IllegalAccessException ignored) {
+ }
+ } else if (InputUtils.isAreaClicked(x + 456, y + 7, 8, 14)) {
+ if (selected < options.length - 1) selected += 1;
+ else selected = 0;
+ try {
+ set(selected);
+ } catch (IllegalAccessException ignored) {
+ }
+ }
}
}