From 975826256806e19306987e05aa0e59f70d09b0b1 Mon Sep 17 00:00:00 2001 From: Wyvest <45589059+Wyvest@users.noreply.github.com> Date: Wed, 29 Jun 2022 16:10:18 +0700 Subject: unfinished stuff --- .../java/cc/polyfrost/oneconfig/hud/TextHud.java | 57 ++++++++++++---------- 1 file changed, 32 insertions(+), 25 deletions(-) (limited to 'src/main/java/cc/polyfrost/oneconfig/hud') diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java index 4a1a765..013debb 100644 --- a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java +++ b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java @@ -2,7 +2,9 @@ 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.config.elements.BasicOption; import cc.polyfrost.oneconfig.events.EventManager; import cc.polyfrost.oneconfig.events.event.Stage; import cc.polyfrost.oneconfig.events.event.TickEvent; @@ -10,6 +12,7 @@ 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 cc.polyfrost.oneconfig.utils.TickDelay; import java.util.ArrayList; import java.util.List; @@ -30,13 +33,37 @@ public abstract class TextHud extends Hud { ) public int textType = 0; - public TextHud(boolean enabled, int x, int y) { + @Switch( + name = "Cache Text" + ) + public boolean cacheText; + + public TextHud(boolean enabled, int x, int y, boolean caching) { super(enabled, x, y); - EventManager.INSTANCE.register(new TickHandler()); + cacheText = caching; + new TickDelay(() -> { + try { + BasicOption option = BasicOption.getOption(getClass().getField("cacheText")); + option.addHideCondition(() -> !caching); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } + }, 3); + if (caching) { + EventManager.INSTANCE.register(new TickHandler()); + } + } + + public TextHud() { + this(true); } public TextHud(boolean enabled) { - this(enabled, 0, 0); + this(enabled, true); + } + + public TextHud(boolean enabled, boolean caching) { + this(enabled, 0, 0, caching); } /** @@ -46,15 +73,6 @@ public abstract class TextHud extends Hud { */ protected abstract void getLines(List lines); - /** - * This function is called every frame - * - * @param lines The current lines of the hud - */ - protected void getLinesFrequent(List lines) { - - } - /** * This function is called every tick in the move GUI * @@ -64,21 +82,9 @@ public abstract class TextHud extends Hud { getLines(lines); } - /** - * This function is called every frame in the move GUI - * - * @param lines The current lines of the hud - */ - protected void getExampleLinesFrequent(List lines) { - getLinesFrequent(lines); - } - @Override public void draw(int x, int y, float scale) { - if (!HudCore.editing) getLinesFrequent(lines); - else getExampleLinesFrequent(lines); - if (lines == null) return; - +// todo int textY = y; width = 0; for (String line : lines) { @@ -103,6 +109,7 @@ public abstract class TextHud extends Hud { @Subscribe private void onTick(TickEvent event) { if (event.stage != Stage.START) return; + lines.clear(); if (!HudCore.editing) getLines(lines); else getExampleLines(lines); } -- cgit