aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-06-28 13:44:42 +0200
committerDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-06-28 13:44:42 +0200
commit20ff6a1eb88b88ca57a837fc0e68a8cc9437b864 (patch)
tree002bea0cc560754a0d7a2723efe8414b36ffbc05
parent9294eec079ae3268d50d4ad2c8769bf984dd18ca (diff)
downloadOneConfig-20ff6a1eb88b88ca57a837fc0e68a8cc9437b864.tar.gz
OneConfig-20ff6a1eb88b88ca57a837fc0e68a8cc9437b864.tar.bz2
OneConfig-20ff6a1eb88b88ca57a837fc0e68a8cc9437b864.zip
undo wyvest hud changes
-rw-r--r--gradle.properties2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/Conditional.java12
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java3
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/MultiTextHud.java120
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java159
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java86
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/test/TestMultilineHud_Test.java4
7 files changed, 146 insertions, 240 deletions
diff --git a/gradle.properties b/gradle.properties
index 350fe7a..0306eb1 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,6 +1,6 @@
mod_name = OneConfig
mod_id = oneconfig
-mod_version = 0.1.0-alpha35
+mod_version = 0.1.0-alpha36
essential.defaults.loom=0
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/Conditional.java b/src/main/java/cc/polyfrost/oneconfig/hud/Conditional.java
deleted file mode 100644
index d9f9ca9..0000000
--- a/src/main/java/cc/polyfrost/oneconfig/hud/Conditional.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package cc.polyfrost.oneconfig.hud;
-
-import cc.polyfrost.oneconfig.config.elements.BasicOption;
-
-import java.util.ArrayList;
-
-/**
- * Marks that the HUD element has options to add programmatically.
- */
-public interface Conditional {
- void addNewOptions(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 fb6f755..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 Conditional) {
- ((Conditional) hud).addNewOptions(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/MultiTextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/MultiTextHud.java
deleted file mode 100644
index 44bf789..0000000
--- a/src/main/java/cc/polyfrost/oneconfig/hud/MultiTextHud.java
+++ /dev/null
@@ -1,120 +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.elements.config.ConfigSwitch;
-import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
-import cc.polyfrost.oneconfig.libs.universal.UMinecraft;
-import cc.polyfrost.oneconfig.renderer.RenderManager;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public abstract class MultiTextHud extends TextHud implements Conditional {
- 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 final void addNewOptions(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();
- }
- }
- }
-
- @Exclude
- public boolean cacheText = true;
-
- @Override
- public final int getWidth(float scale) {
- return (int) (width * scale);
- }
-
- @Override
- public final int getHeight(float scale) {
- return (int) (height * scale);
- }
-
- @Override
- public final void draw(int x, int y, float scale) {
- update(x, y, scale);
- 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 final void drawExample(int x, int y, float scale) {
- update(x, y, 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);
- }
-
- protected abstract List<String> getLines();
-
- protected List<String> getExampleLines() {
- return getLines();
- }
-
- /**
- * Ran before the HUD is drawn.
- *
- * Can be used to update values but not necessarily process / render them.
- * This should only be used if absolutely necessary.
- */
- protected void update(int x, int y, float scale) {
-
- }
-
- 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 94bb496..7506c30 100644
--- a/src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java
@@ -1,108 +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.elements.config.ConfigSwitch;
-import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
-import cc.polyfrost.oneconfig.libs.universal.UMinecraft;
-import cc.polyfrost.oneconfig.renderer.RenderManager;
-import java.util.ArrayList;
-
-public abstract class SingleTextHud extends TextHud implements Conditional {
-
- 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 addNewOptions(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();
- }
- }
- }
-
- @Exclude
- public boolean cacheText = true;
-
- @Switch(
- name = "Brackets"
- )
- public boolean brackets = false;
+ /**
+ * This function is called every tick
+ *
+ * @return The new text
+ */
+ protected abstract String getText();
- @Text(
- name = "Title"
- )
- public String title;
+ /**
+ * This function is called every frame
+ *
+ * @return The new text, null to use the cached value
+ */
+ protected String getTextFrequent() {
+ return null;
+ }
- @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> getLines() {
+ return Collections.singletonList(getCompleteText(getText()));
}
@Override
- public int getHeight(float scale) {
- return (int) (UMinecraft.getFontRenderer().FONT_HEIGHT * scale);
+ protected List<String> getLinesFrequent() {
+ String text = getTextFrequent();
+ if (text == null) return null;
+ return Collections.singletonList(getCompleteText(text));
}
@Override
- public void draw(int x, int y, float scale) {
- update(x, y, scale);
- RenderManager.drawScaledString(getCompleteText(false), x, y, color.getRGB(), RenderManager.TextType.toType(textType), scale);
+ protected List<String> getExampleLines() {
+ return Collections.singletonList(getCompleteText(getExampleText()));
}
@Override
- public void drawExample(int x, int y, float scale) {
- update(x, y, scale);
- RenderManager.drawScaledString(getCompleteText(true), x, y, color.getRGB(), RenderManager.TextType.toType(textType), scale);
+ protected List<String> getExampleLinesFrequent() {
+ String text = getExampleTextFrequent();
+ if (text == null) return null;
+ return Collections.singletonList(getCompleteText(text));
}
- protected final String getCompleteText(boolean example) {
+ protected final String getCompleteText(String text) {
boolean showTitle = !title.trim().isEmpty();
StringBuilder builder = new StringBuilder();
if (brackets) {
@@ -113,7 +86,7 @@ public abstract class SingleTextHud extends TextHud implements Conditional {
builder.append(title).append(": ");
}
- builder.append(example ? getExampleText() : (cachedString == null ? getText() : cachedString));
+ builder.append(text);
if (showTitle && titleLocation == 1) {
builder.append(" ").append(title);
@@ -125,32 +98,20 @@ public abstract class SingleTextHud extends TextHud implements Conditional {
return builder.toString();
}
- public abstract String getText();
-
- public String getExampleText() {
- return getText();
- }
- /**
- * Ran before the HUD is drawn.
- *
- * Can be used to update values but not necessarily process / render them.
- * This should only be used if absolutely necessary.
- */
- protected void update(int x, int y, float scale) {
+ @Switch(
+ name = "Brackets"
+ )
+ public boolean brackets = false;
- }
+ @Text(
+ name = "Title"
+ )
+ public String title;
- private class TextCacher {
- @Subscribe
- private void onTick(TickEvent event) {
- if (event.stage == Stage.START) {
- if (cacheText) {
- cachedString = getText();
- } else {
- cachedString = null;
- }
- }
- }
- }
-}
+ @Dropdown(
+ name = "Title Location",
+ options = {"Left", "Right"}
+ )
+ public int titleLocation = 0;
+} \ No newline at end of file
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java
index 74a7602..a604b69 100644
--- a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java
@@ -3,8 +3,19 @@ package cc.polyfrost.oneconfig.hud;
import cc.polyfrost.oneconfig.config.annotations.Color;
import cc.polyfrost.oneconfig.config.annotations.Dropdown;
import cc.polyfrost.oneconfig.config.core.OneColor;
+import cc.polyfrost.oneconfig.events.event.TickEvent;
+import cc.polyfrost.oneconfig.internal.hud.HudCore;
+import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
+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"
)
@@ -16,8 +27,77 @@ abstract class TextHud extends Hud {
)
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> getLines();
+
+ /**
+ * This function is called every frame
+ *
+ * @return The new lines, null if you want to use the cached lines
+ */
+ protected List<String> getLinesFrequent() {
+ return null;
+ }
+
+ /**
+ * This function is called every tick in the move GUI
+ *
+ * @return The new lines
+ */
+ protected List<String> getExampleLines() {
+ return getLines();
+ }
+
+ /**
+ * 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> getExampleLinesFrequent() {
+ return getLinesFrequent();
+ }
+
+ @Override
+ public void draw(int x, int y, float scale) {
+ List<String> frequentLines = HudCore.editing ? getExampleLinesFrequent() : getLinesFrequent();
+ 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);
+ }
+
+ @Subscribe
+ public void onTick(TickEvent event) {
+ if (!HudCore.editing) lines = getLines();
+ else lines = getExampleLines();
+ }
+} \ No newline at end of file
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 c94f5f7..e7ba8af 100644
--- a/src/main/java/cc/polyfrost/oneconfig/test/TestMultilineHud_Test.java
+++ b/src/main/java/cc/polyfrost/oneconfig/test/TestMultilineHud_Test.java
@@ -1,12 +1,12 @@
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);
}