aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/hud/interfaces/TextHud.java
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-05-03 18:25:32 +0200
committerDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-05-03 18:25:32 +0200
commita0ff501947a84b268e099524a06b56a6b900dad2 (patch)
treedb27ca1b28dbc7e57b8c99f54c80732d3042e856 /src/main/java/cc/polyfrost/oneconfig/hud/interfaces/TextHud.java
parentb798930b21b89b81be05a31281f768667a6dd7f3 (diff)
downloadOneConfig-a0ff501947a84b268e099524a06b56a6b900dad2.tar.gz
OneConfig-a0ff501947a84b268e099524a06b56a6b900dad2.tar.bz2
OneConfig-a0ff501947a84b268e099524a06b56a6b900dad2.zip
move to cc.polyfrost
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/hud/interfaces/TextHud.java')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/interfaces/TextHud.java94
1 files changed, 94 insertions, 0 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/interfaces/TextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/interfaces/TextHud.java
new file mode 100644
index 0000000..0027786
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/interfaces/TextHud.java
@@ -0,0 +1,94 @@
+package cc.polyfrost.oneconfig.hud.interfaces;
+
+import cc.polyfrost.oneconfig.lwjgl.RenderManager;
+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;
+ boolean doExample = false;
+ private List<String> cachedLines;
+ private int cachedWidth;
+ private int cachedHeight;
+ 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++) {
+ RenderManager.drawScaledString(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);
+ }
+}