diff --git a/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHUD.java b/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHUD.java
index 53028db..8ac82e1 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHUD.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHUD.java
@@ -25,16 +25,16 @@
import java.util.List;
public class DynamicHUD implements ClientModInitializer {
- public static MinecraftClient MC = MinecraftClient.getInstance();
- public static String MOD_ID = "dynamichud";
- private static final Logger logger = LoggerFactory.getLogger("DynamicHud");
- private static final List widgetRenderers = new ArrayList<>();
/**
* This is a map to store the list of widgets for each widget file to be saved.
*
* Allows saving widgets across different mods with same save file name.
*/
- public static final HashMap> fileMap = new HashMap<>();
+ public static final HashMap> fileMap = new HashMap<>();
+ private static final Logger logger = LoggerFactory.getLogger("DynamicHud");
+ private static final List widgetRenderers = new ArrayList<>();
+ public static MinecraftClient MC = MinecraftClient.getInstance();
+ public static String MOD_ID = "dynamichud";
public static void addWidgetRenderer(WidgetRenderer widgetRenderer) {
widgetRenderers.add(widgetRenderer);
@@ -52,6 +52,18 @@ public static void printWarn(String msg) {
logger.warn(msg);
}
+ /**
+ * Opens the MovableScreen when the specified key is pressed.
+ *
+ * @param key The key to listen for
+ * @param screen The AbstractMoveableScreen instance to use to set the screen
+ */
+ public static void openDynamicScreen(KeyBinding key, AbstractMoveableScreen screen) {
+ if (key.wasPressed()) {
+ MC.setScreen(screen);
+ }
+ }
+
@Override
public void onInitializeClient() {
printInfo("Initialising DynamicHud");
@@ -67,62 +79,62 @@ public void onInitializeClient() {
FabricLoader.getInstance()
.getEntrypointContainers("dynamicHud", DynamicHudIntegration.class)
.forEach(entrypoint -> {
- ModMetadata metadata = entrypoint.getProvider().getMetadata();
- String modId = metadata.getId();
- AbstractMoveableScreen screen;
- try {
- DynamicHudIntegration DHIntegration = entrypoint.getEntrypoint();
- DHIntegration.init();
-
- File widgetsFile = DHIntegration.getWidgetsFile();
-
- if(widgetsFile.exists()) {
- WidgetManager.loadWidgets(widgetsFile);
- }else{
- DHIntegration.addWidgets();
- }
- DHIntegration.initAfter();
-
- screen = DHIntegration.getMovableScreen();
-
- KeyBinding binding = DHIntegration.getKeyBind();
-
- DHIntegration.registerCustomWidgets();
-
- WidgetRenderer widgetRenderer = DHIntegration.getWidgetRenderer();
- addWidgetRenderer(widgetRenderer);
-
- List widgets = fileMap.get(widgetsFile.getName());
-
- if(widgets == null) {
- fileMap.put(widgetsFile.getName(), widgetRenderer.getWidgets());
- }else{
- widgetRenderer.getWidgets().addAll(widgets);
- fileMap.put(widgetsFile.getName(), widgetRenderer.getWidgets());
- }
-
- //Register events for rendering, saving, loading, and opening the hudEditor
- ClientTickEvents.START_CLIENT_TICK.register((client)-> {
- openDynamicScreen(binding, screen);
+ ModMetadata metadata = entrypoint.getProvider().getMetadata();
+ String modId = metadata.getId();
+ AbstractMoveableScreen screen;
+ try {
+ DynamicHudIntegration DHIntegration = entrypoint.getEntrypoint();
+ DHIntegration.init();
+
+ File widgetsFile = DHIntegration.getWidgetsFile();
+
+ if (widgetsFile.exists()) {
+ WidgetManager.loadWidgets(widgetsFile);
+ } else {
+ DHIntegration.addWidgets();
+ }
+ DHIntegration.initAfter();
+
+ screen = DHIntegration.getMovableScreen();
+
+ KeyBinding binding = DHIntegration.getKeyBind();
+
+ DHIntegration.registerCustomWidgets();
+
+ WidgetRenderer widgetRenderer = DHIntegration.getWidgetRenderer();
+ addWidgetRenderer(widgetRenderer);
+
+ List widgets = fileMap.get(widgetsFile.getName());
+
+ if (widgets == null) {
+ fileMap.put(widgetsFile.getName(), widgetRenderer.getWidgets());
+ } else {
+ widgetRenderer.getWidgets().addAll(widgets);
+ fileMap.put(widgetsFile.getName(), widgetRenderer.getWidgets());
+ }
+
+ //Register events for rendering, saving, loading, and opening the hudEditor
+ ClientTickEvents.START_CLIENT_TICK.register((client) -> {
+ openDynamicScreen(binding, screen);
+ });
+
+ // Save during exiting a world, server or Minecraft itself
+ // Also saved when a resource pack is reloaded.
+ ServerLifecycleEvents.SERVER_STOPPING.register(server -> saveWidgetsSafely(widgetsFile, fileMap.get(widgetsFile.getName())));
+ ServerLifecycleEvents.END_DATA_PACK_RELOAD.register((server, resourceManager, s) -> saveWidgetsSafely(widgetsFile, fileMap.get(widgetsFile.getName())));
+ ServerPlayConnectionEvents.DISCONNECT.register((handler, packetSender) -> saveWidgetsSafely(widgetsFile, fileMap.get(widgetsFile.getName())));
+ Runtime.getRuntime().addShutdownHook(new Thread(() -> saveWidgetsSafely(widgetsFile, fileMap.get(widgetsFile.getName()))));
+
+ printInfo(String.format("Integration of mod %s was successful", modId));
+ } catch (Throwable e) {
+ if (e instanceof IOException) {
+ logger.warn("An error has occurred while loading widgets of mod {}", modId, e);
+ } else {
+ logger.warn("Mod {} has incorrect implementation of DynamicHUD", modId, e);
+ }
+ }
});
- // Save during exiting a world, server or Minecraft itself
- // Also saved when a resource pack is reloaded.
- ServerLifecycleEvents.SERVER_STOPPING.register(server -> saveWidgetsSafely(widgetsFile,fileMap.get(widgetsFile.getName())));
- ServerLifecycleEvents.END_DATA_PACK_RELOAD.register((server, resourceManager, s) -> saveWidgetsSafely(widgetsFile,fileMap.get(widgetsFile.getName())));
- ServerPlayConnectionEvents.DISCONNECT.register((handler, packetSender) -> saveWidgetsSafely(widgetsFile,fileMap.get(widgetsFile.getName())));
- Runtime.getRuntime().addShutdownHook(new Thread(() -> saveWidgetsSafely(widgetsFile,fileMap.get(widgetsFile.getName()))));
-
- printInfo(String.format("Integration of mod %s was successful",modId));
- } catch (Throwable e) {
- if(e instanceof IOException){
- logger.warn("An error has occurred while loading widgets of mod {}", modId,e);
- }else {
- logger.warn("Mod {} has incorrect implementation of DynamicHUD", modId, e);
- }
- }
- });
-
ServerLifecycleEvents.SERVER_STOPPING.register(server -> GlobalConfig.HANDLER.save());
ServerLifecycleEvents.END_DATA_PACK_RELOAD.register((server, resourceManager, s) -> GlobalConfig.HANDLER.save());
ServerPlayConnectionEvents.DISCONNECT.register((handler, packetSender) -> GlobalConfig.HANDLER.save());
@@ -131,24 +143,14 @@ public void onInitializeClient() {
HudRenderCallback.EVENT.register(new HudRender());
}
+
private void saveWidgetsSafely(File widgetsFile, List widgets) {
try {
- WidgetManager.saveWidgets(widgetsFile,widgets);
+ WidgetManager.saveWidgets(widgetsFile, widgets);
} catch (IOException e) {
logger.error("Failed to save widgets. Widgets passed: {}", widgets);
throw new RuntimeException(e);
}
}
- /**
- * Opens the MovableScreen when the specified key is pressed.
- *
- * @param key The key to listen for
- * @param screen The AbstractMoveableScreen instance to use to set the screen
- */
- public static void openDynamicScreen(KeyBinding key, AbstractMoveableScreen screen) {
- if (key.wasPressed()) {
- MC.setScreen(screen);
- }
- }
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHudIntegration.java b/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHudIntegration.java
index 6e76760..1a7ef92 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHudIntegration.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHudIntegration.java
@@ -63,7 +63,7 @@ public interface DynamicHudIntegration {
/**
* Initializes the DynamicHud integration.
*
- * Suggested to be used to initialize {@link com.tanishisherewith.dynamichud.newTrial.utils.DynamicValueRegistry} and widgets with their respective values
+ * Suggested to be used to initialize {@link com.tanishisherewith.dynamichud.newTrial.utils.DynamicValueRegistry} and widgets with their respective values
*
*/
void init();
@@ -76,15 +76,17 @@ public interface DynamicHudIntegration {
/**
* To register custom widgets. This method can be overridden by implementations.
*/
- default void registerCustomWidgets(){}
+ default void registerCustomWidgets() {
+ }
/**
* Performs any necessary initialization after the widgets have been added. This method can be overridden by implementations.
*
- * Suggested to be used to initialize a {@link WidgetRenderer} object with the added widgets.
+ * Suggested to be used to initialize a {@link WidgetRenderer} object with the added widgets.
*
*/
- default void initAfter(){}
+ default void initAfter() {
+ }
/**
* Returns the file where widgets are to be saved and loaded from.
@@ -94,6 +96,7 @@ default void initAfter(){}
default File getWidgetsFile() {
return WIDGETS_FILE;
}
+
/**
* Returns the keybind to open the {@link AbstractMoveableScreen} instance.
*
@@ -116,7 +119,7 @@ default KeyBinding getKeyBind() {
*
* @return The widget renderer.
*/
- default WidgetRenderer getWidgetRenderer(){
+ default WidgetRenderer getWidgetRenderer() {
return new WidgetRenderer(WidgetManager.getWidgets());
}
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHudTest.java b/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHudTest.java
index ff97576..9c4a431 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHudTest.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHudTest.java
@@ -17,16 +17,17 @@ public class DynamicHudTest implements DynamicHudIntegration {
TextWidget Example2Widget;
DynamicValueRegistry registry;
WidgetRenderer renderer;
+
@Override
public void init() {
//Global registry
- DynamicValueRegistry.registerGlobal("FPS",() -> "FPS: "+ DynamicHUD.MC.getCurrentFps());
+ DynamicValueRegistry.registerGlobal("FPS", () -> "FPS: " + DynamicHUD.MC.getCurrentFps());
//Local registry
registry = new DynamicValueRegistry(DynamicHUD.MOD_ID);
- registry.registerLocal("FPS",()-> "FPS C-DVR: "+ DynamicHUD.MC.getCurrentFps());
+ registry.registerLocal("FPS", () -> "FPS C-DVR: " + DynamicHUD.MC.getCurrentFps());
- textWidget = new TextWidget.Builder()
+ textWidget = new TextWidget.Builder()
.setX(300)
.setY(100)
.setDraggable(true)
@@ -36,7 +37,7 @@ public void init() {
.shouldScale(false)
.build();
- Example2Widget = new TextWidget.Builder()
+ Example2Widget = new TextWidget.Builder()
.setX(200)
.setY(100)
.setDraggable(true)
@@ -53,7 +54,8 @@ public void addWidgets() {
WidgetManager.addWidget(textWidget);
WidgetManager.addWidget(Example2Widget);
}
- public void initAfter(){
+
+ public void initAfter() {
List widgets = WidgetManager.getWidgetsForMod(DynamicHUD.MOD_ID);
renderer = new WidgetRenderer(widgets);
@@ -64,7 +66,8 @@ public void initAfter(){
@Override
public AbstractMoveableScreen getMovableScreen() {
- return new AbstractMoveableScreen(Text.literal("Editor"), renderer) {};
+ return new AbstractMoveableScreen(Text.literal("Editor"), renderer) {
+ };
}
@Override
diff --git a/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHudTestTWO.java b/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHudTestTWO.java
index a449c5e..9615f2c 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHudTestTWO.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/newTrial/DynamicHudTestTWO.java
@@ -2,19 +2,16 @@
import com.tanishisherewith.dynamichud.newTrial.screens.AbstractMoveableScreen;
import com.tanishisherewith.dynamichud.newTrial.utils.DynamicValueRegistry;
-import com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.Option;
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.multiplayer.MultiplayerScreen;
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 org.lwjgl.opengl.GL;
import java.io.File;
import java.util.List;
@@ -22,10 +19,11 @@
public class DynamicHudTestTWO implements DynamicHudIntegration {
TextWidget exampleWidget;
WidgetRenderer renderer;
+
@Override
public void init() {
//Global registry
- DynamicValueRegistry.registerGlobal("CPS",() -> "NOT FPS");
+ DynamicValueRegistry.registerGlobal("CPS", () -> "NOT FPS");
exampleWidget = new TextWidget.Builder()
@@ -51,14 +49,15 @@ public KeyBinding getKeyBind() {
@Override
public File getWidgetsFile() {
- return new File(FILE_DIRECTORY,"widgets_new.nbt");
+ return new File(FILE_DIRECTORY, "widgets_new.nbt");
}
@Override
public void addWidgets() {
WidgetManager.addWidget(exampleWidget);
}
- public void initAfter(){
+
+ public void initAfter() {
List widgets = WidgetManager.getWidgetsForMod("CustomMod");
renderer = new WidgetRenderer(widgets);
@@ -69,7 +68,8 @@ public void initAfter(){
@Override
public AbstractMoveableScreen getMovableScreen() {
- return new AbstractMoveableScreen(Text.literal("Editor 2"), renderer) {};
+ return new AbstractMoveableScreen(Text.literal("Editor 2"), renderer) {
+ };
}
@Override
diff --git a/src/main/java/com/tanishisherewith/dynamichud/newTrial/HudRender.java b/src/main/java/com/tanishisherewith/dynamichud/newTrial/HudRender.java
index bd842b0..48a7014 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/newTrial/HudRender.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/newTrial/HudRender.java
@@ -7,8 +7,8 @@
public class HudRender implements HudRenderCallback {
@Override
public void onHudRender(DrawContext drawContext, float tickDelta) {
- for(WidgetRenderer widgetRenderer: DynamicHUD.getWidgetRenderers()){
- widgetRenderer.renderWidgets(drawContext,-120,-120);
+ for (WidgetRenderer widgetRenderer : DynamicHUD.getWidgetRenderers()) {
+ widgetRenderer.renderWidgets(drawContext, -120, -120);
}
}
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/newTrial/config/GlobalConfig.java b/src/main/java/com/tanishisherewith/dynamichud/newTrial/config/GlobalConfig.java
index e59ad0c..64a97f7 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/newTrial/config/GlobalConfig.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/newTrial/config/GlobalConfig.java
@@ -11,7 +11,6 @@
import net.minecraft.util.Identifier;
public class GlobalConfig {
- private static GlobalConfig INSTANCE = new GlobalConfig();
public static ConfigClassHandler HANDLER = ConfigClassHandler.createBuilder(GlobalConfig.class)
.id(new Identifier("dynamichud", "dynamichud_config"))
.serializer(config -> GsonConfigSerializerBuilder.create(config)
@@ -19,15 +18,19 @@ public class GlobalConfig {
.setJson5(true)
.build())
.build();
-
+ private static final GlobalConfig INSTANCE = new GlobalConfig();
/**
* Common scale for all widgets. Set by the user using YACL.
*/
@SerialEntry
public float scale = 1.0f;
+ public static GlobalConfig get() {
+ return INSTANCE;
+ }
+
public Screen createYACLGUI() {
- return YetAnotherConfigLib.createBuilder()
+ return YetAnotherConfigLib.createBuilder()
.title(Text.literal("DynamicHUD config screen."))
.category(ConfigCategory.createBuilder()
.name(Text.literal("General"))
@@ -39,14 +42,11 @@ public Screen createYACLGUI() {
.name(Text.literal("Scale"))
.description(OptionDescription.of(Text.literal("Set scale for all widgets.")))
.binding(1.0f, () -> this.scale, newVal -> this.scale = newVal)
- .controller(floatOption -> FloatSliderControllerBuilder.create(floatOption).range(0.1f,2.5f).step(0.1f))
+ .controller(floatOption -> FloatSliderControllerBuilder.create(floatOption).range(0.1f, 2.5f).step(0.1f))
.build())
.build())
.build())
.build()
.generateScreen(null);
}
- public static GlobalConfig get(){
- return INSTANCE;
- }
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/newTrial/helpers/ColorHelper.java b/src/main/java/com/tanishisherewith/dynamichud/newTrial/helpers/ColorHelper.java
index 8a35f38..7426687 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/newTrial/helpers/ColorHelper.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/newTrial/helpers/ColorHelper.java
@@ -9,28 +9,18 @@
*/
public class ColorHelper {
public static int r, g, b, a;
+
public ColorHelper(int r, int g, int b) {
- this.r = r;
- this.g = g;
- this.b = b;
- this.a = 255;
+ ColorHelper.r = r;
+ ColorHelper.g = g;
+ ColorHelper.b = b;
+ a = 255;
validate();
}
+
public ColorHelper() {
}
- public void validate() {
- if (r < 0) r = 0;
- else if (r > 255) r = 255;
-
- if (g < 0) g = 0;
- else if (g > 255) g = 255;
- if (b < 0) b = 0;
- else if (b > 255) b = 255;
-
- if (a < 0) a = 0;
- else if (a > 255) a = 255;
- }
/**
* Returns a color as an integer value given its red, green and blue components.
*
@@ -82,10 +72,10 @@ public static int getColorFromHue(float hue) {
public static int ColorToInt(Color color) {
return color.getRGB();
}
- public static float[] getRainbowColor()
- {
+
+ public static float[] getRainbowColor() {
float x = System.currentTimeMillis() % 2000 / 1000F;
- float pi = (float)Math.PI;
+ float pi = (float) Math.PI;
float[] rainbow = new float[3];
rainbow[0] = 0.5F + 0.5F * MathHelper.sin(x * pi);
@@ -105,7 +95,6 @@ public static Color getRainbowColor(int speed) {
return Color.getHSBColor(hue, 1.0f, 1.0f);
}
-
/**
* Changes alpha on color.
*
@@ -119,6 +108,7 @@ public static Color changeAlpha(Color color, int alpha) {
else
return new Color(0);
}
+
public static int fromRGBA(int r, int g, int b, int a) {
return (r << 16) + (g << 8) + (b) + (a << 24);
}
@@ -138,8 +128,22 @@ public static int toRGBAB(int color) {
public static int toRGBAA(int color) {
return (color >> 24) & 0x000000FF;
}
- public int toInt()
- {
- return new Color(r,b,g,a).getRGB();
+
+ public void validate() {
+ if (r < 0) r = 0;
+ else if (r > 255) r = 255;
+
+ if (g < 0) g = 0;
+ else if (g > 255) g = 255;
+
+ if (b < 0) b = 0;
+ else if (b > 255) b = 255;
+
+ if (a < 0) a = 0;
+ else if (a > 255) a = 255;
+ }
+
+ public int toInt() {
+ return new Color(r, b, g, a).getRGB();
}
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/newTrial/helpers/DrawHelper.java b/src/main/java/com/tanishisherewith/dynamichud/newTrial/helpers/DrawHelper.java
index d036afd..ea1d60f 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/newTrial/helpers/DrawHelper.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/newTrial/helpers/DrawHelper.java
@@ -281,6 +281,7 @@ public static void drawRainbowGradient(Matrix4f matrix, float x, float y, float
/* ==== Drawing filled and outline circles ==== */
+
/**
* Draws an outline of a circle
*
@@ -783,10 +784,6 @@ public static void drawHorizontalLine(Matrix4f matrix4f, float x1, float width,
drawRectangle(matrix4f, x1, y, width, thickness, color);
}
- public enum Direction {
- /* LEFT_RIGHT means from left to right. Same for others */
- LEFT_RIGHT, TOP_BOTTOM, RIGHT_LEFT, BOTTOM_TOP
- }
/**
* Draws an outlined box on the screen.
*
@@ -805,8 +802,9 @@ public static void drawOutlinedBox(DrawContext drawContext, int x1, int y1, int
/**
* This method assumes that the x, y coords are the origin of a widget.
- * @param x X position of widget
- * @param y Y position of widget
+ *
+ * @param x X position of widget
+ * @param y Y position of widget
* @param scale Scale the matrices
*/
public static void scaleAndPosition(MatrixStack matrices, float x, float y, float scale) {
@@ -818,17 +816,19 @@ public static void scaleAndPosition(MatrixStack matrices, float x, float y, floa
// Scale the matrix
matrices.scale(scale, scale, 1.0F);
- matrices.translate(-x,-y,0);
+ matrices.translate(-x, -y, 0);
}
+
/**
* This method scales the matrices by the centre of the widget
- * @param x X position of widget
- * @param y Y position of widget
+ *
+ * @param x X position of widget
+ * @param y Y position of widget
* @param height height of widget
- * @param width width of widget
- * @param scale Scale the matrices
+ * @param width width of widget
+ * @param scale Scale the matrices
*/
- public static void scaleAndPosition(MatrixStack matrices, float x, float y,float width, float height, float scale) {
+ public static void scaleAndPosition(MatrixStack matrices, float x, float y, float width, float height, float scale) {
matrices.push(); // Save the current transformation state
// Translate the origin back to the desired position
@@ -840,8 +840,13 @@ public static void scaleAndPosition(MatrixStack matrices, float x, float y,float
matrices.translate(-(x + width / 2.0f), -(y + height / 2.0f), 0);
}
- public static void stopScaling(MatrixStack matrices){
+ public static void stopScaling(MatrixStack matrices) {
matrices.pop(); // Restore the previous transformation state
}
+ public enum Direction {
+ /* LEFT_RIGHT means from left to right. Same for others */
+ LEFT_RIGHT, TOP_BOTTOM, RIGHT_LEFT, BOTTOM_TOP
+ }
+
}
\ No newline at end of file
diff --git a/src/main/java/com/tanishisherewith/dynamichud/newTrial/helpers/TextureHelper.java b/src/main/java/com/tanishisherewith/dynamichud/newTrial/helpers/TextureHelper.java
index 37c36c6..f73aaae 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/newTrial/helpers/TextureHelper.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/newTrial/helpers/TextureHelper.java
@@ -202,7 +202,7 @@ public static void drawItemTextureWithTextAndScale(DrawContext drawContext,
drawContext.getMatrices().scale(textScale, textScale, 11.0f);
float scaledX = textX / textScale;
float scaledY = textY / textScale;
- drawContext.drawText(textRenderer, text, (int) scaledX + 1, (int) scaledY +1, color, false);
+ drawContext.drawText(textRenderer, text, (int) scaledX + 1, (int) scaledY + 1, color, false);
drawContext.getMatrices().pop();
}
customItemRenderer = new CustomItemRenderer(itemStack, itemScale);
diff --git a/src/main/java/com/tanishisherewith/dynamichud/newTrial/screens/AbstractMoveableScreen.java b/src/main/java/com/tanishisherewith/dynamichud/newTrial/screens/AbstractMoveableScreen.java
index ef22c98..72194f5 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/newTrial/screens/AbstractMoveableScreen.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/newTrial/screens/AbstractMoveableScreen.java
@@ -6,13 +6,12 @@
import net.minecraft.text.Text;
public abstract class AbstractMoveableScreen extends Screen {
- protected boolean shouldPause = false; // To pause if the screen is opened or not
public final WidgetRenderer widgetRenderer;
public int snapSize = 100;
+ protected boolean shouldPause = false; // To pause if the screen is opened or not
/**
* Constructs a AbstractMoveableScreen object.
- *
*/
public AbstractMoveableScreen(Text title, WidgetRenderer renderer) {
super(title);
@@ -21,19 +20,19 @@ public AbstractMoveableScreen(Text title, WidgetRenderer renderer) {
@Override
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
- widgetRenderer.mouseDragged(mouseX,mouseY,button, snapSize);
+ widgetRenderer.mouseDragged(mouseX, mouseY, button, snapSize);
return false;
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
- widgetRenderer.mouseClicked(mouseX,mouseY,button);
+ widgetRenderer.mouseClicked(mouseX, mouseY, button);
return false;
}
@Override
public boolean mouseReleased(double mouseX, double mouseY, int button) {
- widgetRenderer.mouseReleased(mouseX,mouseY,button);
+ widgetRenderer.mouseReleased(mouseX, mouseY, button);
return false;
}
@@ -51,7 +50,7 @@ public boolean keyReleased(int keyCode, int scanCode, int modifiers) {
@Override
public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
- widgetRenderer.mouseScrolled(mouseX,mouseY,verticalAmount,horizontalAmount);
+ widgetRenderer.mouseScrolled(mouseX, mouseY, verticalAmount, horizontalAmount);
return super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount);
}
@@ -65,12 +64,12 @@ public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmou
*/
@Override
public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) {
- if(this.client.world == null) {
+ if (this.client.world == null) {
this.renderBackgroundTexture(drawContext);
}
// Draw each widget
widgetRenderer.isInEditor = true;
- widgetRenderer.renderWidgets(drawContext,mouseX,mouseY);
+ widgetRenderer.renderWidgets(drawContext, mouseX, mouseY);
}
@Override
@@ -88,7 +87,8 @@ public void setShouldPause(boolean shouldPause) {
public boolean shouldPause() {
return shouldPause;
}
- public void setSnapSize(int size){
+
+ public void setSnapSize(int size) {
this.snapSize = size;
}
}
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 393a969..811ef62 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/newTrial/utils/DynamicValueRegistry.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/newTrial/utils/DynamicValueRegistry.java
@@ -1,6 +1,8 @@
package com.tanishisherewith.dynamichud.newTrial.utils;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
import java.util.function.Supplier;
/**
@@ -20,12 +22,14 @@
public class DynamicValueRegistry extends System {
/**
* A map that holds the global registry of suppliers.
+ *
* @see #localRegistry
*/
private static final Map> globalRegistry = new HashMap<>();
/**
* A map that holds the local registry of suppliers.
+ *
* @see #globalRegistry
*/
private final Map> localRegistry = new HashMap<>();
@@ -43,23 +47,13 @@ public DynamicValueRegistry(String modId) {
/**
* Registers a supplier in the global registry.
*
- * @param key The key under which the supplier is to be registered.
+ * @param key The key under which the supplier is to be registered.
* @param supplier The supplier to be registered.
*/
public static void registerGlobal(String key, Supplier> supplier) {
globalRegistry.put(key, supplier);
}
- /**
- * Registers a supplier in the local registry.
- *
- * @param key The key under which the supplier is to be registered.
- * @param supplier The supplier to be registered.
- */
- public void registerLocal(String key, Supplier> supplier) {
- localRegistry.put(key, supplier);
- }
-
/**
* Retrieves a supplier from the global registry.
*
@@ -70,6 +64,16 @@ public static Supplier> getGlobal(String key) {
return globalRegistry.get(key);
}
+ /**
+ * Registers a supplier in the local registry.
+ *
+ * @param key The key under which the supplier is to be registered.
+ * @param supplier The supplier to be registered.
+ */
+ public void registerLocal(String key, Supplier> supplier) {
+ localRegistry.put(key, supplier);
+ }
+
/**
* Retrieves a supplier from the local registry, falling back to the global registry if necessary.
*
@@ -93,7 +97,7 @@ public Supplier> get(String key) {
*
* @param map The map to be set as the local registry.
*/
- public void setLocalRegistry(Map> map){
+ public void setLocalRegistry(Map> map) {
localRegistry.putAll(map);
}
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/newTrial/utils/System.java b/src/main/java/com/tanishisherewith/dynamichud/newTrial/utils/System.java
index 8022537..f741907 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/newTrial/utils/System.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/newTrial/utils/System.java
@@ -5,20 +5,19 @@
import java.util.concurrent.ConcurrentHashMap;
public abstract class System {
- protected final String modId;
-
// A map to store all instances of DynamicValueRegistry by modId
protected static final Map> instances = new ConcurrentHashMap<>();
+ protected final String modId;
public System(String modId) {
this.modId = modId;
}
- public String getModId() {
- return modId;
- }
-
public static List getInstances(String modId) {
return instances.get(modId);
}
+
+ public String getModId() {
+ return modId;
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/tanishisherewith/dynamichud/newTrial/utils/Util.java b/src/main/java/com/tanishisherewith/dynamichud/newTrial/utils/Util.java
index 0bfe69b..d1e04c4 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/newTrial/utils/Util.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/newTrial/utils/Util.java
@@ -3,10 +3,6 @@
import com.tanishisherewith.dynamichud.newTrial.DynamicHUD;
public class Util {
- public enum Quadrant {
- UPPER_LEFT, UPPER_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT
- }
-
public static Quadrant getQuadrant(int x, int y) {
int screenWidth = DynamicHUD.MC.getWindow().getScaledWidth();
int screenHeight = DynamicHUD.MC.getWindow().getScaledHeight();
@@ -26,4 +22,8 @@ public static Quadrant getQuadrant(int x, int y) {
}
}
+ public enum Quadrant {
+ UPPER_LEFT, UPPER_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT
+ }
+
}
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 398037c..2f1d401 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
@@ -8,32 +8,32 @@
import java.util.List;
public class ContextMenu {
- public int x,y;
- protected float scale = 0.0f;
private final List
*
- * Called in {@link com.tanishisherewith.dynamichud.mixins.ScreenMixin}
+ * Called in {@link com.tanishisherewith.dynamichud.mixins.ScreenMixin}
*
*
*
- * @param newWidth Screen width after resize
- * @param newHeight Screen height after resize
- * @param previousWidth Screen width before resize
+ * @param newWidth Screen width after resize
+ * @param newHeight Screen height after resize
+ * @param previousWidth Screen width before resize
* @param previousHeight Screen height before resize
*/
- public static void onScreenResized(int newWidth, int newHeight, int previousWidth, int previousHeight) {
- for (Widget widget : widgets) {
- // To ensure that infinite coords is not returned
- if(widget.xPercent <= 0.0f){
- widget.xPercent = (float) widget.getX()/previousWidth;
- }
- if(widget.yPercent <= 0.0f){
- widget.yPercent = (float) widget.getY()/previousHeight;
- }
-
- // Use the stored percentages to calculate the new position
- float newX = widget.xPercent * newWidth;
- float newY = widget.yPercent * newHeight;
-
- // Ensure the widget is within the screen bounds
- newX = MathHelper.clamp(newX, 0, newWidth - widget.getWidth());
- newY = MathHelper.clamp(newY, 0, newHeight - widget.getHeight());
-
- // Update the widget's position
- widget.setPosition((int) newX, (int) newY);
-
- // Update the stored percentages with the new screen size (after resize).
- widget.xPercent = (float) widget.getX() / newWidth;
- widget.yPercent = (float) widget.getY() / newHeight;
- }
- }
+ public static void onScreenResized(int newWidth, int newHeight, int previousWidth, int previousHeight) {
+ for (Widget widget : widgets) {
+ // To ensure that infinite coords is not returned
+ if (widget.xPercent <= 0.0f) {
+ widget.xPercent = (float) widget.getX() / previousWidth;
+ }
+ if (widget.yPercent <= 0.0f) {
+ widget.yPercent = (float) widget.getY() / previousHeight;
+ }
+
+ // Use the stored percentages to calculate the new position
+ float newX = widget.xPercent * newWidth;
+ float newY = widget.yPercent * newHeight;
+
+ // Ensure the widget is within the screen bounds
+ newX = MathHelper.clamp(newX, 0, newWidth - widget.getWidth());
+ newY = MathHelper.clamp(newY, 0, newHeight - widget.getHeight());
+
+ // Update the widget's position
+ widget.setPosition((int) newX, (int) newY);
+
+ // Update the stored percentages with the new screen size (after resize).
+ widget.xPercent = (float) widget.getX() / newWidth;
+ widget.yPercent = (float) widget.getY() / newHeight;
+ }
+ }
/**
@@ -148,7 +154,7 @@ public static void onScreenResized(int newWidth, int newHeight, int previousWidt
*
* @param file The file to save to
*/
- public static void saveWidgets(File file,List widgets) throws IOException {
+ public static void saveWidgets(File file, List widgets) throws IOException {
NbtCompound rootTag = new NbtCompound();
NbtList widgetList = new NbtList();
@@ -202,18 +208,18 @@ public static void loadWidgets(File file) throws IOException {
widgets.clear();
if (file.exists()) {
- NbtCompound rootTag = NbtIo.read(file.toPath());
- NbtList widgetList = rootTag.getList("widgets", NbtType.COMPOUND);
-
- for (int i = 0; i < widgetList.size(); i++) {
- NbtCompound widgetTag = widgetList.getCompound(i);
- WidgetData> widgetData = widgetDataMap.get(widgetTag.getString("name"));
- Widget widget = widgetData.createWidget();
- printInfo("Loading Widget: " + widget);
- widget.readFromTag(widgetTag);
- widgets.add(widget);
- }
- }else{
+ NbtCompound rootTag = NbtIo.read(file.toPath());
+ NbtList widgetList = rootTag.getList("widgets", NbtType.COMPOUND);
+
+ for (int i = 0; i < widgetList.size(); i++) {
+ NbtCompound widgetTag = widgetList.getCompound(i);
+ WidgetData> widgetData = widgetDataMap.get(widgetTag.getString("name"));
+ Widget widget = widgetData.createWidget();
+ printInfo("Loading Widget: " + widget);
+ widget.readFromTag(widgetTag);
+ widgets.add(widget);
+ }
+ } else {
printWarn("Widget File does not exist. Try saving one first");
}
}
@@ -226,6 +232,7 @@ public static void loadWidgets(File file) throws IOException {
public static List getWidgets() {
return widgets;
}
+
/**
* Returns the list of managed widgets with the same modID.
*
diff --git a/src/main/java/com/tanishisherewith/dynamichud/newTrial/widget/WidgetRenderer.java b/src/main/java/com/tanishisherewith/dynamichud/newTrial/widget/WidgetRenderer.java
index f299f26..34baac0 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/newTrial/widget/WidgetRenderer.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/newTrial/widget/WidgetRenderer.java
@@ -12,10 +12,10 @@
public class WidgetRenderer {
public final List> allowedScreens = new CopyOnWriteArrayList<>();
- private boolean renderInGameHud = true;
public boolean isInEditor = false;
- List widgets;
public Widget selectedWidget = null;
+ List widgets;
+ private boolean renderInGameHud = true;
/**
* Add the list of widgets the widgetRenderer should render
@@ -24,15 +24,16 @@ public class WidgetRenderer {
*
* @param widgets List of widgets to render
*/
- public WidgetRenderer(List widgets){
+ public WidgetRenderer(List widgets) {
this.widgets = widgets;
addScreen(GameMenuScreen.class);
}
- public void addWidget(Widget widget){
+
+ public void addWidget(Widget widget) {
widgets.add(widget);
}
- public void addScreen(Class extends Screen> screen){
+ public void addScreen(Class extends Screen> screen) {
allowedScreens.add(screen);
}
@@ -41,93 +42,98 @@ public void shouldRenderInGameHud(boolean renderInGameHud) {
}
public void renderWidgets(DrawContext context, int mouseX, int mouseY) {
- if(WidgetManager.getWidgets().isEmpty()) return;
+ if (WidgetManager.getWidgets().isEmpty()) return;
Screen currentScreen = DynamicHUD.MC.currentScreen;
- if(currentScreen == null && renderInGameHud){
+ if (currentScreen == null && renderInGameHud) {
for (Widget widget : widgets) {
widget.isInEditor = false;
- widget.render(context,0,0);
+ widget.render(context, 0, 0);
}
return;
}
- if(currentScreen instanceof AbstractMoveableScreen){
+ if (currentScreen instanceof AbstractMoveableScreen) {
for (Widget widget : widgets) {
widget.isInEditor = true;
- widget.renderInEditor(context,mouseX,mouseY);
+ widget.renderInEditor(context, mouseX, mouseY);
}
return;
}
if (currentScreen != null && allowedScreens.contains(DynamicHUD.MC.currentScreen.getClass()) && !this.isInEditor) {
for (Widget widget : widgets) {
widget.isInEditor = false;
- widget.render(context,0,0);
+ widget.render(context, 0, 0);
}
}
}
- public void mouseClicked(double mouseX, double mouseY, int button){
+
+ public void mouseClicked(double mouseX, double mouseY, int button) {
Screen currentScreen = DynamicHUD.MC.currentScreen;
- if(currentScreen == null) {
+ if (currentScreen == null) {
return;
}
- if(currentScreen instanceof AbstractMoveableScreen){
+ if (currentScreen instanceof AbstractMoveableScreen) {
for (Widget widget : widgets) {
// This essentially acts as a Z - layer where the widget first in the list is moved and dragged
// if they are overlapped on each other.
- if(widget.mouseClicked(mouseX,mouseY,button)){
+ if (widget.mouseClicked(mouseX, mouseY, button)) {
selectedWidget = widget;
return;
}
}
}
}
- public void mouseDragged(double mouseX, double mouseY, int button, int snapSize){
+
+ public void mouseDragged(double mouseX, double mouseY, int button, int snapSize) {
Screen currentScreen = DynamicHUD.MC.currentScreen;
- if(currentScreen == null) {
+ if (currentScreen == null) {
return;
}
- if(currentScreen instanceof AbstractMoveableScreen){
+ if (currentScreen instanceof AbstractMoveableScreen) {
for (Widget widget : widgets) {
// This essentially acts as a Z - layer where the widget first in the list is moved and dragged
// if they are overlapped on each other.
- if(widget.mouseDragged(mouseX,mouseY,button,snapSize)){
+ if (widget.mouseDragged(mouseX, mouseY, button, snapSize)) {
selectedWidget = widget;
return;
}
}
}
}
- public void mouseScrolled(double mouseX, double mouseY, double vAmount,double hAmount){
+
+ public void mouseScrolled(double mouseX, double mouseY, double vAmount, double hAmount) {
Screen currentScreen = DynamicHUD.MC.currentScreen;
- if(currentScreen == null) {
+ if (currentScreen == null) {
return;
}
- if(currentScreen instanceof AbstractMoveableScreen){
+ if (currentScreen instanceof AbstractMoveableScreen) {
for (Widget widget : widgets) {
- widget.mouseScrolled(mouseX,mouseY,vAmount,hAmount);
+ widget.mouseScrolled(mouseX, mouseY, vAmount, hAmount);
}
}
}
- public void keyPressed(int keyCode){
+ public void keyPressed(int keyCode) {
Screen currentScreen = DynamicHUD.MC.currentScreen;
- if(currentScreen instanceof AbstractMoveableScreen && (keyCode == GLFW.GLFW_KEY_LEFT_SHIFT || keyCode == GLFW.GLFW_KEY_RIGHT_SHIFT)) {
+ if (currentScreen instanceof AbstractMoveableScreen && (keyCode == GLFW.GLFW_KEY_LEFT_SHIFT || keyCode == GLFW.GLFW_KEY_RIGHT_SHIFT)) {
for (Widget widget : widgets) {
widget.shiftDown = true;
}
}
}
- public void keyReleased(int keyCode){
+
+ public void keyReleased(int keyCode) {
Screen currentScreen = DynamicHUD.MC.currentScreen;
- if(currentScreen instanceof AbstractMoveableScreen && (keyCode == GLFW.GLFW_KEY_LEFT_SHIFT || keyCode == GLFW.GLFW_KEY_RIGHT_SHIFT)) {
+ if (currentScreen instanceof AbstractMoveableScreen && (keyCode == GLFW.GLFW_KEY_LEFT_SHIFT || keyCode == GLFW.GLFW_KEY_RIGHT_SHIFT)) {
for (Widget widget : widgets) {
widget.shiftDown = false;
}
}
}
- public void onCloseScreen(){
- if(DynamicHUD.MC.currentScreen instanceof AbstractMoveableScreen){
+
+ public void onCloseScreen() {
+ if (DynamicHUD.MC.currentScreen instanceof AbstractMoveableScreen) {
for (Widget widget : widgets) {
widget.onClose();
}
@@ -138,14 +144,14 @@ public List getWidgets() {
return widgets;
}
- public void mouseReleased(double mouseX, double mouseY, int button){
+ public void mouseReleased(double mouseX, double mouseY, int button) {
Screen currentScreen = DynamicHUD.MC.currentScreen;
- if(currentScreen == null) {
+ if (currentScreen == null) {
return;
}
- if(currentScreen instanceof AbstractMoveableScreen){
+ if (currentScreen instanceof AbstractMoveableScreen) {
for (Widget widget : widgets) {
- widget.mouseReleased(mouseX,mouseY,button);
+ widget.mouseReleased(mouseX, mouseY, button);
}
}
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/newTrial/widgets/TextWidget.java b/src/main/java/com/tanishisherewith/dynamichud/newTrial/widgets/TextWidget.java
index a75269f..5715ce1 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/newTrial/widgets/TextWidget.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/newTrial/widgets/TextWidget.java
@@ -4,33 +4,34 @@
import com.tanishisherewith.dynamichud.newTrial.config.GlobalConfig;
import com.tanishisherewith.dynamichud.newTrial.utils.DynamicValueRegistry;
import com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.ContextMenu;
-import com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.options.*;
+import com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.options.BooleanOption;
+import com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.options.DoubleOption;
+import com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.options.EnumOption;
+import com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.options.ListOption;
import com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.options.coloroption.ColorOption;
import com.tanishisherewith.dynamichud.newTrial.widget.Widget;
import com.tanishisherewith.dynamichud.newTrial.widget.WidgetData;
import net.minecraft.client.gui.DrawContext;
-import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.nbt.NbtCompound;
import org.lwjgl.glfw.GLFW;
-import java.awt.Color;
-import java.util.*;
+import java.awt.*;
+import java.util.Arrays;
+import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
public class TextWidget extends Widget {
- public static WidgetData DATA = new WidgetData<>("TextWidget","Display Text on screen",TextWidget::new);
- Supplier textSupplier;
- String dynamicRegistryKey = "";
- DynamicValueRegistry dynamicValueRegistry = null;
+ public Color textColor; public static WidgetData DATA = new WidgetData<>("TextWidget", "Display Text on screen", TextWidget::new);
protected boolean shadow; // Whether to draw a shadow behind the text
protected boolean rainbow; // Whether to apply a rainbow effect to the text
protected int rainbowSpeed = 2; //Speed of the rainbow effect
+ Supplier textSupplier;
+ String dynamicRegistryKey = "";
+ DynamicValueRegistry dynamicValueRegistry = null;
private ContextMenu menu;
- public Color textColor;
-
public TextWidget() {
- this(null,null,false,false,Color.WHITE,"unknown");
+ this(null, null, false, false, Color.WHITE, "unknown");
}
/**
@@ -40,8 +41,8 @@ public TextWidget() {
* @param shadow
* @param rainbow
*/
- public TextWidget(String dynamicRegistryKey, boolean shadow, boolean rainbow,Color color,String modID) {
- super(DATA,modID);
+ public TextWidget(String dynamicRegistryKey, boolean shadow, boolean rainbow, Color color, String modID) {
+ super(DATA, modID);
this.dynamicRegistryKey = dynamicRegistryKey;
textSupplier = (Supplier) DynamicValueRegistry.getGlobal(dynamicRegistryKey);
this.shadow = shadow;
@@ -57,11 +58,11 @@ public TextWidget(String dynamicRegistryKey, boolean shadow, boolean rainbow,Col
* @param shadow
* @param rainbow
*/
- public TextWidget(DynamicValueRegistry dynamicValueRegistry,String dynamicRegistryKey, boolean shadow, boolean rainbow,Color color,String modID) {
- super(DATA,modID);
+ public TextWidget(DynamicValueRegistry dynamicValueRegistry, String dynamicRegistryKey, boolean shadow, boolean rainbow, Color color, String modID) {
+ super(DATA, modID);
this.dynamicRegistryKey = dynamicRegistryKey;
this.dynamicValueRegistry = dynamicValueRegistry;
- if(dynamicValueRegistry != null) {
+ if (dynamicValueRegistry != null) {
textSupplier = (Supplier) dynamicValueRegistry.get(dynamicRegistryKey);
}
this.textColor = color;
@@ -69,49 +70,46 @@ public TextWidget(DynamicValueRegistry dynamicValueRegistry,String dynamicRegist
this.rainbow = rainbow;
createMenu();
}
- public void createMenu(){
- menu = new ContextMenu(getX(),getY());
- menu.addOption(new BooleanOption("Shadow",()->this.shadow,value-> this.shadow = value));
- menu.addOption(new BooleanOption("Rainbow",()->this.rainbow,value-> this.rainbow = value));
- menu.addOption(new ColorOption("TextColor",menu,()-> textColor, value -> textColor = value));
- menu.addOption(new DoubleOption("RainbowSpeed",1,4,1.0f, ()->(double)this.rainbowSpeed, value-> this.rainbowSpeed = value.intValue()));
+
+ public void createMenu() {
+ menu = new ContextMenu(getX(), getY());
+ menu.addOption(new BooleanOption("Shadow", () -> this.shadow, value -> this.shadow = value));
+ menu.addOption(new BooleanOption("Rainbow", () -> this.rainbow, value -> this.rainbow = value));
+ menu.addOption(new ColorOption("TextColor", menu, () -> textColor, value -> textColor = value));
+ menu.addOption(new DoubleOption("RainbowSpeed", 1, 4, 1.0f, () -> (double) this.rainbowSpeed, value -> this.rainbowSpeed = value.intValue()));
/* TEST */
AtomicReference enums = new AtomicReference<>(Enum.Enum1);
AtomicReference option = new AtomicReference<>("Enum1");
menu.addOption(new EnumOption<>("Enum", enums::get, enums::set, Enum.values()));
- List options = Arrays.asList("List1","List2","List3");
+ List options = Arrays.asList("List1", "List2", "List3");
menu.addOption(new ListOption<>("List", option::get, option::set, options));
}
- public enum Enum{
- Enum1,
- Enum2,
- Enum3
- }
+
@Override
- public void renderWidget(DrawContext drawContext,int mouseX, int mouseY) {
+ public void renderWidget(DrawContext drawContext, int mouseX, int mouseY) {
int color = rainbow ? ColorHelper.getColorFromHue((System.currentTimeMillis() % (5000 * rainbowSpeed) / (5000f * rainbowSpeed))) : textColor.getRGB();
if (textSupplier != null) {
String text = textSupplier.get();
- drawContext.drawText(mc.textRenderer, text,getX() + 2, getY() + 2, color, shadow);
- widgetBox.setSizeAndPosition(getX(), getY(), mc.textRenderer.getWidth(text) + 3, mc.textRenderer.fontHeight + 2,this.shouldScale,GlobalConfig.get().scale);
+ drawContext.drawText(mc.textRenderer, text, getX() + 2, getY() + 2, color, shadow);
+ widgetBox.setSizeAndPosition(getX(), getY(), mc.textRenderer.getWidth(text) + 3, mc.textRenderer.fontHeight + 2, this.shouldScale, GlobalConfig.get().scale);
}
menu.render(drawContext, getX() - 2, getY(), (int) Math.ceil(getHeight()));
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
- if(button == GLFW.GLFW_MOUSE_BUTTON_RIGHT && widgetBox.isMouseOver(mouseX,mouseY)){
+ if (button == GLFW.GLFW_MOUSE_BUTTON_RIGHT && widgetBox.isMouseOver(mouseX, mouseY)) {
menu.toggleDisplay();
}
- menu.mouseClicked(mouseX,mouseY,button);
+ menu.mouseClicked(mouseX, mouseY, button);
return super.mouseClicked(mouseX, mouseY, button);
}
@Override
public void mouseReleased(double mouseX, double mouseY, int button) {
- menu.mouseReleased(mouseX,mouseY,button);
+ menu.mouseReleased(mouseX, mouseY, button);
super.mouseReleased(mouseX, mouseY, button);
}
@@ -130,11 +128,11 @@ public void onClose() {
@Override
public void writeToTag(NbtCompound tag) {
super.writeToTag(tag);
- tag.putString("DynamicRegistryKey",dynamicRegistryKey);
- tag.putBoolean("Shadow",shadow);
- tag.putBoolean("Rainbow",rainbow);
- tag.putInt("TextColor",textColor.getRGB());
- tag.putInt("RainbowSpeed",rainbowSpeed);
+ tag.putString("DynamicRegistryKey", dynamicRegistryKey);
+ tag.putBoolean("Shadow", shadow);
+ tag.putBoolean("Rainbow", rainbow);
+ tag.putInt("TextColor", textColor.getRGB());
+ tag.putInt("RainbowSpeed", rainbowSpeed);
// If true then it means that we should use local registry and if false (i.e. null) then use global registry
tag.putBoolean("DynamicValueRegistry", dynamicValueRegistry != null);
@@ -152,20 +150,27 @@ public void readFromTag(NbtCompound tag) {
// If true then it means that we should use local registry and if false (i.e. null) then use global registry
boolean dvrObj = tag.getBoolean("DynamicValueRegistry");
- if(!dvrObj){
+ if (!dvrObj) {
this.textSupplier = (Supplier) DynamicValueRegistry.getGlobal(dynamicRegistryKey);
return;
}
- for(DynamicValueRegistry dvr: DynamicValueRegistry.getInstances(modId)){
+ for (DynamicValueRegistry dvr : DynamicValueRegistry.getInstances(modId)) {
//Unfortunately, this method takes the value from the first local registry with the key.
//It returns to prevent overriding with other registries
this.textSupplier = (Supplier) dvr.get(dynamicRegistryKey);
return;
}
createMenu();
- }
- public static class Builder extends WidgetBuilder {
+ }
+
+ public enum Enum {
+ Enum1,
+ Enum2,
+ Enum3
+ }
+
+ public static class Builder extends WidgetBuilder {
protected boolean shadow = false;
protected boolean rainbow = false;
protected String dynamicRegistryKey = "";
@@ -181,14 +186,17 @@ public Builder rainbow(boolean rainbow) {
this.rainbow = rainbow;
return self();
}
+
public Builder setDRKey(String dynamicRegistryKey) {
this.dynamicRegistryKey = dynamicRegistryKey;
return self();
}
+
public Builder setDVR(DynamicValueRegistry dynamicValueRegistry) {
this.dynamicValueRegistry = dynamicValueRegistry;
return self();
}
+
public Builder setTextColor(Color textColor) {
this.textColor = textColor;
return self();
@@ -202,15 +210,17 @@ protected Builder self() {
@Override
public TextWidget build() {
TextWidget widget;
- if(dynamicValueRegistry == null) {
- widget = new TextWidget(dynamicRegistryKey, shadow, rainbow,textColor,modID);
- }else{
- widget = new TextWidget(dynamicValueRegistry,dynamicRegistryKey, shadow, rainbow,textColor,modID);
+ if (dynamicValueRegistry == null) {
+ widget = new TextWidget(dynamicRegistryKey, shadow, rainbow, textColor, modID);
+ } else {
+ widget = new TextWidget(dynamicValueRegistry, dynamicRegistryKey, shadow, rainbow, textColor, modID);
}
- widget.setPosition(x,y);
+ widget.setPosition(x, y);
widget.setDraggable(isDraggable);
widget.setShouldScale(shouldScale);
return widget;
}
}
+
+
}