Skip to content

Commit

Permalink
Fix tooltips not working for buttons that override renderButton
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Aug 28, 2023
1 parent 69d22a9 commit 5253209
Showing 1 changed file with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,22 @@ public boolean isMouseOver(double mouseX, double mouseY) {
}

@Override
public void renderButton(DrawContext context, int mouseX, int mouseY, float partialTicks) {
MinecraftClient mc = MinecraftClient.getInstance();
public void render(DrawContext context, int mouseX, int mouseY, float tickDelta) {
if (!visible) {
return;
}
getStyle().getTooltip().ifPresentOrElse(tooltip -> {
if (tooltip != prevTooltip) {
prevTooltip = tooltip;
setTooltip(tooltip.toTooltip());
}
}, () -> setTooltip(null));
super.render(context, mouseX, mouseY, tickDelta);
}

@Override
public void renderButton(DrawContext context, int mouseX, int mouseY, float tickDelta) {
MinecraftClient mc = MinecraftClient.getInstance();
RenderSystem.setShader(GameRenderer::getPositionTexProgram);
RenderSystem.setShaderColor(1, 1, 1, alpha);
RenderSystem.enableBlend();
Expand All @@ -196,29 +209,18 @@ public void renderButton(DrawContext context, int mouseX, int mouseY, float part
GlStateManager.SrcFactor.SRC_ALPHA,
GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);

int state = getTextureY();

renderButtonBlit(context, getX(), getY(), state, getWidth(), height);
renderButtonBlit(context, getX(), getY(), getTextureY(), getWidth(), height);
renderBackground(context, mc, mouseX, mouseY);
setMessage(getStyle().getText());
drawIcon(context, mouseX, mouseY, tickDelta);

int foreColor = getStyle().getColor();
if (!active) {
foreColor = 10526880;
} else if (isHovered()) {
foreColor = 16777120;
}

setMessage(getStyle().getText());
drawIcon(context, mouseX, mouseY, partialTicks);
renderForground(context, mc, mouseX, mouseY, foreColor | MathHelper.ceil(alpha * 255F) << 24);

getStyle().getTooltip().ifPresentOrElse(tooltip -> {
if (tooltip != prevTooltip) {
prevTooltip = tooltip;
setTooltip(tooltip.toTooltip());
this.getTooltipPositioner();
}
}, () -> setTooltip(null));
}

@Override
Expand Down

0 comments on commit 5253209

Please sign in to comment.