aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/Config.java26
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java16
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/elements/OptionCategory.java8
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/elements/OptionPage.java7
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java7
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/migration/VigilanceMigrator.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/profiles/Profiles.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java14
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java12
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java8
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java8
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java1
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java20
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/Hud.java12
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilanceConfig.java (renamed from src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig.java)2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilanceName.java (renamed from src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceName.java)2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilantAccessor.java (renamed from src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilantAccessor.java)2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java1
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java4
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java48
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/renderer/TextRenderer.java217
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/renderer/font/FontManager.java12
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/renderer/font/Fonts.java19
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java14
25 files changed, 339 insertions, 127 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/Config.java
index 9557728..8a5608e 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/Config.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/Config.java
@@ -38,6 +38,7 @@ public class Config {
transient protected final String configFile;
transient protected final Gson gson = new GsonBuilder().setExclusionStrategies(new ProfileExclusionStrategy()).excludeFieldsWithModifiers(Modifier.TRANSIENT).setPrettyPrinting().create();
transient protected final Gson nonProfileSpecificGson = new GsonBuilder().setExclusionStrategies(new NonProfileSpecificExclusionStrategy()).excludeFieldsWithModifiers(Modifier.TRANSIENT).setPrettyPrinting().create();
+ transient protected final HashMap<Field, Object> defaults = new HashMap<>();
transient public Mod mod;
public transient boolean hasBeenInitialized = false;
public boolean enabled;
@@ -45,7 +46,7 @@ public class Config {
/**
* @param modData information about the mod
* @param configFile file where config is stored
- * @param enabled whether the mod is enabled or not
+ * @param enabled whether the mod is enabled or not
*/
public Config(Mod modData, String configFile, boolean enabled) {
this.configFile = configFile;
@@ -138,7 +139,7 @@ public class Config {
if (optionPage.location() == PageLocation.TOP) subcategory.topButtons.add(button);
else subcategory.bottomButtons.add(button);
} else if (field.isAnnotationPresent(HUD.class)) {
- HUDUtils.addHudOptions(page, field, instance);
+ HUDUtils.addHudOptions(page, field, instance, this);
}
}
}
@@ -306,18 +307,19 @@ public class Config {
}
/**
+ * @param field The field to get the default value from
+ * @return The default value of the given field
+ */
+ public Object getDefault(Field field) {
+ return defaults.get(field);
+ }
+
+ /**
* Reset this config file to its defaults.
- * @return true if successful, false if not.
- * @deprecated <b>not implemented yet.</b>
*/
- @Deprecated
- public boolean reset() {
- try {
- // TODO
- } catch (Exception e) {
- e.printStackTrace();
- return false;
+ public void reset() {
+ for (BasicOption option : optionNames.values()) {
+ option.reset(this);
}
- return true;
}
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java b/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java
index 86b339b..6f9b47a 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java
@@ -1,5 +1,7 @@
package cc.polyfrost.oneconfig.config.elements;
+import cc.polyfrost.oneconfig.config.Config;
+
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.function.Supplier;
@@ -86,6 +88,20 @@ public abstract class BasicOption {
}
/**
+ * Reset the field to its default value
+ *
+ * @param config The config the field is in
+ */
+ public void reset(Config config) {
+ Object object = config.getDefault(field);
+ if (object == null) return;
+ try {
+ set(object);
+ } catch (IllegalAccessException ignored) {
+ }
+ }
+
+ /**
* @return If the option is enabled, based on the dependencies
*/
public boolean isEnabled() {
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionCategory.java b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionCategory.java
index 4a37bfc..f144f60 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionCategory.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionCategory.java
@@ -1,7 +1,15 @@
package cc.polyfrost.oneconfig.config.elements;
+import cc.polyfrost.oneconfig.config.Config;
+
import java.util.ArrayList;
public class OptionCategory {
public final ArrayList<OptionSubcategory> subcategories = new ArrayList<>();
+
+ public void reset(Config config) {
+ for (OptionSubcategory subcategory : subcategories) {
+ subcategory.reset(config);
+ }
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionPage.java b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionPage.java
index 5eaac8b..916e1d9 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionPage.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionPage.java
@@ -1,5 +1,6 @@
package cc.polyfrost.oneconfig.config.elements;
+import cc.polyfrost.oneconfig.config.Config;
import cc.polyfrost.oneconfig.config.data.Mod;
import java.util.LinkedHashMap;
@@ -13,4 +14,10 @@ public class OptionPage {
this.name = name;
this.mod = mod;
}
+
+ public void reset(Config config) {
+ for (OptionCategory subcategory : categories.values()) {
+ subcategory.reset(config);
+ }
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java
index 365ddb6..e1342d4 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java
@@ -1,5 +1,6 @@
package cc.polyfrost.oneconfig.config.elements;
+import cc.polyfrost.oneconfig.config.Config;
import cc.polyfrost.oneconfig.internal.assets.Colors;
import cc.polyfrost.oneconfig.gui.OneConfigGui;
import cc.polyfrost.oneconfig.gui.elements.config.ConfigPageButton;
@@ -104,4 +105,10 @@ public class OptionSubcategory {
public String getName() {
return name;
}
+
+ public void reset(Config config) {
+ for (BasicOption option : options) {
+ options.remove(config);
+ }
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/migration/VigilanceMigrator.java b/src/main/java/cc/polyfrost/oneconfig/config/migration/VigilanceMigrator.java
index f09d648..aed1919 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/migration/VigilanceMigrator.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/migration/VigilanceMigrator.java
@@ -1,6 +1,6 @@
package cc.polyfrost.oneconfig.config.migration;
-import cc.polyfrost.oneconfig.config.compatibility.vigilance.VigilanceName;
+import cc.polyfrost.oneconfig.internal.config.compatibility.vigilance.VigilanceName;
import java.io.BufferedReader;
import java.io.File;
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/profiles/Profiles.java b/src/main/java/cc/polyfrost/oneconfig/config/profiles/Profiles.java
index 29a9daa..686fb69 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/profiles/Profiles.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/profiles/Profiles.java
@@ -60,7 +60,7 @@ public class Profiles {
public static void loadProfile(String profile) {
ConfigCore.saveAll();
OneConfigConfig.currentProfile = profile;
- //OneConfig.config.save(); todo do we actually need this
+ OneConfigConfig.getInstance().save();
ConfigCore.reInitAll();
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java
index f5b1d3f..fc90c01 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java
@@ -1,13 +1,13 @@
package cc.polyfrost.oneconfig.gui;
-import cc.polyfrost.oneconfig.internal.config.core.ConfigCore;
import cc.polyfrost.oneconfig.hud.Hud;
+import cc.polyfrost.oneconfig.internal.config.core.ConfigCore;
import cc.polyfrost.oneconfig.internal.hud.HudCore;
-import cc.polyfrost.oneconfig.libs.universal.UResolution;
-import cc.polyfrost.oneconfig.renderer.RenderManager;
import cc.polyfrost.oneconfig.libs.universal.UKeyboard;
import cc.polyfrost.oneconfig.libs.universal.UMatrixStack;
+import cc.polyfrost.oneconfig.libs.universal.UResolution;
import cc.polyfrost.oneconfig.libs.universal.UScreen;
+import cc.polyfrost.oneconfig.renderer.RenderManager;
import cc.polyfrost.oneconfig.utils.gui.GuiUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -44,7 +44,7 @@ public class HudGui extends UScreen implements GuiPause {
}
for (Hud hud : HudCore.huds) {
- if (hud.enabled) processHud(matrixStack, hud, mouseX);
+ if (hud.isEnabled()) processHud(matrixStack, hud, mouseX);
}
}
@@ -128,7 +128,7 @@ public class HudGui extends UScreen implements GuiPause {
float width = editingHud.getWidth(editingHud.scale) + editingHud.paddingX * editingHud.scale;
ArrayList<Float> verticalLines = new ArrayList<>();
for (Hud hud : HudCore.huds) {
- if (!hud.enabled) continue;
+ if (!hud.isEnabled()) continue;
verticalLines.addAll(getXSnappingHud(hud));
}
getSpaceSnapping(verticalLines);
@@ -167,7 +167,7 @@ public class HudGui extends UScreen implements GuiPause {
float height = editingHud.getHeight(editingHud.scale) + editingHud.paddingY * editingHud.scale;
ArrayList<Float> horizontalLines = new ArrayList<>();
for (Hud hud : HudCore.huds) {
- if (!hud.enabled) continue;
+ if (!hud.isEnabled()) continue;
horizontalLines.addAll(getYSnappingHud(hud));
}
getSpaceSnapping(horizontalLines);
@@ -229,7 +229,7 @@ public class HudGui extends UScreen implements GuiPause {
}
editingHud = null;
for (Hud hud : HudCore.huds) {
- if (!hud.enabled) continue;
+ if (!hud.isEnabled()) continue;
if (mouseClickedHud(hud, (int) mouseX, (int) mouseY))
break;
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
index 1095ae0..41d0b4f 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
@@ -109,7 +109,8 @@ public class OneConfigGui extends UScreen implements GuiPause {
RenderManager.setAlpha(vg, 0.5f);
} else {
backArrow.disable(false);
- if (!backArrow.isHovered() || Platform.getMousePlatform().isButtonDown(0)) RenderManager.setAlpha(vg, 0.8f);
+ if (!backArrow.isHovered() || Platform.getMousePlatform().isButtonDown(0))
+ RenderManager.setAlpha(vg, 0.8f);
}
RenderManager.drawSvg(vg, SVGs.CARET_LEFT, x + 246, y + 22, 28, 28);
RenderManager.setAlpha(vg, 1f);
@@ -118,7 +119,8 @@ public class OneConfigGui extends UScreen implements GuiPause {
RenderManager.setAlpha(vg, 0.5f);
} else {
forwardArrow.disable(false);
- if (!forwardArrow.isHovered() || Platform.getMousePlatform().isButtonDown(0)) RenderManager.setAlpha(vg, 0.8f);
+ if (!forwardArrow.isHovered() || Platform.getMousePlatform().isButtonDown(0))
+ RenderManager.setAlpha(vg, 0.8f);
}
RenderManager.drawSvg(vg, SVGs.CARET_RIGHT, x + 294, y + 22, 28, 28);
RenderManager.setAlpha(vg, 1f);
@@ -140,7 +142,7 @@ public class OneConfigGui extends UScreen implements GuiPause {
}
ScissorManager.scissor(vg, x + 224, y + 72, 1056, 728);
- Scissor blockedClicks = InputUtils.blockInputArea(x + 224, y, 1056,72);
+ Scissor blockedClicks = InputUtils.blockInputArea(x + 224, y, 1056, 72);
if (prevPage != null && animation != null) {
float pageProgress = animation.get(GuiUtils.getDeltaTime());
if (!animation.isReversed()) {
@@ -188,9 +190,7 @@ public class OneConfigGui extends UScreen implements GuiPause {
public void onKeyPressed(int keyCode, char typedChar, @Nullable UKeyboard.Modifiers modifiers) {
UKeyboard.allowRepeatEvents(true);
try {
- if (keyCode == 1 && currentPage.parents.size() > 1) {
- openPage(currentPage.parents.get(currentPage.parents.size() - 2));
- } else if (allowClose) super.onKeyPressed(keyCode, typedChar, modifiers);
+ if (allowClose) super.onKeyPressed(keyCode, typedChar, modifiers);
textInputField.keyTyped(typedChar, keyCode);
if (currentColorSelector != null) currentColorSelector.keyTyped(typedChar, keyCode);
currentPage.keyTyped(typedChar, keyCode);
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java
index ddcf6eb..fa48592 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java
@@ -1,13 +1,13 @@
package cc.polyfrost.oneconfig.gui.elements.config;
import cc.polyfrost.oneconfig.config.annotations.Dropdown;
-import cc.polyfrost.oneconfig.internal.assets.Colors;
import cc.polyfrost.oneconfig.config.elements.BasicOption;
import cc.polyfrost.oneconfig.gui.animations.ColorAnimation;
+import cc.polyfrost.oneconfig.internal.assets.Colors;
+import cc.polyfrost.oneconfig.internal.assets.SVGs;
import cc.polyfrost.oneconfig.platform.Platform;
import cc.polyfrost.oneconfig.renderer.RenderManager;
import cc.polyfrost.oneconfig.renderer.font.Fonts;
-import cc.polyfrost.oneconfig.internal.assets.SVGs;
import cc.polyfrost.oneconfig.renderer.scissor.Scissor;
import cc.polyfrost.oneconfig.utils.InputUtils;
import cc.polyfrost.oneconfig.utils.color.ColorPalette;
@@ -43,8 +43,8 @@ public class ConfigDropdown extends BasicOption {
else hovered = InputUtils.isAreaHovered(x + 352, y, 640, 32) && isEnabled();
if (hovered && InputUtils.isClicked() || opened && InputUtils.isClicked(true) &&
- (size == 1 && !InputUtils.isAreaHovered(x + 224, y + 40, 256, options.length * 32) ||
- size == 2 && !InputUtils.isAreaHovered(x + 352, y + 40, 640, options.length * 32))) {
+ (size == 1 && !InputUtils.isAreaHovered(x + 224, y + 40, 256, options.length * 32, true) ||
+ size == 2 && !InputUtils.isAreaHovered(x + 352, y + 40, 640, options.length * 32, true))) {
opened = !opened;
backgroundColor.setPalette(opened ? ColorPalette.PRIMARY : ColorPalette.SECONDARY);
if (opened) inputScissor = InputUtils.blockAllInput();
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java
index 552051f..054915c 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java
@@ -129,18 +129,18 @@ public class TextInputField extends BasicElement {
float width;
StringBuilder s = new StringBuilder();
if (multiLine) {
- wrappedText = TextUtils.wrapText(vg, input, this.width - 24, 14f, Fonts.REGULAR.font);
+ wrappedText = TextUtils.wrapText(vg, input, this.width - 24, 14f, Fonts.REGULAR);
lines = wrappedText.size();
if (!toggled) caretPos = wrappedText.get(wrappedText.size() - 1).length();
int caretLine = (int) MathUtils.clamp(getCaretLine(caretPos), 0, wrappedText.size() - 1);
- width = RenderManager.getTextWidth(vg, wrappedText.get(caretLine).substring(0, getLineCaret(caretPos, caretLine)), 14f, Fonts.REGULAR.font);
+ width = RenderManager.getTextWidth(vg, wrappedText.get(caretLine).substring(0, getLineCaret(caretPos, caretLine)), 14f, Fonts.REGULAR);
} else if (!password) {
- width = RenderManager.getTextWidth(vg, input.substring(0, caretPos), 14f, Fonts.REGULAR.font);
+ width = RenderManager.getTextWidth(vg, input.substring(0, caretPos), 14f, Fonts.REGULAR);
} else {
for (int i = 0; i < input.length(); i++) {
s.append("*");
}
- width = RenderManager.getTextWidth(vg, s.substring(0, caretPos), 14f, Fonts.REGULAR.font);
+ width = RenderManager.getTextWidth(vg, s.substring(0, caretPos), 14f, Fonts.REGULAR);
}
if (hovered) {
int state = Platform.getMousePlatform().getButtonState(0); //todo does this work
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java
index 5f454f2..8a2e226 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java
@@ -9,6 +9,7 @@ import cc.polyfrost.oneconfig.internal.assets.Colors;
import cc.polyfrost.oneconfig.internal.config.OneConfigConfig;
import cc.polyfrost.oneconfig.internal.config.core.ConfigCore;
import cc.polyfrost.oneconfig.renderer.RenderManager;
+import cc.polyfrost.oneconfig.renderer.TextRenderer;
import cc.polyfrost.oneconfig.renderer.font.Fonts;
import cc.polyfrost.oneconfig.utils.color.ColorPalette;
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java b/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java
index e91a7ce..a67177c 100644
--- a/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java
@@ -1,5 +1,6 @@
package cc.polyfrost.oneconfig.hud;
+import cc.polyfrost.oneconfig.config.Config;
import cc.polyfrost.oneconfig.config.annotations.HUD;
import cc.polyfrost.oneconfig.config.core.ConfigUtils;
import cc.polyfrost.oneconfig.config.elements.BasicOption;
@@ -11,10 +12,11 @@ import java.lang.reflect.Field;
import java.util.ArrayList;
public class HUDUtils {
- public static void addHudOptions(OptionPage page, Field field, Object instance) {
+ public static void addHudOptions(OptionPage page, Field field, Object instance, Config config) {
HUD hudAnnotation = field.getAnnotation(HUD.class);
Hud hud = (Hud) ConfigUtils.getField(field, instance);
if (hud == null) return;
+ hud.setConfig(config);
HudCore.huds.add(hud);
String category = hudAnnotation.category();
String subcategory = hudAnnotation.subcategory();
@@ -24,21 +26,21 @@ public class HUDUtils {
options.add(new ConfigSwitch(hud.getClass().getField("enabled"), hud, "Enabled", category, subcategory, 2));
options.addAll(ConfigUtils.getClassOptions(hud));
options.add(new ConfigCheckbox(hud.getClass().getField("rounded"), hud, "Rounded corners", category, subcategory, 1));
- options.get(options.size() - 1).addDependency(() -> hud.enabled);
+ options.get(options.size() - 1).addDependency(hud::isEnabled);
options.add(new ConfigCheckbox(hud.getClass().getField("border"), hud, "Outline/border", category, subcategory, 1));
- options.get(options.size() - 1).addDependency(() -> hud.enabled);
+ options.get(options.size() - 1).addDependency(hud::isEnabled);
options.add(new ConfigColorElement(hud.getClass().getField("bgColor"), hud, "Background color:", category, subcategory, 1, true));
- options.get(options.size() - 1).addDependency(() -> hud.enabled);
+ options.get(options.size() - 1).addDependency(hud::isEnabled);
options.add(new ConfigColorElement(hud.getClass().getField("borderColor"), hud, "Border color:", category, subcategory, 1, true));
- options.get(options.size() - 1).addDependency(() -> hud.enabled && hud.border);
+ options.get(options.size() - 1).addDependency(() -> hud.isEnabled() && hud.border);
options.add(new ConfigSlider(hud.getClass().getField("cornerRadius"), hud, "Corner radius:", category, subcategory, 0, 10, 0));
- options.get(options.size() - 1).addDependency(() -> hud.enabled && hud.rounded);
+ options.get(options.size() - 1).addDependency(() -> hud.isEnabled() && hud.rounded);
options.add(new ConfigSlider(hud.getClass().getField("borderSize"), hud, "Border thickness:", category, subcategory, 0, 10, 0));
- options.get(options.size() - 1).addDependency(() -> hud.enabled && hud.border);
+ options.get(options.size() - 1).addDependency(() -> hud.isEnabled() && hud.border);
options.add(new ConfigSlider(hud.getClass().getField("paddingX"), hud, "X-Padding", category, subcategory, 0, 50, 0));
- options.get(options.size() - 1).addDependency(() -> hud.enabled);
+ options.get(options.size() - 1).addDependency(hud::isEnabled);
options.add(new ConfigSlider(hud.getClass().getField("paddingY"), hud, "Y-Padding", category, subcategory, 0, 50, 0));
- options.get(options.size() - 1).addDependency(() -> hud.enabled);
+ options.get(options.size() - 1).addDependency(hud::isEnabled);
} catch (NoSuchFieldException ignored) {
}
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java b/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java
index 982bee9..05a4f76 100644
--- a/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java
@@ -40,6 +40,7 @@ import cc.polyfrost.oneconfig.renderer.RenderManager;
*/
public abstract class Hud {
public boolean enabled;
+ transient private Config config;
public boolean rounded;
public boolean border;
public OneColor bgColor;
@@ -236,6 +237,17 @@ public abstract class Hud {
return (float) (screenHeight - (1d - yUnscaled) * screenHeight - (getHeight(scale) + paddingY * scale));
}
+ /**
+ * @return If the hud is enabled
+ */
+ public boolean isEnabled() {
+ return enabled && (config == null || config.enabled);
+ }
+
+ public void setConfig(Config config) {
+ this.config = config;
+ }
+
@Switch(
name = "Show in Chat"
)
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java
index 381e0a8..8dd8ac3 100644
--- a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java
@@ -103,7 +103,7 @@ public abstract class TextHud extends Hud {
private class TickHandler {
@Subscribe
private void onTick(TickEvent event) {
- if (event.stage != Stage.START) return;
+ if (event.stage != Stage.START || !isEnabled()) return;
lines.clear();
if (!HudCore.editing) getLines(lines);
else getExampleLines(lines);
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilanceConfig.java
index 97dd0cb..689bf25 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilanceConfig.java
@@ -1,4 +1,4 @@
-package cc.polyfrost.oneconfig.config.compatibility.vigilance;
+package cc.polyfrost.oneconfig.internal.config.compatibility.vigilance;
import cc.polyfrost.oneconfig.config.core.ConfigUtils;
import cc.polyfrost.oneconfig.internal.config.core.ConfigCore;
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceName.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilanceName.java
index 8417ad8..ff84d3c 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceName.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilanceName.java
@@ -1,4 +1,4 @@
-package cc.polyfrost.oneconfig.config.compatibility.vigilance;
+package cc.polyfrost.oneconfig.internal.config.compatibility.vigilance;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilantAccessor.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilantAccessor.java
index c449bd9..f059dbc 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilantAccessor.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilantAccessor.java
@@ -1,4 +1,4 @@
-package cc.polyfrost.oneconfig.config.compatibility.vigilance;
+package cc.polyfrost.oneconfig.internal.config.compatibility.vigilance;
import gg.essential.vigilance.data.PropertyCollector;
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java
index ab796c7..c5724e5 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java
@@ -40,7 +40,6 @@ public class ConfigCore {
}
public static void sortMods() {
-
ArrayList<Mod> mods = new ArrayList<>(ConfigCore.mods);
ConfigCore.mods = mods.stream().filter((mod -> OneConfigConfig.favoriteMods.contains(mod.name))).sorted().collect(Collectors.toList());
mods.removeAll(ConfigCore.mods);
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java b/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java
index 2bbd3b7..31604ed 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java
@@ -15,8 +15,8 @@ public class HudCore {
public void onRender(HudRenderEvent event) {
if (editing) return;
for (Hud hud : huds) {
- if (hud.enabled)
- hud.drawAll(event.matrices, hud.getXScaled(UResolution.getScaledWidth()), hud.getYScaled(UResolution.getScaledHeight()), hud.scale, true);
+ if (!hud.isEnabled()) continue;
+ hud.drawAll(event.matrices, hud.getXScaled(UResolution.getScaledWidth()), hud.getYScaled(UResolution.getScaledHeight()), hud.scale, true);
}
}
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java b/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java
index 5869ffb..b747088 100644
--- a/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java
+++ b/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java
@@ -292,22 +292,6 @@ public final class RenderManager {
* @param font The font.
* @see cc.polyfrost.oneconfig.renderer.font.Font
*/
- public static void drawText(long vg, String text, float x, float y, int color, float size, Fonts font) {
- drawText(vg, text, x, y, color, size, font.font);
- }
-
- /**
- * Draws a String with the given parameters.
- *
- * @param vg The NanoVG context.
- * @param text The text.
- * @param x The x position.
- * @param y The y position.
- * @param color The color.
- * @param size The size.
- * @param font The font.
- * @see cc.polyfrost.oneconfig.renderer.font.Font
- */
public static void drawText(long vg, String text, float x, float y, int color, float size, Font font) {
nvgBeginPath(vg);
nvgFontSize(vg, size);
@@ -331,22 +315,6 @@ public final class RenderManager {
* @param size The size.
* @param font The font.
*/
- public static void drawWrappedString(long vg, String text, float x, float y, float width, int color, float size, Fonts font) {
- drawWrappedString(vg, text, x, y, width, color, size, font.font);
- }
-
- /**
- * Draws a String wrapped at the given width, with the given parameters.
- *
- * @param vg The NanoVG context.
- * @param text The text.
- * @param x The x position.
- * @param y The y position.
- * @param width The width.
- * @param color The color.
- * @param size The size.
- * @param font The font.
- */
public static void drawWrappedString(long vg, String text, float x, float y, float width, int color, float size, Font font) {
nvgBeginPath(vg);
nvgFontSize(vg, size);
@@ -366,18 +334,6 @@ public final class RenderManager {
* @see RenderManager#drawText(long, String, float, float, int, float, Font)
* @see InputUtils#isAreaClicked(int, int, int, int)
*/
- public static void drawURL(long vg, String url, float x, float y, float size, Fonts font) {
- drawURL(vg, url, x, y, size, font.font);
- }
-
- /**
- * Draw a formatted URL (a string in blue with an underline) that when clicked, opens the given text.
- *
- * <p><b>This does NOT scale to Minecraft's GUI scale!</b></p>
- *
- * @see RenderManager#drawText(long, String, float, float, int, float, Font)
- * @see InputUtils#isAreaClicked(int, int, int, int)
- */
public static void drawURL(long vg, String url, float x, float y, float size, Font font) {
drawText(vg, url, x, y, Colors.PRIMARY_500, size, font);
float length = getTextWidth(vg, url, size, font);
@@ -487,10 +443,6 @@ public final class RenderManager {
drawRoundImage(vg, filePath.filePath, x, y, width, height, radius);
}
- public static float getTextWidth(long vg, String text, float fontSize, Fonts font) {
- return getTextWidth(vg, text, fontSize, font.font);
- }
-
/**
* Get the width of the provided String.
*
diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/TextRenderer.java b/src/main/java/cc/polyfrost/oneconfig/renderer/TextRenderer.java
new file mode 100644
index 0000000..95071d1
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/renderer/TextRenderer.java
@@ -0,0 +1,217 @@
+package cc.polyfrost.oneconfig.renderer;
+
+import cc.polyfrost.oneconfig.internal.assets.Colors;
+import cc.polyfrost.oneconfig.renderer.font.Font;
+import cc.polyfrost.oneconfig.utils.InputUtils;
+import cc.polyfrost.oneconfig.utils.NetworkUtils;
+import com.google.common.annotations.Beta;
+import org.lwjgl.nanovg.NVGColor;
+
+import java.util.ArrayList;
+
+import static cc.polyfrost.oneconfig.renderer.RenderManager.color;
+import static org.lwjgl.nanovg.NanoVG.*;
+
+public class TextRenderer {
+ /**
+ * Draws a String with the given parameters.
+ *
+ * @param vg The NanoVG context.
+ * @param text The text.
+ * @param x The x position.
+ * @param y The y position.
+ * @param color The color.
+ * @param size The size.
+ * @param font The font.
+ * @param letterSpacing The letter spacing
+ * @see cc.polyfrost.oneconfig.renderer.font.Font
+ */
+ public static void drawText(long vg, String text, float x, float y, int color, float size, Font font, float letterSpacing) {
+ nvgBeginPath(vg);
+ nvgFontSize(vg, size);
+ nvgTextLetterSpacing(vg, letterSpacing);
+ nvgFontFace(vg, font.getName());
+ nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE);
+ NVGColor nvgColor = color(vg, color);
+ nvgText(vg, x, y, text);
+ nvgFill(vg);
+ nvgColor.free();
+ }
+
+ /**
+ * Draws a String with the given parameters.
+ *
+ * @param vg The NanoVG context.
+ * @param text The text.
+ * @param x The x position.
+ * @param y The y position.
+ * @param color The color.
+ * @param size The size.
+ * @param font The font.
+ * @see cc.polyfrost.oneconfig.renderer.font.Font
+ */
+ public static void drawText(long vg, String text, float x, float y, int color, float size, Font font) {
+ drawText(vg, text, x, y, color, size, font, 0);
+ }
+
+ /**
+ * Draws a String with the given parameters.
+ *
+ * @param vg The NanoVG context.
+ * @param text The text.
+ * @param x The x position.
+ * @param y The y position.
+ * @param color The color.
+ * @param size The size.
+ * @param font The font.
+ * @param lineHeight The line height
+ * @param letterSpacing The letter spacing
+ * @see cc.polyfrost.oneconfig.renderer.font.Font
+ */
+ public static void drawText(long vg, ArrayList<String> text, float x, float y, int color, float size, Font font, float lineHeight, float letterSpacing) {
+ float textY = y;
+ for (String line : text) {
+ drawText(vg, line, x, textY, color, size, font, letterSpacing);
+ textY += lineHeight;
+ }
+ }
+
+ /**
+ * Draws a String with the given parameters.
+ *
+ * @param vg The NanoVG context.
+ * @param text The text.
+ * @param x The x position.
+ * @param y The y position.
+ * @param color The color.
+ * @param size The size.
+ * @param font The font.
+ * @param lineHeight The line height
+ * @see cc.polyfrost.oneconfig.renderer.font.Font
+ */
+ public static void drawText(long vg, ArrayList<String> text, float x, float y, int color, float size, Font font, float lineHeight) {
+ drawText(vg, text, x, y, color, size, font, lineHeight, 0);
+ }
+
+ /**
+ * Draws a String wrapped at the given width, with the given parameters.
+ *
+ * @param vg The NanoVG context.
+ * @param text The text.
+ * @param x The x position.
+ * @param y The y position.
+ * @param width The width.
+ * @param color The color.
+ * @param size The size.
+ * @param font The font.
+ */
+ public static void drawWrappedString(long vg, String text, float x, float y, float width, int color, float size, Font font) {
+ nvgBeginPath(vg);
+ nvgFontSize(vg, size);
+ nvgFontFace(vg, font.getName());
+ nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE);
+ NVGColor nvgColor = color(vg, color);
+ nvgTextBox(vg, x, y, width, text);
+ nvgFill(vg);
+ nvgColor.free();
+ }
+
+ /**
+ * Draw a formatted URL (a string in blue with an underline) that when clicked, opens the given text.
+ *
+ * <p><b>This does NOT scale to Minecraft's GUI scale!</b></p>
+ *
+ * @see RenderManager#drawText(long, String, float, float, int, float, Font)
+ * @see InputUtils#isAreaClicked(int, int, int, int)
+ */
+ public static void drawURL(long vg, String url, float x, float y, float size, Font font) {
+ drawText(vg, url, x, y, Colors.PRIMARY_500, size, font);
+ float length = getTextWidth(vg, url, size, font);
+ RenderManager.drawRectangle(vg, x, y + size / 2, length, 1, Colors.PRIMARY_500);
+ if (InputUtils.isAreaClicked((int) (x - 2), (int) (y - 1), (int) (length + 4), (int) (size / 2 + 3))) {
+ NetworkUtils.browseLink(url);
+ }
+ }
+
+ /**
+ * Get the width of the provided String.
+ *
+ * @param vg The NanoVG context.
+ * @param text The text.
+ * @param fontSize The font size.
+ * @param font The font.
+ * @param letterSpacing The letter spacing
+ * @return The width of the text.
+ */
+ public static float getTextWidth(long vg, String text, float fontSize, Font font, float letterSpacing) {
+ float[] bounds = new float[4];
+ nvgFontSize(vg, fontSize);
+ nvgTextLetterSpacing(vg, letterSpacing);
+ nvgFontFace(vg, font.getName());
+ return nvgTextBounds(vg, 0, 0, text, bounds);
+ }
+
+ /**
+ * Get the width of the provided String.
+ *
+ * @param vg The NanoVG context.
+ * @param text The text.
+ * @param fontSize The font size.
+ * @param font The font.
+ * @return The width of the text.
+ */
+ public static float getTextWidth(long vg, String text, float fontSize, Font font) {
+ return getTextWidth(vg, text, fontSize, font, 0);
+ }
+
+ /**
+ * Wraps a string into an array of lines.
+ *
+ * @param vg The NanoVG context.
+ * @param text The text to wrap.
+ * @param maxWidth The maximum width of each line.
+ * @param fontSize The font size.
+ * @param font The font to use.
+ * @param letterSpacing The letter spacing
+ * @return The array of lines.
+ */
+ @Beta
+ public static ArrayList<String> wrapText(long vg, String text, float maxWidth, float fontSize, Font font, float letterSpacing) {
+ ArrayList<String> wrappedText = new ArrayList<>();
+ text += " ";
+ int prevIndex = 0;
+ for (int i = text.indexOf(" "); i >= 0; i = text.indexOf(" ", i + 1)) {
+ String textPart = text.substring(0, i);
+ float textWidth = getTextWidth(vg, textPart, fontSize, font, letterSpacing);
+ if (textWidth < maxWidth) {
+ prevIndex = i;
+ continue;
+ }
+ wrappedText.add(text.substring(0, prevIndex) + " ");
+ wrappedText.addAll(wrapText(vg, text.substring(prevIndex + 1), maxWidth, fontSize, font, letterSpacing));
+ break;
+ }
+ if (wrappedText.size() == 0) wrappedText.add(text);
+ String temp = wrappedText.get(wrappedText.size() - 1);
+ if (temp.length() != 0) {
+ wrappedText.remove(wrappedText.size() - 1);
+ wrappedText.add(temp.substring(0, temp.length() - 1));
+ }
+ return wrappedText;
+ }
+
+ /**
+ * Wraps a string into an array of lines.
+ *
+ * @param vg The NanoVG context.
+ * @param text The text to wrap.
+ * @param maxWidth The maximum width of each line.
+ * @param fontSize The font size.
+ * @param font The font to use.
+ * @return The array of lines.
+ */
+ @Beta
+ public static ArrayList<String> wrapText(long vg, String text, float maxWidth, float fontSize, Font font) {
+ return wrapText(vg, text, maxWidth, fontSize, font, 0);
+ }
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/font/FontManager.java b/src/main/java/cc/polyfrost/oneconfig/renderer/font/FontManager.java
index 388911d..79ac518 100644
--- a/src/main/java/cc/polyfrost/oneconfig/renderer/font/FontManager.java
+++ b/src/main/java/cc/polyfrost/oneconfig/renderer/font/FontManager.java
@@ -3,6 +3,7 @@ package cc.polyfrost.oneconfig.renderer.font;
import cc.polyfrost.oneconfig.utils.IOUtils;
import java.io.IOException;
+import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import static org.lwjgl.nanovg.NanoVG.nvgCreateFontMem;
@@ -17,8 +18,15 @@ public class FontManager {
*/
public void initialize(long vg) {
- for (Fonts fonts : Fonts.values()) {
- loadFont(vg, fonts.font);
+ for (Field field : Fonts.class.getDeclaredFields()) {
+ try {
+ field.setAccessible(true);
+ Object font = field.get(null);
+ if (!(font instanceof Font)) continue;
+ loadFont(vg, (Font) font);
+ } catch (Exception e) {
+ throw new RuntimeException("Could not initialize fonts");
+ }
}
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/font/Fonts.java b/src/main/java/cc/polyfrost/oneconfig/renderer/font/Fonts.java
index 9b6193f..3120c7b 100644
--- a/src/main/java/cc/polyfrost/oneconfig/renderer/font/Fonts.java
+++ b/src/main/java/cc/polyfrost/oneconfig/renderer/font/Fonts.java
@@ -1,15 +1,10 @@
package cc.polyfrost.oneconfig.renderer.font;
-public enum Fonts {
- BOLD(new Font("inter-bold", "/assets/oneconfig/font/Bold.otf")),
- SEMIBOLD(new Font("inter-semibold", "/assets/oneconfig/font/SemiBold.otf")),
- MEDIUM(new Font("inter-medium", "/assets/oneconfig/font/Medium.otf")),
- REGULAR(new Font("inter-regular", "/assets/oneconfig/font/Regular.otf")),
- MINECRAFT_REGULAR(new Font("mc-regular", "/assets/oneconfig/font/Minecraft-Regular.otf")),
- MINECRAFT_BOLD(new Font("mc-bold", "/assets/oneconfig/font/Minecraft-Bold.otf"));
- public final Font font;
-
- Fonts(Font font) {
- this.font = font;
- }
+public class Fonts {
+ public static final Font BOLD = new Font("inter-bold", "/assets/oneconfig/font/Bold.otf");
+ public static final Font SEMIBOLD = new Font("inter-semibold", "/assets/oneconfig/font/SemiBold.otf");
+ public static final Font MEDIUM = new Font("inter-medium", "/assets/oneconfig/font/Medium.otf");
+ public static final Font REGULAR = new Font("inter-regular", "/assets/oneconfig/font/Regular.otf");
+ public static final Font MINECRAFT_REGULAR = new Font("mc-regular", "/assets/oneconfig/font/Minecraft-Regular.otf");
+ public static final Font MINECRAFT_BOLD = new Font("mc-bold", "/assets/oneconfig/font/Minecraft-Bold.otf");
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java
index 51b42d8..265e2f4 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java
@@ -21,20 +21,6 @@ public final class TextUtils {
* @param font The font to use.
* @return The array of lines.
*/
- public static ArrayList<String> wrapText(long vg, String text, float maxWidth, float fontSize, Fonts font) {
- return wrapText(vg, text, maxWidth, fontSize, font.font);
- }
-
- /**
- * Wraps a string into an array of lines.
- *
- * @param vg The NanoVG context.
- * @param text The text to wrap.
- * @param maxWidth The maximum width of each line.
- * @param fontSize The font size.
- * @param font The font to use.
- * @return The array of lines.
- */
public static ArrayList<String> wrapText(long vg, String text, float maxWidth, float fontSize, Font font) {
ArrayList<String> wrappedText = new ArrayList<>();
text += " ";