diff options
author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-06-29 16:10:18 +0700 |
---|---|---|
committer | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-06-29 16:10:43 +0700 |
commit | 975826256806e19306987e05aa0e59f70d09b0b1 (patch) | |
tree | de3f33b41cd63774b92c4075a051b12a4cb2d4d5 | |
parent | d4c12a8786597a38fe1a8e31b5be3835dffbb0c6 (diff) | |
download | OneConfig-975826256806e19306987e05aa0e59f70d09b0b1.tar.gz OneConfig-975826256806e19306987e05aa0e59f70d09b0b1.tar.bz2 OneConfig-975826256806e19306987e05aa0e59f70d09b0b1.zip |
unfinished stuff
5 files changed, 57 insertions, 30 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java b/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java index 86b339b..e3b3b16 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java @@ -2,6 +2,7 @@ package cc.polyfrost.oneconfig.config.elements; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.HashMap; import java.util.function.Supplier; @SuppressWarnings({"unused"}) @@ -16,6 +17,8 @@ public abstract class BasicOption { private final ArrayList<Runnable> listeners = new ArrayList<>(); private final ArrayList<Supplier<Boolean>> hideConditions = new ArrayList<>(); + private static final HashMap<Field, BasicOption> options = new HashMap<>(); + /** * Initialize option * @@ -31,7 +34,10 @@ public abstract class BasicOption { this.size = size; this.category = category; this.subcategory = subcategory; - if (field != null) field.setAccessible(true); + if (field != null) { + field.setAccessible(true); + options.put(field, this); + } } /** @@ -128,4 +134,8 @@ public abstract class BasicOption { public void addHideCondition(Supplier<Boolean> supplier) { this.hideConditions.add(supplier); } + + public static BasicOption getOption(Field field) { + return options.get(field); + } } 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); } /** @@ -47,15 +74,6 @@ public abstract class TextHud extends Hud { protected abstract void getLines(List<String> lines); /** - * This function is called every frame - * - * @param lines The current lines of the hud - */ - protected void getLinesFrequent(List<String> lines) { - - } - - /** * This function is called every tick in the move GUI * * @param lines The current lines of the hud @@ -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<String> 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); } diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/init/OneConfigInit.java b/src/main/java/cc/polyfrost/oneconfig/internal/init/OneConfigInit.java index 3d924ac..1f70815 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/init/OneConfigInit.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/init/OneConfigInit.java @@ -1,15 +1,11 @@ package cc.polyfrost.oneconfig.internal.init; -import net.minecraft.launchwrapper.Launch; -import org.spongepowered.asm.launch.MixinBootstrap; import org.spongepowered.asm.mixin.Mixins; @SuppressWarnings("unused") public class OneConfigInit { public static void initialize(String[] args) { - Launch.blackboard.put("oneconfig.initialized", true); - MixinBootstrap.init(); Mixins.addConfiguration("mixins.oneconfig.json"); } } diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/OneConfigTweaker.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/OneConfigTweaker.java index 8b822de..d302b9d 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/OneConfigTweaker.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/OneConfigTweaker.java @@ -71,6 +71,7 @@ public class OneConfigTweaker implements ITweaker { @Override public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) { + MixinBootstrap.init(); boolean captureNext = false; for (String arg : args) { if (captureNext) { diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/holder/Holder.java b/src/main/java/cc/polyfrost/oneconfig/utils/holder/Holder.java new file mode 100644 index 0000000..9488d4b --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/utils/holder/Holder.java @@ -0,0 +1,13 @@ +package cc.polyfrost.oneconfig.utils.holder; + +public abstract class Holder<T> { + protected T holder; + public Holder(T holder) { + this.holder = holder; + } + + + public abstract T getHolder() throws UnsupportedOperationException; + + public abstract void setHolder() throws UnsupportedOperationException; +} |