aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/polyfrost/oneconfig/gui
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
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')
-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
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java39
5 files changed, 82 insertions, 33 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) {
+ }
+ }
}
}
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 2b31421..4827ebe 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java
@@ -3,6 +3,7 @@ package io.polyfrost.oneconfig.gui.pages;
import io.polyfrost.oneconfig.config.OneConfigConfig;
import io.polyfrost.oneconfig.config.data.OptionPage;
import io.polyfrost.oneconfig.config.interfaces.BasicOption;
+import io.polyfrost.oneconfig.gui.elements.config.ConfigPageButton;
import io.polyfrost.oneconfig.lwjgl.RenderManager;
import io.polyfrost.oneconfig.lwjgl.font.Fonts;
@@ -20,13 +21,19 @@ public class ModConfigPage extends Page {
String selectedCategory = page.categories.keySet().stream().findFirst().get();
int optionX = x + 30;
int optionY = y + (page.categories.size() == 1 ? 16 : 64);
+
+ for (ConfigPageButton page : page.categories.get(selectedCategory).topPages) {
+ page.draw(vg, optionX, optionY);
+ optionY += page.getHeight() + 16;
+ }
+
int backgroundSize = 48;
- for (String subCategory : page.categories.get(selectedCategory).keySet()) {
+ for (String subCategory : page.categories.get(selectedCategory).subcategories.keySet()) {
backgroundSize += 32;
- for (int i = 0; i < page.categories.get(selectedCategory).get(subCategory).size(); i++) {
- BasicOption option = page.categories.get(selectedCategory).get(subCategory).get(i);
- if (i + 1 < page.categories.get(selectedCategory).get(subCategory).size()) {
- BasicOption nextOption = page.categories.get(selectedCategory).get(subCategory).get(i + 1);
+ for (int i = 0; i < page.categories.get(selectedCategory).subcategories.get(subCategory).size(); i++) {
+ BasicOption option = page.categories.get(selectedCategory).subcategories.get(subCategory).get(i);
+ if (i + 1 < page.categories.get(selectedCategory).subcategories.get(subCategory).size()) {
+ BasicOption nextOption = page.categories.get(selectedCategory).subcategories.get(subCategory).get(i + 1);
if (option.size == 1 && option.hasHalfSize() && nextOption.size == 1 && nextOption.hasHalfSize()) {
backgroundSize += Math.max(option.getHeight(), nextOption.getHeight()) + 16;
i++;
@@ -39,14 +46,14 @@ public class ModConfigPage extends Page {
RenderManager.drawRoundedRect(vg, x + 14, optionY, 1024, backgroundSize, OneConfigConfig.GRAY_900, 20);
optionY += 16;
- for (String subCategory : page.categories.get(selectedCategory).keySet()) {
+ for (String subCategory : page.categories.get(selectedCategory).subcategories.keySet()) {
RenderManager.drawString(vg, subCategory, optionX, optionY + 16, OneConfigConfig.WHITE_90, 24f, Fonts.INTER_MEDIUM);
optionY += 48;
- for (int i = 0; i < page.categories.get(selectedCategory).get(subCategory).size(); i++) {
- BasicOption option = page.categories.get(selectedCategory).get(subCategory).get(i);
+ for (int i = 0; i < page.categories.get(selectedCategory).subcategories.get(subCategory).size(); i++) {
+ BasicOption option = page.categories.get(selectedCategory).subcategories.get(subCategory).get(i);
option.draw(vg, optionX, optionY);
- if (i + 1 < page.categories.get(selectedCategory).get(subCategory).size()) {
- BasicOption nextOption = page.categories.get(selectedCategory).get(subCategory).get(i + 1);
+ if (i + 1 < page.categories.get(selectedCategory).subcategories.get(subCategory).size()) {
+ BasicOption nextOption = page.categories.get(selectedCategory).subcategories.get(subCategory).get(i + 1);
if (option.size == 1 && option.hasHalfSize() && nextOption.size == 1 && nextOption.hasHalfSize()) {
nextOption.draw(vg, optionX + 512, optionY);
optionY += Math.max(option.getHeight(), nextOption.getHeight()) + 16;
@@ -57,6 +64,12 @@ public class ModConfigPage extends Page {
optionY += option.getHeight() + 16;
}
}
+ optionY += 16;
+
+ for (ConfigPageButton page : page.categories.get(selectedCategory).bottomPages) {
+ page.draw(vg, optionX, optionY);
+ optionY += page.getHeight() + 16;
+ }
}
@Override
@@ -68,9 +81,9 @@ public class ModConfigPage extends Page {
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);
+ for (String subCategory : page.categories.get(selectedCategory).subcategories.keySet()) {
+ for (int i = 0; i < page.categories.get(selectedCategory).subcategories.get(subCategory).size(); i++) {
+ page.categories.get(selectedCategory).subcategories.get(subCategory).get(i).keyTyped(key, keyCode);
}
}
}