diff --git a/src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java b/src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java index 18b14c4..1c86728 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java +++ b/src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java @@ -13,7 +13,6 @@ import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.option.KeyBinding; import net.minecraft.client.util.InputUtil; import net.minecraft.resource.LifecycledResourceManager; import net.minecraft.server.MinecraftServer; diff --git a/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHUD.java b/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHUD.java index 900c4ce..5643c84 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHUD.java +++ b/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHUD.java @@ -163,6 +163,7 @@ public void onInitializeClient() { ServerPlayConnectionEvents.DISCONNECT.register((handler, packetSender) -> GlobalConfig.HANDLER.save()); ClientLifecycleEvents.CLIENT_STOPPING.register((minecraftClient)->GlobalConfig.HANDLER.save()); + HudRenderCallback.EVENT.register(new HudRender()); } diff --git a/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHudIntegration.java b/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHudIntegration.java index 6018497..e28a507 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHudIntegration.java +++ b/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHudIntegration.java @@ -40,10 +40,10 @@ public interface DynamicHudIntegration { * The key binding for opening the editor screen. */ KeyBinding EDITOR_SCREEN_KEY_BINDING = KeyBindingHelper.registerKeyBinding(new KeyBinding( - TRANSLATION_KEY, - INPUT_TYPE, - KEY, - KEYBIND_CATEGORY + "DynamicHud Editor Screen", + InputUtil.Type.KEYSYM, + GLFW.GLFW_KEY_RIGHT_SHIFT, + "DynamicHud" )); /** diff --git a/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHudTestTwo.java b/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHudTestTwo.java deleted file mode 100644 index 82479c8..0000000 --- a/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHudTestTwo.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.tanishisherewith.dynamichud.newTrial; - -import com.tanishisherewith.dynamichud.newTrial.screens.AbstractMoveableScreen; -import com.tanishisherewith.dynamichud.newTrial.utils.DynamicValueRegistry; -import com.tanishisherewith.dynamichud.newTrial.widget.Widget; -import com.tanishisherewith.dynamichud.newTrial.widget.WidgetManager; -import com.tanishisherewith.dynamichud.newTrial.widget.WidgetRenderer; -import com.tanishisherewith.dynamichud.newTrial.widgets.TextWidget; -import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; -import net.minecraft.client.gui.screen.TitleScreen; -import net.minecraft.client.gui.screen.option.OptionsScreen; -import net.minecraft.client.option.KeyBinding; -import net.minecraft.text.Text; -import org.lwjgl.glfw.GLFW; - -import java.io.File; -import java.util.List; - -public class DynamicHudTestTwo implements DynamicHudIntegration { - TextWidget exampleWidget; - WidgetRenderer renderer; - - @Override - public void init() { - //Global registry - DynamicValueRegistry.registerGlobal("CPS", () -> "NOT FPS"); - - - exampleWidget = new TextWidget.Builder() - .setX(150) - .setY(100) - .setDraggable(true) - .rainbow(true) - .setDRKey("CPS") - .setModID("CustomMod") - .shouldScale(true) - .build(); - } - - @Override - public KeyBinding getKeyBind() { - return KeyBindingHelper.registerKeyBinding(new KeyBinding( - "DynamicHUD editor screenn", - INPUT_TYPE, - GLFW.GLFW_KEY_RIGHT_CONTROL, - "CATEGORY 2" - )); - } - - @Override - public File getWidgetsFile() { - return new File(FILE_DIRECTORY, "widgets_new.nbt"); - } - - @Override - public void addWidgets() { - WidgetManager.addWidget(exampleWidget); - } - - public void initAfter() { - List widgets = WidgetManager.getWidgetsForMod("CustomMod"); - - renderer = new WidgetRenderer(widgets); - renderer.shouldRenderInGameHud(true); - renderer.addScreen(OptionsScreen.class); - renderer.addScreen(TitleScreen.class); - } - - @Override - public AbstractMoveableScreen getMovableScreen() { - return new AbstractMoveableScreen(Text.literal("Editor 2"), renderer) { - }; - } - - @Override - public WidgetRenderer getWidgetRenderer() { - return renderer; - } - -} diff --git a/src/main/java/com/tanishisherewith/dynamichud/newTrial/utils/DynamicValueRegistry.java b/src/main/java/com/tanishisherewith/dynamichud/newTrial/utils/DynamicValueRegistry.java index 811ef62..6eee0ba 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/newTrial/utils/DynamicValueRegistry.java +++ b/src/main/java/com/tanishisherewith/dynamichud/newTrial/utils/DynamicValueRegistry.java @@ -13,7 +13,7 @@ *
  *     {@code
  *     DynamicValueRegistry dvr = new DynamicValueRegistry("mod_id");
- *     dvr.registerGlobal("ABC",//YourSupplier);
+ *     dvr.registerLocal("ABC",//YourSupplier);
  *     Supplier result = dvr.get("ABC");
  *     }
  * 
diff --git a/src/main/java/com/tanishisherewith/dynamichud/newTrial/utils/contextmenu/ContextMenu.java b/src/main/java/com/tanishisherewith/dynamichud/newTrial/utils/contextmenu/ContextMenu.java index 18086f9..1911b5d 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/newTrial/utils/contextmenu/ContextMenu.java +++ b/src/main/java/com/tanishisherewith/dynamichud/newTrial/utils/contextmenu/ContextMenu.java @@ -46,6 +46,7 @@ public void render(DrawContext drawContext, int x, int y, int height) { int yOffset = y1 + 3; this.width = 10; for (Option option : options) { + if(!option.shouldRender())continue; option.render(drawContext, x + 2, yOffset); this.width = Math.max(this.width, option.width + padding); yOffset += option.height + 1; diff --git a/src/main/java/com/tanishisherewith/dynamichud/newTrial/utils/contextmenu/Option.java b/src/main/java/com/tanishisherewith/dynamichud/newTrial/utils/contextmenu/Option.java index 676af06..8244df8 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/newTrial/utils/contextmenu/Option.java +++ b/src/main/java/com/tanishisherewith/dynamichud/newTrial/utils/contextmenu/Option.java @@ -18,6 +18,7 @@ public abstract class Option { protected T defaultValue = null; protected MinecraftClient mc = MinecraftClient.getInstance(); private Widget selectedWidget; // The widget that this context menu is associated with + public Supplier shouldRender = ()->true; public Option(Supplier getter, Consumer setter) { this.getter = getter; @@ -25,6 +26,13 @@ public Option(Supplier getter, Consumer setter) { value = get(); defaultValue = get(); } + public Option(Supplier getter, Consumer setter,Supplier shouldRender) { + this.getter = getter; + this.setter = setter; + this.shouldRender = shouldRender; + value = get(); + defaultValue = get(); + } protected T get() { return getter.get(); @@ -63,4 +71,13 @@ public void keyReleased(int key) { public boolean isMouseOver(double mouseX, double mouseY) { return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height; } + + public Option setShouldRender(Supplier shouldRender) { + this.shouldRender = shouldRender; + return this; + } + + public boolean shouldRender(){ + return shouldRender.get(); + } }