aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/Config.java4
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java58
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/Cacheable.java9
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java3
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/Hud.java102
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/MultiTextHud.java116
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java156
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java96
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java11
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/test/TestHud_Test.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/test/TestMultilineHud_Test.java6
11 files changed, 191 insertions, 372 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/Config.java
index f864d71..6ef9494 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/Config.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/Config.java
@@ -48,9 +48,7 @@ public class Config {
*/
public Config(Mod modData, String configFile, boolean initialize) {
this.configFile = configFile;
- if (initialize) {
- init(modData);
- }
+ if (initialize) init(modData);
}
/**
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java
index 8364afe..b13170a 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java
@@ -59,13 +59,12 @@ public class HudGui extends UScreen {
editingHud.yUnscaled = (yFloat + (hud.getHeight(hud.scale) + hud.paddingY * hud.scale)) / (double) this.height;
}
- int width = (int) (hud.getWidth(hud.scale) + hud.paddingX * hud.scale);
- int height = (int) (hud.getHeight(hud.scale) + hud.paddingY * hud.scale);
+ int width = (int) (hud.getExampleWidth(hud.scale) + hud.paddingX * hud.scale);
+ int height = (int) (hud.getExampleHeight(hud.scale) + hud.paddingY * hud.scale);
int x = (int) hud.getXScaled(this.width);
int y = (int) hud.getYScaled(this.height);
- if (hud.parent == null)
- hud.drawExampleAll(x, y, hud.scale, true);
+ hud.drawExampleAll(x, y, hud.scale, true);
int color = new Color(215, 224, 235).getRGB();
if (editingHud == hud) {
color = new Color(43, 159, 235).getRGB();
@@ -83,35 +82,12 @@ public class HudGui extends UScreen {
if (hud == editingHud && !isDragging) {
RenderManager.setupAndDraw(true, (vg) -> RenderManager.drawCircle(vg, x + width, y + height, 3, new Color(43, 159, 235).getRGB()));
}
-
- if (hud.childBottom != null) processHud(hud.childBottom, mouseX);
- if (hud.childRight != null) processHud(hud.childRight, mouseX);
}
private void setPosition(float newX, float newY, boolean snap) {
float width = editingHud.getWidth(editingHud.scale) + editingHud.paddingX * editingHud.scale;
float height = editingHud.getHeight(editingHud.scale) + editingHud.paddingY * editingHud.scale;
- /* Childing disabled since it still needs some extra work
- if (editingHud.childRight != null) {
- HudCore.huds.add(editingHud.childRight);
- editingHud.childRight.parent = null;
- editingHud.childRight = null;
- }
- if (editingHud.childBottom != null) {
- HudCore.huds.add(editingHud.childBottom);
- editingHud.childBottom.parent = null;
- editingHud.childBottom = null;
- }
- if (editingHud.parent != null) {
- HudCore.huds.add(editingHud);
- if (editingHud.parent.childBottom == editingHud)
- editingHud.parent.childBottom = null;
- else if (editingHud.parent.childRight == editingHud)
- editingHud.parent.childRight = null;
- editingHud.parent = null;
- }*/
-
if (newX < 0)
newX = 0;
else if (newX + width > this.width)
@@ -127,11 +103,6 @@ public class HudGui extends UScreen {
if (snapX != newX || snapY != newY) {
newX = snapX;
newY = snapY;
- for (Hud hud : HudCore.huds) {
- if (!hud.enabled) continue;
- if (findParent(hud, snapX, snapY))
- break;
- }
}
}
@@ -145,25 +116,6 @@ public class HudGui extends UScreen {
editingHud.yUnscaled = (newY + height) / (double) this.height;
}
- 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);
- int hudY = (int) hud.getYScaled(this.height);
- if (hudX + hudWidth == snapX && hudY == snapY && hud.childRight == null) {
- editingHud.parent = hud;
- hud.childRight = editingHud;
- HudCore.huds.remove(editingHud);
- return true;
- } else if (hudX == snapX && hudY + hudHeight == snapY && hud.childBottom == null) {
- editingHud.parent = hud;
- hud.childBottom = editingHud;
- HudCore.huds.remove(editingHud);
- return true;
- }
- return hud.childRight != null && findParent(hud.childRight, snapX, snapY) || hud.childBottom != null && findParent(hud.childBottom, snapX, snapY);
- }
-
private float getXSnapping(float pos, boolean rightOnly) {
float width = editingHud.getWidth(editingHud.scale) + editingHud.paddingX * editingHud.scale;
ArrayList<Float> verticalLines = new ArrayList<>();
@@ -196,7 +148,6 @@ public class HudGui extends UScreen {
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));
int hudWidth = (int) (hud.getWidth(hud.scale) + hud.paddingX * hud.scale);
int hudX = (int) hud.getXScaled(this.width);
verticalLines.add((float) hudX);
@@ -236,7 +187,6 @@ public class HudGui extends UScreen {
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));
int hudHeight = (int) (hud.getHeight(hud.scale) + hud.paddingY * hud.scale);
int hudY = (int) hud.getYScaled(this.height);
horizontalLines.add((float) hudY);
@@ -290,7 +240,7 @@ public class HudGui extends UScreen {
isDragging = true;
return true;
}
- return hud.childBottom != null && mouseClickedHud(hud.childBottom, mouseX, mouseY) || hud.childRight != null && mouseClickedHud(hud.childRight, mouseX, mouseY);
+ return false;
}
@Override
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/Cacheable.java b/src/main/java/cc/polyfrost/oneconfig/hud/Cacheable.java
deleted file mode 100644
index c4ff151..0000000
--- a/src/main/java/cc/polyfrost/oneconfig/hud/Cacheable.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package cc.polyfrost.oneconfig.hud;
-
-import cc.polyfrost.oneconfig.config.elements.BasicOption;
-
-import java.util.ArrayList;
-
-public interface Cacheable {
- void addCacheOptions(String category, String subcategory, ArrayList<BasicOption> options);
-}
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java b/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java
index babb810..e91a7ce 100644
--- a/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java
@@ -23,9 +23,6 @@ public class HUDUtils {
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));
- if (hud instanceof Cacheable) {
- ((Cacheable) hud).addCacheOptions(category, subcategory, options);
- }
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/Hud.java b/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java
index 61e960d..62cfb2e 100644
--- a/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java
@@ -1,14 +1,19 @@
package cc.polyfrost.oneconfig.hud;
+import cc.polyfrost.oneconfig.config.annotations.Switch;
import cc.polyfrost.oneconfig.config.core.OneColor;
+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 cc.polyfrost.oneconfig.config.Config;
+import net.minecraft.client.gui.GuiChat;
/**
* 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},
+ * If you simply want to display text, extend {@link TextHud} or {@link SingleTextHud},
* 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.
@@ -47,9 +52,6 @@ public abstract class Hud {
public float scale;
public float paddingX;
public float paddingY;
- public Hud parent;
- public Hud childRight;
- public Hud childBottom;
/**
* @param enabled If the hud is enabled
@@ -158,6 +160,13 @@ public abstract class Hud {
}
/**
+ * @return If the background should be drawn
+ */
+ public boolean drawBackground() {
+ return true;
+ }
+
+ /**
* Draw the background, the hud and all childed huds, used by HudCore
*
* @param x X-coordinate
@@ -166,12 +175,11 @@ public abstract class Hud {
* @param background If background should be drawn or not
*/
public void drawAll(float x, float y, float scale, boolean background) {
- if (background) drawBackground(x, y, getTotalWidth(scale), getTotalHeight(scale), scale);
+ if (!showInGuis && UScreen.getCurrentScreen() != null && !(UScreen.getCurrentScreen() instanceof OneConfigGui)) return;
+ if (!showInChat && UScreen.getCurrentScreen() instanceof GuiChat) return;
+ if (!showInDebug && UMinecraft.getSettings().showDebugInfo) return;
+ if (background && drawBackground()) drawBackground(x, y, getWidth(scale), getHeight(scale), scale);
draw((int) (x + paddingX * scale / 2f), (int) (y + paddingY * scale / 2f), scale);
- if (childRight != null)
- childRight.drawAll((int) x + paddingX * scale / 2f + getWidth(scale), (int) y, childRight.scale, false);
- if (childBottom != null)
- childBottom.drawAll((int) x, (int) y + paddingY * scale / 2f + getHeight(scale), childBottom.scale, false);
}
/**
@@ -183,12 +191,8 @@ public abstract class Hud {
* @param background If background should be drawn or not
*/
public void drawExampleAll(float x, float y, float scale, boolean background) {
- if (background) drawBackground(x, y, getTotalExampleWidth(scale), getTotalExampleHeight(scale), scale);
+ if (background) drawBackground(x, y, getWidth(scale), getHeight(scale), scale);
drawExample((int) (x + paddingX * scale / 2f), (int) (y + paddingY * scale / 2f), scale);
- if (childRight != null)
- childRight.drawExampleAll((int) x + paddingX * scale / 2f + getWidth(scale), (int) y, childRight.scale, false);
- if (childBottom != null)
- childBottom.drawExampleAll((int) x, (int) y + paddingY * scale / 2f + getHeight(scale), childBottom.scale, false);
}
/**
@@ -219,14 +223,8 @@ public abstract class Hud {
* @return X-coordinate of the hud
*/
public float getXScaled(int screenWidth) {
- if (parent != null && parent.childRight == this) {
- return parent.getXScaled(screenWidth) + parent.getWidth(parent.scale) + parent.paddingX * parent.scale / 2f;
- } else if (parent != null) {
- return parent.getXScaled(screenWidth);
- }
- if (xUnscaled <= 0.5) {
+ if (xUnscaled <= 0.5)
return (int) (screenWidth * xUnscaled);
- }
return (float) (screenWidth - (1d - xUnscaled) * screenWidth - (getWidth(scale) + paddingX * scale));
}
@@ -235,58 +233,22 @@ public abstract class Hud {
* @return Y-coordinate of the hud
*/
public float getYScaled(int screenHeight) {
- if (parent != null && parent.childBottom == this) {
- return parent.getYScaled(screenHeight) + parent.getHeight(parent.scale) + parent.paddingY * parent.scale / 2f;
- } else if (parent != null) {
- return parent.getYScaled(screenHeight);
- }
- if (yUnscaled <= 0.5) {
- return (int) (screenHeight * yUnscaled);
- }
+ if (yUnscaled <= 0.5) return (int) (screenHeight * yUnscaled);
return (float) (screenHeight - (1d - yUnscaled) * screenHeight - (getHeight(scale) + paddingY * scale));
}
- /**
- * @param scale Scale of the hud
- * @return The width of the hud and all childed huds
- */
- public float getTotalWidth(float scale) {
- float width = getWidth(scale);
- if (childRight != null) width += childRight.getTotalWidth(childRight.scale) + paddingY * scale / 2f;
- if (childBottom != null) width = Math.max(childBottom.getTotalWidth(childBottom.scale), width);
- return width;
- }
+ @Switch(
+ name = "Show in Chat"
+ )
+ public boolean showInChat = true;
- /**
- * @param scale Scale of the hud
- * @return The height of the hud and all childed huds
- */
- public float getTotalHeight(float scale) {
- float height = getHeight(scale);
- if (childBottom != null) height += childBottom.getTotalHeight(childBottom.scale) + paddingY * scale / 2f;
- if (childRight != null) height = Math.max(childRight.getTotalHeight(childRight.scale), height);
- return height;
- }
-
- /**
- * @param scale Scale of the hud
- * @return The example width of the hud and all childed huds
- */
- public float getTotalExampleWidth(float scale) {
- float width = getExampleWidth(scale);
- if (childRight != null) width += childRight.getTotalExampleWidth(childRight.scale) + paddingX * scale / 2f;
- if (childBottom != null) width = Math.max(childBottom.getTotalExampleWidth(childBottom.scale), width);
- return width;
- }
+ @Switch(
+ name = "Show in F3 (Debug)"
+ )
+ public boolean showInDebug = false;
- /**
- * @param scale Scale of the hud
- * @return The example height of the hud and all childed huds
- */
- public float getTotalExampleHeight(float scale) {
- float height = getExampleHeight(scale);
- if (childBottom != null) height += childBottom.getTotalExampleHeight(childBottom.scale) + paddingY * scale / 2f;
- if (childRight != null) height = Math.max(childRight.getTotalExampleHeight(childRight.scale), height);
- return height;
- }
+ @Switch(
+ name = "Show in GUIs"
+ )
+ public boolean showInGuis = true;
} \ No newline at end of file
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/MultiTextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/MultiTextHud.java
deleted file mode 100644
index 5dbff4c..0000000
--- a/src/main/java/cc/polyfrost/oneconfig/hud/MultiTextHud.java
+++ /dev/null
@@ -1,116 +0,0 @@
-package cc.polyfrost.oneconfig.hud;
-
-import cc.polyfrost.oneconfig.config.annotations.Exclude;
-import cc.polyfrost.oneconfig.config.elements.BasicOption;
-import cc.polyfrost.oneconfig.events.EventManager;
-import cc.polyfrost.oneconfig.events.event.Stage;
-import cc.polyfrost.oneconfig.events.event.TickEvent;
-import cc.polyfrost.oneconfig.gui.OneConfigGui;
-import cc.polyfrost.oneconfig.gui.elements.config.ConfigSwitch;
-import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
-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.ArrayList;
-import java.util.List;
-
-public abstract class MultiTextHud extends TextHud implements Cacheable {
- private transient int width = 100;
- private transient int height;
- private transient List<String> cachedStrings = null;
- private transient final boolean caching;
-
- public MultiTextHud(boolean enabled) {
- this(enabled, 0, 0);
- }
-
- public MultiTextHud(boolean enabled, boolean caching) {
- this(enabled, 0, 0, caching);
- }
-
- public MultiTextHud(boolean enabled, int x, int y) {
- this(enabled, x, y, true);
- }
-
- public MultiTextHud(boolean enabled, int x, int y, boolean caching) {
- super(enabled, x, y);
- this.caching = caching;
- if (caching) {
- EventManager.INSTANCE.register(new TextCacher());
- }
- }
-
- @Override
- public void addCacheOptions(String category, String subcategory, ArrayList<BasicOption> options) {
- if (caching) {
- try {
- System.out.println("AIJSIOJ!!");
- options.add(new ConfigSwitch(getClass().getField("cacheText"), this, "Cache Text", category, subcategory, 1));
- } catch (NoSuchFieldException e) {
- e.printStackTrace();
- }
- }
- }
-
- @Exclude(type = Exclude.ExcludeType.HUD)
- public boolean cacheText = true;
-
- @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 : cachedStrings == null ? getLines() : cachedStrings) {
- 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();
- }
-
- private class TextCacher {
- @Subscribe
- private void onTick(TickEvent event) {
- if (event.stage == Stage.START) {
- if (cacheText) {
- cachedStrings = getLines();
- } else {
- cachedStrings = null;
- }
- }
- }
- }
-}
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java
index f1a4125..2e32d8a 100644
--- a/src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java
@@ -1,113 +1,81 @@
package cc.polyfrost.oneconfig.hud;
import cc.polyfrost.oneconfig.config.annotations.Dropdown;
-import cc.polyfrost.oneconfig.config.annotations.Exclude;
import cc.polyfrost.oneconfig.config.annotations.Switch;
import cc.polyfrost.oneconfig.config.annotations.Text;
-import cc.polyfrost.oneconfig.config.elements.BasicOption;
-import cc.polyfrost.oneconfig.events.EventManager;
-import cc.polyfrost.oneconfig.events.event.Stage;
-import cc.polyfrost.oneconfig.events.event.TickEvent;
-import cc.polyfrost.oneconfig.gui.OneConfigGui;
-import cc.polyfrost.oneconfig.gui.elements.config.ConfigSwitch;
-import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
-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.ArrayList;
-
-public abstract class SingleTextHud extends TextHud implements Cacheable {
-
- private transient String cachedString = null;
- private transient final boolean caching;
-
- public SingleTextHud(String title) {
- this(title, true);
- }
+import java.util.Collections;
+import java.util.List;
+
+public abstract class SingleTextHud extends TextHud {
public SingleTextHud(String title, boolean enabled) {
this(title, enabled, 0, 0);
}
- public SingleTextHud(String title, boolean enabled, boolean caching) {
- this(title, enabled, 0, 0, caching);
- }
-
public SingleTextHud(String title, boolean enabled, int x, int y) {
- this(title, enabled, x, y, true);
- }
-
- public SingleTextHud(String title, boolean enabled, int x, int y, boolean caching) {
super(enabled, x, y);
this.title = title;
- this.caching = caching;
- if (caching) {
- EventManager.INSTANCE.register(new TextCacher());
- }
}
- @Override
- public void addCacheOptions(String category, String subcategory, ArrayList<BasicOption> options) {
- if (caching) {
- try {
- options.add(new ConfigSwitch(getClass().getField("cacheText"), this, "Cache Text", category, subcategory, 1));
- } catch (NoSuchFieldException e) {
- e.printStackTrace();
- }
- }
+ /**
+ * This function is called every tick
+ *
+ * @return The new text
+ */
+ protected abstract String getText();
+
+ /**
+ * This function is called every frame
+ *
+ * @return The new text, null to use the cached value
+ */
+ protected String getTextFrequent() {
+ return null;
}
- @Exclude(type = Exclude.ExcludeType.HUD)
- public boolean cacheText = true;
-
- @Switch(
- name = "Brackets"
- )
- public boolean brackets = false;
-
- @Text(
- name = "Title"
- )
- public String title;
-
- @Dropdown(
- name = "Title Location",
- options = {"Left", "Right"}
- )
- public int titleLocation = 0;
+ /**
+ * This function is called every tick in the move GUI
+ *
+ * @return The new text
+ */
+ protected String getExampleText() {
+ return getText();
+ }
- @Override
- public int getWidth(float scale) {
- return (int) (UMinecraft.getFontRenderer().getStringWidth(getCompleteText(false)) * scale);
+ /**
+ * This function is called every frame in the move GUI
+ *
+ * @return The new text, null to use the cached value
+ */
+ protected String getExampleTextFrequent() {
+ return getTextFrequent();
}
@Override
- public int getExampleWidth(float scale) {
- return (int) (UMinecraft.getFontRenderer().getStringWidth(getCompleteText(true)) * scale);
+ protected List<String> update() {
+ return Collections.singletonList(getCompleteText(getText()));
}
@Override
- public int getHeight(float scale) {
- return (int) (UMinecraft.getFontRenderer().FONT_HEIGHT * scale);
+ protected List<String> updateFrequent() {
+ String text = getTextFrequent();
+ if (text == null) return null;
+ return Collections.singletonList(getCompleteText(text));
}
@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);
+ protected List<String> updateExampleFrequent() {
+ String text = getExampleTextFrequent();
+ if (text == null) return null;
+ return Collections.singletonList(getCompleteText(text));
}
@Override
- public void drawExample(int x, int y, float scale) {
- RenderManager.drawScaledString(getCompleteText(true), x, y, color.getRGB(), RenderManager.TextType.toType(textType), scale);
+ protected List<String> updateExample() {
+ return Collections.singletonList(getCompleteText(getExampleText()));
}
- protected final String getCompleteText(boolean example) {
+ protected final String getCompleteText(String text) {
boolean showTitle = !title.trim().isEmpty();
StringBuilder builder = new StringBuilder();
if (brackets) {
@@ -118,7 +86,7 @@ public abstract class SingleTextHud extends TextHud implements Cacheable {
builder.append(title).append(": ");
}
- builder.append(example ? getExampleText() : (cachedString == null ? getText() : cachedString));
+ builder.append(text);
if (showTitle && titleLocation == 1) {
builder.append(" ").append(title);
@@ -130,22 +98,20 @@ public abstract class SingleTextHud extends TextHud implements Cacheable {
return builder.toString();
}
- public abstract String getText();
- public String getExampleText() {
- return getText();
- }
+ @Switch(
+ name = "Brackets"
+ )
+ public boolean brackets = false;
- private class TextCacher {
- @Subscribe
- private void onTick(TickEvent event) {
- if (event.stage == Stage.START) {
- if (cacheText) {
- cachedString = getText();
- } else {
- cachedString = null;
- }
- }
- }
- }
+ @Text(
+ name = "Title"
+ )
+ public String title;
+
+ @Dropdown(
+ name = "Title Location",
+ options = {"Left", "Right"}
+ )
+ public int titleLocation = 0;
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java
index 7a05ef7..7895f26 100644
--- a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java
@@ -2,38 +2,98 @@ package cc.polyfrost.oneconfig.hud;
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 cc.polyfrost.oneconfig.internal.hud.HudCore;
+import cc.polyfrost.oneconfig.libs.universal.UMinecraft;
+import cc.polyfrost.oneconfig.renderer.RenderManager;
+
+import java.util.List;
+
+public abstract class TextHud extends Hud {
+ protected transient List<String> lines = null;
+ private transient int width;
+ private transient int height;
-abstract class TextHud extends Hud {
@Color(
name = "Text Color"
)
public OneColor color = new OneColor(255, 255, 255);
- @Switch(
- name = "Show in Chat"
- )
- public boolean showInChat;
-
- @Switch(
- name = "Show in F3 (Debug)"
- )
- public boolean showInDebug;
-
- @Switch(
- name = "Show in GUIs"
- )
- public boolean showInGuis = true;
-
@Dropdown(
name = "Text Type",
options = {"No Shadow", "Shadow", "Full Shadow"}
)
public int textType = 0;
-
public TextHud(boolean enabled, int x, int y) {
super(enabled, x, y);
}
+ public TextHud(boolean enabled) {
+ this(enabled, 0, 0);
+ }
+
+ /**
+ * This function is called every tick
+ *
+ * @return The new lines
+ */
+ protected abstract List<String> update();
+
+ /**
+ * This function is called every frame
+ *
+ * @return The new lines, null if you want to use the cached lines
+ */
+ protected List<String> updateFrequent() {
+ return null;
+ }
+
+ /**
+ * This function is called every tick in the move GUI
+ *
+ * @return The new lines
+ */
+ protected List<String> updateExample() {
+ return update();
+ }
+
+ /**
+ * This function is called every frame in the move GUI
+ *
+ * @return The new lines, null if you want to use the cached lines
+ */
+ protected List<String> updateExampleFrequent() {
+ return updateFrequent();
+ }
+
+ @Override
+ public void draw(int x, int y, float scale) {
+ List<String> frequentLines = HudCore.editing ? updateExampleFrequent() : updateFrequent();
+ if (frequentLines != null) lines = frequentLines;
+ if (lines == null) return;
+
+ int textY = y;
+ width = 0;
+ for (String line : lines) {
+ 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 int getWidth(float scale) {
+ return (int) (width * scale);
+ }
+
+ @Override
+ public int getHeight(float scale) {
+ return (int) (height * scale);
+ }
+
+ public void tick() {
+ if (!HudCore.editing) lines = update();
+ else lines = updateExample();
+ }
}
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 2d92b3c..79bf4d8 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java
@@ -1,7 +1,9 @@
package cc.polyfrost.oneconfig.internal.hud;
import cc.polyfrost.oneconfig.events.event.HudRenderEvent;
+import cc.polyfrost.oneconfig.events.event.TickEvent;
import cc.polyfrost.oneconfig.hud.Hud;
+import cc.polyfrost.oneconfig.hud.TextHud;
import cc.polyfrost.oneconfig.libs.universal.UResolution;
import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
@@ -19,4 +21,13 @@ public class HudCore {
hud.drawAll(hud.getXScaled(UResolution.getScaledWidth()), hud.getYScaled(UResolution.getScaledHeight()), hud.scale, true);
}
}
+
+ @Subscribe
+ public void onTick(TickEvent event) {
+ for (Hud hud : huds) {
+ if (hud instanceof TextHud) {
+ ((TextHud) hud).tick();
+ }
+ }
+ }
}
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 d62f664..ae557c7 100644
--- a/src/main/java/cc/polyfrost/oneconfig/test/TestHud_Test.java
+++ b/src/main/java/cc/polyfrost/oneconfig/test/TestHud_Test.java
@@ -11,7 +11,7 @@ public class TestHud_Test extends SingleTextHud {
public boolean yes;
public TestHud_Test() {
- super("Time");
+ super("Time", true);
}
@Override
diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestMultilineHud_Test.java b/src/main/java/cc/polyfrost/oneconfig/test/TestMultilineHud_Test.java
index d3bad28..48ccfb2 100644
--- a/src/main/java/cc/polyfrost/oneconfig/test/TestMultilineHud_Test.java
+++ b/src/main/java/cc/polyfrost/oneconfig/test/TestMultilineHud_Test.java
@@ -1,18 +1,18 @@
package cc.polyfrost.oneconfig.test;
-import cc.polyfrost.oneconfig.hud.MultiTextHud;
+import cc.polyfrost.oneconfig.hud.TextHud;
import com.google.common.collect.Lists;
import net.minecraft.client.Minecraft;
import java.util.List;
-public class TestMultilineHud_Test extends MultiTextHud {
+public class TestMultilineHud_Test extends TextHud {
public TestMultilineHud_Test() {
super(true);
}
@Override
- public List<String> getLines() {
+ public List<String> update() {
return Lists.newArrayList(String.valueOf(System.currentTimeMillis()), String.valueOf(Minecraft.getSystemTime()));
}
}