aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/polyfrost
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io/polyfrost')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/OneConfig.java2
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/annotations/HudComponent.java13
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java13
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigHud.java22
-rw-r--r--src/main/java/io/polyfrost/oneconfig/hud/HudCore.java18
-rw-r--r--src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java48
-rw-r--r--src/main/java/io/polyfrost/oneconfig/hud/interfaces/TextHud.java98
-rw-r--r--src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java31
-rw-r--r--src/main/java/io/polyfrost/oneconfig/test/TestConfig.java4
-rw-r--r--src/main/java/io/polyfrost/oneconfig/test/TestHud.java23
10 files changed, 257 insertions, 15 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/OneConfig.java b/src/main/java/io/polyfrost/oneconfig/OneConfig.java
index 3b80a47..da4a604 100644
--- a/src/main/java/io/polyfrost/oneconfig/OneConfig.java
+++ b/src/main/java/io/polyfrost/oneconfig/OneConfig.java
@@ -2,6 +2,7 @@ package io.polyfrost.oneconfig;
import io.polyfrost.oneconfig.command.OneConfigCommand;
import io.polyfrost.oneconfig.config.OneConfigConfig;
+import io.polyfrost.oneconfig.hud.HudCore;
import io.polyfrost.oneconfig.test.TestConfig;
import io.polyfrost.oneconfig.themes.Themes;
import net.minecraft.client.Minecraft;
@@ -35,6 +36,7 @@ public class OneConfig {
testConfig = new TestConfig();
ClientCommandHandler.instance.registerCommand(new OneConfigCommand());
MinecraftForge.EVENT_BUS.register(this);
+ MinecraftForge.EVENT_BUS.register(new HudCore());
Themes.openTheme(new File("OneConfig/themes/one.zip").getAbsoluteFile());
}
}
diff --git a/src/main/java/io/polyfrost/oneconfig/config/annotations/HudComponent.java b/src/main/java/io/polyfrost/oneconfig/config/annotations/HudComponent.java
new file mode 100644
index 0000000..5e1cd62
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/config/annotations/HudComponent.java
@@ -0,0 +1,13 @@
+package io.polyfrost.oneconfig.config.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface HudComponent {
+ String name();
+ String description() default "";
+}
diff --git a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java
index 4cd6fdf..2e3e92d 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java
@@ -6,6 +6,8 @@ import io.polyfrost.oneconfig.config.core.ConfigCore;
import io.polyfrost.oneconfig.config.data.ModData;
import io.polyfrost.oneconfig.config.profiles.Profiles;
import io.polyfrost.oneconfig.gui.elements.config.*;
+import io.polyfrost.oneconfig.hud.HudCore;
+import io.polyfrost.oneconfig.hud.interfaces.BasicHud;
import java.io.*;
import java.lang.reflect.Field;
@@ -94,6 +96,17 @@ public class Config {
} else if (field.isAnnotationPresent(TextField.class)) {
TextField textField = field.getAnnotation(TextField.class);
options.add(new OConfigText(field, textField.name(), textField.description(), textField.placeholder(), textField.hideText()));
+ } else if (field.isAnnotationPresent(HudComponent.class)) {
+ HudComponent hudComponent = field.getAnnotation(HudComponent.class);
+ options.add(new OConfigHud(field, hudComponent.name(), hudComponent.description()));
+ try {
+ Object hud = field.get(BasicHud.class);
+ HudCore.huds.add((BasicHud) hud);
+ System.out.println("here");
+ System.out.println(HudCore.huds.size());
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ }
} else {
Option customOption = processCustomOption(field);
if (customOption != null)
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigHud.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigHud.java
new file mode 100644
index 0000000..2d6141a
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/OConfigHud.java
@@ -0,0 +1,22 @@
+package io.polyfrost.oneconfig.gui.elements.config;
+
+import io.polyfrost.oneconfig.config.interfaces.Option;
+
+import java.lang.reflect.Field;
+
+public class OConfigHud extends Option {
+
+ public OConfigHud(Field field, String name, String description) {
+ super(field, name, description);
+ }
+
+ @Override
+ public int getHeight() {
+ return 0;
+ }
+
+ @Override
+ public void draw(int x, int y, int width, int mouseX, int mouseY) {
+
+ }
+}
diff --git a/src/main/java/io/polyfrost/oneconfig/hud/HudCore.java b/src/main/java/io/polyfrost/oneconfig/hud/HudCore.java
new file mode 100644
index 0000000..c0e29d1
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/hud/HudCore.java
@@ -0,0 +1,18 @@
+package io.polyfrost.oneconfig.hud;
+
+import io.polyfrost.oneconfig.hud.interfaces.BasicHud;
+import net.minecraftforge.client.event.RenderGameOverlayEvent;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+
+import java.util.ArrayList;
+
+public class HudCore {
+ public static ArrayList<BasicHud> huds = new ArrayList<>();
+
+ @SubscribeEvent
+ public void onRender(RenderGameOverlayEvent.Post event) {
+ if (event.type != RenderGameOverlayEvent.ElementType.ALL) return;
+ for (BasicHud hud : huds)
+ hud.drawAll(20,20, 5);
+ }
+}
diff --git a/src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java b/src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java
new file mode 100644
index 0000000..121c258
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java
@@ -0,0 +1,48 @@
+package io.polyfrost.oneconfig.hud.interfaces;
+
+import io.polyfrost.oneconfig.renderer.Renderer;
+
+import java.awt.*;
+
+public abstract class BasicHud {
+ public int normalX;
+ public int normalY;
+ public int paddingX = 5;
+ public int paddingY = 5;
+ public boolean background = true;
+ public boolean rounded = false;
+
+ public abstract int getWidth(float scale);
+
+ public abstract int getHeight(float scale);
+
+ public abstract void draw(int x, int y, float scale);
+
+ public int getExampleWidth(float scale) {
+ return getWidth(scale);
+ }
+
+ public int getExampleHeight(float scale) {
+ return getHeight(scale);
+ }
+
+ public void drawAll(int x, int y, float scale) {
+ drawBackGround(x, y, scale);
+ draw(x, y, scale);
+ }
+
+ public void drawExampleAll(int x, int y, float scale) {
+ drawBackGround(x, y, scale);
+ drawExample(x, y, scale);
+ }
+
+ public void drawExample(int x, int y, float scale) {
+ draw(x, y, scale);
+ }
+
+ private void drawBackGround(int x, int y, float scale) {
+ Renderer.drawRoundRect(x - paddingX * scale / 2f, y - paddingY * scale / 2f,
+ getWidth(scale) + paddingX * scale, getHeight(scale) + paddingY * scale,
+ (2 * scale), new Color(0, 0, 0, 100).getRGB());
+ }
+}
diff --git a/src/main/java/io/polyfrost/oneconfig/hud/interfaces/TextHud.java b/src/main/java/io/polyfrost/oneconfig/hud/interfaces/TextHud.java
new file mode 100644
index 0000000..33bbd79
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/hud/interfaces/TextHud.java
@@ -0,0 +1,98 @@
+package io.polyfrost.oneconfig.hud.interfaces;
+
+import io.polyfrost.oneconfig.renderer.Renderer;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.FontRenderer;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+import net.minecraftforge.fml.common.gameevent.TickEvent;
+
+import java.util.List;
+
+public class TextHud extends BasicHud {
+ /**
+ * Currently doesn't work because of double extend, will have to be redone somehow (I have no idea how yet)
+ */
+ private final FontRenderer fb = Minecraft.getMinecraft().fontRendererObj;
+ boolean shadow = false;
+ private List<String> cachedLines;
+ private int cachedWidth;
+ private int cachedHeight;
+ boolean doExample = false;
+ private List<String> cachedExampleLines;
+ private int cachedExampleWidth;
+ private int cachedExampleHeight;
+
+ protected List<String> update() {
+ return null;
+ }
+
+ @SubscribeEvent
+ private void onTick(TickEvent.ClientTickEvent event) {
+ if (event.phase != TickEvent.Phase.START) return;
+ cachedLines = update();
+ if (cachedLines != null) {
+ cachedHeight = cachedLines.size() * (fb.FONT_HEIGHT + 3);
+ cachedWidth = 0;
+ for (String line : cachedLines) {
+ int width = fb.getStringWidth(line);
+ if (width > cachedWidth)
+ cachedWidth = width;
+ }
+ }
+ if (doExample) {
+ cachedExampleLines = updateExample();
+ if (cachedExampleLines != null) {
+ cachedExampleHeight = cachedExampleLines.size() * 12;
+ cachedExampleWidth = 0;
+ for (String line : cachedExampleLines) {
+ int width = fb.getStringWidth(line);
+ if (width > cachedExampleWidth)
+ cachedExampleWidth = width;
+ }
+ }
+ }
+ }
+
+ protected List<String> updateExample() {
+ return update();
+ }
+
+ @Override
+ public void draw(int x, int y, float scale) {
+ if (cachedLines != null)
+ drawText(cachedLines, x, y, scale);
+ }
+
+ @Override
+ public void drawExample(int x, int y, float scale) {
+ doExample = true;
+ if (cachedExampleLines != null)
+ drawText(cachedExampleLines, x, y, scale);
+ }
+
+ private void drawText(List<String> lines, int x, int y, float scale) {
+ for (int i = 0; i < lines.size(); i++) {
+ Renderer.drawTextScale(lines.get(i), x, y + i * 12, 0xffffff, shadow, scale);
+ }
+ }
+
+ @Override
+ public int getWidth(float scale) {
+ return (int) (cachedWidth * scale);
+ }
+
+ @Override
+ public int getHeight(float scale) {
+ return (int) (cachedHeight * scale);
+ }
+
+ @Override
+ public int getExampleWidth(float scale) {
+ return (int) (cachedExampleWidth * scale);
+ }
+
+ @Override
+ public int getExampleHeight(float scale) {
+ return (int) (cachedExampleHeight * scale);
+ }
+}
diff --git a/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java b/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java
index 012fdc8..8329bcc 100644
--- a/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java
+++ b/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java
@@ -18,8 +18,8 @@ public class Renderer extends Gui {
public static final Logger renderLog = LogManager.getLogger("OneConfig Renderer");
private static final Minecraft mc = Minecraft.getMinecraft();
private static final FontRenderer fr = mc.fontRendererObj;
- private static Tessellator tessellator = Tessellator.getInstance();
- private static WorldRenderer worldRenderer = tessellator.getWorldRenderer();
+ private static final Tessellator tessellator = Tessellator.getInstance();
+ private static final WorldRenderer worldRenderer = tessellator.getWorldRenderer();
public static void drawRectangle(int left, int top, int right, int bottom, int color) {
@@ -40,7 +40,7 @@ public class Renderer extends Gui {
Gui.drawScaledCustomSizeModalRect(x, y, 0, 0, targetX, targetY, targetX, targetY, targetX, targetY);
}
- public static void drawRegularPolygon(double x, double y, int radius, int sides, int color, double lowerAngle, double upperAngle) {
+ public static void drawRegularPolygon(double x, double y, float radius, int sides, int color, double lowerAngle, double upperAngle) {
GL11.glDisable(GL11.GL_TEXTURE_2D);
setGlColor(color);
GlStateManager.enableBlend();
@@ -68,27 +68,28 @@ public class Renderer extends Gui {
GL11.glEnable(GL11.GL_TEXTURE_2D);
}
- public static void drawRegularPolygon(double x, double y, int radius, int sides, int color) {
+ public static void drawRegularPolygon(double x, double y, float radius, int sides, int color) {
drawRegularPolygon(x, y, radius, sides, color, 0d, 10000d);
}
/**
* Draw a round rectangle at the given coordinates.
+ *
* @param radius radius of the corners
- * @param color color as a rgba integer
+ * @param color color as a rgba integer
*/
- public static void drawRoundRect(double x, double y, double width, double height, int radius, int color) {
+ public static void drawRoundRect(double x, double y, double width, double height, float radius, int color) {
GL11.glEnable(GL11.GL_BLEND);
//GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
- Gui.drawRect((int) x + radius, (int) y, (int) (x + width - radius), (int) (y + radius), color); // top
- Gui.drawRect((int) x + radius, (int) (y + height - radius), (int) (x + width - radius), (int) (y + height), color); // bottom
- Gui.drawRect((int) x, (int) y + radius, (int) (x + width), (int) (y + height - radius), color); // main
- drawRegularPolygon(x + radius, y + radius, radius, 80, color, 0d, 4.75d); // top left
- drawRegularPolygon(x + width - radius, y + radius, radius, 80, color, 7.8d, 10d); // top right
- drawRegularPolygon(x + radius, y + height - radius, radius, 80, color, 4.7d, 6.3d); // bottom left
- drawRegularPolygon(x + width - radius, y + height - radius, radius, 80, color, 6.25d, 7.9d); // bottom right
+ Gui.drawRect((int) (x + radius), (int) y, (int) (x + width - radius), (int) (y + radius), color); // top
+ Gui.drawRect((int) (x + radius), (int) (y + height - radius), (int) (x + width - radius), (int) (y + height), color); // bottom
+ Gui.drawRect((int) x, (int) (y + radius), (int) (x + width), (int) (y + height - radius), color); // main
+ drawRegularPolygon(x + radius - 0.5, y + radius - 0.5, radius, 80, color, 0d, 4.75d); // top left
+ drawRegularPolygon(x + width - radius - 0.5, y + radius - 0.5, radius, 80, color, 7.8d, 10d); // top right
+ drawRegularPolygon(x + radius - 0.5, y + height - radius - 0.5, radius, 80, color, 4.7d, 6.3d); // bottom left
+ drawRegularPolygon(x + width - radius - 0.5, y + height - radius - 0.5, radius, 80, color, 6.25d, 7.9d); // bottom right
GL11.glDisable(GL11.GL_BLEND);
- GL11.glColor4f(1f,1f,1f,1f);
+ GL11.glColor4f(1f, 1f, 1f, 1f);
}
public static float clamp(float number) {
@@ -131,7 +132,7 @@ public class Renderer extends Gui {
float f = (float) (color >> 16 & 255) / 255.0F;
float f2 = (float) (color & 255) / 255.0F;
float f3 = (float) (color >> 24 & 255) / 255.0F;
- GlStateManager.color(f,f1,f2,f3);
+ GlStateManager.color(f, f1, f2, f3);
}
}
diff --git a/src/main/java/io/polyfrost/oneconfig/test/TestConfig.java b/src/main/java/io/polyfrost/oneconfig/test/TestConfig.java
index 387d298..6de3dea 100644
--- a/src/main/java/io/polyfrost/oneconfig/test/TestConfig.java
+++ b/src/main/java/io/polyfrost/oneconfig/test/TestConfig.java
@@ -1,6 +1,7 @@
package io.polyfrost.oneconfig.test;
import io.polyfrost.oneconfig.config.annotations.Category;
+import io.polyfrost.oneconfig.config.annotations.HudComponent;
import io.polyfrost.oneconfig.config.annotations.Switch;
import io.polyfrost.oneconfig.config.annotations.TextField;
import io.polyfrost.oneconfig.config.data.ModData;
@@ -18,6 +19,9 @@ public class TestConfig extends Config {
public static String text = "Very cool text";
}
+ @HudComponent(name = "text hud")
+ public static TestHud testTextHud = new TestHud();
+
public TestConfig() {
super(new ModData("hacks", ModType.QOL, "ShadyDev", "1.0"), "hacksConfig.json");
}
diff --git a/src/main/java/io/polyfrost/oneconfig/test/TestHud.java b/src/main/java/io/polyfrost/oneconfig/test/TestHud.java
new file mode 100644
index 0000000..0ce2984
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/test/TestHud.java
@@ -0,0 +1,23 @@
+package io.polyfrost.oneconfig.test;
+
+import io.polyfrost.oneconfig.hud.interfaces.BasicHud;
+import io.polyfrost.oneconfig.renderer.Renderer;
+import net.minecraft.client.Minecraft;
+
+public class TestHud extends BasicHud {
+
+ @Override
+ public int getWidth(float scale) {
+ return (int) (Minecraft.getMinecraft().fontRendererObj.getStringWidth("FPS: " + Minecraft.getDebugFPS()) * scale);
+ }
+
+ @Override
+ public int getHeight(float scale) {
+ return (int) (9 * scale);
+ }
+
+ @Override
+ public void draw(int x, int y, float scale) {
+ Renderer.drawTextScale("FPS: " + Minecraft.getDebugFPS(), x, y, 0xffffff, false, scale);
+ }
+}