Skip to content

Commit

Permalink
Fixed an issue with tooltip wrapping.
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon3055 committed Apr 13, 2024
1 parent 512050d commit d712280
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
22 changes: 16 additions & 6 deletions src/main/java/codechicken/lib/gui/modular/lib/GuiRender.java
Original file line number Diff line number Diff line change
Expand Up @@ -1302,11 +1302,8 @@ public void renderTooltip(Component message, double mouseX, double mouseY) {
}

public void renderTooltip(Component message, double mouseX, double mouseY, int backgroundTop, int backgroundBottom, int borderTop, int borderBottom) {
this.renderTooltip(List.of(message.getVisualOrderText()), mouseX, mouseY, backgroundTop, backgroundBottom, borderTop, borderBottom);
}

public void componentTooltip(List<Component> tooltips, double mouseX, double mouseY) {
componentTooltip(tooltips, mouseX, mouseY, 0xf0100010, 0xf0100010, 0x505000ff, 0x5028007f);
List<ClientTooltipComponent> list = ForgeHooksClient.gatherTooltipComponents(tooltipStack, List.of(message), Optional.empty(), (int) mouseX, guiWidth(), guiHeight(), font());
this.renderTooltipInternal(list, mouseX, mouseY, backgroundTop, backgroundBottom, borderTop, borderBottom, DefaultTooltipPositioner.INSTANCE);
}

public void componentTooltip(List<Component> tooltips, double mouseX, double mouseY, int backgroundTop, int backgroundBottom, int borderTop, int borderBottom) {
Expand All @@ -1318,21 +1315,34 @@ public void componentTooltip(List<? extends FormattedText> tooltips, double mous
componentTooltip(tooltips, mouseX, mouseY, 0xf0100010, 0xf0100010, 0x505000ff, 0x5028007f, stack);
}

public void componentTooltip(List<? extends net.minecraft.network.chat.FormattedText> tooltips, double mouseX, double mouseY, int backgroundTop, int backgroundBottom, int borderTop, int borderBottom, ItemStack stack) {
public void componentTooltip(List<? extends FormattedText> tooltips, double mouseX, double mouseY) {
componentTooltip(tooltips, mouseX, mouseY, 0xf0100010, 0xf0100010, 0x505000ff, 0x5028007f, ItemStack.EMPTY);
}

public void componentTooltip(List<? extends FormattedText> tooltips, double mouseX, double mouseY, int backgroundTop, int backgroundBottom, int borderTop, int borderBottom, ItemStack stack) {
this.tooltipStack = stack;
List<ClientTooltipComponent> list = ForgeHooksClient.gatherTooltipComponents(tooltipStack, tooltips, Optional.empty(), (int) mouseX, guiWidth(), guiHeight(), font());
this.renderTooltipInternal(list, mouseX, mouseY, backgroundTop, backgroundBottom, borderTop, borderBottom, DefaultTooltipPositioner.INSTANCE);
this.tooltipStack = ItemStack.EMPTY;
}

/**
* Warning: This tooltip method with not automatically wrap tooltip lines
*/
public void renderTooltip(List<? extends FormattedCharSequence> tooltips, double mouseX, double mouseY) {
renderTooltip(tooltips, mouseX, mouseY, 0xf0100010, 0xf0100010, 0x505000ff, 0x5028007f);
}

/**
* Warning: This tooltip method with not automatically wrap tooltip lines
*/
public void renderTooltip(List<? extends FormattedCharSequence> tooltips, double mouseX, double mouseY, int backgroundTop, int backgroundBottom, int borderTop, int borderBottom) {
this.renderTooltipInternal(tooltips.stream().map(ClientTooltipComponent::create).collect(Collectors.toList()), mouseX, mouseY, backgroundTop, backgroundBottom, borderTop, borderBottom, DefaultTooltipPositioner.INSTANCE);
}

/**
* Warning: This tooltip method with not automatically wrap tooltip lines
*/
public void renderTooltip(List<FormattedCharSequence> tooltips, ClientTooltipPositioner positioner, double mouseX, double mouseY, int backgroundTop, int backgroundBottom, int borderTop, int borderBottom) {
this.renderTooltipInternal(tooltips.stream().map(ClientTooltipComponent::create).collect(Collectors.toList()), mouseX, mouseY, backgroundTop, backgroundBottom, borderTop, borderBottom, positioner);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;

/**
Expand Down Expand Up @@ -100,7 +101,7 @@ default boolean renderTooltip(GuiRender render, double mouseX, double mouseY) {
List<Component> list = supplier.get();
if (list.isEmpty()) return false;
//Run all components though split to account for newline characters in translations
render.renderTooltip(list.stream().flatMap(component -> render.font().split(component, Integer.MAX_VALUE).stream()).toList(), mouseX, mouseY);
render.componentTooltip(list.stream().flatMap(component -> render.font().getSplitter().splitLines(component, Integer.MAX_VALUE, component.getStyle()).stream()).toList(), mouseX, mouseY);
return true;
}
}

0 comments on commit d712280

Please sign in to comment.