From cb6a665d28e704f4e6f1949750b82947d0c2e932 Mon Sep 17 00:00:00 2001 From: Yasin Date: Sun, 30 Jun 2024 14:13:34 +0200 Subject: fixes #378 The click behavior of the Quicknavbutton has been changed so that it is more like a button click. The button is therefore pressed for 2.5 seconds. This has the advantage that the button can be pressed again if an error occurs. Otherwise, everything is the same, i.e. if the container name is recognized, it remains pressed and cannot be pressed again. A fade animation has also been added. --- .../skyblock/quicknav/QuickNavButton.java | 42 ++++++++++++++++++---- 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'src/main') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNavButton.java b/src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNavButton.java index f7f33d0f..21574fd8 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNavButton.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNavButton.java @@ -18,10 +18,16 @@ import net.minecraft.util.Identifier; @Environment(value = EnvType.CLIENT) public class QuickNavButton extends ClickableWidget { private final int index; - private boolean toggled; + private final boolean toggled; + private boolean temporaryToggled = false; private final String command; private final ItemStack icon; + private static final long TOGGLE_DURATION = 250; + private long toggleTime; + + private float alpha = 1.0f; + /** * Checks if the current tab is a top tab based on its index. * @@ -32,7 +38,7 @@ public class QuickNavButton extends ClickableWidget { } public boolean toggled() { - return toggled; + return toggled || temporaryToggled; } /** @@ -49,6 +55,7 @@ public class QuickNavButton extends ClickableWidget { this.toggled = toggled; this.command = command; this.icon = icon; + this.toggleTime = 0; } private void updateCoordinates() { @@ -71,10 +78,12 @@ public class QuickNavButton extends ClickableWidget { */ @Override public void onClick(double mouseX, double mouseY) { - if (!this.toggled) { - this.toggled = true; + if (!this.temporaryToggled) { + this.temporaryToggled = true; + this.toggleTime = System.currentTimeMillis(); MessageScheduler.INSTANCE.sendMessageAfterCooldown(command); // TODO : add null check with log error + this.alpha = 0.5f; } } @@ -93,17 +102,38 @@ public class QuickNavButton extends ClickableWidget { this.updateCoordinates(); RenderSystem.disableDepthTest(); + if (this.temporaryToggled && System.currentTimeMillis() - this.toggleTime >= TOGGLE_DURATION) { + this.temporaryToggled = false; // Reset toggled state + } + //"animation" + if (this.alpha < 1.0f) { + this.alpha += 0.05f; + if (this.alpha > 1.0f) { + this.alpha = 1.0f; + } + } + + //"animation" + RenderSystem.enableBlend(); + RenderSystem.defaultBlendFunc(); + RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, this.alpha); + // Construct the texture identifier based on the index and toggled state - Identifier tabTexture = Identifier.ofVanilla("container/creative_inventory/tab_" + (isTopTab() ? "top" : "bottom") + "_" + (toggled ? "selected" : "unselected") + "_" + (index % 7 + 1)); + Identifier tabTexture = Identifier.ofVanilla("container/creative_inventory/tab_" + (isTopTab() ? "top" : "bottom") + "_" + (toggled() ? "selected" : "unselected") + "_" + (index % 7 + 1)); // Render the button texture context.drawGuiTexture(tabTexture, this.getX(), this.getY(), this.width, this.height); // Render the button icon int yOffset = this.index < 7 ? 1 : -1; context.drawItem(this.icon, this.getX() + 5, this.getY() + 8 + yOffset); + //prevent "fading animation" on not quicknav stuff + RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); + RenderSystem.disableBlend(); + RenderSystem.enableDepthTest(); } @Override - protected void appendClickableNarrations(NarrationMessageBuilder builder) {} + protected void appendClickableNarrations(NarrationMessageBuilder builder) { + } } -- cgit