diff --git a/src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java b/src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java index 45cc39a..6790c1b 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java +++ b/src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java @@ -86,7 +86,7 @@ public void checkToEnableTestIntegration(){ @Override public void onInitializeClient() { - printInfo("Initialising DynamicHud"); + printInfo("Initialising DynamicHUD"); // Add WidgetData of included widgets WidgetManager.registerCustomWidgets( diff --git a/src/main/java/com/tanishisherewith/dynamichud/config/GlobalConfig.java b/src/main/java/com/tanishisherewith/dynamichud/config/GlobalConfig.java index 23da97e..d67ae80 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/config/GlobalConfig.java +++ b/src/main/java/com/tanishisherewith/dynamichud/config/GlobalConfig.java @@ -16,6 +16,7 @@ import net.minecraft.util.Identifier; import java.awt.*; +import java.util.LinkedList; public final class GlobalConfig { public static final ConfigClassHandler HANDLER = ConfigClassHandler.createBuilder(GlobalConfig.class) @@ -28,7 +29,7 @@ public final class GlobalConfig { private static final GlobalConfig INSTANCE = new GlobalConfig(); /** - * Common scale for all widgets. Set by the user using YACL. + * Common scale for all widgets. */ @SerialEntry private float scale = 1.0f; @@ -92,11 +93,11 @@ public Screen createYACLGUI() { .binding(new Color(0, 0, 0, 128), () -> this.hudActiveColor, newVal -> this.hudActiveColor = newVal) .controller(ColorControllerBuilder::create) .build()) - .option(Option.createBuilder() - .name(Text.literal("Widget HUD Inactive Background Color")) - .description(OptionDescription.of(Text.literal("Color of the background of the widget when it will NOT be rendered"))) - .binding(new Color(255, 0, 0, 128), () -> this.hudInactiveColor, newVal -> this.hudInactiveColor = newVal) - .controller(ColorControllerBuilder::create) + .option(Option.createBuilder() + .name(Text.literal("Widget HUD Inactive Background Color")) + .description(OptionDescription.of(Text.literal("Color of the background of the widget when it will NOT be rendered"))) + .binding(new Color(255, 0, 0, 128), () -> this.hudInactiveColor, newVal -> this.hudInactiveColor = newVal) + .controller(ColorControllerBuilder::create) .build()) .build()) .save(HANDLER::save) diff --git a/src/main/java/com/tanishisherewith/dynamichud/helpers/DrawHelper.java b/src/main/java/com/tanishisherewith/dynamichud/helpers/DrawHelper.java index bab2136..d59ac29 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/helpers/DrawHelper.java +++ b/src/main/java/com/tanishisherewith/dynamichud/helpers/DrawHelper.java @@ -2,6 +2,7 @@ import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.systems.VertexSorter; import com.tanishisherewith.dynamichud.DynamicHUD; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.render.*; @@ -12,10 +13,13 @@ import java.awt.*; +import static com.tanishisherewith.dynamichud.helpers.TextureHelper.mc; + /** * Credits: HeliosClient */ public class DrawHelper { + public static VertexSorter vertexSorter; /** * Draws a singular gradient rectangle on screen with the given parameters @@ -792,6 +796,21 @@ public static void drawOutlinedBox(DrawContext drawContext, int x1, int y1, int drawContext.fill(x2 - 1, y1 + 1, x2, y2 - 1, color); } + public static void unscaledProjection() { + vertexSorter = RenderSystem.getVertexSorting(); + RenderSystem.setProjectionMatrix(new Matrix4f().setOrtho(0, mc.getWindow().getFramebufferWidth(), mc.getWindow().getFramebufferHeight(), 0, 1000, 21000), VertexSorter.BY_Z); + } + + public static void scaledProjection() { + RenderSystem.setProjectionMatrix(new Matrix4f().setOrtho(0, (float) (mc.getWindow().getFramebufferWidth() / mc.getWindow().getScaleFactor()), (float) (mc.getWindow().getFramebufferHeight() / mc.getWindow().getScaleFactor()), 0, 1000, 21000), vertexSorter); + } + + public static void customScaledProjection(float scale) { + vertexSorter = RenderSystem.getVertexSorting(); + RenderSystem.setProjectionMatrix(new Matrix4f().setOrtho(0, mc.getWindow().getFramebufferWidth() / scale, mc.getWindow().getFramebufferHeight() / scale, 0, 1000, 21000), VertexSorter.BY_Z); + } + + /** * This method assumes that the x, y coords are the origin of a widget. * 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 b56a408..c47d690 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenu.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenu.java @@ -16,7 +16,6 @@ import java.util.List; public class ContextMenu implements Input { - public final Color darkerBackgroundColor; //The properties of a context menu protected final ContextMenuProperties properties; @@ -26,7 +25,6 @@ public class ContextMenu implements Input { // Width is counted while the options are being rendered. // FinalWidth is the width at the end of the count. protected int width = 0; - protected int finalWidth = 0; protected int height = 0, widgetHeight = 0; protected boolean shouldDisplay = false; protected float scale = 0.0f; @@ -116,8 +114,8 @@ public void toggleDisplay() { @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { if (!shouldDisplay) return false; - for (Option option : options) { - option.mouseClicked(mouseX, mouseY, button); + for (Option option : options) { + option.getRenderer().mouseClicked(option, mouseX, mouseY, button); } return properties.getSkin().mouseClicked(this, mouseX, mouseY, button); } @@ -125,8 +123,8 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { @Override public boolean mouseReleased(double mouseX, double mouseY, int button) { if (!shouldDisplay) return false; - for (Option option : options) { - option.mouseReleased(mouseX, mouseY, button); + for (Option option : options) { + option.getRenderer().mouseReleased(option,mouseX, mouseY, button); } return properties.getSkin().mouseReleased(this, mouseX, mouseY, button); } @@ -134,8 +132,8 @@ public boolean mouseReleased(double mouseX, double mouseY, int button) { @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); + for (Option option : options) { + option.getRenderer().mouseDragged(option,mouseX, mouseY, button, deltaX, deltaY); } return properties.getSkin().mouseDragged(this, mouseX, mouseY, button, deltaX, deltaY); } @@ -143,8 +141,8 @@ public boolean mouseDragged(double mouseX, double mouseY, int button, double del @Override public void keyPressed(int key, int scanCode, int modifiers) { if (!shouldDisplay) return; - for (Option option : options) { - option.keyPressed(key, scanCode, modifiers); + for (Option option : options) { + option.getRenderer().keyPressed(option,key, scanCode, modifiers); } properties.getSkin().keyPressed(this, key, scanCode, modifiers); @@ -153,8 +151,8 @@ public void keyPressed(int key, int scanCode, int modifiers) { @Override public void keyReleased(int key, int scanCode, int modifiers) { if (!shouldDisplay) return; - for (Option option : options) { - option.keyReleased(key, scanCode, modifiers); + for (Option option : options) { + option.getRenderer().keyReleased(option,key, scanCode, modifiers); } properties.getSkin().keyReleased(this, key, scanCode, modifiers); @@ -162,15 +160,17 @@ public void keyReleased(int key, int scanCode, int 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.getRenderer().mouseScrolled(option,mouseX, mouseY, horizontalAmount, verticalAmount); } properties.getSkin().mouseScrolled(this, mouseX, mouseY, horizontalAmount, verticalAmount); } @Override public void charTyped(char c) { - + for (Option option : options) { + option.charTyped(c); + } } public void set(int x, int y, int widgetHeight) { @@ -199,14 +199,6 @@ 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; } 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 84538b6..85a8657 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenuProperties.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenuProperties.java @@ -14,7 +14,7 @@ public class ContextMenuProperties { private int padding = 5; // The amount of padding around the rectangle private int heightOffset = 4; // Height offset from the widget private boolean drawBorder = true; - private boolean shadow = false; + private boolean shadow = true; private boolean roundedCorners = true; private int cornerRadius = 3; private boolean hoverEffect = true; diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/layout/LayoutContext.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/layout/LayoutContext.java new file mode 100644 index 0000000..62e3f0c --- /dev/null +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/layout/LayoutContext.java @@ -0,0 +1,83 @@ +package com.tanishisherewith.dynamichud.utils.contextmenu.layout; + +import com.tanishisherewith.dynamichud.utils.contextmenu.options.Option; + +public class LayoutContext { + private final Offset indent; + private final Option parentOption; + + public LayoutContext() { + this(Offset.zero(), null); + } + + public LayoutContext(Offset margin, Option parentOption) { + this.indent = margin; + this.parentOption = parentOption; + } + + public Offset getIndent() { + return indent; + } + + public Option getParentOption() { + return parentOption; + } + + // Builder-style methods for creating new contexts + public LayoutContext withIndent(Offset indent) { + return new LayoutContext(indent, this.parentOption); + } + + public LayoutContext withParent(Option parent) { + return new LayoutContext(this.indent, parent); + } + + public LayoutContext addIndent(Offset additionalIndent) { + return new LayoutContext( + this.indent.add(additionalIndent), + this.parentOption + ); + } + + // Utility methods for calculating positions + public int getEffectiveX(int baseX) { + return baseX + indent.left; + } + + public int getEffectiveY(int baseY) { + return baseY + indent.top; + } + + public int getEffectiveWidth(int baseWidth) { + return baseWidth + indent.left; + } + + public int getEffectiveHeight(int baseHeight) { + return baseHeight + indent.top; + } + + public static class Offset { + public final int left; + public final int top; + + public Offset(int all) { + this(all, all); + } + + public Offset(int horizontal, int vertical) { + this.left = horizontal; + this.top = vertical; + } + + public static Offset zero() { + return new Offset(0); + } + + public Offset add(Offset other) { + return new Offset( + this.left + other.left, + this.top + other.top + ); + } + } +} 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 9b68f63..ee382a7 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 @@ -10,12 +10,10 @@ import java.util.function.Supplier; public class BooleanOption extends Option { - public String name = "Empty"; private final BooleanType booleanType; public BooleanOption(String name, Supplier getter, Consumer setter, BooleanType booleanType) { - super(getter, setter); - this.name = name; + super(name,getter, setter); this.booleanType = booleanType; this.renderer.init(this); } 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 f7c41fe..41a932d 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 @@ -8,16 +8,14 @@ import java.util.function.Supplier; public class ColorOption extends Option { - public String name = "Empty"; public boolean isVisible = false; private ContextMenu parentMenu = null; private ColorGradient colorGradient = null; public ColorOption(String name, ContextMenu parentMenu, Supplier getter, Consumer setter) { - super(getter, setter); - this.name = name; + super(name,getter, setter); this.parentMenu = parentMenu; - colorGradient = new ColorGradient(x + this.parentMenu.getFinalWidth(), y - 10, get(), this::set, 50, 100); + colorGradient = new ColorGradient(x + this.parentMenu.getWidth(), y - 10, get(), this::set, 50, 100); this.renderer.init(this); } @@ -26,7 +24,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { if (isMouseOver(mouseX, mouseY)) { isVisible = !isVisible; if (isVisible) { - colorGradient.setPos(this.x + parentMenu.getFinalWidth() + 7, y - 10); + colorGradient.setPos(this.x + parentMenu.getWidth() + 7, y - 10); colorGradient.display(); } else { colorGradient.close(); 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 8848cf9..0e470a1 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 @@ -11,16 +11,14 @@ import java.util.function.Supplier; public class DoubleOption extends Option { - public String name = "Empty"; public double minValue = 0.0; public double maxValue = 0.0; - float step = 0.1f; + public 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); - this.name = name; + super(name,getter, setter); this.value = get(); this.minValue = minValue; this.maxValue = maxValue; @@ -54,13 +52,19 @@ public boolean mouseReleased(double mouseX, double mouseY, int button) { return super.mouseReleased(mouseX, mouseY, button); } - public void step(double mouseX) { + private void step(double mouseX) { + this.step(mouseX,x); + } + + public void step(double mouseX,double x) { double newValue = minValue + (float) (mouseX - x) / width * (maxValue - minValue); // Round the new value to the nearest step newValue = Math.round(newValue / step) * step; + newValue = Math.clamp(newValue,minValue,maxValue); set(newValue); } + @Override public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { if (isMouseOver(mouseX, mouseY) && isDragging) { @@ -68,4 +72,12 @@ public boolean mouseDragged(double mouseX, double mouseY, int button, double del } return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); } + + public void setDragging(boolean dragging) { + isDragging = dragging; + } + + public boolean isDragging() { + return isDragging; + } } 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 f2031e5..f28db96 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 @@ -5,12 +5,10 @@ public class EnumOption> extends Option { private final E[] values; - public String name = "Empty"; private int currentIndex = 0; public EnumOption(String name, Supplier getter, Consumer setter, E[] values) { - super(getter, setter); - this.name = name; + super(name,getter, setter); this.values = values; this.value = get(); for (int i = 0; i < values.length; i++) { 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 624ebd9..5622356 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 @@ -6,12 +6,10 @@ public class ListOption extends Option { private final List values; - public String name = "Empty"; private int currentIndex = 0; public ListOption(String name, Supplier getter, Consumer setter, List values) { - super(getter, setter); - this.name = name; + super(name,getter, setter); this.values = values; this.value = getter.get(); for (int i = 0; i < values.size(); i++) { diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/Option.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/Option.java index 1c295b3..5273ec6 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/Option.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/Option.java @@ -3,7 +3,7 @@ import com.tanishisherewith.dynamichud.DynamicHUD; import com.tanishisherewith.dynamichud.utils.Input; import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuProperties; -import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.SkinRenderer; +import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.interfaces.SkinRenderer; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; @@ -11,6 +11,7 @@ import java.util.function.Supplier; public abstract class Option implements Input { + public String name = "Empty", description = ""; public T value = null; protected int x, y; protected int width = 0; @@ -23,11 +24,12 @@ public abstract class Option implements Input { protected ContextMenuProperties properties; protected SkinRenderer> renderer; - public Option(Supplier getter, Consumer setter) { - this(getter, setter, () -> true); + public Option(String name,Supplier getter, Consumer setter) { + this(name,getter, setter, () -> true); } - public Option(Supplier getter, Consumer setter, Supplier shouldRender, ContextMenuProperties properties) { + public Option(String name,Supplier getter, Consumer setter, Supplier shouldRender, ContextMenuProperties properties) { + this.name = name; this.getter = getter; this.setter = setter; this.shouldRender = shouldRender; @@ -36,8 +38,8 @@ public Option(Supplier getter, Consumer setter, Supplier shouldRe updateProperties(properties); } - public Option(Supplier getter, Consumer setter, Supplier shouldRender) { - this(getter, setter, shouldRender, ContextMenuProperties.createGenericSimplified()); + public Option(String name,Supplier getter, Consumer setter, Supplier shouldRender) { + this(name,getter, setter, shouldRender, ContextMenuProperties.createGenericSimplified()); } public T get() { @@ -68,41 +70,32 @@ 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); } public boolean mouseReleased(double mouseX, double mouseY, int button) { - return isMouseOver(mouseX, mouseY) || renderer.mouseReleased(this, mouseX, mouseY, button); + return isMouseOver(mouseX, mouseY); } 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); + return isMouseOver(mouseX, mouseY); } - public void mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { - renderer.mouseScrolled(this, mouseX, mouseY, horizontalAmount, verticalAmount); - } + public void mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {} @Override - public void keyPressed(int key, int scanCode, int modifiers) { - renderer.keyPressed(this, key, scanCode, modifiers); - } + public void keyPressed(int key, int scanCode, int modifiers) {} @Override - public void charTyped(char c) { - - } + public void charTyped(char c) {} @Override - public void keyReleased(int key, int scanCode, int modifiers) { - renderer.keyReleased(this, key, scanCode, modifiers); - } + public void keyReleased(int key, int scanCode, int modifiers) {} /** * Called when the context menu closes */ - public void onClose() { - } + public void onClose() {} public boolean isMouseOver(double mouseX, double mouseY) { return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height; @@ -157,4 +150,12 @@ public void set(int x, int y) { this.x = x; this.y = y; } + public Option description(String description){ + this.description = description; + return this; + } + + public SkinRenderer> getRenderer() { + return renderer; + } } diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/OptionGroup.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/OptionGroup.java new file mode 100644 index 0000000..36a0b75 --- /dev/null +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/OptionGroup.java @@ -0,0 +1,114 @@ +package com.tanishisherewith.dynamichud.utils.contextmenu.options; + +import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuProperties; +import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.interfaces.SkinRenderer; +import net.minecraft.client.gui.DrawContext; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +// A group is just another type of Option that contains other options +public class OptionGroup extends Option { + private final List