From beb3e023a5a76b5cbc475b90d9a99f440513baed Mon Sep 17 00:00:00 2001 From: tanishisherewithhh <120117618+tanishisherewithhh@users.noreply.github.com> Date: Wed, 17 Apr 2024 13:41:34 +0530 Subject: [PATCH] Optimisation --- .../dynamichud/config/GlobalConfig.java | 14 ++++++++++++++ .../options/coloroption/ColorGradientPicker.java | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/tanishisherewith/dynamichud/config/GlobalConfig.java b/src/main/java/com/tanishisherewith/dynamichud/config/GlobalConfig.java index 7c34869..ff11e4f 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/config/GlobalConfig.java +++ b/src/main/java/com/tanishisherewith/dynamichud/config/GlobalConfig.java @@ -1,6 +1,7 @@ package com.tanishisherewith.dynamichud.config; import dev.isxander.yacl3.api.*; +import dev.isxander.yacl3.api.controller.BooleanControllerBuilder; import dev.isxander.yacl3.api.controller.FloatSliderControllerBuilder; import dev.isxander.yacl3.config.v2.api.ConfigClassHandler; import dev.isxander.yacl3.config.v2.api.SerialEntry; @@ -25,6 +26,9 @@ public class GlobalConfig { @SerialEntry private float scale = 1.0f; + @SerialEntry + private boolean showColorPickerPreview = true; + public static GlobalConfig get() { return INSTANCE; } @@ -44,6 +48,12 @@ public final Screen createYACLGUI() { .binding(1.0f, () -> this.scale, newVal -> this.scale = newVal) .controller(floatOption -> FloatSliderControllerBuilder.create(floatOption).range(0.1f, 2.5f).step(0.1f)) .build()) + .option(Option.createBuilder() + .name(Text.literal("Show Color picker preview")) + .description(OptionDescription.of(Text.literal("Shows the preview below your mouse pointer on selecting color from the screen. Note: You may drop some frames with the preview on."))) + .binding(true, () -> this.showColorPickerPreview, newVal -> this.showColorPickerPreview = newVal) + .controller(booleanOption -> BooleanControllerBuilder.create(booleanOption).yesNoFormatter()) + .build()) .build()) .build()) .build() @@ -52,4 +62,8 @@ public final Screen createYACLGUI() { public float getScale(){ return scale; } + + public boolean showColorPickerPreview() { + return showColorPickerPreview; + } } 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 66c676d..801e652 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 @@ -1,5 +1,6 @@ package com.tanishisherewith.dynamichud.utils.contextmenu.options.coloroption; +import com.tanishisherewith.dynamichud.config.GlobalConfig; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gl.Framebuffer; import net.minecraft.client.gui.DrawContext; @@ -66,7 +67,7 @@ public void render(DrawContext drawContext, int x1, int y1) { colorPickerButton.render(drawContext, x + 24 + boxSize, y + client.textRenderer.fontHeight + gradientSlider.getHeight() + 8); alphaSlider.render(drawContext, x + 10 + boxSize, y + client.textRenderer.fontHeight + gradientSlider.getHeight() + 10); - if (colorPickerButton.isPicking()) { + if (colorPickerButton.isPicking() && GlobalConfig.get().showColorPickerPreview()) { // Draw the preview box near cursor //Translate cursor screen position to minecraft's scaled window