aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/Config.java90
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/core/ConfigCore.java42
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java18
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/test/TestHud.java24
4 files changed, 107 insertions, 67 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/Config.java
index d0d8acf..65d6b00 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/Config.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/Config.java
@@ -137,67 +137,35 @@ public class Config {
}
}
ArrayList<BasicOption> options = category.subcategories.get(category.subcategories.size() - 1).options;
- switch (option.type()) {
- case SWITCH:
- options.add(new ConfigSwitch(field, instance, option.name(), option.size()));
- break;
- case CHECKBOX:
- options.add(new ConfigCheckbox(field, instance, option.name(), option.size()));
- break;
- case TEXT:
- options.add(new ConfigTextBox(field, instance, option.name(), option.size(), option.placeholder(), option.secure(), option.multiLine()));
- break;
- case DUAL_OPTION:
- options.add(new ConfigDualOption(field, instance, option.name(), option.size(), option.options()));
- break;
- case DROPDOWN:
- options.add(new ConfigDropdown(field, instance, option.name(), option.size(), option.options()));
- break;
- case SLIDER:
- options.add(new ConfigSlider(field, instance, option.name(), option.size(), option.min(), option.max(), option.step()));
- break;
- case INFO:
- options.add(new ConfigInfo(field, instance, option.name(), option.size(), option.infoType()));
- break;
- case COLOR:
- options.add(new ConfigColorElement(field, instance, option.name(), option.size()));
- break;
- case HEADER:
- options.add(new ConfigHeader(field, instance, option.name(), option.size()));
- break;
- case BUTTON:
- options.add(new ConfigButton(field, instance, option.name(), option.size(), option.buttonText()));
- break;
- case KEYBIND:
- options.add(new ConfigKeyBind(field, instance, option.name(), option.size()));
- break;
- case HUD:
- try {
- field.setAccessible(true);
- BasicHud hud = (BasicHud) field.get(instance);
- HudCore.huds.add(hud);
- options.add(new ConfigHeader(field, hud, option.name(), 1));
- options.add(new ConfigSwitch(hud.getClass().getField("enabled"), hud, "Enabled", 1));
- options.add(new ConfigCheckbox(hud.getClass().getField("rounded"), hud, "Rounded corners", 1));
- options.get(options.size() - 1).setDependency(() -> hud.enabled);
- options.add(new ConfigCheckbox(hud.getClass().getField("border"), hud, "Outline/border", 1));
- options.get(options.size() - 1).setDependency(() -> hud.enabled);
- options.add(new ConfigColorElement(hud.getClass().getField("bgColor"), hud, "Background color:", 1));
- options.get(options.size() - 1).setDependency(() -> hud.enabled);
- options.add(new ConfigColorElement(hud.getClass().getField("borderColor"), hud, "Border color:", 1));
- options.get(options.size() - 1).setDependency(() -> hud.enabled && hud.border);
- options.add(new ConfigSlider(hud.getClass().getField("cornerRadius"), hud, "Corner radius:", 2, 0, 10, 0));
- options.get(options.size() - 1).setDependency(() -> hud.enabled && hud.rounded);
- options.add(new ConfigSlider(hud.getClass().getField("borderSize"), hud, "Border thickness:", 2, 0, 10, 0));
- options.get(options.size() - 1).setDependency(() -> hud.enabled && hud.border);
- options.add(new ConfigSlider(hud.getClass().getField("paddingX"), hud, "X-Padding", 2, 0, 50, 0));
- options.get(options.size() - 1).setDependency(() -> hud.enabled);
- options.add(new ConfigSlider(hud.getClass().getField("paddingY"), hud, "Y-Padding", 2, 0, 50, 0));
- options.get(options.size() - 1).setDependency(() -> hud.enabled);
- } catch (IllegalAccessException | NoSuchFieldException e) {
- e.printStackTrace();
- }
- break;
+ if (option.type() == OptionType.HUD) {
+ try {
+ field.setAccessible(true);
+ BasicHud hud = (BasicHud) field.get(instance);
+ HudCore.huds.add(hud);
+ options.add(new ConfigHeader(field, hud, option.name(), 1));
+ options.add(new ConfigSwitch(hud.getClass().getField("enabled"), hud, "Enabled", 1));
+ options.addAll(ConfigCore.getClassOptions(hud));
+ options.add(new ConfigCheckbox(hud.getClass().getField("rounded"), hud, "Rounded corners", 1));
+ options.get(options.size() - 1).setDependency(() -> hud.enabled);
+ options.add(new ConfigCheckbox(hud.getClass().getField("border"), hud, "Outline/border", 1));
+ options.get(options.size() - 1).setDependency(() -> hud.enabled);
+ options.add(new ConfigColorElement(hud.getClass().getField("bgColor"), hud, "Background color:", 1));
+ options.get(options.size() - 1).setDependency(() -> hud.enabled);
+ options.add(new ConfigColorElement(hud.getClass().getField("borderColor"), hud, "Border color:", 1));
+ options.get(options.size() - 1).setDependency(() -> hud.enabled && hud.border);
+ options.add(new ConfigSlider(hud.getClass().getField("cornerRadius"), hud, "Corner radius:", 2, 0, 10, 0));
+ options.get(options.size() - 1).setDependency(() -> hud.enabled && hud.rounded);
+ options.add(new ConfigSlider(hud.getClass().getField("borderSize"), hud, "Border thickness:", 2, 0, 10, 0));
+ options.get(options.size() - 1).setDependency(() -> hud.enabled && hud.border);
+ options.add(new ConfigSlider(hud.getClass().getField("paddingX"), hud, "X-Padding", 2, 0, 50, 0));
+ options.get(options.size() - 1).setDependency(() -> hud.enabled);
+ options.add(new ConfigSlider(hud.getClass().getField("paddingY"), hud, "Y-Padding", 2, 0, 50, 0));
+ options.get(options.size() - 1).setDependency(() -> hud.enabled);
+ } catch (IllegalAccessException | NoSuchFieldException e) {
+ e.printStackTrace();
+ }
+ } else {
+ options.add(ConfigCore.getOption(option, field, instance));
}
if (!option.type().equals(OptionType.HUD))
optionNames.put(pagePrefix + field.getName(), options.get(options.size() - 1));
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigCore.java b/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigCore.java
index a000f7c..f1aa1ab 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigCore.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigCore.java
@@ -1,8 +1,12 @@
package cc.polyfrost.oneconfig.config.core;
+import cc.polyfrost.oneconfig.config.annotations.Option;
import cc.polyfrost.oneconfig.config.data.Mod;
+import cc.polyfrost.oneconfig.config.elements.BasicOption;
+import cc.polyfrost.oneconfig.gui.elements.config.*;
import cc.polyfrost.oneconfig.hud.HudCore;
+import java.lang.reflect.Field;
import java.util.ArrayList;
public class ConfigCore {
@@ -22,4 +26,42 @@ public class ConfigCore {
modData.config.init(modData);
}
}
+
+ public static BasicOption getOption(Option option, Field field, Object instance) {
+ switch (option.type()) {
+ case SWITCH:
+ return new ConfigSwitch(field, instance, option.name(), option.size());
+ case CHECKBOX:
+ return new ConfigCheckbox(field, instance, option.name(), option.size());
+ case TEXT:
+ return new ConfigTextBox(field, instance, option.name(), option.size(), option.placeholder(), option.secure(), option.multiLine());
+ case DUAL_OPTION:
+ return new ConfigDualOption(field, instance, option.name(), option.size(), option.options());
+ case DROPDOWN:
+ return new ConfigDropdown(field, instance, option.name(), option.size(), option.options());
+ case SLIDER:
+ return new ConfigSlider(field, instance, option.name(), option.size(), option.min(), option.max(), option.step());
+ case INFO:
+ return new ConfigInfo(field, instance, option.name(), option.size(), option.infoType());
+ case COLOR:
+ return new ConfigColorElement(field, instance, option.name(), option.size());
+ case HEADER:
+ return new ConfigHeader(field, instance, option.name(), option.size());
+ case BUTTON:
+ return new ConfigButton(field, instance, option.name(), option.size(), option.buttonText());
+ case KEYBIND:
+ return new ConfigKeyBind(field, instance, option.name(), option.size());
+ }
+ return null;
+ }
+
+ public static ArrayList<BasicOption> getClassOptions(Object hud) {
+ ArrayList<BasicOption> options = new ArrayList<>();
+ for (Field field : hud.getClass().getDeclaredFields()) {
+ if (!field.isAnnotationPresent(Option.class)) continue;
+ Option option = field.getAnnotation(Option.class);
+ options.add(getOption(option, field, hud));
+ }
+ return options;
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java
index f868660..99df46b 100644
--- a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java
@@ -3,25 +3,35 @@ package cc.polyfrost.oneconfig.hud;
import cc.polyfrost.oneconfig.renderer.RenderManager;
import gg.essential.universal.UMinecraft;
+import java.util.List;
+
public abstract class TextHud extends BasicHud {
+ private transient int width = 100;
+ private transient int height;
public TextHud(boolean enabled, int x, int y) {
super(enabled, x, y);
}
@Override
public int getWidth(float scale) {
- return (int) (UMinecraft.getFontRenderer().getStringWidth(getText()) * scale);
+ return (int) (width * scale);
}
@Override
public int getHeight(float scale) {
- return (int) (9 * scale);
+ return (int) (height * scale);
}
@Override
public void draw(int x, int y, float scale) {
- RenderManager.drawScaledString(getText(), x, y, 0xffffff, false, scale);
+ int textY = y;
+ for (String line : getLines()) {
+ RenderManager.drawScaledString(line, x, textY, 0xffffff, false, scale);
+ width = Math.max(width, UMinecraft.getFontRenderer().getStringWidth(line));
+ textY += 12 * scale;
+ }
+ height = (int) ((textY - y) / scale);
}
- public abstract String getText();
+ public abstract List<String> getLines();
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestHud.java b/src/main/java/cc/polyfrost/oneconfig/test/TestHud.java
index d11340c..930d827 100644
--- a/src/main/java/cc/polyfrost/oneconfig/test/TestHud.java
+++ b/src/main/java/cc/polyfrost/oneconfig/test/TestHud.java
@@ -1,15 +1,35 @@
package cc.polyfrost.oneconfig.test;
+import cc.polyfrost.oneconfig.config.annotations.Option;
+import cc.polyfrost.oneconfig.config.data.OptionType;
import cc.polyfrost.oneconfig.hud.TextHud;
import net.minecraft.client.Minecraft;
+import java.util.ArrayList;
+import java.util.List;
+
public class TestHud extends TextHud {
public TestHud(boolean enabled, int x, int y) {
super(enabled, x, y);
}
@Override
- public String getText() {
- return "FPS: " + Minecraft.getDebugFPS();
+ public List<String> getLines() {
+ ArrayList<String> lines = new ArrayList<>();
+ lines.add("FPS: " + Minecraft.getDebugFPS());
+ if (hasSecondLine) lines.add(secondLine);
+ return lines;
}
+
+ @Option(
+ name = "Enable Second Line",
+ type = OptionType.SWITCH
+ )
+ public boolean hasSecondLine = false;
+
+ @Option(
+ name = "Second Line Text",
+ type = OptionType.TEXT
+ )
+ public String secondLine = "Epic text";
}