From 25af2e00ff6199fbdfe9dc994df246900617c9e9 Mon Sep 17 00:00:00 2001 From: tanishisherewithhh <120117618+tanishisherewithhh@users.noreply.github.com> Date: Wed, 9 Oct 2024 13:08:20 +0530 Subject: [PATCH] Error fixing --- .../dynamichud/DynamicHUD.java | 148 +++++++------- .../dynamichud/DynamicHudIntegration.java | 7 +- .../dynamichud/HudRender.java | 2 +- .../dynamichud/ModMenuIntegration.java | 1 - .../dynamichud/config/GlobalConfig.java | 9 +- .../dynamichud/helpers/DrawHelper.java | 4 +- .../dynamichud/helpers/TextureHelper.java | 55 ++--- .../screens/AbstractMoveableScreen.java | 31 +-- .../dynamichud/utils/BooleanPool.java | 1 + .../dynamichud/utils/Input.java | 22 ++ .../utils/contextmenu/ContextMenu.java | 104 +++++----- .../utils/contextmenu/ContextMenuManager.java | 46 +++-- .../contextmenu/ContextMenuProperties.java | 157 +++++++------- .../dynamichud/utils/contextmenu/Option.java | 87 ++++---- .../contextmenuscreen/ContextMenuScreen.java | 21 +- .../contextmenu/options/BooleanOption.java | 29 +-- .../contextmenu/options/ColorOption.java | 12 +- .../contextmenu/options/DoubleOption.java | 13 +- .../utils/contextmenu/options/EnumOption.java | 8 +- .../utils/contextmenu/options/ListOption.java | 6 +- .../contextmenu/options/RunnableOption.java | 10 +- .../contextmenu/options/SubMenuOption.java | 26 +-- .../coloroption/ColorGradientPicker.java | 2 +- .../coloroption/ColorPickerButton.java | 2 +- .../contextmenu/skinsystem/ClassicSkin.java | 88 ++++---- .../contextmenu/skinsystem/MinecraftSkin.java | 193 +++++++++--------- .../utils/contextmenu/skinsystem/Skin.java | 23 ++- .../contextmenu/skinsystem/SkinRenderer.java | 14 +- .../dynamichud/widget/Widget.java | 58 ++---- .../dynamichud/widget/WidgetManager.java | 5 +- .../dynamichud/widgets/ItemWidget.java | 20 +- .../dynamichud/widgets/TextWidget.java | 20 +- 32 files changed, 644 insertions(+), 580 deletions(-) create mode 100644 src/main/java/com/tanishisherewith/dynamichud/utils/Input.java diff --git a/src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java b/src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java index 3062df2..45cc39a 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java +++ b/src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java @@ -2,7 +2,6 @@ import com.tanishisherewith.dynamichud.config.GlobalConfig; import com.tanishisherewith.dynamichud.screens.AbstractMoveableScreen; -import com.tanishisherewith.dynamichud.utils.BooleanPool; import com.tanishisherewith.dynamichud.widget.Widget; import com.tanishisherewith.dynamichud.widget.WidgetManager; import com.tanishisherewith.dynamichud.widget.WidgetRenderer; @@ -19,21 +18,18 @@ import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.ModContainer; import net.fabricmc.loader.api.entrypoint.EntrypointContainer; -import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; import net.fabricmc.loader.api.metadata.ModMetadata; -import net.fabricmc.loader.api.metadata.ModOrigin; -import net.fabricmc.loader.language.JavaLanguageAdapter; -import net.fabricmc.loader.language.LanguageAdapter; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.main.Main; import net.minecraft.client.option.KeyBinding; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; -import java.nio.file.Path; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Objects; @Environment(EnvType.CLIENT) public class DynamicHUD implements ClientModInitializer { @@ -43,6 +39,7 @@ public class DynamicHUD implements ClientModInitializer { * Allows saving widgets across different mods with same save file name. */ public static final HashMap> FILE_MAP = new HashMap<>(); + public static final Logger logger = LoggerFactory.getLogger("DynamicHud"); private static final List widgetRenderers = new ArrayList<>(); public static MinecraftClient MC = MinecraftClient.getInstance(); @@ -77,6 +74,16 @@ public static void openDynamicScreen(KeyBinding key, AbstractMoveableScreen scre } } + public void checkToEnableTestIntegration(){ + String[] args = FabricLoader.getInstance().getLaunchArguments(true); + for (int i = 0; i < args.length; i++) { + if (args[i].equals("--dynamicHudTest") && i + 1 < args.length) { + enableTestIntegration = Boolean.parseBoolean(args[i + 1]); + break; + } + } + } + @Override public void onInitializeClient() { printInfo("Initialising DynamicHud"); @@ -90,13 +97,7 @@ public void onInitializeClient() { //YACL load GlobalConfig.HANDLER.load(); - String[] args = FabricLoader.getInstance().getLaunchArguments(true); - for (int i = 0; i < args.length; i++) { - if (args[i].equals("--dynamicHudTest") && i + 1 < args.length) { - enableTestIntegration = Boolean.parseBoolean(args[i + 1]); - break; - } - } + checkToEnableTestIntegration(); printInfo("Integrating mods..."); List> integrations = new ArrayList<>(getRegisteredIntegrations()); @@ -110,81 +111,82 @@ public void onInitializeClient() { } for (EntrypointContainer entrypoint : integrations) { - ModMetadata metadata = entrypoint.getProvider().getMetadata(); - String modId = metadata.getId(); + ModMetadata metadata = entrypoint.getProvider().getMetadata(); + String modId = metadata.getId(); - printInfo(String.format("Supported mod with id %s was found!", modId)); + printInfo(String.format("Supported mod with id %s was found!", modId)); - AbstractMoveableScreen screen; - KeyBinding binding; - WidgetRenderer widgetRenderer; - File widgetsFile; - try { - DynamicHudIntegration DHIntegration = entrypoint.getEntrypoint(); + AbstractMoveableScreen screen; + KeyBinding binding; + WidgetRenderer widgetRenderer; + File widgetsFile; + try { + DynamicHudIntegration DHIntegration = entrypoint.getEntrypoint(); - //Calls the init method - DHIntegration.init(); + //Calls the init method + DHIntegration.init(); - //Gets the widget file to save and load the widgets from - widgetsFile = DHIntegration.getWidgetsFile(); + //Gets the widget file to save and load the widgets from + widgetsFile = DHIntegration.getWidgetsFile(); - // Adds / loads widgets from file - if (WidgetManager.doesWidgetFileExist(widgetsFile)) { - WidgetManager.loadWidgets(widgetsFile); - } else { - DHIntegration.addWidgets(); - } + // Adds / loads widgets from file + if (WidgetManager.doesWidgetFileExist(widgetsFile)) { + WidgetManager.loadWidgets(widgetsFile); + } else { + DHIntegration.addWidgets(); + } - //Calls the second init method - DHIntegration.initAfter(); + //Calls the second init method + DHIntegration.initAfter(); - // Get the instance of AbstractMoveableScreen - screen = Objects.requireNonNull(DHIntegration.getMovableScreen()); + // Get the instance of AbstractMoveableScreen + screen = Objects.requireNonNull(DHIntegration.getMovableScreen()); - // Get the keybind to open the screen instance - binding = DHIntegration.getKeyBind(); + // Get the keybind to open the screen instance + binding = DHIntegration.getKeyBind(); - //Register custom widget datas by WidgetManager.registerCustomWidgets(); - DHIntegration.registerCustomWidgets(); + //Register custom widget datas by WidgetManager.registerCustomWidgets(); + DHIntegration.registerCustomWidgets(); - //WidgetRenderer with widgets instance - widgetRenderer = DHIntegration.getWidgetRenderer(); - addWidgetRenderer(widgetRenderer); + //WidgetRenderer with widgets instance + widgetRenderer = DHIntegration.getWidgetRenderer(); + addWidgetRenderer(widgetRenderer); - List widgets = FILE_MAP.get(widgetsFile.getName()); + List widgets = FILE_MAP.get(widgetsFile.getName()); - if (widgets == null || widgets.isEmpty()) { - FILE_MAP.put(widgetsFile.getName(), widgetRenderer.getWidgets()); - } else { - widgets.addAll(widgetRenderer.getWidgets()); - FILE_MAP.put(widgetsFile.getName(), widgets); - } + if (widgets == null || widgets.isEmpty()) { + FILE_MAP.put(widgetsFile.getName(), widgetRenderer.getWidgets()); + } else { + widgets.addAll(widgetRenderer.getWidgets()); + FILE_MAP.put(widgetsFile.getName(), widgets); + } - //Register events for rendering, saving, loading, and opening the hudEditor - ClientTickEvents.START_CLIENT_TICK.register((client) -> openDynamicScreen(binding, screen)); + //Register events for rendering, saving, loading, and opening the hudEditor + ClientTickEvents.START_CLIENT_TICK.register((client) -> openDynamicScreen(binding, screen)); - /* === Saving === */ + /* === Saving === */ + // Each mod is hooked to the fabric's event system to save its widget. - //When a player exits a world (SinglePlayer worlds) or a server stops - ServerLifecycleEvents.SERVER_STOPPING.register(server -> saveWidgetsSafely(widgetsFile, FILE_MAP.get(widgetsFile.getName()))); + //When a player exits a world (SinglePlayer worlds) or a server stops + ServerLifecycleEvents.SERVER_STOPPING.register(server -> saveWidgetsSafely(widgetsFile, FILE_MAP.get(widgetsFile.getName()))); - // When a resource pack is reloaded. - ServerLifecycleEvents.END_DATA_PACK_RELOAD.register((server, resourceManager, s) -> saveWidgetsSafely(widgetsFile, FILE_MAP.get(widgetsFile.getName()))); + // When a resource pack is reloaded. + ServerLifecycleEvents.END_DATA_PACK_RELOAD.register((server, resourceManager, s) -> saveWidgetsSafely(widgetsFile, FILE_MAP.get(widgetsFile.getName()))); - //When player disconnects - ServerPlayConnectionEvents.DISCONNECT.register((handler, packetSender) -> saveWidgetsSafely(widgetsFile, FILE_MAP.get(widgetsFile.getName()))); + //When player disconnects + ServerPlayConnectionEvents.DISCONNECT.register((handler, packetSender) -> saveWidgetsSafely(widgetsFile, FILE_MAP.get(widgetsFile.getName()))); - //When minecraft closes - ClientLifecycleEvents.CLIENT_STOPPING.register((minecraftClient) -> saveWidgetsSafely(widgetsFile, FILE_MAP.get(widgetsFile.getName()))); + //When minecraft closes + ClientLifecycleEvents.CLIENT_STOPPING.register((minecraftClient) -> saveWidgetsSafely(widgetsFile, FILE_MAP.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.error("Mod {} has improper implementation of DynamicHUD", modId, e); - } - } + 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.error("Mod {} has improper implementation of DynamicHUD", modId, e); + } + } } printInfo("(DynamicHUD) Integration of supported mods was successful"); @@ -209,7 +211,7 @@ private List> getRegisteredIntegratio /** * This makes it so that if minecraft is launched with the program arguments *

- * {@code --dynamicHudTest true} + * {@code --dynamicHudTest true} *

* then it will * load the {@link DynamicHudTest} class as an entrypoint, eliminating any errors due to human incapacity of @@ -236,7 +238,7 @@ public DynamicHudIntegration getEntrypoint() { @Override public ModContainer getProvider() { - return FabricLoader.getInstance().getModContainer("dynamichud").orElseThrow(); + return FabricLoader.getInstance().getModContainer(MOD_ID).orElseThrow(); } }; } diff --git a/src/main/java/com/tanishisherewith/dynamichud/DynamicHudIntegration.java b/src/main/java/com/tanishisherewith/dynamichud/DynamicHudIntegration.java index 484f981..0e25ed0 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/DynamicHudIntegration.java +++ b/src/main/java/com/tanishisherewith/dynamichud/DynamicHudIntegration.java @@ -9,7 +9,6 @@ import net.minecraft.client.option.KeyBinding; import net.minecraft.client.util.InputUtil; import org.lwjgl.glfw.GLFW; -import org.lwjgl.system.NonnullDefault; import java.io.File; @@ -85,7 +84,7 @@ public interface DynamicHudIntegration { * WidgetManager.registerCustomWidget(TextWidget.DATA); * } * - * + *

* Custom widgets can be registered in any method in the interface * but to avoid any errors and mishaps it is recommended you add them here */ @@ -125,11 +124,11 @@ default KeyBinding getKeyBind() { *

* !! Should never be null !! *

- *

+ *

* * @return The movable screen. */ - AbstractMoveableScreen getMovableScreen(); + AbstractMoveableScreen getMovableScreen(); /** * To return a {@link WidgetRenderer} object. diff --git a/src/main/java/com/tanishisherewith/dynamichud/HudRender.java b/src/main/java/com/tanishisherewith/dynamichud/HudRender.java index a7832cf..49ed9f4 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/HudRender.java +++ b/src/main/java/com/tanishisherewith/dynamichud/HudRender.java @@ -9,7 +9,7 @@ * Using the fabric event {@link HudRenderCallback} to render widgets in the game HUD. * Mouse positions are passed in the negatives even though theoretically it's in the centre of the screen. */ -public class HudRender implements HudRenderCallback{ +public class HudRender implements HudRenderCallback { @Override public void onHudRender(DrawContext drawContext, RenderTickCounter tickCounter) { diff --git a/src/main/java/com/tanishisherewith/dynamichud/ModMenuIntegration.java b/src/main/java/com/tanishisherewith/dynamichud/ModMenuIntegration.java index 7cab250..668a7ed 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/ModMenuIntegration.java +++ b/src/main/java/com/tanishisherewith/dynamichud/ModMenuIntegration.java @@ -3,7 +3,6 @@ import com.tanishisherewith.dynamichud.config.GlobalConfig; import com.terraformersmc.modmenu.api.ConfigScreenFactory; import com.terraformersmc.modmenu.api.ModMenuApi; -import net.minecraft.client.gui.screen.Screen; public class ModMenuIntegration implements ModMenuApi { diff --git a/src/main/java/com/tanishisherewith/dynamichud/config/GlobalConfig.java b/src/main/java/com/tanishisherewith/dynamichud/config/GlobalConfig.java index 8621b99..eedd866 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/config/GlobalConfig.java +++ b/src/main/java/com/tanishisherewith/dynamichud/config/GlobalConfig.java @@ -41,7 +41,7 @@ public static GlobalConfig get() { return INSTANCE; } - public final Screen createYACLGUI() { + public Screen createYACLGUI() { return YetAnotherConfigLib.createBuilder() .title(Text.literal("DynamicHUD config screen.")) .category(ConfigCategory.createBuilder() @@ -71,8 +71,8 @@ public final Screen createYACLGUI() { .option(Option.createBuilder() .name(Text.literal("Snap Size")) .description(OptionDescription.of(Text.literal("Grid size for snapping widgets"))) - .binding( 100, () -> this.snapSize, newVal -> this.snapSize = newVal) - .controller(integerOption -> IntegerFieldControllerBuilder.create(integerOption).range(10,500)) + .binding(100, () -> this.snapSize, newVal -> this.snapSize = newVal) + .controller(integerOption -> IntegerFieldControllerBuilder.create(integerOption).range(10, 500)) .build()) .build()) .build()) @@ -80,7 +80,8 @@ public final Screen createYACLGUI() { .build() .generateScreen(null); } - public float getScale(){ + + public float getScale() { return scale; } diff --git a/src/main/java/com/tanishisherewith/dynamichud/helpers/DrawHelper.java b/src/main/java/com/tanishisherewith/dynamichud/helpers/DrawHelper.java index c310b07..bab2136 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/helpers/DrawHelper.java +++ b/src/main/java/com/tanishisherewith/dynamichud/helpers/DrawHelper.java @@ -47,7 +47,7 @@ public static void drawGradient(Matrix4f matrix4f, float x, float y, float width RenderSystem.defaultBlendFunc(); RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA); RenderSystem.setShader(GameRenderer::getPositionColorProgram); - + switch (direction) { case LEFT_RIGHT: bufferBuilder.vertex(matrix4f, x, y + height, 0.0F).color(startRed, startGreen, startBlue, startAlpha); @@ -508,7 +508,7 @@ public static void drawFilledQuadrant(Matrix4f matrix4f, float xCenter, float yC float alpha = (float) (color >> 24 & 255) / 255.0F; Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR); + BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR); RenderSystem.setShader(GameRenderer::getPositionColorProgram); RenderSystem.enableBlend(); diff --git a/src/main/java/com/tanishisherewith/dynamichud/helpers/TextureHelper.java b/src/main/java/com/tanishisherewith/dynamichud/helpers/TextureHelper.java index 8e8bcdd..53a96ce 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/helpers/TextureHelper.java +++ b/src/main/java/com/tanishisherewith/dynamichud/helpers/TextureHelper.java @@ -14,7 +14,7 @@ public class TextureHelper { static MinecraftClient mc = MinecraftClient.getInstance(); public static NativeImage loadTexture(Identifier textureId) { - if(mc.getResourceManager().getResource(textureId).isPresent()) { + if (mc.getResourceManager().getResource(textureId).isPresent()) { try (InputStream inputStream = mc.getResourceManager().getResource(textureId).get().getInputStream()) { return NativeImage.read(inputStream); } catch (IOException e) { @@ -24,7 +24,7 @@ public static NativeImage loadTexture(Identifier textureId) { return null; } - public static NativeImage resizeTexture(NativeImage image, int newWidth, int newHeight) { + public static NativeImage resizeTexture(NativeImage image, int newWidth, int newHeight) { NativeImage result = new NativeImage(newWidth, newHeight, false); int oldWidth = image.getWidth(); @@ -41,49 +41,51 @@ public static NativeImage resizeTexture(NativeImage image, int newWidth, int ne return result; } + public static NativeImage resizeTextureUsingBilinearInterpolation(NativeImage image, int newWidth, int newHeight) { NativeImage result = new NativeImage(newWidth, newHeight, false); - float x_ratio = ((float)(image.getWidth()-1))/newWidth; - float y_ratio = ((float)(image.getHeight()-1))/newHeight; + float x_ratio = ((float) (image.getWidth() - 1)) / newWidth; + float y_ratio = ((float) (image.getHeight() - 1)) / newHeight; float x_diff, y_diff, blue, red, green; int offset, a, b, c, d, index; - for (int i=0;i>8)&0xff)*(1-x_diff)*(1-y_diff) + ((b>>8)&0xff)*(x_diff)*(1-y_diff) + - ((c>>8)&0xff)*(y_diff)*(1-x_diff) + ((d>>8)&0xff)*(x_diff*y_diff); + green = ((a >> 8) & 0xff) * (1 - x_diff) * (1 - y_diff) + ((b >> 8) & 0xff) * (x_diff) * (1 - y_diff) + + ((c >> 8) & 0xff) * (y_diff) * (1 - x_diff) + ((d >> 8) & 0xff) * (x_diff * y_diff); // Red element - red = ((a>>16)&0xff)*(1-x_diff)*(1-y_diff) + ((b>>16)&0xff)*(x_diff)*(1-y_diff) + - ((c>>16)&0xff)*(y_diff)*(1-x_diff) + ((d>>16)&0xff)*(x_diff*y_diff); + red = ((a >> 16) & 0xff) * (1 - x_diff) * (1 - y_diff) + ((b >> 16) & 0xff) * (x_diff) * (1 - y_diff) + + ((c >> 16) & 0xff) * (y_diff) * (1 - x_diff) + ((d >> 16) & 0xff) * (x_diff * y_diff); result.setColor(j, i, - ((((int)red)<<16)&0xff0000) | - ((((int)green)<<8)&0xff00) | - ((int)blue)&0xff); + ((((int) red) << 16) & 0xff0000) | + ((((int) green) << 8) & 0xff00) | + ((int) blue) & 0xff); } } return result; } - public static NativeImage invertTexture(NativeImage image) { + + public static NativeImage invertTexture(NativeImage image) { int width = image.getWidth(); int height = image.getHeight(); NativeImage result = new NativeImage(width, height, false); @@ -117,8 +119,8 @@ public static NativeImage rotateTexture(NativeImage image, int degrees) { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { - int newX = (int)((x - centerX) * Math.cos(angle) - (y - centerY) * Math.sin(angle) + centerX); - int newY = (int)((x - centerX) * Math.sin(angle) + (y - centerY) * Math.cos(angle) + centerY); + int newX = (int) ((x - centerX) * Math.cos(angle) - (y - centerY) * Math.sin(angle) + centerX); + int newY = (int) ((x - centerX) * Math.sin(angle) + (y - centerY) * Math.cos(angle) + centerY); if (newX >= 0 && newX < width && newY >= 0 && newY < height) { result.setColor(newY, newX, image.getColor(x, y)); @@ -188,6 +190,7 @@ public static NativeImage applyGrayScaleFilter(NativeImage image) { return result; } + public static NativeImage cropTexture(NativeImage image, int x, int y, int width, int height) { NativeImage result = new NativeImage(width, height, false); @@ -263,9 +266,9 @@ public static int getAverageColor(NativeImage image) { } } - int redAverage = (int)(redTotal / pixelCount); - int greenAverage = (int)(greenTotal / pixelCount); - int blueAverage = (int)(blueTotal / pixelCount); + int redAverage = (int) (redTotal / pixelCount); + int greenAverage = (int) (greenTotal / pixelCount); + int blueAverage = (int) (blueTotal / pixelCount); return (redAverage << 16) | (greenAverage << 8) | blueAverage; } diff --git a/src/main/java/com/tanishisherewith/dynamichud/screens/AbstractMoveableScreen.java b/src/main/java/com/tanishisherewith/dynamichud/screens/AbstractMoveableScreen.java index 95c4801..b26cf11 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/screens/AbstractMoveableScreen.java +++ b/src/main/java/com/tanishisherewith/dynamichud/screens/AbstractMoveableScreen.java @@ -28,44 +28,50 @@ public void onDisplayed() { @Override public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { widgetRenderer.mouseDragged(mouseX, mouseY, button, GlobalConfig.get().getSnapSize()); - ContextMenuManager.getInstance().handleMouseDragged(mouseX,mouseY,button,deltaX,deltaY); + ContextMenuManager.getInstance().mouseDragged(mouseX, mouseY, button, deltaX, deltaY); return false; } @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - if(widgetRenderer.mouseClicked(mouseX, mouseY, button)){ - handleClickOnWidget(widgetRenderer.selectedWidget,mouseX,mouseY,button); + if (widgetRenderer.mouseClicked(mouseX, mouseY, button)) { + handleClickOnWidget(widgetRenderer.selectedWidget, mouseX, mouseY, button); } - ContextMenuManager.getInstance().handleMouseClicked(mouseX,mouseY,button); + ContextMenuManager.getInstance().mouseClicked(mouseX, mouseY, button); return false; } + @Override + public boolean charTyped(char chr, int modifiers) { + ContextMenuManager.getInstance().charTyped(chr); + return super.charTyped(chr, modifiers); + } + @Override public boolean mouseReleased(double mouseX, double mouseY, int button) { widgetRenderer.mouseReleased(mouseX, mouseY, button); - ContextMenuManager.getInstance().handleMouseReleased(mouseX,mouseY,button); + ContextMenuManager.getInstance().mouseReleased(mouseX, mouseY, button); return false; } @Override public boolean keyPressed(int keyCode, int scanCode, int modifiers) { widgetRenderer.keyPressed(keyCode); - ContextMenuManager.getInstance().handleKeyPressed(keyCode, scanCode, modifiers); + ContextMenuManager.getInstance().keyPressed(keyCode, scanCode, modifiers); return super.keyPressed(keyCode, scanCode, modifiers); } @Override public boolean keyReleased(int keyCode, int scanCode, int modifiers) { widgetRenderer.keyReleased(keyCode); - ContextMenuManager.getInstance().handleKeyReleased(keyCode, scanCode, modifiers); + ContextMenuManager.getInstance().keyReleased(keyCode, scanCode, modifiers); return super.keyReleased(keyCode, scanCode, modifiers); } @Override public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { widgetRenderer.mouseScrolled(mouseX, mouseY, verticalAmount, horizontalAmount); - ContextMenuManager.getInstance().handleMouseScrolled(mouseX, mouseY, horizontalAmount,verticalAmount); + ContextMenuManager.getInstance().mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); return super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); } @@ -83,14 +89,14 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) if (this.client.world == null) { renderInGameBackground(drawContext); } - drawContext.drawText(client.textRenderer,title,client.getWindow().getScaledWidth()/2 - client.textRenderer.getWidth(title.getString())/2,textRenderer.fontHeight/2,-1,true); + drawContext.drawText(client.textRenderer, title, client.getWindow().getScaledWidth() / 2 - client.textRenderer.getWidth(title.getString()) / 2, textRenderer.fontHeight / 2, -1, true); // Draw each widget widgetRenderer.renderWidgets(drawContext, mouseX, mouseY); - ContextMenuManager.getInstance().renderAll(drawContext,mouseX,mouseY); + ContextMenuManager.getInstance().renderAll(drawContext, mouseX, mouseY); - if(GlobalConfig.get().shouldDisplayDescriptions()) { + if (GlobalConfig.get().shouldDisplayDescriptions()) { for (Widget widget : widgetRenderer.getWidgets()) { if (widget == null || widget.shiftDown) continue; @@ -101,7 +107,8 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) } } } - public void handleClickOnWidget(Widget widget, double mouseX, double mouseY, int button){ + + public void handleClickOnWidget(Widget widget, double mouseX, double mouseY, int button) { } diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/BooleanPool.java b/src/main/java/com/tanishisherewith/dynamichud/utils/BooleanPool.java index 9c518b5..aaf3abd 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/BooleanPool.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/BooleanPool.java @@ -9,6 +9,7 @@ public class BooleanPool { public static void put(String key, boolean value) { pool.put(key, value); } + public static void remove(String key) { pool.remove(key); } diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/Input.java b/src/main/java/com/tanishisherewith/dynamichud/utils/Input.java new file mode 100644 index 0000000..cd2ad2e --- /dev/null +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/Input.java @@ -0,0 +1,22 @@ +package com.tanishisherewith.dynamichud.utils; + + +public interface Input { + boolean mouseClicked(double mouseX, double mouseY, int button); + + boolean mouseReleased(double mouseX, double mouseY, int button); + + boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY); + + void keyPressed(int key, int scanCode, int modifiers); + + void keyReleased(int key, int scanCode, int modifiers); + + void mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount); + + default boolean isMouseOver(double mouseX, double mouseY, double x, double y, double width, double height) { + return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height; + } + + void charTyped(char c); +} diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenu.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenu.java index 8736a93..529bca9 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenu.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenu.java @@ -2,7 +2,7 @@ import com.tanishisherewith.dynamichud.DynamicHUD; import com.tanishisherewith.dynamichud.helpers.DrawHelper; -import com.tanishisherewith.dynamichud.utils.contextmenu.contextmenuscreen.ContextMenuScreen; +import com.tanishisherewith.dynamichud.utils.Input; import com.tanishisherewith.dynamichud.utils.contextmenu.contextmenuscreen.ContextMenuScreenFactory; import com.tanishisherewith.dynamichud.utils.contextmenu.contextmenuscreen.DefaultContextMenuScreenFactory; import net.minecraft.client.gui.DrawContext; @@ -14,12 +14,13 @@ import java.util.Collections; import java.util.List; -public class ContextMenu { +public class ContextMenu implements Input { + public final Color darkerBackgroundColor; //The properties of a context menu protected final ContextMenuProperties properties; - private final List> options = new ArrayList<>(); // The list of options in the context menu + private final ContextMenuScreenFactory screenFactory; public int x, y; // Width is counted while the options are being rendered. // FinalWidth is the width at the end of the count. @@ -28,9 +29,7 @@ public class ContextMenu { private int height = 0, widgetHeight = 0; private boolean shouldDisplay = false; private float scale = 0.0f; - public final Color darkerBackgroundColor; private Screen parentScreen = null; - private final ContextMenuScreenFactory screenFactory; private boolean newScreenFlag = false; public ContextMenu(int x, int y, ContextMenuProperties properties) { @@ -64,37 +63,34 @@ public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY DrawHelper.scaleAndPosition(drawContext.getMatrices(), x, y, scale); properties.getSkin().setContextMenu(this); - properties.getSkin().renderContextMenu(drawContext,this,mouseX,mouseY); + properties.getSkin().renderContextMenu(drawContext, this, mouseX, mouseY); DrawHelper.stopScaling(drawContext.getMatrices()); } - public boolean isMouseOver(int mouseX, int mouseY, int x, int y, int width, int height){ - return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height; - } public void update() { - if(!properties.enableAnimations()){ + if (!properties.enableAnimations()) { scale = 1.0f; return; } // Update the scale - if(shouldDisplay){ - scale += 0.1f; - } else{ - scale -= 0.1f; + if (shouldDisplay) { + scale += 0.1f; + } else { + scale -= 0.1f; } - scale = MathHelper.clamp(scale,0,1.0f); + scale = MathHelper.clamp(scale, 0, 1.0f); } public void close() { - if(properties.getSkin().shouldCreateNewScreen() && scale <= 0 && parentScreen != null){ + if (properties.getSkin().shouldCreateNewScreen() && scale <= 0 && parentScreen != null) { shouldDisplay = false; newScreenFlag = false; DynamicHUD.MC.setScreen(parentScreen); } - for(Option option: options){ + for (Option option : options) { option.onClose(); } shouldDisplay = false; @@ -118,56 +114,67 @@ public void toggleDisplay() { } } - public void mouseClicked(double mouseX, double mouseY, int button) { - if (!shouldDisplay) return; + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (!shouldDisplay) return false; for (Option option : options) { option.mouseClicked(mouseX, mouseY, button); } - properties.getSkin().mouseClicked(this,mouseX,mouseY,button); + return properties.getSkin().mouseClicked(this, mouseX, mouseY, button); } - public void mouseReleased(double mouseX, double mouseY, int button) { - if (!shouldDisplay) return; + @Override + public boolean mouseReleased(double mouseX, double mouseY, int button) { + if (!shouldDisplay) return false; for (Option option : options) { option.mouseReleased(mouseX, mouseY, button); } - properties.getSkin().mouseReleased(this,mouseX,mouseY,button); + return properties.getSkin().mouseReleased(this, mouseX, mouseY, button); } - public void mouseDragged(double mouseX, double mouseY, int button,double deltaX, double deltaY) { - if (!shouldDisplay) return; + @Override + public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { + if (!shouldDisplay) return false; for (Option option : options) { - option.mouseDragged(mouseX, mouseY, button,deltaX,deltaY); + option.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); } - properties.getSkin().mouseDragged(this,mouseX,mouseY,button,deltaX,deltaY); + return properties.getSkin().mouseDragged(this, mouseX, mouseY, button, deltaX, deltaY); } + @Override public void keyPressed(int key, int scanCode, int modifiers) { if (!shouldDisplay) return; for (Option option : options) { - option.keyPressed(key); + option.keyPressed(key, scanCode, modifiers); } - properties.getSkin().keyPressed(this,key,scanCode,modifiers); + properties.getSkin().keyPressed(this, key, scanCode, modifiers); } + @Override public void keyReleased(int key, int scanCode, int modifiers) { if (!shouldDisplay) return; for (Option option : options) { - option.keyReleased(key); + option.keyReleased(key, scanCode, modifiers); } - properties.getSkin().keyReleased(this,key,scanCode,modifiers); + properties.getSkin().keyReleased(this, key, scanCode, modifiers); } + @Override public void mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { - for(Option option: options){ - option.mouseScrolled(mouseX,mouseY,horizontalAmount,verticalAmount); + for (Option option : options) { + option.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); } - properties.getSkin().mouseScrolled(this,mouseX,mouseY,horizontalAmount,verticalAmount); + properties.getSkin().mouseScrolled(this, mouseX, mouseY, horizontalAmount, verticalAmount); + } + + @Override + public void charTyped(char c) { + } - public void set(int x,int y, int widgetHeight){ + public void set(int x, int y, int widgetHeight) { this.x = x; this.y = y; this.widgetHeight = widgetHeight; @@ -180,6 +187,7 @@ public int getX() { public int getY() { return y; } + public List> getOptions() { return Collections.unmodifiableList(options); } @@ -188,9 +196,18 @@ public int getHeight() { return height; } + public void setHeight(int height) { + this.height = height; + } + public int getFinalWidth() { return finalWidth; } + + public void setFinalWidth(int finalWidth) { + this.finalWidth = finalWidth; + } + public int getWidth() { return width; } @@ -199,30 +216,23 @@ public void setWidth(int width) { this.width = width; } - public void setFinalWidth(int finalWidth) { - this.finalWidth = finalWidth; - } - public ContextMenuProperties getProperties() { return properties; } + public void setWidgetHeight(int widgetHeight) { this.widgetHeight = widgetHeight; } - public void setHeight(int height) { - this.height = height; - } - public float getScale() { return scale; } - public void setVisible(boolean shouldDisplay) { - this.shouldDisplay = shouldDisplay; - } - public boolean isVisible() { return shouldDisplay; } + + public void setVisible(boolean shouldDisplay) { + this.shouldDisplay = shouldDisplay; + } } diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenuManager.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenuManager.java index 29b5773..2be522e 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenuManager.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenuManager.java @@ -1,17 +1,17 @@ package com.tanishisherewith.dynamichud.utils.contextmenu; +import com.tanishisherewith.dynamichud.utils.Input; import net.minecraft.client.gui.DrawContext; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; -public class ContextMenuManager { +public class ContextMenuManager implements Input { private static final ContextMenuManager INSTANCE = new ContextMenuManager(); private final List providers = new ArrayList<>(); - private ContextMenuManager() {} + private ContextMenuManager() { + } public static ContextMenuManager getInstance() { return INSTANCE; @@ -30,34 +30,47 @@ public void renderAll(DrawContext drawContext, int mouseX, int mouseY) { } } - public void handleMouseClicked(double mouseX, double mouseY, int button) { + public void onClose() { + for (ContextMenuProvider provider : providers) { + provider.getContextMenu().close(); + } + } + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { for (ContextMenuProvider provider : providers) { ContextMenu contextMenu = provider.getContextMenu(); if (contextMenu != null) { contextMenu.mouseClicked(mouseX, mouseY, button); } } + return false; } - public void handleMouseReleased(double mouseX, double mouseY, int button) { + @Override + public boolean mouseReleased(double mouseX, double mouseY, int button) { for (ContextMenuProvider provider : providers) { ContextMenu contextMenu = provider.getContextMenu(); if (contextMenu != null) { contextMenu.mouseReleased(mouseX, mouseY, button); } } + return false; } - public void handleMouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { + @Override + public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { for (ContextMenuProvider provider : providers) { ContextMenu contextMenu = provider.getContextMenu(); if (contextMenu != null) { contextMenu.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); } } + return false; } - public void handleKeyPressed(int key, int scanCode, int modifiers) { + @Override + public void keyPressed(int key, int scanCode, int modifiers) { for (ContextMenuProvider provider : providers) { ContextMenu contextMenu = provider.getContextMenu(); if (contextMenu != null) { @@ -66,7 +79,8 @@ public void handleKeyPressed(int key, int scanCode, int modifiers) { } } - public void handleKeyReleased(int key, int scanCode, int modifiers) { + @Override + public void keyReleased(int key, int scanCode, int modifiers) { for (ContextMenuProvider provider : providers) { ContextMenu contextMenu = provider.getContextMenu(); if (contextMenu != null) { @@ -75,7 +89,8 @@ public void handleKeyReleased(int key, int scanCode, int modifiers) { } } - public void handleMouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { + @Override + public void mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { for (ContextMenuProvider provider : providers) { ContextMenu contextMenu = provider.getContextMenu(); if (contextMenu != null) { @@ -83,9 +98,14 @@ public void handleMouseScrolled(double mouseX, double mouseY, double horizontalA } } } - public void onClose(){ - for(ContextMenuProvider provider: providers){ - provider.getContextMenu().close(); + + @Override + public void charTyped(char c) { + for (ContextMenuProvider provider : providers) { + ContextMenu contextMenu = provider.getContextMenu(); + if (contextMenu != null) { + contextMenu.charTyped(c); + } } } } diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenuProperties.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenuProperties.java index 330f561..2576b4e 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenuProperties.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenuProperties.java @@ -1,7 +1,6 @@ package com.tanishisherewith.dynamichud.utils.contextmenu; import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.ClassicSkin; -import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.MinecraftSkin; import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.Skin; import java.awt.*; @@ -21,7 +20,8 @@ public class ContextMenuProperties { private boolean enableAnimations = true; private Skin skin = new ClassicSkin(); - private ContextMenuProperties() {} + private ContextMenuProperties() { + } public static Builder builder() { return new ContextMenuProperties().new Builder(); @@ -31,8 +31,84 @@ public static ContextMenuProperties createGenericSimplified() { return new ContextMenuProperties().new Builder().build(); } + // Getters for all properties + public Color getBackgroundColor() { + return backgroundColor; + } + + public Color getBorderColor() { + return borderColor; + } + + public float getBorderWidth() { + return borderWidth; + } + + public int getPadding() { + return padding; + } + + public int getHeightOffset() { + return heightOffset; + } + + public void setHeightOffset(int heightOffset) { + this.heightOffset = heightOffset; + } + + public boolean shouldDrawBorder() { + return drawBorder; + } + + public boolean shadow() { + return shadow; + } + + public boolean roundedCorners() { + return roundedCorners; + } + + public int getCornerRadius() { + return cornerRadius; + } + + public boolean hoverEffect() { + return hoverEffect; + } + + public Color getHoverColor() { + return hoverColor; + } + + public boolean enableAnimations() { + return enableAnimations; + } + + public Skin getSkin() { + return skin; + } + + public ContextMenuProperties copy() { + return ContextMenuProperties.builder() + .backgroundColor(backgroundColor) + .borderColor(borderColor) + .borderWidth(borderWidth) + .padding(padding) + .heightOffset(heightOffset) + .drawBorder(drawBorder) + .shadow(shadow) + .roundedCorners(roundedCorners) + .cornerRadius(cornerRadius) + .hoverEffect(hoverEffect) + .hoverColor(hoverColor) + .skin(skin) + .enableAnimations(enableAnimations) + .build(); + } + public class Builder { - private Builder() {} + private Builder() { + } public Builder backgroundColor(Color backgroundColor) { ContextMenuProperties.this.backgroundColor = backgroundColor; @@ -103,79 +179,4 @@ public ContextMenuProperties build() { return ContextMenuProperties.this; } } - - // Getters for all properties - public Color getBackgroundColor() { - return backgroundColor; - } - - public Color getBorderColor() { - return borderColor; - } - - public float getBorderWidth() { - return borderWidth; - } - - public int getPadding() { - return padding; - } - - public int getHeightOffset() { - return heightOffset; - } - - public boolean shouldDrawBorder() { - return drawBorder; - } - - public boolean shadow() { - return shadow; - } - - public boolean roundedCorners() { - return roundedCorners; - } - - public int getCornerRadius() { - return cornerRadius; - } - - public boolean hoverEffect() { - return hoverEffect; - } - - public Color getHoverColor() { - return hoverColor; - } - - public boolean enableAnimations() { - return enableAnimations; - } - - public Skin getSkin() { - return skin; - } - - public void setHeightOffset(int heightOffset) { - this.heightOffset = heightOffset; - } - - public ContextMenuProperties copy(){ - return ContextMenuProperties.builder() - .backgroundColor(backgroundColor) - .borderColor(borderColor) - .borderWidth(borderWidth) - .padding(padding) - .heightOffset(heightOffset) - .drawBorder(drawBorder) - .shadow(shadow) - .roundedCorners(roundedCorners) - .cornerRadius(cornerRadius) - .hoverEffect(hoverEffect) - .hoverColor(hoverColor) - .skin(skin) - .enableAnimations(enableAnimations) - .build(); - } } \ No newline at end of file diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/Option.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/Option.java index 08bd0ae..95d81b7 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/Option.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/Option.java @@ -1,19 +1,20 @@ package com.tanishisherewith.dynamichud.utils.contextmenu; +import com.tanishisherewith.dynamichud.DynamicHUD; +import com.tanishisherewith.dynamichud.utils.Input; import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.SkinRenderer; -import com.tanishisherewith.dynamichud.widget.Widget; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import java.util.function.Consumer; import java.util.function.Supplier; -public abstract class Option { +public abstract class Option implements Input { + public T value = null; protected int x, y; protected int width = 0; protected int height = 0; - public T value = null; - protected Supplier shouldRender = () -> true; + protected Supplier shouldRender; protected Supplier getter; protected Consumer setter; protected T defaultValue = null; @@ -22,10 +23,10 @@ public abstract class Option { protected SkinRenderer> renderer; public Option(Supplier getter, Consumer setter) { - this(getter,setter,()->true); + this(getter, setter, () -> true); } - public Option(Supplier getter, Consumer setter, Supplier shouldRender,ContextMenuProperties properties) { + public Option(Supplier getter, Consumer setter, Supplier shouldRender, ContextMenuProperties properties) { this.getter = getter; this.setter = setter; this.shouldRender = shouldRender; @@ -35,7 +36,7 @@ public Option(Supplier getter, Consumer setter, Supplier shouldRe } public Option(Supplier getter, Consumer setter, Supplier shouldRender) { - this(getter,setter,shouldRender,ContextMenuProperties.createGenericSimplified()); + this(getter, setter, shouldRender, ContextMenuProperties.createGenericSimplified()); } public T get() { @@ -47,16 +48,16 @@ public void set(T value) { setter.accept(value); } - public void updateProperties(ContextMenuProperties properties){ + public void updateProperties(ContextMenuProperties properties) { this.properties = properties; this.renderer = properties.getSkin().getRenderer((Class>) this.getClass()); if (renderer == null) { - System.err.println("Renderer not found for class: " + this.getClass().getName()); + DynamicHUD.logger.error("Renderer not found for class: {}", this.getClass().getName()); throw new RuntimeException(); } } - public void render(DrawContext drawContext, int x, int y,int mouseX, int mouseY) { + public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) { this.x = x; this.y = y; @@ -65,30 +66,41 @@ public void render(DrawContext drawContext, int x, int y,int mouseX, int mouseY) } public boolean mouseClicked(double mouseX, double mouseY, int button) { - return isMouseOver(mouseX, mouseY) || renderer.mouseClicked(this,mouseX,mouseY,button); - + return isMouseOver(mouseX, mouseY) || renderer.mouseClicked(this, mouseX, mouseY, button); } public boolean mouseReleased(double mouseX, double mouseY, int button) { - return isMouseOver(mouseX, mouseY) || renderer.mouseReleased(this,mouseX,mouseY,button); + return isMouseOver(mouseX, mouseY) || renderer.mouseReleased(this, mouseX, mouseY, button); } - public boolean mouseDragged(double mouseX, double mouseY, int button,double deltaX, double deltaY) { - return isMouseOver(mouseX, mouseY) || renderer.mouseDragged(this,mouseX,mouseY,button,deltaX,deltaY); + public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { + return isMouseOver(mouseX, mouseY) || renderer.mouseDragged(this, mouseX, mouseY, button, deltaX, deltaY); } - public void keyPressed(int key) { - renderer.keyPressed(this,key); + public void mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { + renderer.mouseScrolled(this, mouseX, mouseY, horizontalAmount, verticalAmount); } - public void keyReleased(int key) { - renderer.keyReleased(this,key); + + @Override + public void keyPressed(int key, int scanCode, int modifiers) { + renderer.keyPressed(this, key, scanCode, modifiers); } - public void mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { - renderer.mouseScrolled(this,mouseX,mouseY,horizontalAmount,verticalAmount); + + @Override + public void charTyped(char c) { + } - //Called when the context menu closes - public void onClose(){} + @Override + public void keyReleased(int key, int scanCode, int modifiers) { + renderer.keyReleased(this, key, scanCode, modifiers); + } + + /** + * Called when the context menu closes + */ + public void onClose() { + } public boolean isMouseOver(double mouseX, double mouseY) { return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height; @@ -107,38 +119,39 @@ public ContextMenuProperties getProperties() { return properties; } + public int getY() { + return y; + } + public void setY(int y) { this.y = y; } + public int getX() { + return x; + } + public void setX(int x) { this.x = x; } - public void setWidth(int width) { - this.width = width; + public int getHeight() { + return height; } public void setHeight(int height) { this.height = height; } - public int getY() { - return y; - } - - public int getX() { - return x; + public int getWidth() { + return width; } - public int getHeight() { - return height; + public void setWidth(int width) { + this.width = width; } - public int getWidth() { - return width; - } - public void set(int x, int y){ + public void set(int x, int y) { this.x = x; this.y = y; } diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/contextmenuscreen/ContextMenuScreen.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/contextmenuscreen/ContextMenuScreen.java index 9584622..d398086 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/contextmenuscreen/ContextMenuScreen.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/contextmenuscreen/ContextMenuScreen.java @@ -3,7 +3,6 @@ import com.tanishisherewith.dynamichud.helpers.DrawHelper; import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu; import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuProperties; -import com.tanishisherewith.dynamichud.widget.WidgetRenderer; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; import net.minecraft.text.Text; @@ -12,7 +11,7 @@ public class ContextMenuScreen extends Screen { ContextMenu contextMenu; ContextMenuProperties properties; - protected ContextMenuScreen(ContextMenu menu,ContextMenuProperties properties) { + protected ContextMenuScreen(ContextMenu menu, ContextMenuProperties properties) { super(Text.of("ContextMenu screen")); this.contextMenu = menu; this.properties = properties; @@ -27,14 +26,14 @@ public void onDisplayed() { @Override public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) { contextMenu.update(); - DrawHelper.scaleAndPosition(drawContext.getMatrices(), (float) width /2, (float) height /2,contextMenu.getScale()); + DrawHelper.scaleAndPosition(drawContext.getMatrices(), (float) width / 2, (float) height / 2, contextMenu.getScale()); properties.getSkin().setContextMenu(contextMenu); - properties.getSkin().renderContextMenu(drawContext,contextMenu,mouseX,mouseY); + properties.getSkin().renderContextMenu(drawContext, contextMenu, mouseX, mouseY); DrawHelper.stopScaling(drawContext.getMatrices()); - if(contextMenu.getScale() <= 0 && !contextMenu.isVisible()){ + if (contextMenu.getScale() <= 0 && !contextMenu.isVisible()) { contextMenu.close(); } } @@ -46,37 +45,37 @@ protected void renderDarkening(DrawContext context) { @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - contextMenu.mouseClicked(mouseX,mouseY,button); + contextMenu.mouseClicked(mouseX, mouseY, button); return super.mouseClicked(mouseX, mouseY, button); } @Override public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { - contextMenu.mouseDragged(mouseX,mouseY,button,deltaX,deltaY); + contextMenu.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); } @Override public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { - contextMenu.mouseScrolled(mouseX,mouseY,horizontalAmount,verticalAmount); + contextMenu.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); return super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); } @Override public boolean mouseReleased(double mouseX, double mouseY, int button) { - contextMenu.mouseReleased(mouseX,mouseY,button); + contextMenu.mouseReleased(mouseX, mouseY, button); return super.mouseReleased(mouseX, mouseY, button); } @Override public boolean keyReleased(int keyCode, int scanCode, int modifiers) { - contextMenu.keyReleased(keyCode,scanCode,modifiers); + contextMenu.keyReleased(keyCode, scanCode, modifiers); return super.keyReleased(keyCode, scanCode, modifiers); } @Override public boolean keyPressed(int keyCode, int scanCode, int modifiers) { - contextMenu.keyPressed(keyCode,scanCode,modifiers); + contextMenu.keyPressed(keyCode, scanCode, modifiers); return super.keyPressed(keyCode, scanCode, modifiers); } diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/BooleanOption.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/BooleanOption.java index c2366c8..08ffa66 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/BooleanOption.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/BooleanOption.java @@ -13,7 +13,7 @@ public class BooleanOption extends Option { public String name = "Empty"; - private BooleanType booleanType; + private final BooleanType booleanType; public BooleanOption(String name, Supplier getter, Consumer setter, BooleanType booleanType) { super(getter, setter); @@ -21,25 +21,26 @@ public BooleanOption(String name, Supplier getter, Consumer se this.booleanType = booleanType; this.renderer.init(this); } + public BooleanOption(String name, Supplier getter, Consumer setter) { - this(name,getter,setter,BooleanType.TRUE_FALSE); + this(name, getter, setter, BooleanType.TRUE_FALSE); } public BooleanOption(String name, boolean defaultValue) { - this(name,defaultValue,BooleanType.TRUE_FALSE); + this(name, defaultValue, BooleanType.TRUE_FALSE); } - public BooleanOption(String name, boolean defaultValue,BooleanType type) { - this(name, () -> BooleanPool.get(name), value -> BooleanPool.put(name, value),type); + public BooleanOption(String name, boolean defaultValue, BooleanType type) { + this(name, () -> BooleanPool.get(name), value -> BooleanPool.put(name, value), type); BooleanPool.put(name, defaultValue); } @Override - public void render(DrawContext drawContext, int x, int y,int mouseX, int mouseY) { + public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) { value = get(); - super.render(drawContext, x, y,mouseX,mouseY); + super.render(drawContext, x, y, mouseX, mouseY); - // properties.getSkin().getRenderer(BooleanOption.class).render(drawContext,this,x,y,mouseX,mouseY); + // properties.getSkin().getRenderer(BooleanOption.class).render(drawContext,this,x,y,mouseX,mouseY); /* int color = value ? Color.GREEN.getRGB() : Color.RED.getRGB(); drawContext.drawText(mc.textRenderer, Text.of(name), x, y, color, false); @@ -56,25 +57,25 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { set(value); return true; } - return super.mouseClicked(mouseX,mouseY,button); + return super.mouseClicked(mouseX, mouseY, button); } public BooleanType getBooleanType() { return booleanType; } - public enum BooleanType{ + public enum BooleanType { ON_OFF(ScreenTexts::onOrOff), TRUE_FALSE(aBoolean -> aBoolean ? Text.of("True") : Text.of("False")), - YES_NO(aBoolean -> aBoolean ? ScreenTexts.YES: ScreenTexts.NO); + YES_NO(aBoolean -> aBoolean ? ScreenTexts.YES : ScreenTexts.NO); - private final Function function; + private final Function function; - BooleanType(Function function){ + BooleanType(Function function) { this.function = function; } - public Text getText(boolean val){ + public Text getText(boolean val) { return function.apply(val); } } diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/ColorOption.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/ColorOption.java index fc52ce5..dc31a33 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/ColorOption.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/ColorOption.java @@ -1,11 +1,9 @@ package com.tanishisherewith.dynamichud.utils.contextmenu.options; -import com.tanishisherewith.dynamichud.helpers.DrawHelper; import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu; import com.tanishisherewith.dynamichud.utils.contextmenu.Option; import com.tanishisherewith.dynamichud.utils.contextmenu.options.coloroption.ColorGradientPicker; import net.minecraft.client.gui.DrawContext; -import net.minecraft.text.Text; import java.awt.*; import java.util.function.Consumer; @@ -26,10 +24,10 @@ public ColorOption(String name, ContextMenu parentMenu, Supplier getter, } @Override - public void render(DrawContext drawContext, int x, int y,int mouseX, int mouseY) { - super.render(drawContext, x, y,mouseX,mouseY); + public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) { + super.render(drawContext, x, y, mouseX, mouseY); - // properties.getSkin().getRenderer(ColorOption.class).render(drawContext,this,x,y,mouseX,mouseY); + // properties.getSkin().getRenderer(ColorOption.class).render(drawContext,this,x,y,mouseX,mouseY); /* int color = isVisible ? Color.GREEN.getRGB() : Color.RED.getRGB(); @@ -76,9 +74,9 @@ public boolean mouseReleased(double mouseX, double mouseY, int button) { } @Override - public boolean mouseDragged(double mouseX, double mouseY, int button,double deltaX, double deltaY) { + public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { colorPicker.mouseDragged(mouseX, mouseY, button); - return super.mouseDragged(mouseX, mouseY, button,deltaX,deltaY); + return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); } public ColorGradientPicker getColorPicker() { diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/DoubleOption.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/DoubleOption.java index 59316eb..d51ef4a 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/DoubleOption.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/DoubleOption.java @@ -3,7 +3,6 @@ import com.tanishisherewith.dynamichud.helpers.DrawHelper; import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu; import com.tanishisherewith.dynamichud.utils.contextmenu.Option; -import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; import org.apache.commons.lang3.Validate; import org.lwjgl.glfw.GLFW; @@ -14,11 +13,11 @@ public class DoubleOption extends Option { public String name = "Empty"; - float step = 0.1f; - private boolean isDragging = false; public double minValue = 0.0; public double maxValue = 0.0; + float step = 0.1f; ContextMenu parentMenu; + private boolean isDragging = false; public DoubleOption(String name, double minValue, double maxValue, float step, Supplier getter, Consumer setter, ContextMenu parentMenu) { super(getter, setter); @@ -35,9 +34,9 @@ public DoubleOption(String name, double minValue, double maxValue, float step, S } @Override - public void render(DrawContext drawContext, int x, int y,int mouseX, int mouseY) { + public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) { value = get(); - super.render(drawContext, x, y,mouseX,mouseY); + super.render(drawContext, x, y, mouseX, mouseY); //properties.getSkin().getRenderer(DoubleOption.class).render(drawContext,this,x,y,mouseX,mouseY); @@ -108,10 +107,10 @@ public void step(double mouseX) { } @Override - public boolean mouseDragged(double mouseX, double mouseY, int button,double deltaX, double deltaY) { + public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { if (isMouseOver(mouseX, mouseY) && isDragging) { step(mouseX); } - return super.mouseDragged(mouseX, mouseY, button,deltaX,deltaY); + return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); } } diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/EnumOption.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/EnumOption.java index ceace21..59de1b4 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/EnumOption.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/EnumOption.java @@ -2,9 +2,7 @@ import com.tanishisherewith.dynamichud.utils.contextmenu.Option; import net.minecraft.client.gui.DrawContext; -import net.minecraft.text.Text; -import java.awt.*; import java.util.function.Consumer; import java.util.function.Supplier; @@ -28,9 +26,9 @@ public EnumOption(String name, Supplier getter, Consumer setter, E[] value } @Override - public void render(DrawContext drawContext, int x, int y,int mouseX, int mouseY) { + public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) { value = get(); - super.render(drawContext, x, y,mouseX,mouseY); + super.render(drawContext, x, y, mouseX, mouseY); // properties.getSkin().getRenderer(EnumOption.class).render(drawContext,this,x,y,mouseX,mouseY); @@ -46,7 +44,7 @@ public void render(DrawContext drawContext, int x, int y,int mouseX, int mouseY) @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (super.mouseClicked(mouseX,mouseY,button)) { + if (super.mouseClicked(mouseX, mouseY, button)) { if (button == 0) { currentIndex = (currentIndex + 1) % values.length; if (currentIndex > values.length - 1) { diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/ListOption.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/ListOption.java index 382973f..c28def6 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/ListOption.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/ListOption.java @@ -2,9 +2,7 @@ import com.tanishisherewith.dynamichud.utils.contextmenu.Option; import net.minecraft.client.gui.DrawContext; -import net.minecraft.text.Text; -import java.awt.*; import java.util.List; import java.util.function.Consumer; import java.util.function.Supplier; @@ -29,9 +27,9 @@ public ListOption(String name, Supplier getter, Consumer setter, List v } @Override - public void render(DrawContext drawContext, int x, int y,int mouseX, int mouseY) { + public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) { value = get(); - super.render(drawContext, x, y,mouseX,mouseY); + super.render(drawContext, x, y, mouseX, mouseY); // properties.getSkin().getRenderer(ListOption.class).render(drawContext,this,x,y,mouseX,mouseY); /* diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/RunnableOption.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/RunnableOption.java index dae637d..7d169d4 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/RunnableOption.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/RunnableOption.java @@ -3,9 +3,7 @@ import com.tanishisherewith.dynamichud.utils.BooleanPool; import com.tanishisherewith.dynamichud.utils.contextmenu.Option; import net.minecraft.client.gui.DrawContext; -import net.minecraft.text.Text; -import java.awt.*; import java.util.function.Consumer; import java.util.function.Supplier; @@ -28,15 +26,15 @@ public RunnableOption(String name, Supplier getter, Consumer s this.renderer.init(this); } - public RunnableOption(String name, boolean defaultValue,Runnable task) { - this(name, () -> BooleanPool.get(name), value -> BooleanPool.put(name, value),task); + public RunnableOption(String name, boolean defaultValue, Runnable task) { + this(name, () -> BooleanPool.get(name), value -> BooleanPool.put(name, value), task); BooleanPool.put(name, defaultValue); } @Override - public void render(DrawContext drawContext, int x, int y,int mouseX, int mouseY) { + public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) { value = get(); - super.render(drawContext, x, y,mouseX,mouseY); + super.render(drawContext, x, y, mouseX, mouseY); //properties.getSkin().getRenderer(RunnableOption.class).render(drawContext,this,x,y,mouseX,mouseY); diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/SubMenuOption.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/SubMenuOption.java index 737f815..6fbc3a8 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/SubMenuOption.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/SubMenuOption.java @@ -5,11 +5,8 @@ import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuProperties; import com.tanishisherewith.dynamichud.utils.contextmenu.Option; import net.minecraft.client.gui.DrawContext; -import net.minecraft.text.Text; -import java.awt.*; import java.util.Objects; -import java.util.Properties; import java.util.function.Consumer; import java.util.function.Supplier; @@ -30,25 +27,28 @@ public SubMenuOption(String name, ContextMenu parentMenu, Supplier gett Objects.requireNonNull(parentMenu, "Parent Menu cannot be null"); this.name = name; this.parentMenu = parentMenu; - this.subMenu = new ContextMenu(parentMenu.x + parentMenu.getFinalWidth(), this.y,properties); + this.subMenu = new ContextMenu(parentMenu.x + parentMenu.getFinalWidth(), this.y, properties); this.subMenu.getProperties().setHeightOffset(0); this.subMenu.setVisible(get()); this.renderer.init(this); } + public SubMenuOption(String name, ContextMenu parentMenu, ContextMenuProperties properties) { - this(name, parentMenu, () -> BooleanPool.get(name), value -> BooleanPool.put(name, value),properties); + this(name, parentMenu, () -> BooleanPool.get(name), value -> BooleanPool.put(name, value), properties); } + public SubMenuOption(String name, ContextMenu parentMenu, Supplier getter, Consumer setter) { - this(name,parentMenu,getter,setter,parentMenu.getProperties().copy()); + this(name, parentMenu, getter, setter, parentMenu.getProperties().copy()); } + public SubMenuOption(String name, ContextMenu parentMenu) { - this(name, parentMenu, () -> BooleanPool.get(name), value -> BooleanPool.put(name, value),parentMenu.getProperties().copy()); + this(name, parentMenu, () -> BooleanPool.get(name), value -> BooleanPool.put(name, value), parentMenu.getProperties().copy()); } @Override - public void render(DrawContext drawContext, int x, int y,int mouseX,int mouseY) { - super.render(drawContext,x,y,mouseX,mouseY); - // properties.getSkin().getRenderer(SubMenuOption.class).render(drawContext,this,x,y,mouseX,mouseY); + public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) { + super.render(drawContext, x, y, mouseX, mouseY); + // properties.getSkin().getRenderer(SubMenuOption.class).render(drawContext,this,x,y,mouseX,mouseY); } @Override @@ -69,9 +69,9 @@ public boolean mouseReleased(double mouseX, double mouseY, int button) { } @Override - public boolean mouseDragged(double mouseX, double mouseY, int button,double deltaX, double deltaY) { - subMenu.mouseDragged(mouseX, mouseY, button,deltaX, deltaY); - return super.mouseDragged(mouseX, mouseY, button,deltaX, deltaY); + public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { + subMenu.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); + return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); } public SubMenuOption getOption() { diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/ColorGradientPicker.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/ColorGradientPicker.java index 9d1ed11..6ec3a7b 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/ColorGradientPicker.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/ColorGradientPicker.java @@ -19,9 +19,9 @@ public class ColorGradientPicker { private final ColorPickerButton colorPickerButton; private final AlphaSlider alphaSlider; private final int boxSize; + private final Color initialColor; private int x, y; private boolean display = false; - private final Color initialColor; public ColorGradientPicker(int x, int y, Color initialColor, Consumer onColorSelected, int boxSize, int colors) { this.x = x; diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/ColorPickerButton.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/ColorPickerButton.java index 3afa00e..967bb14 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/ColorPickerButton.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/ColorPickerButton.java @@ -25,7 +25,7 @@ public void render(DrawContext drawContext, int x, int y) { drawContext.getMatrices().push(); drawContext.getMatrices().translate(0, 0, 404); // Draw the button - drawContext.fill(x + 2, y + 2, x + width - 2, y + height - 2, isPicking() ? Color.GREEN.getRGB() : 0xFFAAAAAA); + drawContext.fill(x + 2, y + 2, x + width - 2, y + height - 2, isPicking() ? Color.GREEN.getRGB() : 0xFFAAAAAA); drawContext.drawCenteredTextWithShadow(MinecraftClient.getInstance().textRenderer, "Pick", x + width / 2, y + (height - 8) / 2, 0xFFFFFFFF); drawContext.getMatrices().pop(); } diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ClassicSkin.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ClassicSkin.java index 1328571..9936f48 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ClassicSkin.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ClassicSkin.java @@ -51,7 +51,7 @@ public void renderContextMenu(DrawContext drawContext, ContextMenu contextMenu, // Adjust mouse coordinates based on the scale if (contextMenu.getProperties().hoverEffect() && contextMenu.isMouseOver(mouseX, mouseY, contextMenu.x + 1, yOffset - 1, contextMenu.getFinalWidth() - 2, option.getHeight())) { - drawBackground(matrices, contextMenu, properties, yOffset - 1,contextMenu.getFinalWidth(), option.getHeight() + 1, contextMenu.getProperties().getHoverColor().getRGB(),false); + drawBackground(matrices, contextMenu, properties, yOffset - 1, contextMenu.getFinalWidth(), option.getHeight() + 1, contextMenu.getProperties().getHoverColor().getRGB(), false); } option.render(drawContext, contextMenu.x + 4, yOffset, mouseX, mouseY); @@ -69,13 +69,13 @@ public void renderContextMenu(DrawContext drawContext, ContextMenu contextMenu, } private void drawBackground(MatrixStack matrices, ContextMenu contextMenu, ContextMenuProperties properties) { - drawBackground(matrices, contextMenu, properties, contextMenu.y,contextMenu.getWidth(), contextMenu.getHeight(), properties.getBackgroundColor().getRGB(),properties.shadow()); + drawBackground(matrices, contextMenu, properties, contextMenu.y, contextMenu.getWidth(), contextMenu.getHeight(), properties.getBackgroundColor().getRGB(), properties.shadow()); } - private void drawBackground(MatrixStack matrices, ContextMenu contextMenu, ContextMenuProperties properties, int yOffset,int width, int height, int color,boolean shadow) { + private void drawBackground(MatrixStack matrices, ContextMenu contextMenu, ContextMenuProperties properties, int yOffset, int width, int height, int color, boolean shadow) { // Wow so good code. if (properties.roundedCorners()) { - if(shadow){ + if (shadow) { DrawHelper.drawRoundedRectangleWithShadowBadWay(matrices.peek().getPositionMatrix(), contextMenu.x, yOffset, @@ -87,7 +87,7 @@ private void drawBackground(MatrixStack matrices, ContextMenu contextMenu, Conte 1, 1 ); - }else { + } else { DrawHelper.drawRoundedRectangle(matrices.peek().getPositionMatrix(), contextMenu.x, yOffset, @@ -98,7 +98,7 @@ private void drawBackground(MatrixStack matrices, ContextMenu contextMenu, Conte ); } } else { - if(shadow){ + if (shadow) { DrawHelper.drawRectangleWithShadowBadWay(matrices.peek().getPositionMatrix(), contextMenu.x, yOffset, @@ -109,7 +109,7 @@ private void drawBackground(MatrixStack matrices, ContextMenu contextMenu, Conte 1, 1 ); - }else { + } else { DrawHelper.drawRectangle(matrices.peek().getPositionMatrix(), contextMenu.x, yOffset, @@ -162,7 +162,7 @@ public void render(DrawContext drawContext, ColorOption option, int x, int y, in option.setHeight(mc.textRenderer.fontHeight); option.setWidth(mc.textRenderer.getWidth(option.name) + 1); - int shadowOpacity = Math.min(option.value.getAlpha(),90); + int shadowOpacity = Math.min(option.value.getAlpha(), 90); DrawHelper.drawRoundedRectangleWithShadowBadWay(drawContext.getMatrices().peek().getPositionMatrix(), x + option.getWidth(), y - 1, @@ -178,6 +178,42 @@ public void render(DrawContext drawContext, ColorOption option, int x, int y, in } } + public static class ClassicEnumRenderer> implements SkinRenderer> { + @Override + public void render(DrawContext drawContext, EnumOption option, int x, int y, int mouseX, int mouseY) { + option.setHeight(mc.textRenderer.fontHeight + 1); + option.setWidth(mc.textRenderer.getWidth(option.name + ": " + option.value.name()) + 1); + + drawContext.drawText(mc.textRenderer, Text.of(option.name + ": "), x, y, Color.WHITE.getRGB(), false); + drawContext.drawText(mc.textRenderer, Text.of(option.value.name()), x + mc.textRenderer.getWidth(option.name + ": ") + 1, y, Color.CYAN.getRGB(), false); + } + } + + public static class ClassicSubMenuRenderer implements SkinRenderer { + @Override + public void render(DrawContext drawContext, SubMenuOption option, int x, int y, int mouseX, int mouseY) { + int color = option.value ? Color.GREEN.getRGB() : Color.RED.getRGB(); + drawContext.drawText(mc.textRenderer, Text.of(option.name), x, y, color, false); + option.setHeight(mc.textRenderer.fontHeight); + option.setWidth(mc.textRenderer.getWidth(option.name) + 1); + + option.getSubMenu().render(drawContext, x + option.getParentMenu().getFinalWidth(), y, mouseX, mouseY); + } + } + + public static class ClassicRunnableRenderer implements SkinRenderer { + Color DARK_RED = new Color(116, 0, 0); + Color DARK_GREEN = new Color(24, 132, 0, 226); + + @Override + public void render(DrawContext drawContext, RunnableOption option, int x, int y, int mouseX, int mouseY) { + option.setHeight(mc.textRenderer.fontHeight); + option.setWidth(mc.textRenderer.getWidth("Run: " + option.name)); + int color = option.value ? DARK_GREEN.getRGB() : DARK_RED.getRGB(); + drawContext.drawText(mc.textRenderer, Text.of(option.name), x, y, color, false); + } + } + public class ClassicDoubleRenderer implements SkinRenderer { @Override public void render(DrawContext drawContext, DoubleOption option, int x, int y, int mouseX, int mouseY) { @@ -218,17 +254,6 @@ public void render(DrawContext drawContext, DoubleOption option, int x, int y, i } } - public static class ClassicEnumRenderer> implements SkinRenderer> { - @Override - public void render(DrawContext drawContext, EnumOption option, int x, int y, int mouseX, int mouseY) { - option.setHeight(mc.textRenderer.fontHeight + 1); - option.setWidth(mc.textRenderer.getWidth(option.name + ": " + option.value.name()) + 1); - - drawContext.drawText(mc.textRenderer, Text.of(option.name + ": "), x, y, Color.WHITE.getRGB(), false); - drawContext.drawText(mc.textRenderer, Text.of(option.value.name()), x + mc.textRenderer.getWidth(option.name + ": ") + 1, y, Color.CYAN.getRGB(), false); - } - } - public class ClassicListRenderer implements SkinRenderer> { @Override public void render(DrawContext drawContext, ListOption option, int x, int y, int mouseX, int mouseY) { @@ -239,29 +264,4 @@ public void render(DrawContext drawContext, ListOption option, int x, int y, drawContext.drawText(mc.textRenderer, Text.of(option.value.toString()), x + mc.textRenderer.getWidth(option.name + ": ") + 1, y + 1, Color.CYAN.getRGB(), false); } } - - public static class ClassicSubMenuRenderer implements SkinRenderer { - @Override - public void render(DrawContext drawContext, SubMenuOption option, int x, int y, int mouseX, int mouseY) { - int color = option.value ? Color.GREEN.getRGB() : Color.RED.getRGB(); - drawContext.drawText(mc.textRenderer, Text.of(option.name), x, y, color, false); - option.setHeight(mc.textRenderer.fontHeight); - option.setWidth(mc.textRenderer.getWidth(option.name) + 1); - - option.getSubMenu().render(drawContext, x + option.getParentMenu().getFinalWidth(), y, mouseX, mouseY); - } - } - - public static class ClassicRunnableRenderer implements SkinRenderer { - Color DARK_RED = new Color(116, 0, 0); - Color DARK_GREEN = new Color(24, 132, 0, 226); - - @Override - public void render(DrawContext drawContext, RunnableOption option, int x, int y, int mouseX, int mouseY) { - option.setHeight(mc.textRenderer.fontHeight); - option.setWidth(mc.textRenderer.getWidth("Run: " + option.name)); - int color = option.value ? DARK_GREEN.getRGB() : DARK_RED.getRGB(); - drawContext.drawText(mc.textRenderer, Text.of(option.name), x, y, color, false); - } - } } \ No newline at end of file diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/MinecraftSkin.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/MinecraftSkin.java index 082c0a1..bbd7a33 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/MinecraftSkin.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/MinecraftSkin.java @@ -8,7 +8,6 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ButtonTextures; -import net.minecraft.client.texture.Sprite; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; @@ -22,18 +21,16 @@ * It tries to imitate the minecraft look and provides various form of panel shades {@link PanelColor} */ public class MinecraftSkin extends Skin { - private static final MinecraftClient mc = MinecraftClient.getInstance(); - private static final int DEFAULT_SCROLLBAR_WIDTH = 10; - private static final int DEFAULT_PANEL_WIDTH = 248; - private static final int DEFAULT_PANEL_HEIGHT = 165; - private static final Identifier DEFAULT_BACKGROUND_PANEL = Identifier.of("minecraft", "textures/gui/demo_background.png"); - public static final ButtonTextures TEXTURES = new ButtonTextures( Identifier.ofVanilla("widget/button"), Identifier.ofVanilla("widget/button_disabled"), Identifier.ofVanilla("widget/button_highlighted") ); - + private static final MinecraftClient mc = MinecraftClient.getInstance(); + private static final int DEFAULT_SCROLLBAR_WIDTH = 10; + private static final int DEFAULT_PANEL_WIDTH = 248; + private static final int DEFAULT_PANEL_HEIGHT = 165; + private static final Identifier DEFAULT_BACKGROUND_PANEL = Identifier.of("minecraft", "textures/gui/demo_background.png"); private static final Identifier SCROLLER_TEXTURE = Identifier.ofVanilla("widget/scroller"); private static final Identifier SCROLL_BAR_BACKGROUND = Identifier.ofVanilla("widget/scroller_background"); @@ -47,50 +44,6 @@ public class MinecraftSkin extends Skin { private double scrollVelocity = 0; private int imageX, imageY; - public enum PanelColor { - COFFEE_BROWN(0.6f, 0.3f, 0.1f, 0.9f), - CREAMY(1.0f, 0.9f, 0.8f, 0.9f), - DARK_PANEL(0.2f, 0.2f, 0.2f, 0.9f), - FOREST_GREEN(0.0f, 0.6f, 0.2f, 0.9f), - GOLDEN_YELLOW(1.0f, 0.8f, 0.0f, 0.9f), - LAVENDER(0.8f, 0.6f, 1.0f, 0.9f), - LIGHT_BLUE(0.6f, 0.8f, 1.0f, 0.9f), - LIME_GREEN(0.7f, 1.0f, 0.3f, 0.9f), - MIDNIGHT_PURPLE(0.3f, 0.0f, 0.5f, 0.9f), - OCEAN_BLUE(0.0f, 0.5f, 1.0f, 0.9f), - ROSE_PINK(1.0f, 0.4f, 0.6f, 0.9f), - SKY_BLUE(0.5f, 0.8f, 1.0f, 0.9f), - SOFT_GREEN(0.6f, 1.0f, 0.6f, 0.9f), - SUNSET_ORANGE(1.0f, 0.5f, 0.0f, 0.9f), - WARM_YELLOW(1.0f, 1.0f, 0.6f, 0.9f), - CUSTOM(0.0f, 0.0f, 0.0f, 0.0f); // PlaceHolder for custom colors - - private float red; - private float green; - private float blue; - private float alpha; - - PanelColor(float red, float green, float blue, float alpha) { - this.red = red; - this.green = green; - this.blue = blue; - this.alpha = alpha; - } - - public void applyColor() { - RenderSystem.setShaderColor(red, green, blue, alpha); - } - - public static PanelColor custom(float red, float green, float blue, float alpha) { - PanelColor custom = CUSTOM; - custom.red = red; - custom.green = green; - custom.blue = blue; - custom.alpha = alpha; - return custom; - } - } - public MinecraftSkin(PanelColor color, Identifier backgroundPanel, int panelWidth, int panelHeight) { super(); this.panelColor = color; @@ -108,8 +61,9 @@ public MinecraftSkin(PanelColor color, Identifier backgroundPanel, int panelWidt setCreateNewScreen(true); } + public MinecraftSkin(PanelColor color) { - this(color,DEFAULT_BACKGROUND_PANEL,DEFAULT_PANEL_WIDTH,DEFAULT_PANEL_HEIGHT); + this(color, DEFAULT_BACKGROUND_PANEL, DEFAULT_PANEL_WIDTH, DEFAULT_PANEL_HEIGHT); } @Override @@ -122,7 +76,7 @@ public void renderContextMenu(DrawContext drawContext, ContextMenu contextMenu, int centerX = screenWidth / 2; int centerY = screenHeight / 2; - contextMenu.set(centerX,centerY,0); + contextMenu.set(centerX, centerY, 0); // Calculate the top-left corner of the image imageX = (screenWidth - panelWidth) / 2; @@ -133,11 +87,11 @@ public void renderContextMenu(DrawContext drawContext, ContextMenu contextMenu, RenderSystem.enableDepthTest(); panelColor.applyColor(); drawContext.drawTexture(BACKGROUND_PANEL, imageX, imageY, 0, 0, panelWidth, panelHeight); - RenderSystem.setShaderColor(1.0f,1.0f,1.0f,1.0f); - drawContext.drawGuiTexture(TEXTURES.get(true, isMouseOver(mouseX,mouseY,imageX + 3,imageY + 3,14,14)), imageX + 3,imageY + 3,14,14); - drawContext.drawText(mc.textRenderer,"X",imageX + 10 - mc.textRenderer.getWidth("X")/2 ,imageY + 6,-1,true); + RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); + drawContext.drawGuiTexture(TEXTURES.get(true, isMouseOver(mouseX, mouseY, imageX + 3, imageY + 3, 14, 14)), imageX + 3, imageY + 3, 14, 14); + drawContext.drawText(mc.textRenderer, "X", imageX + 10 - mc.textRenderer.getWidth("X") / 2, imageY + 6, -1, true); - DrawHelper.enableScissor(imageX,imageY + 2,screenWidth,panelHeight - 4); + DrawHelper.enableScissor(imageX, imageY + 2, screenWidth, panelHeight - 4); int yOffset = imageY + 10 - scrollOffset; contextMenu.setWidth(panelWidth - 4); contextMenu.setFinalWidth(panelWidth - 4); @@ -171,15 +125,14 @@ public void renderContextMenu(DrawContext drawContext, ContextMenu contextMenu, private void drawScrollbar(DrawContext context) { int scrollbarX = imageX + panelWidth + 5; int scrollbarY = imageY; - - // Draw scrollbar background - context.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - RenderSystem.enableBlend(); - RenderSystem.enableDepthTest(); - context.drawGuiTexture(SCROLL_BAR_BACKGROUND, scrollbarX, scrollbarY, DEFAULT_SCROLLBAR_WIDTH, panelHeight); - context.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - if (maxScrollOffset > 0) { + // Draw scrollbar background + context.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + RenderSystem.enableBlend(); + RenderSystem.enableDepthTest(); + context.drawGuiTexture(SCROLL_BAR_BACKGROUND, scrollbarX, scrollbarY, DEFAULT_SCROLLBAR_WIDTH, panelHeight); + context.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + float scrollPercentage = (float) scrollOffset / maxScrollOffset; int handleHeight = Math.max(15, (int) ((float) panelHeight * (panelHeight / (float) contextMenu.getHeight()))); int handleY = scrollbarY + (int) ((panelHeight - handleHeight) * scrollPercentage); @@ -189,7 +142,7 @@ private void drawScrollbar(DrawContext context) { } } - private boolean isMouseOver(double mouseX, double mouseY, double x, double y,double width, double height){ + private boolean isMouseOver(double mouseX, double mouseY, double x, double y, double width, double height) { return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height; } @@ -199,7 +152,7 @@ private void applyMomentum() { scrollOffset = MathHelper.clamp(scrollOffset, 0, maxScrollOffset); // Stop the scrolling if the velocity is very low or if we've reached the limits - if (Math.abs(scrollVelocity) < 0.12 || scrollOffset == 0 || scrollOffset-maxScrollOffset <= 3) { + if (Math.abs(scrollVelocity) < 0.12 || scrollOffset == 0 || scrollOffset - maxScrollOffset <= 3) { scrollVelocity = 0; } else { scrollVelocity *= 0.89; // Apply friction @@ -207,7 +160,6 @@ private void applyMomentum() { } } - @Override public void mouseScrolled(ContextMenu menu, double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { scrollVelocity += verticalAmount; @@ -216,7 +168,7 @@ public void mouseScrolled(ContextMenu menu, double mouseX, double mouseY, double @Override public boolean mouseClicked(ContextMenu menu, double mouseX, double mouseY, int button) { - if(button == GLFW.GLFW_MOUSE_BUTTON_LEFT && isMouseOver(mouseX,mouseY,imageX + 3,imageY + 3,14,14)){ + if (button == GLFW.GLFW_MOUSE_BUTTON_LEFT && isMouseOver(mouseX, mouseY, imageX + 3, imageY + 3, 14, 14)) { contextMenu.close(); } @@ -239,10 +191,54 @@ public boolean mouseDragged(ContextMenu menu, double mouseX, double mouseY, int return super.mouseDragged(menu, mouseX, mouseY, button, deltaX, deltaY); } + public enum PanelColor { + COFFEE_BROWN(0.6f, 0.3f, 0.1f, 0.9f), + CREAMY(1.0f, 0.9f, 0.8f, 0.9f), + DARK_PANEL(0.2f, 0.2f, 0.2f, 0.9f), + FOREST_GREEN(0.0f, 0.6f, 0.2f, 0.9f), + GOLDEN_YELLOW(1.0f, 0.8f, 0.0f, 0.9f), + LAVENDER(0.8f, 0.6f, 1.0f, 0.9f), + LIGHT_BLUE(0.6f, 0.8f, 1.0f, 0.9f), + LIME_GREEN(0.7f, 1.0f, 0.3f, 0.9f), + MIDNIGHT_PURPLE(0.3f, 0.0f, 0.5f, 0.9f), + OCEAN_BLUE(0.0f, 0.5f, 1.0f, 0.9f), + ROSE_PINK(1.0f, 0.4f, 0.6f, 0.9f), + SKY_BLUE(0.5f, 0.8f, 1.0f, 0.9f), + SOFT_GREEN(0.6f, 1.0f, 0.6f, 0.9f), + SUNSET_ORANGE(1.0f, 0.5f, 0.0f, 0.9f), + WARM_YELLOW(1.0f, 1.0f, 0.6f, 0.9f), + CUSTOM(0.0f, 0.0f, 0.0f, 0.0f); // PlaceHolder for custom colors + + private float red; + private float green; + private float blue; + private float alpha; + + PanelColor(float red, float green, float blue, float alpha) { + this.red = red; + this.green = green; + this.blue = blue; + this.alpha = alpha; + } + + public static PanelColor custom(float red, float green, float blue, float alpha) { + PanelColor custom = CUSTOM; + custom.red = red; + custom.green = green; + custom.blue = blue; + custom.alpha = alpha; + return custom; + } + + public void applyColor() { + RenderSystem.setShaderColor(red, green, blue, alpha); + } + } + public class MinecraftBooleanRenderer implements SkinRenderer { @Override public void render(DrawContext drawContext, BooleanOption option, int x, int y, int mouseX, int mouseY) { - drawContext.drawText(mc.textRenderer, option.name, x + 15, y + 25/2 - 5, -1, true); + drawContext.drawText(mc.textRenderer, option.name, x + 15, y + 25 / 2 - 5, -1, true); option.set(x + panelWidth - 75, y); @@ -250,11 +246,11 @@ public void render(DrawContext drawContext, BooleanOption option, int x, int y, drawContext.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.enableBlend(); RenderSystem.enableDepthTest(); - drawContext.drawGuiTexture(TEXTURES.get(true, option.isMouseOver(mouseX,mouseY)), option.getX(),y,width,20); + drawContext.drawGuiTexture(TEXTURES.get(true, option.isMouseOver(mouseX, mouseY)), option.getX(), y, width, 20); drawContext.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); Text text = option.getBooleanType().getText(option.value); int color = option.value ? Color.GREEN.getRGB() : Color.RED.getRGB(); - drawContext.drawText(mc.textRenderer,text,(int) (option.getX() + (width/2.0f) -(mc.textRenderer.getWidth(text)/2.0f)) ,y + 5,color,true); + drawContext.drawText(mc.textRenderer, text, (int) (option.getX() + (width / 2.0f) - (mc.textRenderer.getWidth(text) / 2.0f)), y + 5, color, true); //drawContext.drawTexture(BOOLEAN_TEXTURE); option.setHeight(25); @@ -265,7 +261,7 @@ public void render(DrawContext drawContext, BooleanOption option, int x, int y, @Override public boolean mouseClicked(BooleanOption option, double mouseX, double mouseY, int button) { - if(mouseX >= option.getX() && mouseX <= option.getX() + 50 && mouseY >= option.getY() && mouseY <= option.getY() + option.getHeight()){ + if (mouseX >= option.getX() && mouseX <= option.getX() + 50 && mouseY >= option.getY() && mouseY <= option.getY() + option.getHeight()) { option.set(!option.get()); } return SkinRenderer.super.mouseClicked(option, mouseX, mouseY, button); @@ -275,16 +271,16 @@ public boolean mouseClicked(BooleanOption option, double mouseX, double mouseY, public class MinecraftColorOptionRenderer implements SkinRenderer { @Override public void render(DrawContext drawContext, ColorOption option, int x, int y, int mouseX, int mouseY) { - drawContext.drawText(mc.textRenderer, option.name, x + 15, y + 25/2 - 5, -1, true); + drawContext.drawText(mc.textRenderer, option.name, x + 15, y + 25 / 2 - 5, -1, true); - option.set(x + panelWidth - 75 , y); + option.set(x + panelWidth - 75, y); int width = 20; drawContext.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.enableBlend(); RenderSystem.enableDepthTest(); - drawContext.drawGuiTexture(TEXTURES.get(!option.isVisible, option.isMouseOver(mouseX,mouseY)), option.getX(),y,width,20); - int shadowOpacity = Math.min(option.value.getAlpha(),45); + drawContext.drawGuiTexture(TEXTURES.get(!option.isVisible, option.isMouseOver(mouseX, mouseY)), option.getX(), y, width, 20); + int shadowOpacity = Math.min(option.value.getAlpha(), 45); DrawHelper.drawRectangleWithShadowBadWay(drawContext.getMatrices().peek().getPositionMatrix(), option.getX() + 4, y + 4, @@ -317,33 +313,34 @@ public void init(DoubleOption option) { @Override public void render(DrawContext drawContext, DoubleOption option, int x, int y, int mouseX, int mouseY) { - drawContext.drawText(mc.textRenderer, option.name, x + 15, y + 25/2 - 5, -1, true); + drawContext.drawText(mc.textRenderer, option.name, x + 15, y + 25 / 2 - 5, -1, true); option.setWidth(panelWidth - 150); option.setHeight(25); - option.set(x + panelWidth - 122,y); + option.set(x + panelWidth - 122, y); double sliderX = option.getX() + (option.value - option.minValue) / (option.maxValue - option.minValue) * (option.getWidth() - 8); - boolean isMouseOverHandle = isMouseOver(mouseX,mouseY, sliderX, y); + boolean isMouseOverHandle = isMouseOver(mouseX, mouseY, sliderX, y); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.enableDepthTest(); drawContext.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - drawContext.drawGuiTexture(option.isMouseOver(mouseX,mouseY)? HIGHLIGHTED_TEXTURE : TEXTURE, option.getX(), y, option.getWidth(), 20); - drawContext.drawGuiTexture(isMouseOverHandle ? HANDLE_HIGHLIGHTED_TEXTURE : HANDLE_TEXTURE , (int) Math.round(sliderX), y, 8, 20); + drawContext.drawGuiTexture(option.isMouseOver(mouseX, mouseY) ? HIGHLIGHTED_TEXTURE : TEXTURE, option.getX(), y, option.getWidth(), 20); + drawContext.drawGuiTexture(isMouseOverHandle ? HANDLE_HIGHLIGHTED_TEXTURE : HANDLE_TEXTURE, (int) Math.round(sliderX), y, 8, 20); drawContext.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - drawContext.drawText(mc.textRenderer, String.valueOf(option.value),option.getX() + option.getWidth()/2 - mc.textRenderer.getWidth(option.value.toString())/2 ,y + 5,16777215,false); + drawContext.drawText(mc.textRenderer, String.valueOf(option.value), option.getX() + option.getWidth() / 2 - mc.textRenderer.getWidth(option.value.toString()) / 2, y + 5, 16777215, false); } - private boolean isMouseOver(double mouseX, double mouseY, double x, double y){ + + private boolean isMouseOver(double mouseX, double mouseY, double x, double y) { return mouseX >= x && mouseX <= x + 10 && mouseY >= y && mouseY <= y + 20; } @Override public boolean mouseClicked(DoubleOption option, double mouseX, double mouseY, int button) { - return isMouseOver(mouseX,mouseY,option.getX(),option.getY()); + return isMouseOver(mouseX, mouseY, option.getX(), option.getY()); } } @@ -365,17 +362,17 @@ public void render(DrawContext drawContext, EnumOption option, int x, int y, option.setHeight(25); option.setWidth(maxWidth); - drawContext.drawText(mc.textRenderer, option.name + ": ", x + 15, y + 25/2 - 5, -1, true); + drawContext.drawText(mc.textRenderer, option.name + ": ", x + 15, y + 25 / 2 - 5, -1, true); option.set(x + panelWidth - maxWidth - 25, y); drawContext.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.enableBlend(); RenderSystem.enableDepthTest(); - drawContext.drawGuiTexture(TEXTURES.get(true, option.isMouseOver(mouseX,mouseY)), option.getX(),y,maxWidth,20); + drawContext.drawGuiTexture(TEXTURES.get(true, option.isMouseOver(mouseX, mouseY)), option.getX(), y, maxWidth, 20); drawContext.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); String text = option.get().toString(); - drawContext.drawText(mc.textRenderer,text,option.getX() + maxWidth/2 - mc.textRenderer.getWidth(text)/2 ,y + 5,Color.CYAN.getRGB(),true); + drawContext.drawText(mc.textRenderer, text, option.getX() + maxWidth / 2 - mc.textRenderer.getWidth(text) / 2, y + 5, Color.CYAN.getRGB(), true); } } @@ -397,17 +394,17 @@ public void render(DrawContext drawContext, ListOption option, int x, int y, option.setHeight(25); option.setWidth(maxWidth); - drawContext.drawText(mc.textRenderer, option.name + ": ", x + 15, y + 25/2 - 5, -1, true); + drawContext.drawText(mc.textRenderer, option.name + ": ", x + 15, y + 25 / 2 - 5, -1, true); option.set(x + panelWidth - maxWidth - 25, y); drawContext.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.enableBlend(); RenderSystem.enableDepthTest(); - drawContext.drawGuiTexture(TEXTURES.get(true, option.isMouseOver(mouseX,mouseY)), option.getX(),y,maxWidth,20); + drawContext.drawGuiTexture(TEXTURES.get(true, option.isMouseOver(mouseX, mouseY)), option.getX(), y, maxWidth, 20); drawContext.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); String text = option.get().toString(); - drawContext.drawText(mc.textRenderer,text,option.getX() + maxWidth/2 - mc.textRenderer.getWidth(text)/2 ,y + 5,Color.CYAN.getRGB(),true); + drawContext.drawText(mc.textRenderer, text, option.getX() + maxWidth / 2 - mc.textRenderer.getWidth(text) / 2, y + 5, Color.CYAN.getRGB(), true); } } @@ -417,17 +414,17 @@ public void render(DrawContext drawContext, SubMenuOption option, int x, int y, option.setHeight(20); option.setWidth(30); - drawContext.drawText(mc.textRenderer, option.name, x + 15, y + 25/2 - 5, -1, true); + drawContext.drawText(mc.textRenderer, option.name, x + 15, y + 25 / 2 - 5, -1, true); option.set(x + panelWidth - 75, y); drawContext.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.enableBlend(); RenderSystem.enableDepthTest(); - drawContext.drawGuiTexture(TEXTURES.get(true, option.isMouseOver(mouseX,mouseY)), option.getX(),y, option.getWidth(),20); + drawContext.drawGuiTexture(TEXTURES.get(true, option.isMouseOver(mouseX, mouseY)), option.getX(), y, option.getWidth(), 20); drawContext.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); String text = "Open"; - drawContext.drawText(mc.textRenderer,text,option.getX() + option.getWidth()/2 - mc.textRenderer.getWidth(text)/2 ,y + 5,Color.YELLOW.getRGB(),true); + drawContext.drawText(mc.textRenderer, text, option.getX() + option.getWidth() / 2 - mc.textRenderer.getWidth(text) / 2, y + 5, Color.YELLOW.getRGB(), true); option.getSubMenu().render(drawContext, x + option.getParentMenu().getFinalWidth(), y, mouseX, mouseY); } @@ -442,16 +439,16 @@ public void render(DrawContext drawContext, RunnableOption option, int x, int y, option.setHeight(25); option.setWidth(26); - drawContext.drawText(mc.textRenderer, option.name.replaceFirst("Run: ","") + ": ", x + 15, y + 25/2 - 5, -1, true); + drawContext.drawText(mc.textRenderer, option.name.replaceFirst("Run: ", "") + ": ", x + 15, y + 25 / 2 - 5, -1, true); option.set(x + panelWidth - 75, y); drawContext.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.enableBlend(); RenderSystem.enableDepthTest(); - drawContext.drawGuiTexture(TEXTURES.get(!option.value, option.isMouseOver(mouseX,mouseY)), option.getX(),y, option.getWidth(),20); + drawContext.drawGuiTexture(TEXTURES.get(!option.value, option.isMouseOver(mouseX, mouseY)), option.getX(), y, option.getWidth(), 20); drawContext.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - drawContext.drawText(mc.textRenderer,"Run",option.getX() + option.getWidth()/2 - mc.textRenderer.getWidth("Run")/2 ,y + 5, option.value ? DARK_GREEN.getRGB() : DARK_RED.getRGB(),true); + drawContext.drawText(mc.textRenderer, "Run", option.getX() + option.getWidth() / 2 - mc.textRenderer.getWidth("Run") / 2, y + 5, option.value ? DARK_GREEN.getRGB() : DARK_RED.getRGB(), true); } } } \ No newline at end of file diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/Skin.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/Skin.java index b2007a3..867c949 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/Skin.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/Skin.java @@ -1,7 +1,6 @@ package com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem; import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu; -import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuProvider; import com.tanishisherewith.dynamichud.utils.contextmenu.Option; import net.minecraft.client.gui.DrawContext; @@ -13,14 +12,15 @@ public abstract class Skin { protected Map>, SkinRenderer>> renderers = new HashMap<>(); private boolean createNewScreen; - public > void addRenderer(Class optionClass, SkinRenderer renderer) { - renderers.put(optionClass, renderer); + public Skin(ContextMenu menu) { + this.contextMenu = menu; } - public Skin(ContextMenu menu){ - this.contextMenu = menu; + public Skin() { } - public Skin(){ + + public > void addRenderer(Class optionClass, SkinRenderer renderer) { + renderers.put(optionClass, renderer); } @SuppressWarnings("unchecked") @@ -50,9 +50,14 @@ public boolean mouseDragged(ContextMenu menu, double mouseX, double mouseY, int return false; } - public void keyPressed(ContextMenu menu, int key,int scanCode, int modifiers) {} - public void keyReleased(ContextMenu menu, int key,int scanCode, int modifiers) {} - public void mouseScrolled(ContextMenu menu, double mouseX, double mouseY, double horizontalAmount, double verticalAmount){} + public void keyPressed(ContextMenu menu, int key, int scanCode, int modifiers) { + } + + public void keyReleased(ContextMenu menu, int key, int scanCode, int modifiers) { + } + + public void mouseScrolled(ContextMenu menu, double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { + } public boolean shouldCreateNewScreen() { return createNewScreen; diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/SkinRenderer.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/SkinRenderer.java index fc498de..8e7775f 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/SkinRenderer.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/SkinRenderer.java @@ -18,9 +18,15 @@ default boolean mouseDragged(T option, double mouseX, double mouseY, int button, return option.isMouseOver(mouseX, mouseY); } - default void keyPressed(T option, int key) {} + default void keyPressed(T option, int key, int scanCode, int modifiers) { + } + + default void keyReleased(T option, int key, int scanCode, int modifiers) { + } - default void keyReleased(T option, int key) {} - default void mouseScrolled(T option, double mouseX, double mouseY, double horizontalAmount, double verticalAmount){} - default void init(T option){} + default void mouseScrolled(T option, double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { + } + + default void init(T option) { + } } diff --git a/src/main/java/com/tanishisherewith/dynamichud/widget/Widget.java b/src/main/java/com/tanishisherewith/dynamichud/widget/Widget.java index 2e34341..ab3821a 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/widget/Widget.java +++ b/src/main/java/com/tanishisherewith/dynamichud/widget/Widget.java @@ -6,17 +6,12 @@ import com.tanishisherewith.dynamichud.utils.UID; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.option.VideoOptionsScreen; import net.minecraft.nbt.NbtCompound; import net.minecraft.util.math.MathHelper; import org.lwjgl.glfw.GLFW; -import java.util.Properties; -import java.util.Set; - public abstract class Widget { - public enum Anchor { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT, CENTER } - + private final Anchor anchor; // The chosen anchor point public WidgetData DATA; /** * This is the UID of the widget used to identify during loading and saving. @@ -26,23 +21,13 @@ public enum Anchor { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT, CENTER } * @see #modId */ public UID uid = UID.generate(); - protected boolean isInEditor = false; - // Whether the widget is enabled and should be displayed. public boolean display = true; public boolean isDraggable = true; - - private int offsetX, offsetY; // Offset from the anchor point - //Boolean to check if the widget is being dragged public boolean dragging; - //To enable/disable snapping public boolean shiftDown = false; - - // Absolute position of the widget on screen in pixels. - protected int x, y; - protected boolean shouldScale = true; /** * An identifier for widgets to group them under one ID. *

@@ -52,6 +37,10 @@ public enum Anchor { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT, CENTER } * @see #uid */ public String modId = "unknown"; + protected boolean isInEditor = false; + // Absolute position of the widget on screen in pixels. + protected int x, y; + protected boolean shouldScale = true; protected MinecraftClient mc = MinecraftClient.getInstance(); /** * Scale of the current widget. @@ -62,12 +51,12 @@ public enum Anchor { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT, CENTER } //Dimensions of the widget protected WidgetBox widgetBox; int startX, startY; - private final Anchor anchor; // The chosen anchor point - + private int offsetX, offsetY; // Offset from the anchor point public Widget(WidgetData DATA, String modId) { - this(DATA,modId,Anchor.CENTER); + this(DATA, modId, Anchor.CENTER); } - public Widget(WidgetData DATA, String modId,Anchor anchor) { + + public Widget(WidgetData DATA, String modId, Anchor anchor) { this.DATA = DATA; widgetBox = new WidgetBox(0, 0, 0, 0); this.modId = modId; @@ -75,7 +64,6 @@ public Widget(WidgetData DATA, String modId,Anchor anchor) { init(); } - /** * This method is called at the end of the {@link Widget#Widget(WidgetData, String)} constructor. */ @@ -133,8 +121,8 @@ private int getAnchorY(int screenHeight) { // Update position based on anchor and offset void updatePosition(int screenWidth, int screenHeight) { - if(offsetX == 0 || offsetY == 0){ - calculateOffset(x,y,screenWidth,screenHeight); + if (offsetX == 0 || offsetY == 0) { + calculateOffset(x, y, screenWidth, screenHeight); } int anchorX = getAnchorX(screenWidth); @@ -148,10 +136,10 @@ void updatePosition(int screenWidth, int screenHeight) { public void setPosition(int x, int y) { this.x = x; this.y = y; - if(mc.getWindow() != null){ + if (mc.getWindow() != null) { //updatePercentages(); calculateOffset(x, y, mc.getWindow().getScaledWidth(), mc.getWindow().getScaledHeight()); // Set initial offset - updatePosition( mc.getWindow().getScaledWidth(), mc.getWindow().getScaledHeight()); // Initial placement + updatePosition(mc.getWindow().getScaledWidth(), mc.getWindow().getScaledHeight()); // Initial placement } } @@ -185,7 +173,7 @@ public final void render(DrawContext drawContext, int mouseX, int mouseY) { * Renders the widget on the editor screen. */ public final void renderInEditor(DrawContext drawContext, int mouseX, int mouseY) { - if(!isInEditor) return; + if (!isInEditor) return; displayBg(drawContext); @@ -200,7 +188,6 @@ public final void renderInEditor(DrawContext drawContext, int mouseX, int mouseY clampPosition(); } - /** * Renders the widget on the screen *

@@ -213,12 +200,10 @@ public final void renderInEditor(DrawContext drawContext, int mouseX, int mouseY */ public abstract void renderWidget(DrawContext context, int mouseX, int mouseY); - /** * Renders the widget in the editor screen with a background. * Override this method without super call to remove the background. * Could also be used to display placeholder values. - * */ private void renderWidgetInEditor(DrawContext context, int mouseX, int mouseY) { //displayBg(context); @@ -226,12 +211,10 @@ private void renderWidgetInEditor(DrawContext context, int mouseX, int mouseY) { renderWidget(context, mouseX, mouseY); } - /* Input related methods. Override with super call to add your own input-based code like contextMenu */ - public boolean mouseClicked(double mouseX, double mouseY, int button) { if (widgetBox.isMouseOver(mouseX, mouseY) && button == GLFW.GLFW_MOUSE_BUTTON_LEFT) { toggle(); - if(isDraggable) { + if (isDraggable) { startX = (int) (mouseX - x); startY = (int) (mouseY - y); dragging = true; @@ -240,13 +223,16 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { } return false; } - public void clampPosition(){ + + /* Input related methods. Override with super call to add your own input-based code like contextMenu */ + + public void clampPosition() { this.x = (int) MathHelper.clamp(this.x, 0, mc.getWindow().getScaledWidth() - getWidth()); this.y = (int) MathHelper.clamp(this.y, 0, mc.getWindow().getScaledHeight() - getHeight()); } public boolean mouseDragged(double mouseX, double mouseY, int button, int snapSize) { - if(!isDraggable) return false; + if (!isDraggable) return false; if (dragging && button == GLFW.GLFW_MOUSE_BUTTON_LEFT) { int newX = (int) (mouseX - startX); int newY = (int) (mouseY - startY); @@ -287,7 +273,6 @@ public void mouseReleased(double mouseX, double mouseY, int button) { public void mouseScrolled(double mouseX, double mouseY, double vAmount, double hAmount) { } - public boolean toggle() { return this.display = !this.display; } @@ -299,7 +284,6 @@ public void onClose() { /** * Displays a faint grayish background if enabled or faint reddish background if disabled. * Drawn with 2 pixel offset to all sides - * */ protected void displayBg(DrawContext context) { int backgroundColor = this.shouldDisplay() ? ColorHelper.getColor(0, 0, 0, 128) : ColorHelper.getColor(255, 0, 0, 128); @@ -372,6 +356,8 @@ public String toString() { '}'; } + public enum Anchor {TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT, CENTER} + public abstract static class WidgetBuilder { protected int x; protected int y; diff --git a/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetManager.java b/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetManager.java index d3afbcc..489a799 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetManager.java +++ b/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetManager.java @@ -6,7 +6,6 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtIo; import net.minecraft.nbt.NbtList; -import net.minecraft.util.math.MathHelper; import java.io.DataOutputStream; import java.io.File; @@ -182,7 +181,7 @@ public static void loadWidgets(File file) throws IOException { widgets.clear(); if (file.exists() || (file = new File(file.getAbsolutePath() + ".backup")).exists()) { - if(!file.exists()){ + if (!file.exists()) { printWarn("Main file " + file.getAbsolutePath() + " was not found... Loading from a found backup file"); } @@ -205,7 +204,7 @@ public static void loadWidgets(File file) throws IOException { } } - public static boolean doesWidgetFileExist(File file){ + public static boolean doesWidgetFileExist(File file) { return file.exists() || new File(file.getAbsolutePath() + ".backup").exists(); } diff --git a/src/main/java/com/tanishisherewith/dynamichud/widgets/ItemWidget.java b/src/main/java/com/tanishisherewith/dynamichud/widgets/ItemWidget.java index 7b570ba..11d46e4 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/widgets/ItemWidget.java +++ b/src/main/java/com/tanishisherewith/dynamichud/widgets/ItemWidget.java @@ -12,27 +12,26 @@ * This is just an example widget, not supposed to be used. */ public class ItemWidget extends Widget { - public static WidgetData DATA = new WidgetData<>("ItemWidget","Displays item texture", ItemWidget::new); - public ItemStack item; - - public ItemWidget(ItemStack itemStack,String modId) { + public ItemStack item; public static WidgetData DATA = new WidgetData<>("ItemWidget", "Displays item texture", ItemWidget::new); + public ItemWidget(ItemStack itemStack, String modId) { super(DATA, modId); this.item = itemStack; } + public ItemWidget() { this(ItemStack.EMPTY, "empty"); } @Override public void renderWidget(DrawContext context, int mouseX, int mouseY) { - context.drawItem(item,x,y); + context.drawItem(item, x, y); widgetBox.setSizeAndPosition(getX(), getY(), 16, 16, this.shouldScale, GlobalConfig.get().getScale()); } @Override public void writeToTag(NbtCompound tag) { super.writeToTag(tag); - tag.putInt("ItemID",Item.getRawId(item.getItem())); + tag.putInt("ItemID", Item.getRawId(item.getItem())); } @Override @@ -45,8 +44,9 @@ public void setItemStack(ItemStack item) { this.item = item; } - public static class Builder extends WidgetBuilder{ - ItemStack itemStack; + public static class Builder extends WidgetBuilder { + ItemStack itemStack; + public Builder setItemStack(ItemStack itemStack) { this.itemStack = itemStack; return self(); @@ -59,7 +59,9 @@ protected Builder self() { @Override public ItemWidget build() { - return new ItemWidget(itemStack,modID); + return new ItemWidget(itemStack, modID); } } + + } diff --git a/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java b/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java index 4db69cb..b14a296 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java +++ b/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java @@ -7,7 +7,9 @@ import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuManager; import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuProperties; import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuProvider; -import com.tanishisherewith.dynamichud.utils.contextmenu.options.*; +import com.tanishisherewith.dynamichud.utils.contextmenu.options.BooleanOption; +import com.tanishisherewith.dynamichud.utils.contextmenu.options.ColorOption; +import com.tanishisherewith.dynamichud.utils.contextmenu.options.DoubleOption; import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.MinecraftSkin; import com.tanishisherewith.dynamichud.widget.Widget; import com.tanishisherewith.dynamichud.widget.WidgetData; @@ -16,26 +18,22 @@ import org.lwjgl.glfw.GLFW; import java.awt.*; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; public class TextWidget extends Widget implements ContextMenuProvider { public Color textColor; protected boolean shadow; // Whether to draw a shadow behind the text - public static WidgetData DATA = new WidgetData<>("TextWidget", "Display Text on screen", TextWidget::new); protected boolean rainbow; // Whether to apply a rainbow effect to the text + public static WidgetData DATA = new WidgetData<>("TextWidget", "Display Text on screen", TextWidget::new); protected int rainbowSpeed = 2; //Speed of the rainbow effect Supplier textSupplier; String dynamicRegistryKey; DynamicValueRegistry dynamicValueRegistry = null; private ContextMenu menu; - public TextWidget() { this(null, null, false, false, Color.WHITE, "unknown"); } + /** * Searches for the supplier within the {@link DynamicValueRegistry#globalRegistry} using the given registryKey * @@ -85,7 +83,7 @@ public void createMenu() { menu.addOption(new BooleanOption("Shadow", () -> this.shadow, value -> this.shadow = value, BooleanOption.BooleanType.ON_OFF)); menu.addOption(new BooleanOption("Rainbow", () -> this.rainbow, value -> this.rainbow = value, BooleanOption.BooleanType.ON_OFF)); menu.addOption(new ColorOption("TextColor", menu, () -> this.textColor, value -> this.textColor = value)); - menu.addOption(new DoubleOption("RainbowSpeed", 1, 5.0f, 1, () -> (double) this.rainbowSpeed, value -> this.rainbowSpeed = value.intValue(),menu)); + menu.addOption(new DoubleOption("RainbowSpeed", 1, 5.0f, 1, () -> (double) this.rainbowSpeed, value -> this.rainbowSpeed = value.intValue(), menu)); /* TEST AtomicReference option = new AtomicReference<>("Enum1"); @@ -111,7 +109,7 @@ public void renderWidget(DrawContext drawContext, int mouseX, int mouseY) { 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().getScale()); } - menu.set(getX(),getY(),(int) Math.ceil(getHeight())); + menu.set(getX(), getY(), (int) Math.ceil(getHeight())); } @Override @@ -173,7 +171,7 @@ public void readFromTag(NbtCompound tag) { dynamicValueRegistry = dvr; return; } - createMenu(); + createMenu(); } @Override @@ -232,4 +230,6 @@ public TextWidget build() { return widget; } } + + }