aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorYasin <a.piri@hotmail.de>2024-06-30 14:13:34 +0200
committerKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2024-07-26 15:09:00 +0800
commitcb6a665d28e704f4e6f1949750b82947d0c2e932 (patch)
tree5ae6aa1b9c900453c6b4a067947825808a742dd4 /src/main
parent192b16d5d5ec2baf0f561dcbaa8e1edad2fcd1b0 (diff)
downloadSkyblocker-cb6a665d28e704f4e6f1949750b82947d0c2e932.tar.gz
Skyblocker-cb6a665d28e704f4e6f1949750b82947d0c2e932.tar.bz2
Skyblocker-cb6a665d28e704f4e6f1949750b82947d0c2e932.zip
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.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNavButton.java42
1 files changed, 36 insertions, 6 deletions
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) {
+ }
}