aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost
diff options
context:
space:
mode:
authorWyvest <45589059+Wyvest@users.noreply.github.com>2022-06-24 23:44:58 +0700
committerWyvest <45589059+Wyvest@users.noreply.github.com>2022-06-24 23:44:58 +0700
commitf1830199d99b666f28c2b3b246f688f102adb427 (patch)
tree07fba5e7fce5e523223e8fc9da70f7783d7f15f9 /src/main/java/cc/polyfrost
parentd4463b33342ccb5ea86c2a2c9da37b9b861b6674 (diff)
downloadOneConfig-f1830199d99b666f28c2b3b246f688f102adb427.tar.gz
OneConfig-f1830199d99b666f28c2b3b246f688f102adb427.tar.bz2
OneConfig-f1830199d99b666f28c2b3b246f688f102adb427.zip
TextHud revamp
add docs to Hud fix config not saving when exiting prematurely some new events
Diffstat (limited to 'src/main/java/cc/polyfrost')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java15
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java4
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/events/event/PreShutdownEvent.java11
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/events/event/ShutdownEvent.java9
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/events/event/StartEvent.java7
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java24
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java4
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/Hud.java (renamed from src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java)47
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/MultiTextHud.java66
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java97
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java59
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java13
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java10
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java11
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java59
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/test/TestHud_Test.java31
17 files changed, 395 insertions, 78 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java b/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java
index aaa7cca..99b52e3 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java
@@ -12,6 +12,7 @@ import org.jetbrains.annotations.Nullable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;
+import java.util.Arrays;
public class ConfigUtils {
public static BasicOption getOption(Option option, Field field, Object instance) {
@@ -42,9 +43,19 @@ public class ConfigUtils {
return null;
}
- public static ArrayList<BasicOption> getClassOptions(Object object) {
+ public static ArrayList<BasicOption> getClassOptions(Object object, Class<?> parentClass) {
ArrayList<BasicOption> options = new ArrayList<>();
- for (Field field : object.getClass().getDeclaredFields()) {
+ ArrayList<Field> fields = new ArrayList<>(Arrays.asList(object.getClass().getDeclaredFields()));
+ Class<?> clazz = object.getClass();
+ while (true) {
+ clazz = clazz.getSuperclass();
+ if (clazz != null && clazz != parentClass) {
+ fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
+ } else {
+ break;
+ }
+ }
+ for (Field field : fields) {
Option option = findAnnotation(field, Option.class);
if (option == null) continue;
options.add(getOption(option, field, object));
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 eba2f9f..2bee982 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java
@@ -37,7 +37,9 @@ public abstract class BasicOption {
* @param object Java object to set the variable to
*/
protected void set(Object object) throws IllegalAccessException {
- if (field == null) return;
+ if (field == null) {
+ return;
+ }
field.set(parent, object);
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/events/event/PreShutdownEvent.java b/src/main/java/cc/polyfrost/oneconfig/events/event/PreShutdownEvent.java
new file mode 100644
index 0000000..105cfbc
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/events/event/PreShutdownEvent.java
@@ -0,0 +1,11 @@
+package cc.polyfrost.oneconfig.events.event;
+
+/**
+ * Called when the game is about to shut down.
+ * This can be used if anything needs to be done before the screen itself is fully closed
+ * or need to do something before another mod does something via {@link Runtime#addShutdownHook(Thread)}.
+ *
+ * @see ShutdownEvent
+ */
+public class PreShutdownEvent {
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/events/event/ShutdownEvent.java b/src/main/java/cc/polyfrost/oneconfig/events/event/ShutdownEvent.java
new file mode 100644
index 0000000..3f8ee50
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/events/event/ShutdownEvent.java
@@ -0,0 +1,9 @@
+package cc.polyfrost.oneconfig.events.event;
+
+/**
+ * Called when the game is shutting down.
+ *
+ * @see PreShutdownEvent
+ */
+public class ShutdownEvent {
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/events/event/StartEvent.java b/src/main/java/cc/polyfrost/oneconfig/events/event/StartEvent.java
new file mode 100644
index 0000000..2eea91c
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/events/event/StartEvent.java
@@ -0,0 +1,7 @@
+package cc.polyfrost.oneconfig.events.event;
+
+/**
+ * Called when the Minecraft instance is starting.
+ */
+public class StartEvent {
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java
index 939bbaa..8364afe 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java
@@ -1,7 +1,7 @@
package cc.polyfrost.oneconfig.gui;
import cc.polyfrost.oneconfig.internal.config.core.ConfigCore;
-import cc.polyfrost.oneconfig.hud.BasicHud;
+import cc.polyfrost.oneconfig.hud.Hud;
import cc.polyfrost.oneconfig.internal.hud.HudCore;
import cc.polyfrost.oneconfig.renderer.RenderManager;
import cc.polyfrost.oneconfig.libs.universal.UKeyboard;
@@ -14,7 +14,7 @@ import java.awt.*;
import java.util.ArrayList;
public class HudGui extends UScreen {
- private BasicHud editingHud;
+ private Hud editingHud;
private boolean isDragging;
private boolean isScaling;
private int xOffset;
@@ -35,12 +35,12 @@ public class HudGui extends UScreen {
setPosition(mouseX - xOffset, mouseY - yOffset, true);
}
- for (BasicHud hud : HudCore.huds) {
+ for (Hud hud : HudCore.huds) {
if (hud.enabled) processHud(hud, mouseX);
}
}
- private void processHud(BasicHud hud, int mouseX) {
+ private void processHud(Hud hud, int mouseX) {
if (hud == editingHud && isScaling) {
float xFloat = hud.getXScaled(this.width);
float yFloat = hud.getYScaled(this.height);
@@ -127,7 +127,7 @@ public class HudGui extends UScreen {
if (snapX != newX || snapY != newY) {
newX = snapX;
newY = snapY;
- for (BasicHud hud : HudCore.huds) {
+ for (Hud hud : HudCore.huds) {
if (!hud.enabled) continue;
if (findParent(hud, snapX, snapY))
break;
@@ -145,7 +145,7 @@ public class HudGui extends UScreen {
editingHud.yUnscaled = (newY + height) / (double) this.height;
}
- private boolean findParent(BasicHud hud, float snapX, float snapY) {
+ private boolean findParent(Hud hud, float snapX, float snapY) {
int hudWidth = (int) (hud.getWidth(hud.scale) + hud.paddingX * hud.scale);
int hudX = (int) hud.getXScaled(this.width);
int hudHeight = (int) (hud.getHeight(hud.scale) + hud.paddingY * hud.scale);
@@ -167,7 +167,7 @@ public class HudGui extends UScreen {
private float getXSnapping(float pos, boolean rightOnly) {
float width = editingHud.getWidth(editingHud.scale) + editingHud.paddingX * editingHud.scale;
ArrayList<Float> verticalLines = new ArrayList<>();
- for (BasicHud hud : HudCore.huds) {
+ for (Hud hud : HudCore.huds) {
if (!hud.enabled) continue;
verticalLines.addAll(getXSnappingHud(hud));
}
@@ -193,7 +193,7 @@ public class HudGui extends UScreen {
return pos;
}
- private ArrayList<Float> getXSnappingHud(BasicHud hud) {
+ private ArrayList<Float> getXSnappingHud(Hud hud) {
ArrayList<Float> verticalLines = new ArrayList<>();
if (hud == editingHud) return verticalLines;
if (hud.childRight != null) verticalLines.addAll(getXSnappingHud(hud.childRight));
@@ -207,7 +207,7 @@ public class HudGui extends UScreen {
private float getYSnapping(float pos) {
float height = editingHud.getHeight(editingHud.scale) + editingHud.paddingY * editingHud.scale;
ArrayList<Float> horizontalLines = new ArrayList<>();
- for (BasicHud hud : HudCore.huds) {
+ for (Hud hud : HudCore.huds) {
if (!hud.enabled) continue;
horizontalLines.addAll(getYSnappingHud(hud));
}
@@ -233,7 +233,7 @@ public class HudGui extends UScreen {
return pos;
}
- private ArrayList<Float> getYSnappingHud(BasicHud hud) {
+ private ArrayList<Float> getYSnappingHud(Hud hud) {
ArrayList<Float> horizontalLines = new ArrayList<>();
if (hud == editingHud) return horizontalLines;
if (hud.childBottom != null) horizontalLines.addAll(getYSnappingHud(hud.childBottom));
@@ -270,7 +270,7 @@ public class HudGui extends UScreen {
}
}
editingHud = null;
- for (BasicHud hud : HudCore.huds) {
+ for (Hud hud : HudCore.huds) {
if (!hud.enabled) continue;
if (mouseClickedHud(hud, (int) mouseX, (int) mouseY))
break;
@@ -278,7 +278,7 @@ public class HudGui extends UScreen {
}
}
- private boolean mouseClickedHud(BasicHud hud, int mouseX, int mouseY) {
+ private boolean mouseClickedHud(Hud hud, int mouseX, int mouseY) {
int width = (int) (hud.getWidth(hud.scale) + hud.paddingX * hud.scale);
int height = (int) (hud.getHeight(hud.scale) + hud.paddingY * hud.scale);
float x = hud.getXScaled(this.width);
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java b/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java
index 6b28835..fb42e9c 100644
--- a/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java
@@ -13,7 +13,7 @@ import java.util.ArrayList;
public class HUDUtils {
public static void addHudOptions(OptionPage page, Field field, Object instance) {
HUD hudAnnotation = field.getAnnotation(HUD.class);
- BasicHud hud = (BasicHud) ConfigUtils.getField(field, instance);
+ Hud hud = (Hud) ConfigUtils.getField(field, instance);
if (hud == null) return;
HudCore.huds.add(hud);
String category = hudAnnotation.category();
@@ -22,7 +22,7 @@ public class HUDUtils {
try {
options.add(new ConfigHeader(field, hud, hudAnnotation.name(), category, subcategory, 2));
options.add(new ConfigSwitch(hud.getClass().getField("enabled"), hud, "Enabled", category, subcategory, 2));
- options.addAll(ConfigUtils.getClassOptions(hud));
+ options.addAll(ConfigUtils.getClassOptions(hud, Hud.class));
options.add(new ConfigCheckbox(hud.getClass().getField("rounded"), hud, "Rounded corners", category, subcategory, 1));
options.get(options.size() - 1).addDependency(() -> hud.enabled);
options.add(new ConfigCheckbox(hud.getClass().getField("border"), hud, "Outline/border", category, subcategory, 1));
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java
index 445b2ad..71c6c38 100644
--- a/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java
@@ -2,8 +2,39 @@ package cc.polyfrost.oneconfig.hud;
import cc.polyfrost.oneconfig.config.core.OneColor;
import cc.polyfrost.oneconfig.renderer.RenderManager;
+import cc.polyfrost.oneconfig.config.Config;
-public abstract class BasicHud {
+/**
+ * Represents a HUD element in OneConfig.
+ * A HUD element can be used to display useful information to the user, like FPS or CPS.
+ * <p>
+ * If you simply want to display text, extend {@link SingleTextHud} or {@link MultiTextHud},
+ * whichever applies to the use case. Then, override the required methods.
+ * <p>
+ * If you want to display something else, extend this class and override {@link Hud#getWidth(float)}, {@link Hud#getHeight(float)}, and {@link Hud#draw(int, int, float)} with the width, height, and the drawing code respectively.
+ * </p>
+ * <p>
+ * It should also be noted that additional options to the HUD can be added simply by declaring them.
+ * <pre>{@code
+ * public class TestHud extends SingleTextHud {
+ * @literal @Switch(
+ * name = "Additional Option"
+ * )
+ * public boolean additionalOption = true;
+ * }
+ * }</pre>
+ * </p>
+ * To register an element, add it to your OneConfig {@link Config}.
+ * <pre>{@code
+ * * public class YourConfig extends Config {
+ * * @literal @HUD(
+ * * name = "HUD Element"
+ * * )
+ * * public YourHudElement hudElement = new YourHudElement(false);
+ * * }
+ * * }</pre>
+ */
+public abstract class Hud {
public boolean enabled;
public boolean rounded;
public boolean border;
@@ -16,9 +47,9 @@ public abstract class BasicHud {
public float scale;
public float paddingX;
public float paddingY;
- public BasicHud parent;
- public BasicHud childRight;
- public BasicHud childBottom;
+ public Hud parent;
+ public Hud childRight;
+ public Hud childBottom;
/**
* @param enabled If the hud is enabled
@@ -34,7 +65,7 @@ public abstract class BasicHud {
* @param borderSize Thickness of the border
* @param borderColor The color of the border
*/
- public BasicHud(boolean enabled, int x, int y, float scale, boolean rounded, int cornerRadius, int paddingX, int paddingY, OneColor bgColor, boolean border, float borderSize, OneColor borderColor) {
+ public Hud(boolean enabled, int x, int y, float scale, boolean rounded, int cornerRadius, int paddingX, int paddingY, OneColor bgColor, boolean border, float borderSize, OneColor borderColor) {
this.enabled = enabled;
this.scale = scale;
this.rounded = rounded;
@@ -57,7 +88,7 @@ public abstract class BasicHud {
* @param y Y-coordinate of hud on a 1080p display
* @param scale Scale of the hud
*/
- public BasicHud(boolean enabled, int x, int y, int scale) {
+ public Hud(boolean enabled, int x, int y, int scale) {
this(enabled, x, y, scale, false, 2, 5, 5, new OneColor(0, 0, 0, 120), false, 2, new OneColor(0, 0, 0));
}
@@ -66,14 +97,14 @@ public abstract class BasicHud {
* @param x X-coordinate of hud on a 1080p display
* @param y Y-coordinate of hud on a 1080p display
*/
- public BasicHud(boolean enabled, int x, int y) {
+ public Hud(boolean enabled, int x, int y) {
this(enabled, x, y, 1, false, 2, 5, 5, new OneColor(0, 0, 0, 120), false, 2, new OneColor(0, 0, 0));
}
/**
* @param enabled If the hud is enabled
*/
- public BasicHud(boolean enabled) {
+ public Hud(boolean enabled) {
this(enabled, 0, 0, 1, false, 2, 5, 5, new OneColor(0, 0, 0, 120), false, 2, new OneColor(0, 0, 0));
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/MultiTextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/MultiTextHud.java
new file mode 100644
index 0000000..5440f10
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/MultiTextHud.java
@@ -0,0 +1,66 @@
+package cc.polyfrost.oneconfig.hud;
+
+import cc.polyfrost.oneconfig.gui.OneConfigGui;
+import cc.polyfrost.oneconfig.libs.universal.UMinecraft;
+import cc.polyfrost.oneconfig.libs.universal.UScreen;
+import cc.polyfrost.oneconfig.renderer.RenderManager;
+import net.minecraft.client.gui.GuiChat;
+
+import java.util.List;
+
+public abstract class MultiTextHud extends TextHud {
+ private transient int width = 100;
+ private transient int height;
+
+ public MultiTextHud(boolean enabled) {
+ this(enabled, 0, 0);
+ }
+
+ public MultiTextHud(boolean enabled, int x, int y) {
+ super(enabled, x, y);
+ }
+
+ @Override
+ public int getWidth(float scale) {
+ return (int) (width * scale);
+ }
+
+ @Override
+ public int getHeight(float scale) {
+ return (int) (height * scale);
+ }
+
+ @Override
+ public void draw(int x, int y, float scale) {
+ if (!showInGuis && UScreen.getCurrentScreen() != null && !(UScreen.getCurrentScreen() instanceof OneConfigGui)) return;
+ if (!showInChat && UScreen.getCurrentScreen() instanceof GuiChat) return;
+ if (!showInDebug && UMinecraft.getSettings().showDebugInfo) return;
+
+ int textY = y;
+ width = 0;
+ for (String line : getLines()) {
+ RenderManager.drawScaledString(line, x, textY, color.getRGB(), RenderManager.TextType.toType(textType), scale);
+ width = Math.max(width, UMinecraft.getFontRenderer().getStringWidth(line));
+ textY += 12 * scale;
+ }
+ height = (int) ((textY - y) / scale - 3);
+ }
+
+ @Override
+ public void drawExample(int x, int y, float scale) {
+ int textY = y;
+ width = 0;
+ for (String line : getExampleLines()) {
+ RenderManager.drawScaledString(line, x, textY, color.getRGB(), RenderManager.TextType.toType(textType), scale);
+ width = Math.max(width, UMinecraft.getFontRenderer().getStringWidth(line));
+ textY += 12 * scale;
+ }
+ height = (int) ((textY - y) / scale - 3);
+ }
+
+ public abstract List<String> getLines();
+
+ public List<String> getExampleLines() {
+ return getLines();
+ }
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java
new file mode 100644
index 0000000..983047a
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java
@@ -0,0 +1,97 @@
+package cc.polyfrost.oneconfig.hud;
+
+import cc.polyfrost.oneconfig.config.annotations.Dropdown;
+import cc.polyfrost.oneconfig.config.annotations.Switch;
+import cc.polyfrost.oneconfig.config.annotations.Text;
+import cc.polyfrost.oneconfig.gui.OneConfigGui;
+import cc.polyfrost.oneconfig.libs.universal.UMinecraft;
+import cc.polyfrost.oneconfig.libs.universal.UScreen;
+import cc.polyfrost.oneconfig.renderer.RenderManager;
+import net.minecraft.client.gui.GuiChat;
+
+public abstract class SingleTextHud extends TextHud {
+
+ public SingleTextHud(boolean enabled) {
+ this(enabled, 0, 0);
+ }
+
+ public SingleTextHud(boolean enabled, int x, int y) {
+ super(enabled, x, y);
+ }
+
+ @Switch(
+ name = "Brackets"
+ )
+ public boolean brackets = false;
+
+ @Text(
+ name = "Title"
+ )
+ public String title = getDefaultTitle();
+
+ @Dropdown(
+ name = "Title Location",
+ options = {"Left", "Right"}
+ )
+ public int titleLocation = 0;
+
+ public abstract String getDefaultTitle();
+
+ @Override
+ public int getWidth(float scale) {
+ return (int) (UMinecraft.getFontRenderer().getStringWidth(getCompleteText(false)) * scale);
+ }
+
+ @Override
+ public int getExampleWidth(float scale) {
+ return (int) (UMinecraft.getFontRenderer().getStringWidth(getCompleteText(true)) * scale);
+ }
+
+ @Override
+ public int getHeight(float scale) {
+ return (int) (UMinecraft.getFontRenderer().FONT_HEIGHT * scale);
+ }
+
+ @Override
+ public void draw(int x, int y, float scale) {
+ if (!showInGuis && UScreen.getCurrentScreen() != null && !(UScreen.getCurrentScreen() instanceof OneConfigGui)) return;
+ if (!showInChat && UScreen.getCurrentScreen() instanceof GuiChat) return;
+ if (!showInDebug && UMinecraft.getSettings().showDebugInfo) return;
+
+ RenderManager.drawScaledString(getCompleteText(false), x, y, color.getRGB(), RenderManager.TextType.toType(textType), scale);
+ }
+
+ @Override
+ public void drawExample(int x, int y, float scale) {
+ RenderManager.drawScaledString(getCompleteText(true), x, y, color.getRGB(), RenderManager.TextType.toType(textType), scale);
+ }
+
+ protected final String getCompleteText(boolean example) {
+ boolean showTitle = !title.trim().isEmpty();
+ StringBuilder builder = new StringBuilder();
+ if (brackets) {
+ builder.append("[");
+ }
+
+ if (showTitle && titleLocation == 0) {
+ builder.append(title).append(": ");
+ }
+
+ builder.append(example ? getExampleText() : getText());
+
+ if (showTitle && titleLocation == 1) {
+ builder.append(" ").append(title);
+ }
+
+ if (brackets) {
+ builder.append("]");
+ }
+ return builder.toString();
+ }
+
+ public abstract String getText();
+
+ public String getExampleText() {
+ return getText();
+ }
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java
index 738ed21..7a05ef7 100644
--- a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java
@@ -1,38 +1,39 @@
package cc.polyfrost.oneconfig.hud;
-import cc.polyfrost.oneconfig.renderer.RenderManager;
-import cc.polyfrost.oneconfig.libs.universal.UMinecraft;
+import cc.polyfrost.oneconfig.config.annotations.Color;
+import cc.polyfrost.oneconfig.config.annotations.Dropdown;
+import cc.polyfrost.oneconfig.config.annotations.Switch;
+import cc.polyfrost.oneconfig.config.core.OneColor;
-import java.util.List;
+abstract class TextHud extends Hud {
+ @Color(
+ name = "Text Color"
+ )
+ public OneColor color = new OneColor(255, 255, 255);
-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);
- }
+ @Switch(
+ name = "Show in Chat"
+ )
+ public boolean showInChat;
- @Override
- public int getWidth(float scale) {
- return (int) (width * scale);
- }
+ @Switch(
+ name = "Show in F3 (Debug)"
+ )
+ public boolean showInDebug;
- @Override
- public int getHeight(float scale) {
- return (int) (height * scale);
- }
+ @Switch(
+ name = "Show in GUIs"
+ )
+ public boolean showInGuis = true;
+
+ @Dropdown(
+ name = "Text Type",
+ options = {"No Shadow", "Shadow", "Full Shadow"}
+ )
+ public int textType = 0;
- @Override
- public void draw(int x, int y, float scale) {
- int textY = y;
- width = 0;
- 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 - 3);
- }
- public abstract List<String> getLines();
+ public TextHud(boolean enabled, int x, int y) {
+ super(enabled, x, y);
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java b/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java
index 479192d..c91b4e9 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java
@@ -1,6 +1,8 @@
package cc.polyfrost.oneconfig.internal;
import cc.polyfrost.oneconfig.events.EventManager;
+import cc.polyfrost.oneconfig.events.event.ShutdownEvent;
+import cc.polyfrost.oneconfig.gui.OneConfigGui;
import cc.polyfrost.oneconfig.internal.command.OneConfigCommand;
import cc.polyfrost.oneconfig.internal.config.OneConfigConfig;
import cc.polyfrost.oneconfig.internal.config.Preferences;
@@ -8,6 +10,7 @@ import cc.polyfrost.oneconfig.internal.config.core.ConfigCore;
import cc.polyfrost.oneconfig.internal.config.core.KeyBindHandler;
import cc.polyfrost.oneconfig.internal.gui.BlurHandler;
import cc.polyfrost.oneconfig.internal.hud.HudCore;
+import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
import cc.polyfrost.oneconfig.utils.commands.CommandManager;
import cc.polyfrost.oneconfig.utils.gui.GuiUtils;
import cc.polyfrost.oneconfig.utils.hypixel.HypixelUtils;
@@ -21,6 +24,11 @@ import java.io.File;
*/
@net.minecraftforge.fml.common.Mod(modid = "@ID@", name = "@NAME@", version = "@VER@")
public class OneConfig {
+
+ public OneConfig() {
+ EventManager.INSTANCE.register(this);
+ }
+
public static final File oneConfigDir = new File("./OneConfig");
public static final Logger LOGGER = LogManager.getLogger("@NAME@");
public static OneConfigConfig config;
@@ -73,4 +81,9 @@ public class OneConfig {
public static boolean isObfuscated() {
return isObfuscated;
}
+
+ @Subscribe
+ private void onShutdown(ShutdownEvent event) {
+ ConfigCore.saveAll();
+ }
}
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 6b88afa..90c1062 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
@@ -7,9 +7,19 @@ import cc.polyfrost.oneconfig.internal.hud.HudCore;
import java.util.ArrayList;
import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
import java.util.stream.Collectors;
public class ConfigCore {
+ static {
+ new Timer().scheduleAtFixedRate(new TimerTask() {
+ @Override
+ public void run() {
+ saveAll();
+ }
+ }, 30000, 30000);
+ }
public static List<Mod> oneConfigMods = new ArrayList<>();
public static void saveAll() {
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 04a5e69..2d92b3c 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java
@@ -1,20 +1,20 @@
package cc.polyfrost.oneconfig.internal.hud;
import cc.polyfrost.oneconfig.events.event.HudRenderEvent;
-import cc.polyfrost.oneconfig.hud.BasicHud;
+import cc.polyfrost.oneconfig.hud.Hud;
import cc.polyfrost.oneconfig.libs.universal.UResolution;
import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
import java.util.ArrayList;
public class HudCore {
- public static ArrayList<BasicHud> huds = new ArrayList<>();
+ public static ArrayList<Hud> huds = new ArrayList<>();
public static boolean editing = false;
@Subscribe
public void onRender(HudRenderEvent event) {
if (editing) return;
- for (BasicHud hud : huds) {
+ for (Hud hud : huds) {
if (hud.enabled)
hud.drawAll(hud.getXScaled(UResolution.getScaledWidth()), hud.getYScaled(UResolution.getScaledHeight()), hud.scale, true);
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java
index 6308fdb..5fb40f8 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java
@@ -20,6 +20,17 @@ public class MinecraftMixin {
@Shadow
private Timer timer;
+ @Inject(method = "shutdownMinecraftApplet", at = @At("HEAD"))
+ private void onShutdown(CallbackInfo ci) {
+ EventManager.INSTANCE.post(new PreShutdownEvent());
+ }
+
+ @Inject(method = "startGame", at = @At("HEAD"))
+ private void onStart(CallbackInfo ci) {
+ EventManager.INSTANCE.post(new StartEvent());
+ Runtime.getRuntime().addShutdownHook(new Thread(() -> EventManager.INSTANCE.post(new ShutdownEvent())));
+ }
+
@Inject(method = "startGame", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/client/FMLClientHandler;beginMinecraftLoading(Lnet/minecraft/client/Minecraft;Ljava/util/List;Lnet/minecraft/client/resources/IReloadableResourceManager;)V", remap = false), remap = true)
private void onPreLaunch(CallbackInfo ci) {
OneConfig.preLaunch();
diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java b/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java
index d894d1e..b62d752 100644
--- a/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java
+++ b/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java
@@ -20,6 +20,7 @@ import org.lwjgl.nanovg.NVGPaint;
import org.lwjgl.opengl.GL11;
import java.util.function.LongConsumer;
+import java.util.regex.Pattern;
import static org.lwjgl.nanovg.NanoVG.*;
import static org.lwjgl.nanovg.NanoVGGL2.NVG_ANTIALIAS;
@@ -740,14 +741,68 @@ public final class RenderManager {
// gl
- public static void drawScaledString(String text, float x, float y, int color, boolean shadow, float scale) {
+ private static final Pattern regex = Pattern.compile("(?i)\\\\u00A7[0-9a-f]");
+
+ public static int drawBorderedText(String text, float x, float y, int color, int opacity) {
+ String noColors = regex.matcher(text).replaceAll("\u00A7r");
+ int yes = 0;
+ if (opacity > 3) {
+ int xOff = -3;
+ while (xOff < 3) {
+ xOff++;
+ int yOff = -3;
+ while (yOff < 3) {
+ yOff++;
+ if (xOff * xOff != yOff * yOff) {
+ yes +=
+ //#if MODERN==0
+ UMinecraft.getFontRenderer().drawString(
+ noColors, (xOff / 2f) + x, (yOff / 2f) + y, (opacity) << 24, false
+ );
+ //#else
+ //$$ draw(
+ //$$ matrix.toMC(), noColors, (xOff / 2f) + x, (yOff / 2f) + y, (opacity) shl 24
+ //$$ )
+ //#endif
+ }
+ }
+ }
+ }
+ yes +=
+ //#if MODERN==0
+ UMinecraft.getFontRenderer().drawString(text, x, y, color, false);
+ //#else
+ //$$ draw(matrix.toMC(), text, x.toFloat(), y.toFloat(), color)
+ //#endif
+ return yes;
+ }
+
+ public static void drawScaledString(String text, float x, float y, int color, TextType type, float scale) {
UGraphics.GL.pushMatrix();
UGraphics.GL.scale(scale, scale, 1);
- UMinecraft.getFontRenderer().drawString(text, x * (1 / scale), y * (1 / scale), color, shadow);
+ switch (type) {
+ case NONE:
+ UMinecraft.getFontRenderer().drawString(text, x * (1 / scale), y * (1 / scale), color, false);
+ break;
+ case SHADOW:
+ UMinecraft.getFontRenderer().drawString(text, x * (1 / scale), y * (1 / scale), color, true);
+ break;
+ case FULL:
+ drawBorderedText(text, x, y, color, 100);
+ break;
+ }
UGraphics.GL.popMatrix();
}
public static void drawGlRect(int x, int y, int width, int height, int color) {
Gui.drawRect(x, y, x + width, y + height, color);
}
+
+ public enum TextType {
+ NONE, SHADOW, FULL;
+
+ public static TextType toType(int type) {
+ return values()[type];
+ }
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestHud_Test.java b/src/main/java/cc/polyfrost/oneconfig/test/TestHud_Test.java
index 0de9d65..9982e7d 100644
--- a/src/main/java/cc/polyfrost/oneconfig/test/TestHud_Test.java
+++ b/src/main/java/cc/polyfrost/oneconfig/test/TestHud_Test.java
@@ -1,33 +1,26 @@
package cc.polyfrost.oneconfig.test;
import cc.polyfrost.oneconfig.config.annotations.Switch;
-import cc.polyfrost.oneconfig.config.annotations.Text;
-import cc.polyfrost.oneconfig.hud.TextHud;
+import cc.polyfrost.oneconfig.hud.SingleTextHud;
import net.minecraft.client.Minecraft;
-import java.util.ArrayList;
-import java.util.List;
+public class TestHud_Test extends SingleTextHud {
+ @Switch(
+ name = "Custom Option"
+ )
+ public boolean yes;
-public class TestHud_Test extends TextHud {
public TestHud_Test(boolean enabled, int x, int y) {
super(enabled, x, y);
}
@Override
- public List<String> getLines() {
- ArrayList<String> lines = new ArrayList<>();
- lines.add("FPS: " + Minecraft.getDebugFPS());
- if (hasSecondLine) lines.add(secondLine);
- return lines;
+ public String getDefaultTitle() {
+ return "FPS";
}
- @Switch(
- name = "Has Second Line"
- )
- public boolean hasSecondLine = false;
-
- @Text(
- name = "Second Line Text"
- )
- public String secondLine = "Epic text";
+ @Override
+ public String getText() {
+ return Integer.toString(Minecraft.getDebugFPS());
+ }
}