Skip to content

Commit

Permalink
More changes to ModernSkin, OptionalGroups changes, some refactors an…
Browse files Browse the repository at this point in the history
…d interface folder.
  • Loading branch information
tanishisherewithhh committed Oct 25, 2024
1 parent 3f93c11 commit 09cdc78
Show file tree
Hide file tree
Showing 24 changed files with 1,095 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void checkToEnableTestIntegration(){

@Override
public void onInitializeClient() {
printInfo("Initialising DynamicHud");
printInfo("Initialising DynamicHUD");

// Add WidgetData of included widgets
WidgetManager.registerCustomWidgets(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.util.Identifier;

import java.awt.*;
import java.util.LinkedList;

public final class GlobalConfig {
public static final ConfigClassHandler<GlobalConfig> HANDLER = ConfigClassHandler.createBuilder(GlobalConfig.class)
Expand All @@ -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;
Expand Down Expand Up @@ -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.<Color>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.<Color>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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -12,10 +13,13 @@

import java.awt.*;

import static com.tanishisherewith.dynamichud.helpers.TextureHelper.mc;

/**
* Credits: <a href="https://github.com/HeliosMinecraft/HeliosClient/blob/main/src/main/java/dev/heliosclient/util/ColorUtils.java">HeliosClient</a>
*/
public class DrawHelper {
public static VertexSorter vertexSorter;

/**
* Draws a singular gradient rectangle on screen with the given parameters
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -116,35 +114,35 @@ 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);
}

@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);
}

@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);
}

@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);
Expand All @@ -153,24 +151,26 @@ 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);

}

@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) {
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
import java.util.function.Supplier;

public class BooleanOption extends Option<Boolean> {
public String name = "Empty";
private final BooleanType booleanType;

public BooleanOption(String name, Supplier<Boolean> getter, Consumer<Boolean> setter, BooleanType booleanType) {
super(getter, setter);
this.name = name;
super(name,getter, setter);
this.booleanType = booleanType;
this.renderer.init(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
import java.util.function.Supplier;

public class ColorOption extends Option<Color> {
public String name = "Empty";
public boolean isVisible = false;
private ContextMenu parentMenu = null;
private ColorGradient colorGradient = null;

public ColorOption(String name, ContextMenu parentMenu, Supplier<Color> getter, Consumer<Color> 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);
}

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@
import java.util.function.Supplier;

public class DoubleOption extends Option<Double> {
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<Double> getter, Consumer<Double> setter, ContextMenu parentMenu) {
super(getter, setter);
this.name = name;
super(name,getter, setter);
this.value = get();
this.minValue = minValue;
this.maxValue = maxValue;
Expand Down Expand Up @@ -54,18 +52,32 @@ 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) {
step(mouseX);
}
return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
}

public void setDragging(boolean dragging) {
isDragging = dragging;
}

public boolean isDragging() {
return isDragging;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@

public class EnumOption<E extends Enum<E>> extends Option<E> {
private final E[] values;
public String name = "Empty";
private int currentIndex = 0;

public EnumOption(String name, Supplier<E> getter, Consumer<E> 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++) {
Expand Down
Loading

0 comments on commit 09cdc78

Please sign in to comment.