* 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
>) 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 extends Option>>> renderers = new HashMap<>();
private boolean createNewScreen;
- public > void addRenderer(Class optionClass, SkinRenderer super T> 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 super T> 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;
}
}
+
+
}
From 70df427f64d4794849ce36e3d1295f82d2a73651 Mon Sep 17 00:00:00 2001
From: tanishisherewithhh
<120117618+tanishisherewithhh@users.noreply.github.com>
Date: Wed, 9 Oct 2024 16:54:19 +0530
Subject: [PATCH 08/27] Gradle Changes and stuff.
---
.github/workflows/gradle.yml | 2 +-
.../dynamichud/DynamicHudTest.java | 3 +-
.../contextmenu/skinsystem/SkinRenderer.java | 2 +-
.../dynamichud/widget/WidgetManager.java | 42 ++++++++++---------
.../dynamichud/widget/WidgetRenderer.java | 4 ++
5 files changed, 29 insertions(+), 24 deletions(-)
diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml
index ff0fffc..dc32e0f 100644
--- a/.github/workflows/gradle.yml
+++ b/.github/workflows/gradle.yml
@@ -48,7 +48,7 @@ jobs:
path: build/libs/
- name: pre-release action
- uses: softprops/action-gh-release@v2
+ uses: softprops/action-gh-release@v2.0.8
with:
tag_name: "latest"
name: "DynamicHUD Pre-release"
diff --git a/src/main/java/com/tanishisherewith/dynamichud/DynamicHudTest.java b/src/main/java/com/tanishisherewith/dynamichud/DynamicHudTest.java
index bc68bca..383cbed 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/DynamicHudTest.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/DynamicHudTest.java
@@ -87,8 +87,7 @@ public void initAfter() {
@Override
public AbstractMoveableScreen getMovableScreen() {
- return new AbstractMoveableScreen(Text.literal("Editor Screen"), renderer) {
- };
+ return new AbstractMoveableScreen(Text.literal("Editor Screen"), renderer) {};
}
@Override
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 8e7775f..a19887c 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
@@ -3,7 +3,7 @@
import com.tanishisherewith.dynamichud.utils.contextmenu.Option;
import net.minecraft.client.gui.DrawContext;
-public interface SkinRenderer> {
+public interface SkinRenderer> {
void render(DrawContext drawContext, T option, int x, int y, int mouseX, int mouseY);
default boolean mouseClicked(T option, double mouseX, double mouseY, int button) {
diff --git a/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetManager.java b/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetManager.java
index 489a799..a2af510 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetManager.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetManager.java
@@ -180,27 +180,29 @@ public static void saveWidgets(File file, List widgets) throws IOExcepti
public static void loadWidgets(File file) throws IOException {
widgets.clear();
- if (file.exists() || (file = new File(file.getAbsolutePath() + ".backup")).exists()) {
- if (!file.exists()) {
- printWarn("Main file " + file.getAbsolutePath() + " was not found... Loading from a found backup file");
- }
+ if (!file.exists()) {
+ DynamicHUD.logger.warn("Main file {} was not found... Loading from a found backup file", file.getAbsolutePath());
+ file = new File(file.getAbsolutePath() + ".backup");
+ }
- NbtCompound rootTag = NbtIo.read(file.toPath());
- NbtList widgetList = rootTag.getList("widgets", NbtType.COMPOUND);
- if (widgetList == null) {
- printWarn("RootTag or WidgetList is null. File is either empty or corrupted: " + file);
- return;
- }
- for (int i = 0; i < widgetList.size(); i++) {
- NbtCompound widgetTag = widgetList.getCompound(i);
- WidgetData> widgetData = widgetDataMap.get(widgetTag.getString("name"));
- Widget widget = widgetData.createWidget();
- widget.readFromTag(widgetTag);
- printInfo("Loaded Widget: " + widget);
- widgets.add(widget);
- }
- } else {
- printWarn("Widget File does not exist. Try saving one first");
+ NbtCompound rootTag = NbtIo.read(file.toPath());
+
+ if (rootTag == null) {
+ printWarn("RootTag is null. File is either empty or corrupted: " + file);
+ return;
+ }
+ NbtList widgetList = rootTag.getList("widgets", NbtType.COMPOUND);
+ if (widgetList == null) {
+ printWarn("WidgetList is null. File is empty: " + file);
+ return;
+ }
+ for (int i = 0; i < widgetList.size(); i++) {
+ NbtCompound widgetTag = widgetList.getCompound(i);
+ WidgetData> widgetData = widgetDataMap.get(widgetTag.getString("name"));
+ Widget widget = widgetData.createWidget();
+ widget.readFromTag(widgetTag);
+ printInfo("Loaded Widget: " + widget);
+ widgets.add(widget);
}
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetRenderer.java b/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetRenderer.java
index c3eac55..630340f 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetRenderer.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetRenderer.java
@@ -31,6 +31,10 @@ public WidgetRenderer(List widgets) {
addScreen(ContextMenuScreen.class);
}
+ public WidgetRenderer(String modID) {
+ this(WidgetManager.getWidgetsForMod(modID));
+ }
+
public void addWidget(Widget widget) {
widgets.add(widget);
}
From bbdba6dc941d033ca2d65dc455ddd99765c53880 Mon Sep 17 00:00:00 2001
From: tanishisherewithhh
<120117618+tanishisherewithhh@users.noreply.github.com>
Date: Tue, 22 Oct 2024 20:25:09 +0530
Subject: [PATCH 09/27] Removed ModMenuIntegration.java and added a DH button
to option screen
---
build.gradle | 2 --
gradle.properties | 3 +-
.../dynamichud/ModMenuIntegration.java | 13 -------
.../dynamichud/mixins/OptionsScreenMixin.java | 36 +++++++++++++++++++
.../contextmenu/ContextMenuProperties.java | 2 ++
.../dynamichud/widgets/TextWidget.java | 2 +-
src/main/resources/dynamichud.mixins.json | 4 ++-
src/main/resources/fabric.mod.json | 3 --
8 files changed, 43 insertions(+), 22 deletions(-)
delete mode 100644 src/main/java/com/tanishisherewith/dynamichud/ModMenuIntegration.java
create mode 100644 src/main/java/com/tanishisherewith/dynamichud/mixins/OptionsScreenMixin.java
diff --git a/build.gradle b/build.gradle
index 9f94dfe..5bdb604 100644
--- a/build.gradle
+++ b/build.gradle
@@ -34,8 +34,6 @@ dependencies {
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation "dev.isxander:yet-another-config-lib:${project.yacl_version}"
-
- modApi "com.terraformersmc:modmenu:${project.modmenu_version}"
}
processResources {
diff --git a/gradle.properties b/gradle.properties
index e2dee65..b1efe41 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -15,5 +15,4 @@ archives_base_name = dynamichud
# Dependencies
fabric_version=0.102.1+1.21.1
-yacl_version=3.5.0+1.21-fabric
-modmenu_version = 11.0.2
\ No newline at end of file
+yacl_version=3.5.0+1.21-fabric
\ No newline at end of file
diff --git a/src/main/java/com/tanishisherewith/dynamichud/ModMenuIntegration.java b/src/main/java/com/tanishisherewith/dynamichud/ModMenuIntegration.java
deleted file mode 100644
index 668a7ed..0000000
--- a/src/main/java/com/tanishisherewith/dynamichud/ModMenuIntegration.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.tanishisherewith.dynamichud;
-
-import com.tanishisherewith.dynamichud.config.GlobalConfig;
-import com.terraformersmc.modmenu.api.ConfigScreenFactory;
-import com.terraformersmc.modmenu.api.ModMenuApi;
-
-
-public class ModMenuIntegration implements ModMenuApi {
- @Override
- public ConfigScreenFactory> getModConfigScreenFactory() {
- return parent -> GlobalConfig.get().createYACLGUI();
- }
-}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/mixins/OptionsScreenMixin.java b/src/main/java/com/tanishisherewith/dynamichud/mixins/OptionsScreenMixin.java
new file mode 100644
index 0000000..772b49d
--- /dev/null
+++ b/src/main/java/com/tanishisherewith/dynamichud/mixins/OptionsScreenMixin.java
@@ -0,0 +1,36 @@
+package com.tanishisherewith.dynamichud.mixins;
+
+import com.llamalad7.mixinextras.sugar.Local;
+import com.tanishisherewith.dynamichud.config.GlobalConfig;
+import net.minecraft.client.gui.screen.Screen;
+import net.minecraft.client.gui.screen.option.OptionsScreen;
+import net.minecraft.client.gui.widget.ButtonWidget;
+import net.minecraft.client.gui.widget.DirectionalLayoutWidget;
+import net.minecraft.text.Text;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import java.util.function.Supplier;
+
+@Mixin(OptionsScreen.class)
+public abstract class OptionsScreenMixin extends Screen {
+ @Shadow protected abstract ButtonWidget createButton(Text message, Supplier screenSupplier);
+
+ protected OptionsScreenMixin(Text title) {
+ super(title);
+ }
+ @Inject(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/GridWidget$Adder;add(Lnet/minecraft/client/gui/widget/Widget;)Lnet/minecraft/client/gui/widget/Widget;", ordinal = 0))
+ private void init(CallbackInfo ci, @Local(ordinal = 0) DirectionalLayoutWidget directionalLayoutWidget) {
+ DirectionalLayoutWidget directionalLayoutWidget2 = directionalLayoutWidget.add(DirectionalLayoutWidget.horizontal());
+
+ directionalLayoutWidget2.getMainPositioner().marginLeft(-26).marginY(-28);
+
+ ButtonWidget widget = createButton(Text.of("DH"), () -> GlobalConfig.get().createYACLGUI());
+ widget.setDimensions(20, 20);
+
+ directionalLayoutWidget2.add(widget);
+ }
+}
\ No newline at end of file
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 2576b4e..ff70053 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenuProperties.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenuProperties.java
@@ -6,6 +6,8 @@
import java.awt.*;
public class ContextMenuProperties {
+ //Note: Not all of these properties are used in all skins or all places.
+
private Color backgroundColor = new Color(107, 112, 126, 124);
private Color borderColor = Color.BLACK;
private float borderWidth = 1f;
diff --git a/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java b/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java
index b14a296..64c1ef9 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java
@@ -30,10 +30,10 @@ public class TextWidget extends Widget implements ContextMenuProvider {
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
*
diff --git a/src/main/resources/dynamichud.mixins.json b/src/main/resources/dynamichud.mixins.json
index f40333e..f5d7c16 100644
--- a/src/main/resources/dynamichud.mixins.json
+++ b/src/main/resources/dynamichud.mixins.json
@@ -9,5 +9,7 @@
"injectors": {
"defaultRequire": 1
},
- "client": []
+ "client": [
+ "OptionsScreenMixin"
+ ]
}
diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json
index 33a2089..6b9036c 100644
--- a/src/main/resources/fabric.mod.json
+++ b/src/main/resources/fabric.mod.json
@@ -20,9 +20,6 @@
"entrypoints": {
"client": [
"com.tanishisherewith.dynamichud.DynamicHUD"
- ],
- "modmenu": [
- "com.tanishisherewith.dynamichud.ModMenuIntegration"
]
},
"mixins": [
From 5b7f7fbe8242f62f89e3acc190d2dd9d9b1ba643 Mon Sep 17 00:00:00 2001
From: tanishisherewithhh
<120117618+tanishisherewithhh@users.noreply.github.com>
Date: Tue, 22 Oct 2024 22:26:19 +0530
Subject: [PATCH 10/27] Removed unnecessary methods and reverted TextWidget to
use the ClassicSkin
---
.../contextmenu/ContextMenuProperties.java | 5 +--
.../dynamichud/utils/contextmenu/Option.java | 3 +-
.../contextmenu/options/BooleanOption.java | 15 -------
.../contextmenu/options/ColorOption.java | 35 +++------------
.../contextmenu/options/DoubleOption.java | 44 -------------------
.../utils/contextmenu/options/EnumOption.java | 17 -------
.../utils/contextmenu/options/ListOption.java | 15 -------
.../contextmenu/options/RunnableOption.java | 16 -------
.../contextmenu/options/SubMenuOption.java | 6 ---
.../contextmenu/skinsystem/ClassicSkin.java | 4 +-
.../contextmenu/skinsystem/ModernSkin.java | 11 +++++
.../dynamichud/widgets/TextWidget.java | 4 +-
12 files changed, 23 insertions(+), 152 deletions(-)
create mode 100644 src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ModernSkin.java
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 ff70053..84538b6 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenuProperties.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenuProperties.java
@@ -22,15 +22,14 @@ 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();
}
public static ContextMenuProperties createGenericSimplified() {
- return new ContextMenuProperties().new Builder().build();
+ return new ContextMenuProperties();
}
// Getters for all properties
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 95d81b7..6ea6c40 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/Option.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/Option.java
@@ -52,7 +52,7 @@ public void updateProperties(ContextMenuProperties properties) {
this.properties = properties;
this.renderer = properties.getSkin().getRenderer((Class
>) this.getClass());
if (renderer == null) {
- DynamicHUD.logger.error("Renderer not found for class: {}", this.getClass().getName());
+ DynamicHUD.logger.error("Renderer not found for class: {} in the following skin: {}", this.getClass().getName(), properties.getSkin());
throw new RuntimeException();
}
}
@@ -60,6 +60,7 @@ public void updateProperties(ContextMenuProperties properties) {
public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) {
this.x = x;
this.y = y;
+ this.value = get();
// Retrieve the renderer and ensure it is not null
renderer.render(drawContext, this, x, y, mouseX, mouseY);
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 08ffa66..8a548ee 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
@@ -35,21 +35,6 @@ public BooleanOption(String name, boolean defaultValue, BooleanType type) {
BooleanPool.put(name, defaultValue);
}
- @Override
- public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) {
- value = get();
- super.render(drawContext, 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);
- this.height = mc.textRenderer.fontHeight;
- this.width = mc.textRenderer.getWidth(name) + 1;
-
- */
- }
-
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (isMouseOver(mouseX, mouseY) && button == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
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 dc31a33..176d067 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
@@ -12,7 +12,7 @@
public class ColorOption extends Option {
public String name = "Empty";
public boolean isVisible = false;
- public ContextMenu parentMenu = null;
+ private ContextMenu parentMenu = null;
private ColorGradientPicker colorPicker = null;
public ColorOption(String name, ContextMenu parentMenu, Supplier getter, Consumer setter) {
@@ -23,35 +23,6 @@ public ColorOption(String name, ContextMenu parentMenu, Supplier getter,
this.renderer.init(this);
}
- @Override
- 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);
-
- /*
- int color = isVisible ? Color.GREEN.getRGB() : Color.RED.getRGB();
- this.height = mc.textRenderer.fontHeight;
- this.width = mc.textRenderer.getWidth(name) + 8;
- drawContext.drawText(mc.textRenderer, Text.of(name), x, y, color, false);
-
- int shadowOpacity = Math.min(value.getAlpha(),90);
- DrawHelper.drawRoundedRectangleWithShadowBadWay(drawContext.getMatrices().peek().getPositionMatrix(),
- x + width - 4,
- y - 1,
- 8,
- 8,
- 2,
- value.getRGB(),
- shadowOpacity,
- 1,
- 1);
-
- colorPicker.render(drawContext, this.x + parentMenu.finalWidth + 7, y - 10);
-
- */
- }
-
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (isMouseOver(mouseX, mouseY)) {
@@ -88,4 +59,8 @@ public void onClose() {
isVisible = false;
colorPicker.close();
}
+
+ public ContextMenu getParentMenu() {
+ return parentMenu;
+ }
}
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 d51ef4a..7297320 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
@@ -33,50 +33,6 @@ public DoubleOption(String name, double minValue, double maxValue, float step, S
this.renderer.init(this);
}
- @Override
- public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) {
- value = get();
- super.render(drawContext, x, y, mouseX, mouseY);
-
- //properties.getSkin().getRenderer(DoubleOption.class).render(drawContext,this,x,y,mouseX,mouseY);
-
- /*
- this.width = 35;
- this.height = 16;
-
- // Draw the label
- TextRenderer textRenderer = mc.textRenderer;
- DrawHelper.scaleAndPosition(drawContext.getMatrices(), x, y, 0.7f);
- String labelText = name + ": " + String.format("%.1f", value);
- int labelWidth = textRenderer.getWidth(labelText);
- this.width = Math.max(this.width, labelWidth);
- drawContext.drawTextWithShadow(textRenderer, labelText, x, y + 1, 0xFFFFFFFF);
- DrawHelper.stopScaling(drawContext.getMatrices());
-
- float handleWidth = 3;
- float handleHeight = 8;
- double handleX = x + (value - minValue) / (maxValue - minValue) * (width - handleWidth);
- double handleY = y + textRenderer.fontHeight + 1 + ((2 - handleHeight) / 2);
-
- // Draw the slider
- drawSlider(drawContext, x, y + textRenderer.fontHeight + 1, width, handleX);
-
- // Draw the handle
-
- DrawHelper.drawRoundedRectangleWithShadowBadWay(drawContext.getMatrices().peek().getPositionMatrix(),
- (float) handleX,
- (float) handleY,
- handleWidth,
- handleHeight,
- 1,
- 0xFFFFFFFF,
- 90,
- 0.6f,
- 0.6f);
-
- */
- }
-
public void drawSlider(DrawContext drawContext, int sliderX, int sliderY, int sliderWidth, double handleX) {
DrawHelper.drawRectangle(drawContext.getMatrices().peek().getPositionMatrix(), sliderX, sliderY, sliderWidth, 2, 0xFFFFFFFF);
if (handleX - sliderX > 0) {
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 59de1b4..dffd127 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
@@ -25,23 +25,6 @@ public EnumOption(String name, Supplier getter, Consumer setter, E[] value
this.renderer.init(this);
}
- @Override
- public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) {
- value = get();
- super.render(drawContext, x, y, mouseX, mouseY);
-
- // properties.getSkin().getRenderer(EnumOption.class).render(drawContext,this,x,y,mouseX,mouseY);
-
- /*
- this.height = mc.textRenderer.fontHeight + 1;
- this.width = mc.textRenderer.getWidth(name + ": " + value.name()) + 1;
-
- drawContext.drawText(mc.textRenderer, Text.of(name + ": "), x, y, Color.WHITE.getRGB(), false);
- drawContext.drawText(mc.textRenderer, Text.of(value.name()), x + mc.textRenderer.getWidth(name + ": ") + 1, y, Color.CYAN.getRGB(), false);
-
- */
- }
-
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (super.mouseClicked(mouseX, mouseY, button)) {
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 c28def6..2a2c6f4 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
@@ -26,21 +26,6 @@ public ListOption(String name, Supplier getter, Consumer setter, List v
this.renderer.init(this);
}
- @Override
- public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) {
- value = get();
- super.render(drawContext, x, y, mouseX, mouseY);
-
- // properties.getSkin().getRenderer(ListOption.class).render(drawContext,this,x,y,mouseX,mouseY);
-/*
- this.height = mc.textRenderer.fontHeight + 1;
- this.width = mc.textRenderer.getWidth(name + ": " + value.toString()) + 1;
-
- drawContext.drawText(mc.textRenderer, Text.of(name + ": "), x, y, Color.WHITE.getRGB(), false);
- drawContext.drawText(mc.textRenderer, Text.of(value.toString()), x + mc.textRenderer.getWidth(name + ": ") + 1, y, Color.CYAN.getRGB(), false);
-*/
- }
-
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (super.mouseClicked(mouseX, mouseY, button)) {
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 7d169d4..bf85c19 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
@@ -31,22 +31,6 @@ public RunnableOption(String name, boolean defaultValue, Runnable task) {
BooleanPool.put(name, defaultValue);
}
- @Override
- public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) {
- value = get();
- super.render(drawContext, x, y, mouseX, mouseY);
-
- //properties.getSkin().getRenderer(RunnableOption.class).render(drawContext,this,x,y,mouseX,mouseY);
-
- /*
- this.height = mc.textRenderer.fontHeight;
- this.width = mc.textRenderer.getWidth("Run: " + name);
- int color = value ? DARK_GREEN.getRGB() : DARK_RED.getRGB();
- drawContext.drawText(mc.textRenderer, Text.of(name), x, y, color, false);
-
- */
- }
-
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (super.mouseClicked(mouseX, mouseY, button)) {
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 6fbc3a8..b9af8e0 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
@@ -45,12 +45,6 @@ public SubMenuOption(String name, ContextMenu parentMenu) {
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);
- }
-
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (super.mouseClicked(mouseX, mouseY, button)) {
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 9936f48..72b59c5 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
@@ -174,7 +174,7 @@ public void render(DrawContext drawContext, ColorOption option, int x, int y, in
1,
1);
- option.getColorPicker().render(drawContext, x + option.parentMenu.getFinalWidth() + 7, y - 10);
+ option.getColorPicker().render(drawContext, x + option.getParentMenu().getFinalWidth() + 7, y - 10);
}
}
@@ -254,7 +254,7 @@ public void render(DrawContext drawContext, DoubleOption option, int x, int y, i
}
}
- public class ClassicListRenderer implements SkinRenderer> {
+ public static class ClassicListRenderer implements SkinRenderer> {
@Override
public void render(DrawContext drawContext, ListOption option, int x, int y, int mouseX, int mouseY) {
option.setHeight(mc.textRenderer.fontHeight + 1);
diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ModernSkin.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ModernSkin.java
new file mode 100644
index 0000000..b464092
--- /dev/null
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ModernSkin.java
@@ -0,0 +1,11 @@
+package com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem;
+
+import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu;
+import net.minecraft.client.gui.DrawContext;
+
+public class ModernSkin extends Skin{
+ @Override
+ public void renderContextMenu(DrawContext drawContext, ContextMenu contextMenu, int mouseX, int mouseY) {
+
+ }
+}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java b/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java
index 64c1ef9..cd15a26 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java
@@ -74,9 +74,7 @@ public TextWidget(DynamicValueRegistry dynamicValueRegistry, String dynamicRegis
}
public void createMenu() {
- ContextMenuProperties properties = ContextMenuProperties.builder()
- .skin(new MinecraftSkin(MinecraftSkin.PanelColor.DARK_PANEL))
- .build();
+ ContextMenuProperties properties = ContextMenuProperties.createGenericSimplified();
menu = new ContextMenu(getX(), getY(), properties);
menu.getProperties().getSkin().setContextMenu(menu);
From 3f93c11d40edec0d388dac3953b372dc21214479 Mon Sep 17 00:00:00 2001
From: tanishisherewithhh
<120117618+tanishisherewithhh@users.noreply.github.com>
Date: Tue, 22 Oct 2024 23:21:23 +0530
Subject: [PATCH 11/27] Many refactors, renamed files, smoothened MinecraftSkin
panel. Added a panel behind color option as well. Added color settings in
YACL.
---
.../dynamichud/config/GlobalConfig.java | 31 ++++++++++++++++
.../utils/contextmenu/ContextMenu.java | 31 ++++++++--------
.../contextmenuscreen/ContextMenuScreen.java | 1 +
.../contextmenu/options/BooleanOption.java | 2 --
.../contextmenu/options/ColorOption.java | 26 +++++++-------
.../contextmenu/options/DoubleOption.java | 1 -
.../utils/contextmenu/options/EnumOption.java | 3 --
.../utils/contextmenu/options/ListOption.java | 3 --
.../contextmenu/{ => options}/Option.java | 3 +-
.../contextmenu/options/RunnableOption.java | 2 --
.../contextmenu/options/SubMenuOption.java | 2 --
.../options/coloroption/AlphaSlider.java | 8 +++++
...GradientPicker.java => ColorGradient.java} | 35 +++++++++++++++----
.../coloroption/ColorPickerButton.java | 4 ++-
.../{GradientSlider.java => HueSlider.java} | 4 +--
...GradientBox.java => SaturationHueBox.java} | 12 ++++---
.../contextmenu/skinsystem/ClassicSkin.java | 4 +--
.../contextmenu/skinsystem/MinecraftSkin.java | 21 ++++++++---
.../contextmenu/skinsystem/ModernSkin.java | 2 ++
.../utils/contextmenu/skinsystem/Skin.java | 2 +-
.../contextmenu/skinsystem/SkinRenderer.java | 2 +-
.../dynamichud/widget/Widget.java | 2 +-
.../dynamichud/widgets/TextWidget.java | 2 +-
23 files changed, 135 insertions(+), 68 deletions(-)
rename src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/{ => options}/Option.java (96%)
rename src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/{ColorGradientPicker.java => ColorGradient.java} (90%)
rename src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/{GradientSlider.java => HueSlider.java} (97%)
rename src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/{GradientBox.java => SaturationHueBox.java} (93%)
diff --git a/src/main/java/com/tanishisherewith/dynamichud/config/GlobalConfig.java b/src/main/java/com/tanishisherewith/dynamichud/config/GlobalConfig.java
index eedd866..23da97e 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/config/GlobalConfig.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/config/GlobalConfig.java
@@ -1,17 +1,22 @@
package com.tanishisherewith.dynamichud.config;
+import com.tanishisherewith.dynamichud.helpers.ColorHelper;
import dev.isxander.yacl3.api.*;
import dev.isxander.yacl3.api.controller.BooleanControllerBuilder;
+import dev.isxander.yacl3.api.controller.ColorControllerBuilder;
import dev.isxander.yacl3.api.controller.FloatSliderControllerBuilder;
import dev.isxander.yacl3.api.controller.IntegerFieldControllerBuilder;
import dev.isxander.yacl3.config.v2.api.ConfigClassHandler;
import dev.isxander.yacl3.config.v2.api.SerialEntry;
import dev.isxander.yacl3.config.v2.api.serializer.GsonConfigSerializerBuilder;
+import dev.isxander.yacl3.config.v2.impl.autogen.ColorFieldImpl;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
+import java.awt.*;
+
public final class GlobalConfig {
public static final ConfigClassHandler HANDLER = ConfigClassHandler.createBuilder(GlobalConfig.class)
.id(Identifier.of("dynamichud", "dynamichud_config"))
@@ -37,6 +42,12 @@ public final class GlobalConfig {
@SerialEntry
private int snapSize = 100;
+ @SerialEntry
+ private Color hudActiveColor = new Color(0, 0, 0, 128);
+
+ @SerialEntry
+ private Color hudInactiveColor = new Color(255, 0, 0, 128);
+
public static GlobalConfig get() {
return INSTANCE;
}
@@ -75,6 +86,18 @@ public Screen createYACLGUI() {
.controller(integerOption -> IntegerFieldControllerBuilder.create(integerOption).range(10, 500))
.build())
.build())
+ .option(Option.createBuilder()
+ .name(Text.literal("Widget HUD Active Background Color"))
+ .description(OptionDescription.of(Text.literal("Color of the background of the widget when it will be rendered")))
+ .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)
+ .build())
.build())
.save(HANDLER::save)
.build()
@@ -96,4 +119,12 @@ public boolean shouldDisplayDescriptions() {
public int getSnapSize() {
return snapSize;
}
+
+ public Color getHudInactiveColor() {
+ return hudInactiveColor;
+ }
+
+ public Color getHudActiveColor() {
+ return hudActiveColor;
+ }
}
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 529bca9..b56a408 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenu.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenu.java
@@ -5,6 +5,7 @@
import com.tanishisherewith.dynamichud.utils.Input;
import com.tanishisherewith.dynamichud.utils.contextmenu.contextmenuscreen.ContextMenuScreenFactory;
import com.tanishisherewith.dynamichud.utils.contextmenu.contextmenuscreen.DefaultContextMenuScreenFactory;
+import com.tanishisherewith.dynamichud.utils.contextmenu.options.Option;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.math.MathHelper;
@@ -19,18 +20,18 @@ 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;
+ protected final List
> options = new ArrayList<>(); // The list of options in the context menu
+ protected 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.
- private int width = 0;
- private int finalWidth = 0;
- private int height = 0, widgetHeight = 0;
- private boolean shouldDisplay = false;
- private float scale = 0.0f;
- private Screen parentScreen = null;
- private boolean newScreenFlag = false;
+ protected int width = 0;
+ protected int finalWidth = 0;
+ protected int height = 0, widgetHeight = 0;
+ protected boolean shouldDisplay = false;
+ protected float scale = 0.0f;
+ protected Screen parentScreen = null;
+ protected boolean newScreenFlag = false;
public ContextMenu(int x, int y, ContextMenuProperties properties) {
this(x, y, properties, new DefaultContextMenuScreenFactory());
@@ -85,16 +86,14 @@ public void update() {
}
public void close() {
- if (properties.getSkin().shouldCreateNewScreen() && scale <= 0 && parentScreen != null) {
- shouldDisplay = false;
- newScreenFlag = false;
- DynamicHUD.MC.setScreen(parentScreen);
- }
+ shouldDisplay = false;
+ newScreenFlag = false;
for (Option> option : options) {
option.onClose();
}
- shouldDisplay = false;
- newScreenFlag = false;
+ if (properties.getSkin().shouldCreateNewScreen() && scale <= 0 && parentScreen != null) {
+ DynamicHUD.MC.setScreen(parentScreen);
+ }
}
public void open() {
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 d398086..64c6769 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
@@ -82,5 +82,6 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
@Override
public void close() {
contextMenu.close();
+ contextMenu.setVisible(false);
}
}
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 8a548ee..9b68f63 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
@@ -1,8 +1,6 @@
package com.tanishisherewith.dynamichud.utils.contextmenu.options;
import com.tanishisherewith.dynamichud.utils.BooleanPool;
-import com.tanishisherewith.dynamichud.utils.contextmenu.Option;
-import net.minecraft.client.gui.DrawContext;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.Text;
import org.lwjgl.glfw.GLFW;
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 176d067..f7c41fe 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,9 +1,7 @@
package com.tanishisherewith.dynamichud.utils.contextmenu.options;
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 com.tanishisherewith.dynamichud.utils.contextmenu.options.coloroption.ColorGradient;
import java.awt.*;
import java.util.function.Consumer;
@@ -13,13 +11,13 @@ public class ColorOption extends Option {
public String name = "Empty";
public boolean isVisible = false;
private ContextMenu parentMenu = null;
- private ColorGradientPicker colorPicker = null;
+ private ColorGradient colorGradient = null;
public ColorOption(String name, ContextMenu parentMenu, Supplier getter, Consumer setter) {
super(getter, setter);
this.name = name;
this.parentMenu = parentMenu;
- colorPicker = new ColorGradientPicker(x + this.parentMenu.getFinalWidth(), y - 10, get(), this::set, 50, 100);
+ colorGradient = new ColorGradient(x + this.parentMenu.getFinalWidth(), y - 10, get(), this::set, 50, 100);
this.renderer.init(this);
}
@@ -28,36 +26,36 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (isMouseOver(mouseX, mouseY)) {
isVisible = !isVisible;
if (isVisible) {
- colorPicker.setPos(this.x + parentMenu.getFinalWidth() + 7, y - 10);
- colorPicker.display();
+ colorGradient.setPos(this.x + parentMenu.getFinalWidth() + 7, y - 10);
+ colorGradient.display();
} else {
- colorPicker.close();
+ colorGradient.close();
}
}
- colorPicker.mouseClicked(mouseX, mouseY, button);
+ colorGradient.mouseClicked(mouseX, mouseY, button);
return super.mouseClicked(mouseX, mouseY, button);
}
@Override
public boolean mouseReleased(double mouseX, double mouseY, int button) {
- colorPicker.mouseReleased(mouseX, mouseY, button);
+ colorGradient.mouseReleased(mouseX, mouseY, button);
return super.mouseReleased(mouseX, mouseY, button);
}
@Override
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
- colorPicker.mouseDragged(mouseX, mouseY, button);
+ colorGradient.mouseDragged(mouseX, mouseY, button);
return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
}
- public ColorGradientPicker getColorPicker() {
- return colorPicker;
+ public ColorGradient getColorGradient() {
+ return colorGradient;
}
@Override
public void onClose() {
isVisible = false;
- colorPicker.close();
+ colorGradient.close();
}
public ContextMenu getParentMenu() {
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 7297320..8848cf9 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
@@ -2,7 +2,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.gui.DrawContext;
import org.apache.commons.lang3.Validate;
import org.lwjgl.glfw.GLFW;
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 dffd127..f2031e5 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
@@ -1,8 +1,5 @@
package com.tanishisherewith.dynamichud.utils.contextmenu.options;
-import com.tanishisherewith.dynamichud.utils.contextmenu.Option;
-import net.minecraft.client.gui.DrawContext;
-
import java.util.function.Consumer;
import java.util.function.Supplier;
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 2a2c6f4..624ebd9 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
@@ -1,8 +1,5 @@
package com.tanishisherewith.dynamichud.utils.contextmenu.options;
-import com.tanishisherewith.dynamichud.utils.contextmenu.Option;
-import net.minecraft.client.gui.DrawContext;
-
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;
diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/Option.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/Option.java
similarity index 96%
rename from src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/Option.java
rename to src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/Option.java
index 6ea6c40..1c295b3 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/Option.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/Option.java
@@ -1,7 +1,8 @@
-package com.tanishisherewith.dynamichud.utils.contextmenu;
+package com.tanishisherewith.dynamichud.utils.contextmenu.options;
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 net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
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 bf85c19..28cac3e 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
@@ -1,8 +1,6 @@
package com.tanishisherewith.dynamichud.utils.contextmenu.options;
import com.tanishisherewith.dynamichud.utils.BooleanPool;
-import com.tanishisherewith.dynamichud.utils.contextmenu.Option;
-import net.minecraft.client.gui.DrawContext;
import java.util.function.Consumer;
import java.util.function.Supplier;
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 b9af8e0..16928c2 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
@@ -3,8 +3,6 @@
import com.tanishisherewith.dynamichud.utils.BooleanPool;
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu;
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuProperties;
-import com.tanishisherewith.dynamichud.utils.contextmenu.Option;
-import net.minecraft.client.gui.DrawContext;
import java.util.Objects;
import java.util.function.Consumer;
diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/AlphaSlider.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/AlphaSlider.java
index c7a8794..c3c5824 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/AlphaSlider.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/AlphaSlider.java
@@ -63,6 +63,14 @@ public void setX(int x) {
this.x = x;
}
+ public int getWidth() {
+ return width;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+
public boolean isMouseOver(double mouseX, double mouseY) {
return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height;
}
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/ColorGradient.java
similarity index 90%
rename from src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/ColorGradientPicker.java
rename to src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/ColorGradient.java
index 6ec3a7b..2dc749b 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/ColorGradient.java
@@ -11,11 +11,11 @@
import java.nio.ByteBuffer;
import java.util.function.Consumer;
-public class ColorGradientPicker {
+public class ColorGradient {
final MinecraftClient client = MinecraftClient.getInstance();
private final Consumer onColorSelected; // The callback to call when a color is selected
- private final GradientSlider gradientSlider;
- private final GradientBox gradientBox;
+ private final HueSlider gradientSlider;
+ private final SaturationHueBox gradientBox;
private final ColorPickerButton colorPickerButton;
private final AlphaSlider alphaSlider;
private final int boxSize;
@@ -23,13 +23,13 @@ public class ColorGradientPicker {
private int x, y;
private boolean display = false;
- public ColorGradientPicker(int x, int y, Color initialColor, Consumer onColorSelected, int boxSize, int colors) {
+ public ColorGradient(int x, int y, Color initialColor, Consumer onColorSelected, int boxSize, int colors) {
this.x = x;
this.y = y;
this.initialColor = initialColor;
this.onColorSelected = onColorSelected;
- this.gradientSlider = new GradientSlider(x, y, colors, 10);
- this.gradientBox = new GradientBox(x, y + 20, boxSize);
+ this.gradientSlider = new HueSlider(x, y, colors, 10);
+ this.gradientBox = new SaturationHueBox(x, y + 20, boxSize);
this.alphaSlider = new AlphaSlider(x, y, 10, boxSize, initialColor);
float[] hsv = new float[3];
@@ -182,4 +182,27 @@ public void mouseDragged(double mouseX, double mouseY, int button) {
onColorSelected.accept(alphaSlider.getColor());
}
+ public int getBoxSize() {
+ return boxSize;
+ }
+
+ public boolean isDisplay() {
+ return display;
+ }
+
+ public ColorPickerButton getColorPickerButton() {
+ return colorPickerButton;
+ }
+
+ public AlphaSlider getAlphaSlider() {
+ return alphaSlider;
+ }
+
+ public HueSlider getGradientSlider() {
+ return gradientSlider;
+ }
+
+ public SaturationHueBox getGradientBox() {
+ return gradientBox;
+ }
}
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 967bb14..aa04521 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
@@ -33,7 +33,9 @@ public void render(DrawContext drawContext, int x, int y) {
public int getHeight() {
return height;
}
-
+ public int getWidth() {
+ return width;
+ }
public boolean onClick(double mouseX, double mouseY, int button) {
if (button == 0) {
if (mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height) {
diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/GradientSlider.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/HueSlider.java
similarity index 97%
rename from src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/GradientSlider.java
rename to src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/HueSlider.java
index 39f1ff7..d3cd0ba 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/GradientSlider.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/HueSlider.java
@@ -5,7 +5,7 @@
import java.awt.*;
-public class GradientSlider {
+public class HueSlider {
private final int width;
private final int height;
private int x;
@@ -13,7 +13,7 @@ public class GradientSlider {
private float hue = 0.0f;
private boolean isDragging = false;
- public GradientSlider(int x, int y, int width, int height) {
+ public HueSlider(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/GradientBox.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/SaturationHueBox.java
similarity index 93%
rename from src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/GradientBox.java
rename to src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/SaturationHueBox.java
index 49d7699..2332557 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/GradientBox.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/SaturationHueBox.java
@@ -5,7 +5,7 @@
import java.awt.*;
-public class GradientBox {
+public class SaturationHueBox {
private final int size;
private int x;
private int y;
@@ -15,7 +15,7 @@ public class GradientBox {
private boolean isDragging = false;
- public GradientBox(int x, int y, int size) {
+ public SaturationHueBox(int x, int y, int size) {
this.x = x;
this.y = y;
this.size = size;
@@ -31,11 +31,11 @@ public void render(DrawContext drawContext, int x, int y) {
DrawHelper.drawRoundedGradientRectangle(drawContext.getMatrices().peek().getPositionMatrix(), Color.BLACK, Color.BLACK, Color.getHSBColor(hue, 1.0f, 1.0f), Color.WHITE, x, y, size, size, 2);
// Draw the handle
- float handleSize = 3;
+ float handleSize = 1f;
float handleX = x + 2 + saturation * size - handleSize / 2.0f;
float handleY = y + 2 + (1.0f - value) * size - handleSize / 2.0f;
- DrawHelper.drawFilledCircle(drawContext.getMatrices().peek().getPositionMatrix(), handleX, handleY, 1, -1);
+ DrawHelper.drawFilledCircle(drawContext.getMatrices().peek().getPositionMatrix(), handleX, handleY, handleSize, -1);
drawContext.getMatrices().pop();
}
@@ -104,4 +104,8 @@ public void setValue(float value) {
public int getColor() {
return Color.HSBtoRGB(hue, saturation, value);
}
+
+ public int getSize() {
+ return size;
+ }
}
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 72b59c5..d810e29 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
@@ -3,7 +3,7 @@
import com.tanishisherewith.dynamichud.helpers.DrawHelper;
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu;
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuProperties;
-import com.tanishisherewith.dynamichud.utils.contextmenu.Option;
+import com.tanishisherewith.dynamichud.utils.contextmenu.options.Option;
import com.tanishisherewith.dynamichud.utils.contextmenu.options.*;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
@@ -174,7 +174,7 @@ public void render(DrawContext drawContext, ColorOption option, int x, int y, in
1,
1);
- option.getColorPicker().render(drawContext, x + option.getParentMenu().getFinalWidth() + 7, y - 10);
+ option.getColorGradient().render(drawContext, x + option.getParentMenu().getFinalWidth() + 7, y - 10);
}
}
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 bbd7a33..12c9d6e 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
@@ -3,7 +3,7 @@
import com.mojang.blaze3d.systems.RenderSystem;
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.Option;
import com.tanishisherewith.dynamichud.utils.contextmenu.options.*;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
@@ -86,7 +86,7 @@ public void renderContextMenu(DrawContext drawContext, ContextMenu contextMenu,
RenderSystem.enableBlend();
RenderSystem.enableDepthTest();
panelColor.applyColor();
- drawContext.drawTexture(BACKGROUND_PANEL, imageX, imageY, 0, 0, panelWidth, panelHeight);
+ drawContext.drawTexture(BACKGROUND_PANEL, imageX, imageY, 0, 0, panelWidth, panelHeight, 256, 254);
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);
@@ -251,11 +251,10 @@ public void render(DrawContext drawContext, BooleanOption option, int x, int y,
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.drawTexture(BOOLEAN_TEXTURE);
option.setHeight(25);
- //Widths dont matter in this skin
+ //Widths don't matter in this skin
option.setWidth(width);
}
@@ -296,7 +295,19 @@ public void render(DrawContext drawContext, ColorOption option, int x, int y, in
option.setHeight(25);
option.setWidth(width);
- option.getColorPicker().render(drawContext, x + panelWidth + 10, y - 10);
+ DrawHelper.disableScissor(); // Disable scissor test for the color-picker
+ if(option.getColorGradient().isDisplay()) {
+ RenderSystem.enableBlend();
+ RenderSystem.enableDepthTest();
+ panelColor.applyColor();
+ int colorGradientWidth = 28 + option.getColorGradient().getBoxSize() + option.getColorGradient().getAlphaSlider().getWidth() + option.getColorGradient().getColorPickerButton().getWidth();
+ int colorGradientHeight = 18 + option.getColorGradient().getBoxSize() + option.getColorGradient().getGradientBox().getSize() + option.getColorGradient().getGradientSlider().getHeight();
+ drawContext.drawTexture(BACKGROUND_PANEL, x + panelWidth + 3, y - 6, 0, 0, colorGradientWidth,colorGradientHeight, colorGradientWidth, colorGradientHeight);
+ RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
+ }
+ option.getColorGradient().render(drawContext, x + panelWidth + 10, y - 10);
+
+ DrawHelper.enableScissor(imageX, imageY + 2, panelWidth, panelHeight - 4);
}
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ModernSkin.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ModernSkin.java
index b464092..0792408 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ModernSkin.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ModernSkin.java
@@ -3,6 +3,8 @@
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu;
import net.minecraft.client.gui.DrawContext;
+
+//TODO: Complete this
public class ModernSkin extends Skin{
@Override
public void renderContextMenu(DrawContext drawContext, ContextMenu contextMenu, int mouseX, int mouseY) {
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 867c949..fd4dbc7 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,7 @@
package com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem;
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu;
-import com.tanishisherewith.dynamichud.utils.contextmenu.Option;
+import com.tanishisherewith.dynamichud.utils.contextmenu.options.Option;
import net.minecraft.client.gui.DrawContext;
import java.util.HashMap;
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 a19887c..bf03311 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
@@ -1,6 +1,6 @@
package com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem;
-import com.tanishisherewith.dynamichud.utils.contextmenu.Option;
+import com.tanishisherewith.dynamichud.utils.contextmenu.options.Option;
import net.minecraft.client.gui.DrawContext;
public interface SkinRenderer> {
diff --git a/src/main/java/com/tanishisherewith/dynamichud/widget/Widget.java b/src/main/java/com/tanishisherewith/dynamichud/widget/Widget.java
index ab3821a..a8a6a83 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/widget/Widget.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/widget/Widget.java
@@ -286,7 +286,7 @@ public void onClose() {
* 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);
+ int backgroundColor = this.shouldDisplay() ? GlobalConfig.get().getHudActiveColor().getRGB() : GlobalConfig.get().getHudInactiveColor().getRGB();
WidgetBox box = this.getWidgetBox();
DrawHelper.drawRectangle(context.getMatrices().peek().getPositionMatrix(),
box.x,
diff --git a/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java b/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java
index cd15a26..7fd5f8d 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java
@@ -74,7 +74,7 @@ public TextWidget(DynamicValueRegistry dynamicValueRegistry, String dynamicRegis
}
public void createMenu() {
- ContextMenuProperties properties = ContextMenuProperties.createGenericSimplified();
+ ContextMenuProperties properties = ContextMenuProperties.builder().skin(new MinecraftSkin(MinecraftSkin.PanelColor.COFFEE_BROWN)).build();
menu = new ContextMenu(getX(), getY(), properties);
menu.getProperties().getSkin().setContextMenu(menu);
From 09cdc787ad4c98c9d36ba214ca4aa090591ed86c Mon Sep 17 00:00:00 2001
From: tanishisherewithhh
<120117618+tanishisherewithhh@users.noreply.github.com>
Date: Fri, 25 Oct 2024 22:25:32 +0530
Subject: [PATCH 12/27] More changes to ModernSkin, OptionalGroups changes,
some refactors and interface folder.
---
.../dynamichud/DynamicHUD.java | 2 +-
.../dynamichud/config/GlobalConfig.java | 13 +-
.../dynamichud/helpers/DrawHelper.java | 19 +
.../utils/contextmenu/ContextMenu.java | 38 +-
.../contextmenu/ContextMenuProperties.java | 2 +-
.../contextmenu/layout/LayoutContext.java | 83 +++
.../contextmenu/options/BooleanOption.java | 4 +-
.../contextmenu/options/ColorOption.java | 8 +-
.../contextmenu/options/DoubleOption.java | 22 +-
.../utils/contextmenu/options/EnumOption.java | 4 +-
.../utils/contextmenu/options/ListOption.java | 4 +-
.../utils/contextmenu/options/Option.java | 47 +-
.../contextmenu/options/OptionGroup.java | 114 +++
.../contextmenu/options/RunnableOption.java | 3 +-
.../contextmenu/options/SubMenuOption.java | 6 +-
.../options/coloroption/ColorGradient.java | 2 -
.../contextmenu/skinsystem/ClassicSkin.java | 37 +-
.../contextmenu/skinsystem/MinecraftSkin.java | 32 +-
.../contextmenu/skinsystem/ModernSkin.java | 666 +++++++++++++++++-
.../utils/contextmenu/skinsystem/Skin.java | 56 +-
.../skinsystem/interfaces/GroupableSkin.java | 11 +
.../{ => interfaces}/SkinRenderer.java | 11 +-
.../dynamichud/widgets/ItemWidget.java | 8 +-
.../dynamichud/widgets/TextWidget.java | 42 +-
24 files changed, 1095 insertions(+), 139 deletions(-)
create mode 100644 src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/layout/LayoutContext.java
create mode 100644 src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/OptionGroup.java
create mode 100644 src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/interfaces/GroupableSkin.java
rename src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/{ => interfaces}/SkinRenderer.java (71%)
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
groupOptions = new ArrayList<>();
+ protected boolean expanded = false; // Skins can choose to use this or ignore it
+
+ public OptionGroup(String name) {
+ super(name, () -> null, (v) -> {}, () -> true);
+ }
+
+ public void addOption(Option option) {
+ groupOptions.add(option);
+ }
+
+ public List
getGroupOptions() {
+ return Collections.unmodifiableList(groupOptions);
+ }
+
+ @Override
+ public void updateProperties(ContextMenuProperties properties) {
+ this.renderer = new OptionGroupRenderer(); // Set renderer as OptionGroupRenderer
+
+ if(groupOptions == null) return;
+
+ for(Option option: groupOptions){
+ option.updateProperties(properties);
+ }
+ }
+
+ @Override
+ public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) {}
+
+ public boolean isExpanded() {
+ return expanded;
+ }
+
+ public void setExpanded(boolean expanded) {
+ this.expanded = expanded;
+ }
+ public class OptionGroupRenderer implements SkinRenderer
> {
+
+ @Override
+ public void render(DrawContext drawContext, Option option, int x, int y, int mouseX, int mouseY) {}
+
+ @Override
+ public boolean mouseClicked(Option option2, double mouseX, double mouseY, int button) {
+ OptionGroup option = (OptionGroup) option2;
+
+ for (Option subOption : option.getGroupOptions()) {
+ subOption.getRenderer().mouseClicked(subOption,mouseX, mouseY, button);
+ }
+ return SkinRenderer.super.mouseClicked(option, mouseX, mouseY, button);
+ }
+
+ @Override
+ public boolean mouseReleased(Option option2, double mouseX, double mouseY, int button) {
+ OptionGroup option = (OptionGroup) option2;
+
+ for (Option subOption : option.getGroupOptions()) {
+ subOption.getRenderer().mouseReleased(subOption,mouseX, mouseY, button);
+ }
+ return SkinRenderer.super.mouseReleased(option, mouseX, mouseY, button);
+ }
+
+ @Override
+ public boolean mouseDragged(Option option2, double mouseX, double mouseY, int button, double deltaX, double deltaY) {
+ OptionGroup option = (OptionGroup) option2;
+
+ for (Option subOption : option.getGroupOptions()) {
+ subOption.getRenderer().mouseDragged(subOption,mouseX, mouseY, button, deltaX, deltaY);
+ }
+ return SkinRenderer.super.mouseDragged(option, mouseX, mouseY, button, deltaX, deltaY);
+ }
+
+ @Override
+ public void keyPressed(Option option2, int key, int scanCode, int modifiers) {
+ OptionGroup option = (OptionGroup) option2;
+
+ for (Option subOption : option.getGroupOptions()) {
+ subOption.getRenderer().keyPressed(subOption,key, scanCode, modifiers);
+ }
+ SkinRenderer.super.keyPressed(option, key, scanCode, modifiers);
+ }
+
+ @Override
+ public void keyReleased(Option option2, int key, int scanCode, int modifiers) {
+ OptionGroup option = (OptionGroup) option2;
+
+ for (Option subOption : option.getGroupOptions()) {
+ subOption.getRenderer().keyReleased(subOption,key, scanCode, modifiers);
+ }
+ SkinRenderer.super.keyReleased(option, key, scanCode, modifiers);
+ }
+
+ @Override
+ public void mouseScrolled(Option option2, double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
+ OptionGroup option = (OptionGroup) option2;
+
+ for (Option subOption : option.getGroupOptions()) {
+ subOption.getRenderer().mouseScrolled(subOption,mouseX, mouseY, horizontalAmount, verticalAmount);
+ }
+ SkinRenderer.super.mouseScrolled(option, mouseX, mouseY, horizontalAmount, verticalAmount);
+ }
+ }
+}
\ No newline at end of file
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 28cac3e..136ea88 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
@@ -7,7 +7,6 @@
public class RunnableOption extends Option {
private final Runnable task;
- public String name = "Empty";
/**
* Runnable option which runs a task when clicked on it.
@@ -18,7 +17,7 @@ public class RunnableOption extends Option {
* @param task The task to run
*/
public RunnableOption(String name, Supplier getter, Consumer setter, Runnable task) {
- super(getter, setter);
+ super(name,getter, setter);
this.name = "Run: " + name; // prepend the "run" symbol to the name
this.task = task;
this.renderer.init(this);
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 16928c2..03b6b6e 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
@@ -18,14 +18,12 @@
public class SubMenuOption extends Option {
private final ContextMenu subMenu;
private final ContextMenu parentMenu;
- public String name = "Empty";
public SubMenuOption(String name, ContextMenu parentMenu, Supplier getter, Consumer setter, ContextMenuProperties properties) {
- super(getter, setter);
+ super(name,getter, setter);
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.getWidth(), this.y, properties);
this.subMenu.getProperties().setHeightOffset(0);
this.subMenu.setVisible(get());
this.renderer.init(this);
diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/ColorGradient.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/ColorGradient.java
index 2dc749b..f0c53d2 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/ColorGradient.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/ColorGradient.java
@@ -19,14 +19,12 @@ public class ColorGradient {
private final ColorPickerButton colorPickerButton;
private final AlphaSlider alphaSlider;
private final int boxSize;
- private final Color initialColor;
private int x, y;
private boolean display = false;
public ColorGradient(int x, int y, Color initialColor, Consumer onColorSelected, int boxSize, int colors) {
this.x = x;
this.y = y;
- this.initialColor = initialColor;
this.onColorSelected = onColorSelected;
this.gradientSlider = new HueSlider(x, y, colors, 10);
this.gradientBox = new SaturationHueBox(x, y + 20, boxSize);
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 d810e29..51770a3 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
@@ -5,7 +5,7 @@
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuProperties;
import com.tanishisherewith.dynamichud.utils.contextmenu.options.Option;
import com.tanishisherewith.dynamichud.utils.contextmenu.options.*;
-import net.minecraft.client.MinecraftClient;
+import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.interfaces.SkinRenderer;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.util.math.MatrixStack;
@@ -18,18 +18,16 @@
* which should be used when you have a low amount of settings and want quicker way of changing the settings.
*/
public class ClassicSkin extends Skin {
- public static MinecraftClient mc = MinecraftClient.getInstance();
-
public ClassicSkin() {
super();
- addRenderer(BooleanOption.class, new ClassicBooleanRenderer());
- addRenderer(DoubleOption.class, new ClassicDoubleRenderer());
- addRenderer(EnumOption.class, new ClassicEnumRenderer());
- addRenderer(ListOption.class, new ClassicListRenderer());
- addRenderer(SubMenuOption.class, new ClassicSubMenuRenderer());
- addRenderer(RunnableOption.class, new ClassicRunnableRenderer());
- addRenderer(ColorOption.class, new ClassicColorOptionRenderer());
+ addRenderer(BooleanOption.class, ClassicBooleanRenderer::new);
+ addRenderer(DoubleOption.class, ClassicDoubleRenderer::new);
+ addRenderer(EnumOption.class, ClassicEnumRenderer::new);
+ addRenderer(ListOption.class, ClassicListRenderer::new);
+ addRenderer(SubMenuOption.class, ClassicSubMenuRenderer::new);
+ addRenderer(RunnableOption.class, ClassicRunnableRenderer::new);
+ addRenderer(ColorOption.class, ClassicColorOptionRenderer::new);
setCreateNewScreen(false);
}
@@ -45,21 +43,20 @@ public void renderContextMenu(DrawContext drawContext, ContextMenu contextMenu,
drawBackground(matrices, contextMenu, properties);
int yOffset = contextMenu.y + 3;
- contextMenu.setWidth(10);
- for (Option> option : contextMenu.getOptions()) {
+ int width = 10;
+ for (Option> option : getOptions(contextMenu)) {
if (!option.shouldRender()) continue;
// 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);
+ if (contextMenu.getProperties().hoverEffect() && contextMenu.isMouseOver(mouseX, mouseY, contextMenu.x + 1, yOffset - 1, contextMenu.getWidth() - 2, option.getHeight())) {
+ drawBackground(matrices, contextMenu, properties, yOffset - 1, contextMenu.getWidth(), option.getHeight() + 1, contextMenu.getProperties().getHoverColor().getRGB(), false);
}
option.render(drawContext, contextMenu.x + 4, yOffset, mouseX, mouseY);
- contextMenu.setWidth(Math.max(contextMenu.getWidth(), option.getWidth()));
+ width = Math.max(width, option.getWidth());
yOffset += option.getHeight() + 1;
}
- contextMenu.setWidth(contextMenu.getWidth() + properties.getPadding());
- contextMenu.setFinalWidth(contextMenu.getWidth());
+ contextMenu.setWidth(width + properties.getPadding());
contextMenu.setHeight(yOffset - contextMenu.y);
// Draw the border if needed
@@ -174,7 +171,7 @@ public void render(DrawContext drawContext, ColorOption option, int x, int y, in
1,
1);
- option.getColorGradient().render(drawContext, x + option.getParentMenu().getFinalWidth() + 7, y - 10);
+ option.getColorGradient().render(drawContext, x + option.getParentMenu().getWidth() + 7, y - 10);
}
}
@@ -197,7 +194,7 @@ public void render(DrawContext drawContext, SubMenuOption option, int x, int y,
option.setHeight(mc.textRenderer.fontHeight);
option.setWidth(mc.textRenderer.getWidth(option.name) + 1);
- option.getSubMenu().render(drawContext, x + option.getParentMenu().getFinalWidth(), y, mouseX, mouseY);
+ option.getSubMenu().render(drawContext, x + option.getParentMenu().getWidth(), y, mouseX, mouseY);
}
}
@@ -217,7 +214,7 @@ public void render(DrawContext drawContext, RunnableOption option, int x, int y,
public class ClassicDoubleRenderer implements SkinRenderer {
@Override
public void render(DrawContext drawContext, DoubleOption option, int x, int y, int mouseX, int mouseY) {
- option.setWidth(Math.max(35, contextMenu != null ? contextMenu.getFinalWidth() - option.getProperties().getPadding() - 2 : 0));
+ option.setWidth(Math.max(35, contextMenu != null ? contextMenu.getWidth() - option.getProperties().getPadding() - 2 : 0));
option.setHeight(16);
// Draw the label
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 12c9d6e..4c7f345 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
@@ -5,9 +5,11 @@
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu;
import com.tanishisherewith.dynamichud.utils.contextmenu.options.Option;
import com.tanishisherewith.dynamichud.utils.contextmenu.options.*;
-import net.minecraft.client.MinecraftClient;
+import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.interfaces.SkinRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ButtonTextures;
+import net.minecraft.client.sound.PositionedSoundInstance;
+import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
@@ -26,7 +28,6 @@ public class MinecraftSkin extends Skin {
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;
@@ -47,13 +48,13 @@ public class MinecraftSkin extends Skin {
public MinecraftSkin(PanelColor color, Identifier backgroundPanel, int panelWidth, int panelHeight) {
super();
this.panelColor = color;
- addRenderer(BooleanOption.class, new MinecraftBooleanRenderer());
- addRenderer(DoubleOption.class, new MinecraftDoubleRenderer());
- addRenderer(EnumOption.class, new MinecraftEnumRenderer());
- addRenderer(ListOption.class, new MinecraftListRenderer());
- addRenderer(SubMenuOption.class, new MinecraftSubMenuRenderer());
- addRenderer(RunnableOption.class, new MinecraftRunnableRenderer());
- addRenderer(ColorOption.class, new MinecraftColorOptionRenderer());
+ addRenderer(BooleanOption.class, MinecraftBooleanRenderer::new);
+ addRenderer(DoubleOption.class, MinecraftDoubleRenderer::new);
+ addRenderer(EnumOption.class, MinecraftEnumRenderer::new);
+ addRenderer(ListOption.class, MinecraftListRenderer::new);
+ addRenderer(SubMenuOption.class, MinecraftSubMenuRenderer::new);
+ addRenderer(RunnableOption.class, MinecraftRunnableRenderer::new);
+ addRenderer(ColorOption.class, MinecraftColorOptionRenderer::new);
this.panelHeight = panelHeight;
this.panelWidth = panelWidth;
@@ -94,11 +95,10 @@ public void renderContextMenu(DrawContext drawContext, ContextMenu contextMenu,
DrawHelper.enableScissor(imageX, imageY + 2, screenWidth, panelHeight - 4);
int yOffset = imageY + 10 - scrollOffset;
contextMenu.setWidth(panelWidth - 4);
- contextMenu.setFinalWidth(panelWidth - 4);
contextMenu.y = imageY;
int maxYOffset = imageY + panelHeight - 4;
- for (Option> option : contextMenu.getOptions()) {
+ for (Option> option : getOptions(contextMenu)) {
if (!option.shouldRender()) continue;
if (yOffset >= imageY && yOffset <= maxYOffset - option.getHeight() + 4) {
@@ -142,10 +142,6 @@ private void drawScrollbar(DrawContext context) {
}
}
- 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;
- }
-
private void applyMomentum() {
if (scrollVelocity != 0) {
scrollOffset += (int) scrollVelocity;
@@ -169,6 +165,9 @@ 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)) {
+ mc.getSoundManager().play(PositionedSoundInstance.master(
+ SoundEvents.UI_BUTTON_CLICK, 1.0F));
+
contextMenu.close();
}
@@ -180,7 +179,6 @@ public boolean mouseDragged(ContextMenu menu, double mouseX, double mouseY, int
if (button == 0 && mouseX >= imageX + panelWidth + 5 && mouseX <= imageX + panelWidth + 20) {
if (mouseY >= imageY && mouseY <= imageY + panelHeight) {
float scrollPercentage = (float) (mouseY - imageY) / panelHeight;
- int handleY = imageY + (int) ((panelHeight - 15) * scrollPercentage);
// Draw scrollbar handle
scrollOffset = (int) (maxScrollOffset * scrollPercentage);
@@ -437,7 +435,7 @@ public void render(DrawContext drawContext, SubMenuOption option, int x, int y,
String text = "Open";
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);
+ option.getSubMenu().render(drawContext, x + option.getParentMenu().getWidth(), y, mouseX, mouseY);
}
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ModernSkin.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ModernSkin.java
index 0792408..72b8aaf 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ModernSkin.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ModernSkin.java
@@ -1,13 +1,675 @@
package com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem;
+import com.mojang.blaze3d.systems.RenderSystem;
+import com.tanishisherewith.dynamichud.helpers.ColorHelper;
+import com.tanishisherewith.dynamichud.helpers.DrawHelper;
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu;
+import com.tanishisherewith.dynamichud.utils.contextmenu.layout.LayoutContext;
+import com.tanishisherewith.dynamichud.utils.contextmenu.options.*;
+import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.interfaces.GroupableSkin;
+import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.interfaces.SkinRenderer;
import net.minecraft.client.gui.DrawContext;
+import net.minecraft.client.sound.PositionedSoundInstance;
+import net.minecraft.client.util.math.MatrixStack;
+import net.minecraft.sound.SoundEvents;
+import net.minecraft.text.OrderedText;
+import net.minecraft.text.StringVisitable;
+import net.minecraft.util.math.MathHelper;
+import org.lwjgl.glfw.GLFW;
+import java.awt.*;
+import java.util.List;
//TODO: Complete this
-public class ModernSkin extends Skin{
+public class ModernSkin extends Skin implements GroupableSkin {
+ private final Color themeColor;
+ private final float radius;
+ private final String defaultToolTipHeader;
+ private final String defaultToolTipText;
+ Color DARK_GRAY = new Color(20, 20, 20, 229);
+ Color DARKER_GRAY_2 = new Color(12,12,12,246);
+ Color DARKER_GRAY = new Color(10, 10, 10, 243);
+ private int contextMenuX = 0, contextMenuY = 0;
+ private int width = 0, height = 0;
+ private float scaledWidth = 0, scaledHeight = 0;
+ private String TOOLTIP_TEXT;
+ private String TOOLTIP_HEAD;
+ private static int SCALE_FACTOR = 4;
+
+ public ModernSkin(Color themeColor, float radius, String defaultToolTipHeader, String defaultToolTipText) {
+ this.themeColor = themeColor;
+ this.radius = radius;
+ TOOLTIP_TEXT = defaultToolTipText;
+ TOOLTIP_HEAD = defaultToolTipHeader;
+ this.defaultToolTipText = defaultToolTipText;
+ this.defaultToolTipHeader = defaultToolTipHeader;
+
+ addRenderer(BooleanOption.class, ModernBooleanRenderer::new);
+ addRenderer(DoubleOption.class, ModernDoubleRenderer::new);
+ addRenderer(EnumOption.class, ModernEnumRenderer::new);
+ addRenderer(ListOption.class, ModernListRenderer::new);
+ addRenderer(SubMenuOption.class, ModernSubMenuRenderer::new);
+ addRenderer(RunnableOption.class, ModernRunnableRenderer::new);
+ addRenderer(ColorOption.class, ModernColorOptionRenderer::new);
+
+ setCreateNewScreen(true);
+ }
+
+ public ModernSkin(Color themeColor, float radius) {
+ this(themeColor, radius, "Example Tip", "Hover over a setting to see its tool-tip (if present) here!");
+ }
+
+ public ModernSkin(Color themeColor) {
+ this(themeColor, 4);
+ }
+
+ public ModernSkin() {
+ this(Color.CYAN.darker().darker());
+ }
+
+ @Override
+ public LayoutContext.Offset getGroupIndent() {
+ return new LayoutContext.Offset(2, 2);
+ }
+
+ @Override
+ public void renderGroup(DrawContext drawContext, OptionGroup group, int groupX, int groupY, int mouseX, int mouseY) {
+ mouseX = (int) (mc.mouse.getX()/SCALE_FACTOR);
+ mouseY = (int) (mc.mouse.getY()/SCALE_FACTOR);
+
+ if(group.isExpanded()) {
+ DrawHelper.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(),
+ groupX + 1, groupY + 14, width - groupX - 8 + contextMenuX, group.getHeight(), radius, DARKER_GRAY_2.getRGB());
+ }
+
+ String groupText = group.name + " " + (group.isExpanded() ? "-" : "+");
+
+ DrawHelper.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(),
+ groupX + 1, groupY + 1,true,true, !group.isExpanded(),!group.isExpanded(), mc.textRenderer.getWidth(groupText) + 6, 16, radius, DARKER_GRAY_2.getRGB());
+
+ drawContext.drawText(mc.textRenderer, groupText, groupX + 4, groupY + 4, -1, true);
+
+ if(group.isExpanded()) {
+ int yOffset = groupY + 16 + getGroupIndent().top;
+ for (Option> option : group.getGroupOptions()) {
+ if (!option.shouldRender()) continue;
+ option.render(drawContext, groupX + getGroupIndent().left, yOffset, mouseX, mouseY);
+ yOffset += option.getHeight() + 1;
+ }
+
+ group.setHeight(yOffset - groupY - 16);
+ } else{
+ group.setHeight(16);
+ }
+ }
+
@Override
public void renderContextMenu(DrawContext drawContext, ContextMenu contextMenu, int mouseX, int mouseY) {
+ //This is equivalent to "Auto" GUI scale in minecraft options
+ SCALE_FACTOR = mc.getWindow().calculateScaleFactor(0, mc.forcesUnicodeFont());
+
+ mouseX = (int) (mc.mouse.getX()/SCALE_FACTOR);
+ mouseY = (int) (mc.mouse.getY()/SCALE_FACTOR);
+
+ // Apply custom scaling to counteract Minecraft's default scaling
+ DrawHelper.customScaledProjection(SCALE_FACTOR);
+
+ updateContextDimensions();
+ contextMenu.set(contextMenuX, contextMenuY, 0);
+
+ //Background
+ DrawHelper.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(),
+ contextMenuX, contextMenuY, width, height, radius, DARKER_GRAY.getRGB());
+
+ drawBackButton(drawContext, mouseX, mouseY);
+
+ //Tool-Tip width + padding
+ int optionStartX = contextMenu.x + (int) (width * 0.2f) + 10;
+
+ //Background behind the options
+ DrawHelper.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(),
+ optionStartX, contextMenuY + 19, width * 0.8f - 14, height - 23, radius, DARK_GRAY.getRGB());
+
+ int yOffset = contextMenu.y + 19 + 3;
+ for (Option> option : getOptions(contextMenu)) {
+ if (!option.shouldRender()) continue;
+
+ if (option.isMouseOver(mouseX, mouseY)) {
+ setTooltipText(option.name, option.description);
+ }
+
+ if (option instanceof OptionGroup group) {
+ renderGroup(drawContext, group, optionStartX + 2, yOffset, mouseX, mouseY);
+ } else {
+ option.render(drawContext, optionStartX + 2, yOffset, mouseX, mouseY);
+ }
+
+ yOffset += option.getHeight() + 1;
+ }
+
+ contextMenu.setWidth(width);
+ contextMenu.setHeight(height);
+
+ renderToolTipText(drawContext, mouseX, mouseY);
+
+ //Reset our scaling so minecraft runs normally
+ DrawHelper.scaledProjection();
+ }
+
+ private void updateContextDimensions() {
+ scaledWidth = (float) mc.getWindow().getFramebufferWidth() / SCALE_FACTOR;
+ scaledHeight = (float) mc.getWindow().getFramebufferHeight() / SCALE_FACTOR;
+ contextMenuX = (int) (scaledWidth * 0.1f);
+ contextMenuY = (int) (scaledHeight * 0.1f);
+ width = (int) (scaledWidth * 0.8f);
+ height = (int) (scaledHeight * 0.8f);
+ }
+
+ public void drawBackButton(DrawContext drawContext, int mouseX, int mouseY) {
+ String backText = "< Back";
+ int textWidth = mc.textRenderer.getWidth(backText);
+
+ boolean isHoveringOver = isMouseOver(mouseX, mouseY, contextMenuX + 2, contextMenuY + 2, textWidth + 8, 14);
+ int color = isHoveringOver ? themeColor.darker().getRGB() : themeColor.getRGB();
+
+ DrawHelper.drawRoundedRectangleWithShadowBadWay(drawContext.getMatrices().peek().getPositionMatrix(),
+ contextMenuX + 2, contextMenuY + 2, textWidth + 8, 14, radius, color, 125, 2, 2);
+
+ drawContext.drawText(mc.textRenderer, backText, contextMenuX + 6, contextMenuY + 5, -1, true);
+ }
+
+ public void renderToolTipText(DrawContext drawContext, int mouseX, int mouseY) {
+ int tooltipY = contextMenuY + 19;
+ int toolTipWidth = (int) (width * 0.2f) + 4;
+ int toolTipHeight = (int) (height * 0.16f);
+
+ if (!TOOLTIP_TEXT.isEmpty()) {
+ toolTipHeight = Math.max(toolTipHeight, mc.textRenderer.getWrappedLinesHeight(TOOLTIP_TEXT, toolTipWidth)) + 18;
+ toolTipHeight = Math.min(height - 23, toolTipHeight);
+ }
+
+ float textScale = 0.8f;
+
+ // Draw background
+ DrawHelper.drawRoundedRectangle(
+ drawContext.getMatrices().peek().getPositionMatrix(),
+ contextMenuX + 2,
+ tooltipY,
+ toolTipWidth,
+ toolTipHeight,
+ radius,
+ DARK_GRAY.getRGB()
+ );
+ DrawHelper.drawHorizontalLine(
+ drawContext.getMatrices().peek().getPositionMatrix(),
+ contextMenuX + 2,
+ toolTipWidth,
+ tooltipY + 16,
+ 0.7f,
+ ColorHelper.changeAlpha(Color.WHITE, 175).getRGB()
+ );
+
+ if (TOOLTIP_TEXT.isEmpty() || TOOLTIP_HEAD.isEmpty()) {
+ return;
+ }
+
+ //Draw the head text
+ drawContext.drawText(
+ mc.textRenderer,
+ TOOLTIP_HEAD,
+ contextMenuX + 4,
+ tooltipY + 4,
+ -1,
+ true
+ );
+
+ List wrappedText = mc.textRenderer.wrapLines(StringVisitable.plain(TOOLTIP_TEXT), toolTipWidth);
+
+ DrawHelper.scaleAndPosition(drawContext.getMatrices(), contextMenuX + 4, tooltipY + 19, textScale);
+
+ // Draw text
+ int textY = tooltipY + 19;
+ for (OrderedText line : wrappedText) {
+ drawContext.drawText(
+ mc.textRenderer,
+ line,
+ contextMenuX + 2 + 2,
+ textY,
+ -1,
+ false
+ );
+ textY += mc.textRenderer.fontHeight;
+ }
+
+ DrawHelper.stopScaling(drawContext.getMatrices());
+
+ setTooltipText(defaultToolTipHeader, defaultToolTipText);
+ }
+
+ public void setTooltipText(String head_text, String tooltip_text) {
+ TOOLTIP_TEXT = tooltip_text;
+ TOOLTIP_HEAD = head_text;
+ }
+
+ @Override
+ public boolean mouseClicked(ContextMenu menu, double mouseX, double mouseY, int button) {
+ mouseX = mc.mouse.getX()/SCALE_FACTOR;
+ mouseY = mc.mouse.getY()/SCALE_FACTOR;
+
+ if(button == GLFW.GLFW_MOUSE_BUTTON_RIGHT) {
+ int optionStartX = contextMenuX + (int) (width * 0.2f) + 10;
+ int yOffset = contextMenuY + 22;
+ for (Option> option : getOptions(contextMenu)) {
+ if (!option.shouldRender()) continue;
+
+ if (option instanceof OptionGroup group) {
+ if (isMouseOver(mouseX, mouseY, optionStartX + 2, yOffset,
+ mc.textRenderer.getWidth(group.name + " " + (group.isExpanded() ? "-" : "+")) + 6,
+ 16)) {
+ group.setExpanded(!group.isExpanded());
+ }
+ }
+
+ yOffset += option.getHeight() + 1;
+ }
+ }
+ if (button == GLFW.GLFW_MOUSE_BUTTON_LEFT && isMouseOver(mouseX, mouseY, contextMenuX + 2, contextMenuY + 2, mc.textRenderer.getWidth("< Back") + 8, 14)) {
+ mc.getSoundManager().play(PositionedSoundInstance.master(
+ SoundEvents.UI_BUTTON_CLICK, 1.0F));
+ contextMenu.close();
+ }
+ return super.mouseClicked(menu, mouseX, mouseY, button);
+ }
+
+ public Color getThemeColor() {
+ return themeColor;
+ }
+
+ public class ModernBooleanRenderer implements SkinRenderer {
+ private float animationProgress = 0f;
+ private boolean animating = false;
+
+ @Override
+ public void render(DrawContext drawContext, BooleanOption option, int x, int y, int mouseX, int mouseY) {
+ int backgroundWidth = (int) (width * 0.8f - 14);
+
+ option.setHeight(14);
+ option.set(x,y);
+ option.setWidth(backgroundWidth);
+
+ MatrixStack matrices = drawContext.getMatrices();
+
+ // Animate the toggle
+ if (animating) {
+ animationProgress += 0.1f; // Adjust speed as needed
+ if (animationProgress >= 1f) {
+ animationProgress = 0f;
+ animating = false;
+ }
+ }
+
+ int toggleBgX = x + backgroundWidth - 30;
+ // Background
+ boolean active = option.get();
+ Color backgroundColor = active ? getThemeColor() : DARKER_GRAY;
+
+ DrawHelper.drawRoundedRectangleWithShadowBadWay(
+ matrices.peek().getPositionMatrix(),
+ toggleBgX, y + 2, 14, 7,
+ 3,
+ backgroundColor.getRGB(),
+ 125, 1, 1
+ );
+
+ // Draw toggle circle
+ float toggleX = active ? toggleBgX + 10 : toggleBgX + 4;
+ if (animating) {
+ toggleX = MathHelper.lerp(animationProgress, active ? toggleBgX + 4 : toggleBgX + 10, toggleX);
+ }
+
+ DrawHelper.drawFilledCircle(matrices.peek().getPositionMatrix(), toggleX, y + 2 + 3.3f, 2.8f, Color.WHITE.getRGB());
+
+ // Draw option name
+ drawContext.drawText(
+ mc.textRenderer,
+ option.name,
+ x + 2,
+ y + 4,
+ -1,
+ false
+ );
+ }
+
+ @Override
+ public boolean mouseClicked(BooleanOption option, double mouseX, double mouseY, int button) {
+ mouseX = mc.mouse.getX()/SCALE_FACTOR;
+ mouseY = mc.mouse.getY()/SCALE_FACTOR;
+
+ int backgroundWidth = (int) (width * 0.8f - 14);
+ int toggleBgX = option.getX() + backgroundWidth - 30;
+
+ if(isMouseOver(mouseX,mouseY,toggleBgX,option.getY(),14,option.getHeight())){
+ option.set(!option.get());
+ animating = true;
+ return true;
+ }
+ return SkinRenderer.super.mouseClicked(option, mouseX, mouseY, button);
+ }
+ }
+
+ public class ModernColorOptionRenderer implements SkinRenderer {
+ private static final float ANIMATION_SPEED = 0.1f;
+ private float scale = 0f;
+ private boolean display = false;
+
+ public void update(ColorOption option){
+ if(option.getColorGradient().isDisplay() && display){
+ scale += ANIMATION_SPEED;
+ }
+ if(!display){
+ scale -= ANIMATION_SPEED;
+ }
+ scale = MathHelper.clamp(scale,0,1.0f);
+ if(scale <= 0){
+ option.getColorGradient().close();
+ }
+ }
+
+ @Override
+ public void render(DrawContext drawContext, ColorOption option, int x, int y, int mouseX, int mouseY) {
+ update(option);
+
+ int backgroundWidth = (int) (width * 0.8f - 14);
+
+ // Draw option name
+ drawContext.drawText(
+ mc.textRenderer,
+ option.name,
+ x + 2,
+ y + 5,
+ -1,
+ false
+ );
+
+ option.set(x, y);
+
+ int width = 20;
+ int shadowOpacity = Math.min(option.value.getAlpha(), 45);
+
+ //The shape behind the preview
+ DrawHelper.drawRoundedRectangleWithShadowBadWay(drawContext.getMatrices().peek().getPositionMatrix(),
+ x + backgroundWidth - width - 17,
+ y + 1,
+ width + 2,
+ 14,
+ 2,
+ getThemeColor().getRGB(),
+ shadowOpacity,
+ 1,
+ 1);
+
+ //The letter above the shape behind the preview
+ drawContext.drawText(
+ mc.textRenderer,
+ option.getColorGradient().isDisplay() ? "^" : "v",
+ x + backgroundWidth - 21,
+ y + 4,
+ -1,
+ false
+ );
+
+ //Preview
+ DrawHelper.drawRoundedRectangleWithShadowBadWay(drawContext.getMatrices().peek().getPositionMatrix(),
+ x + backgroundWidth - width - 15,
+ y + 2,
+ width - 8,
+ 12,
+ 1,
+ option.value.getRGB(),
+ shadowOpacity,
+ 1,
+ 1);
+
+ int targetHeight = option.getColorGradient().isDisplay() ? (int) (option.getColorGradient().getBoxSize() + option.getColorGradient().getGradientBox().getSize() * scale) : 25;
+ option.setHeight(targetHeight);
+ option.setWidth(width);
+
+ DrawHelper.scaleAndPosition(drawContext.getMatrices(),x + backgroundWidth/2.0f,y, scale);
+
+ option.getColorGradient().render(drawContext, x + backgroundWidth/2 - 50, y + 6);
+
+ DrawHelper.stopScaling(drawContext.getMatrices());
+ }
+
+ @Override
+ public boolean mouseClicked(ColorOption option, double mouseX, double mouseY, int button) {
+ mouseX = mc.mouse.getX()/SCALE_FACTOR;
+ mouseY = mc.mouse.getY()/SCALE_FACTOR;
+ if (button == GLFW.GLFW_MOUSE_BUTTON_LEFT && isMouseOver(mouseX, mouseY, option.getX() + (int) (width * 0.8f - 14) - 37, option.getY(), 30, 23)) {
+ option.isVisible = !option.isVisible;
+ if (option.isVisible) {
+ option.getColorGradient().display();
+ display = true;
+ } else {
+ display = false;
+ }
+ return true;
+ }
+ option.getColorGradient().mouseClicked(mouseX,mouseY,button);
+ return SkinRenderer.super.mouseClicked(option, mouseX, mouseY, button);
+ }
+
+ @Override
+ public boolean mouseDragged(ColorOption option, double mouseX, double mouseY, int button, double deltaX, double deltaY) {
+ mouseX = mc.mouse.getX()/SCALE_FACTOR;
+ mouseY = mc.mouse.getY()/SCALE_FACTOR;
+ option.getColorGradient().mouseDragged(mouseX,mouseY,button);
+ return SkinRenderer.super.mouseDragged(option, mouseX, mouseY, button, deltaX, deltaY);
+ }
+
+ @Override
+ public boolean mouseReleased(ColorOption option, double mouseX, double mouseY, int button) {
+ mouseX = mc.mouse.getX()/SCALE_FACTOR;
+ mouseY = mc.mouse.getY()/SCALE_FACTOR;
+ option.getColorGradient().mouseReleased(mouseX,mouseY,button);
+
+ return SkinRenderer.super.mouseReleased(option, mouseX, mouseY, button);
+ }
+ }
+
+ public class ModernDoubleRenderer implements SkinRenderer {
+ private double displayValue;
+ private static final float ANIMATION_SPEED = 0.1f;
+ @Override
+ public void render(DrawContext drawContext, DoubleOption option, int x, int y, int mouseX, int mouseY) {
+ // Draw option name
+ drawContext.drawText(
+ mc.textRenderer,
+ option.name,
+ x + 2,
+ y,
+ -1,
+ false
+ );
+
+ int backgroundWidth = (int) (width * 0.8f - 14);
+ int sliderBackgroundWidth = 120;
+ int sliderBackgroundHeight = 2;
+ int sliderX = x + backgroundWidth - sliderBackgroundWidth - 10;
+
+ option.set(x,y);
+ option.setWidth(sliderBackgroundWidth);
+ option.setHeight(14);
+
+ // Smoothly interpolate to the new value
+ displayValue = MathHelper.lerp(ANIMATION_SPEED, displayValue, option.get());
+
+ // Background
+ DrawHelper.drawRoundedRectangle(
+ drawContext.getMatrices().peek().getPositionMatrix(),
+ sliderX, y, sliderBackgroundWidth, sliderBackgroundHeight,1, DARKER_GRAY.getRGB()
+ );
+
+ // Active fill
+ int activeFillWidth = (int) ((displayValue - option.minValue) / (option.maxValue - option.minValue) * option.getWidth());
+ Color activeColor = getThemeColor();
+ DrawHelper.drawRoundedRectangle(
+ drawContext.getMatrices().peek().getPositionMatrix(),
+ sliderX, y, activeFillWidth, sliderBackgroundHeight,1, activeColor.getRGB()
+ );
+
+ // Draw slider handle
+ float sliderHandleX = sliderX + activeFillWidth - 5;
+ DrawHelper.drawFilledCircle(drawContext.getMatrices().peek().getPositionMatrix(), sliderHandleX + 5, y + 1, 2, Color.WHITE.getRGB());
+
+ // Draw value text
+ String text = String.format("%.2f", displayValue);
+ DrawHelper.scaleAndPosition(drawContext.getMatrices(),sliderX + 120 - mc.textRenderer.getWidth(text),y + 7,0.6f);
+ drawContext.drawText(
+ mc.textRenderer,
+ text,
+ sliderX + sliderBackgroundWidth + 10 - mc.textRenderer.getWidth(text),
+ y + 2,
+ -1,
+ true
+ );
+ drawContext.getMatrices().pop();
+ }
+
+ @Override
+ public boolean mouseClicked(DoubleOption option, double mouseX, double mouseY, int button) {
+ mouseX = mc.mouse.getX()/SCALE_FACTOR;
+ mouseY = mc.mouse.getY()/SCALE_FACTOR;
+ if (button == GLFW.GLFW_MOUSE_BUTTON_LEFT && isMouseOver(mouseX, mouseY, option.getX() + (int) (width * 0.8f - 14) - 125, option.getY() - 1, option.getWidth() + 2, option.getHeight() + 1)) {
+ option.setDragging(true);
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean mouseDragged(DoubleOption option, double mouseX, double mouseY, int button, double deltaX, double deltaY) {
+ if (option.isDragging()) {
+ mouseX = mc.mouse.getX()/SCALE_FACTOR;
+ int backgroundWidth = (int) (width * 0.8f - 14);
+ int sliderBackgroundWidth = 120;
+ int sliderX = option.getX() + backgroundWidth - sliderBackgroundWidth - 10;
+ option.step(mouseX, sliderX);
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean mouseReleased(DoubleOption option, double mouseX, double mouseY, int button) {
+ if (button == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
+ option.setDragging(false);
+ return true;
+ }
+ return false;
+ }
+ }
+ public class ModernEnumRenderer> implements SkinRenderer> {
+ private int maxWidth = 50;
+
+ private void calculateMaxWidth(EnumOption option) {
+ for (E listValues : option.getValues()) {
+ int width = mc.textRenderer.getWidth(listValues.toString()) + 5;
+ if (width > maxWidth) {
+ maxWidth = width;
+ }
+ }
+ }
+
+ @Override
+ public void render(DrawContext drawContext, EnumOption option, int x, int y, int mouseX, int mouseY) {
+ calculateMaxWidth(option);
+ option.setHeight(25);
+ option.setWidth(maxWidth);
+
+ drawContext.drawText(mc.textRenderer, option.name + ": ", x + 15, y + 25 / 2 - 5, -1, true);
+
+ option.set(x + width - maxWidth - 25, y);
+
+ drawContext.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
+ RenderSystem.enableBlend();
+ RenderSystem.enableDepthTest();
+ 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);
+ }
+ }
+
+ public class ModernListRenderer implements SkinRenderer> {
+ private int maxWidth = 50;
+
+ private void calculateMaxWidth(ListOption option) {
+ for (E listValues : option.getValues()) {
+ int width = mc.textRenderer.getWidth(listValues.toString()) + 5;
+ if (width > maxWidth) {
+ maxWidth = width;
+ }
+ }
+ }
+
+ @Override
+ public void render(DrawContext drawContext, ListOption option, int x, int y, int mouseX, int mouseY) {
+ calculateMaxWidth(option);
+ option.setHeight(25);
+ option.setWidth(maxWidth);
+
+ drawContext.drawText(mc.textRenderer, option.name + ": ", x + 15, y + 25 / 2 - 5, -1, true);
+
+ option.set(x + width - maxWidth - 25, y);
+
+ drawContext.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
+ RenderSystem.enableBlend();
+ RenderSystem.enableDepthTest();
+ 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);
+ }
+ }
+
+ public class ModernSubMenuRenderer implements SkinRenderer {
+ @Override
+ public void render(DrawContext drawContext, SubMenuOption option, int x, int y, int mouseX, int mouseY) {
+ option.setHeight(20);
+ option.setWidth(30);
+
+ drawContext.drawText(mc.textRenderer, option.name, x + 15, y + 25 / 2 - 5, -1, true);
+
+ option.set(x + width - 75, y);
+
+ drawContext.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
+ RenderSystem.enableBlend();
+ RenderSystem.enableDepthTest();
+ 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);
+
+ option.getSubMenu().render(drawContext, x + option.getParentMenu().getWidth(), y, mouseX, mouseY);
+ }
+ }
+
+ public class ModernRunnableRenderer 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(25);
+ option.setWidth(26);
+
+ drawContext.drawText(mc.textRenderer, option.name.replaceFirst("Run: ", "") + ": ", x + 15, y + 25 / 2 - 5, -1, true);
+
+ option.set(x + width - 75, y);
+ drawContext.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
+ RenderSystem.enableBlend();
+ RenderSystem.enableDepthTest();
+ 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);
+ }
}
-}
+}
\ 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 fd4dbc7..1d7eda0 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
@@ -2,14 +2,22 @@
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu;
import com.tanishisherewith.dynamichud.utils.contextmenu.options.Option;
+import com.tanishisherewith.dynamichud.utils.contextmenu.options.OptionGroup;
+import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.interfaces.GroupableSkin;
+import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.interfaces.SkinRenderer;
+import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import java.util.function.Supplier;
public abstract class Skin {
+ protected static final MinecraftClient mc = MinecraftClient.getInstance();
protected ContextMenu contextMenu;
- protected Map>, SkinRenderer extends Option>>> renderers = new HashMap<>();
+ protected Map>, Supplier>>> renderers = new HashMap<>();
private boolean createNewScreen;
public Skin(ContextMenu menu) {
@@ -19,20 +27,56 @@ public Skin(ContextMenu menu) {
public Skin() {
}
- public > void addRenderer(Class optionClass, SkinRenderer super T> renderer) {
+ public > void addRenderer(Class optionClass, Supplier> renderer) {
renderers.put(optionClass, renderer);
}
@SuppressWarnings("unchecked")
public > SkinRenderer getRenderer(Class optionClass) {
- return (SkinRenderer) renderers.get(optionClass);
+ Supplier>> supplier = renderers.get(optionClass);
+ if (supplier != null) {
+ return (SkinRenderer) supplier.get();
+ }
+ return null;
+ }
+
+ /**
+ * Whether this skin supports rendering option groups.
+ * If false, groups should be flattened before rendering.
+ */
+ public boolean supportsGroups() {
+ return this instanceof GroupableSkin; // Check if the skin supports groups
+ }
+
+ /**
+ * Flatten a list of options, expanding any groups into their constituent options.
+ * Used by skins that don't support group rendering.
+ */
+ protected List
> flattenOptions(List
> options) {
+ List
> flattened = new ArrayList<>();
+
+ for (Option> option : options) {
+ if (option instanceof OptionGroup group) {
+ // Create a new list with type List