From de1c8a317226b58fe03497027136eaed1adfd808 Mon Sep 17 00:00:00 2001 From: isXander Date: Mon, 19 Sep 2022 19:11:13 +0100 Subject: 1.4.0 improved tooltips `ButtonOption` now consumes itself, so you can access it when building. --- .../dev/isxander/yacl/gui/TooltipButtonWidget.java | 28 ++++------------------ 1 file changed, 4 insertions(+), 24 deletions(-) (limited to 'src/main/java/dev/isxander/yacl/gui/TooltipButtonWidget.java') diff --git a/src/main/java/dev/isxander/yacl/gui/TooltipButtonWidget.java b/src/main/java/dev/isxander/yacl/gui/TooltipButtonWidget.java index 0f34e61..e59c06c 100644 --- a/src/main/java/dev/isxander/yacl/gui/TooltipButtonWidget.java +++ b/src/main/java/dev/isxander/yacl/gui/TooltipButtonWidget.java @@ -1,19 +1,13 @@ package dev.isxander.yacl.gui; -import dev.isxander.yacl.impl.YACLConstants; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.MultilineText; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.OrderedText; import net.minecraft.text.Text; -import java.util.List; - public class TooltipButtonWidget extends ButtonWidget { - protected float hoveredTicks = 0; - protected int prevMouseX, prevMouseY; protected final Screen screen; protected MultilineText wrappedDescription; @@ -24,27 +18,13 @@ public class TooltipButtonWidget extends ButtonWidget { setTooltip(tooltip); } - @Override - public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { - super.render(matrices, mouseX, mouseY, delta); - - if (isHovered() && (!YACLConstants.HOVER_MOUSE_RESET || (prevMouseX == mouseX && prevMouseY == mouseY))) { - hoveredTicks += delta; - } else { - hoveredTicks = 0; - } - - prevMouseX = mouseX; - prevMouseY = mouseY; - } - - public void renderHoveredTooltip(MatrixStack matrices, int mouseX, int mouseY) { - if (hoveredTicks >= YACLConstants.HOVER_TICKS) { - YACLScreen.renderMultilineTooltip(matrices, MinecraftClient.getInstance().textRenderer, wrappedDescription, mouseX, mouseY, screen.width, screen.height); + public void renderHoveredTooltip(MatrixStack matrices) { + if (isHovered()) { + YACLScreen.renderMultilineTooltip(matrices, MinecraftClient.getInstance().textRenderer, wrappedDescription, x + width / 2, y - 4, y + height + 4, screen.width, screen.height); } } public void setTooltip(Text tooltip) { - wrappedDescription = MultilineText.create(MinecraftClient.getInstance().textRenderer, tooltip, screen.width / 2); + wrappedDescription = MultilineText.create(MinecraftClient.getInstance().textRenderer, tooltip, screen.width / 3); } } -- cgit