private List<ITextComponent> resizeContent(List<String> lines) { List<ITextComponent> ret = new ArrayList<ITextComponent>(); for (String line : lines) { if (line == null) { ret.add(null); continue; } ITextComponent chat = ForgeHooks.newChatWithLinks(line, false); ret.addAll(GuiUtilRenderComponents.splitText(chat, this.listWidth-8, GuiModList.this.fontRendererObj, false, true)); } return ret; }
@Override public void draw(int mouseX, int mouseY, int y, int virtualWidth) { List<ITextComponent> lines = GuiUtilRenderComponents.splitText(text, virtualWidth - 20, fontRenderer, false, false); int runningY = y; for (ITextComponent line : lines) { String strLine = line.getFormattedText(); int halfLineWidth = fontRenderer.getStringWidth(strLine) / 2; int lineLeft = virtualWidth / 2 - halfLineWidth; fontRenderer.drawString(strLine, lineLeft, runningY, 0xffffff); runningY += fontRenderer.FONT_HEIGHT; } ITextComponent hoveredComponent = getHoveredComponent(virtualWidth, y, mouseX, mouseY); if (hoveredComponent != null) GeneralUtils.handleHoverEvent(hoveredComponent.getStyle().getHoverEvent(), mouseX, mouseY); }
private ITextComponent getHoveredComponent(int virtualWidth, int y, int mouseX, int mouseY) { List<ITextComponent> lines = GuiUtilRenderComponents.splitText(text, virtualWidth - 20, fontRenderer, false, false); for (ITextComponent line : lines) { String strLine = line.getFormattedText(); int halfLineWidth = fontRenderer.getStringWidth(strLine) / 2; int lineLeft = virtualWidth / 2 - halfLineWidth; int lineRight = virtualWidth / 2 + halfLineWidth; if (mouseY >= y && mouseY < y + fontRenderer.FONT_HEIGHT && mouseX >= lineLeft && mouseX < lineRight) { ITextComponent hoveredComponent = null; for (ITextComponent sibling : line) { hoveredComponent = sibling; lineLeft += fontRenderer.getStringWidth(GuiUtilRenderComponents .removeTextColorsIfConfigured(sibling.getUnformattedComponentText(), false)); if (mouseX < lineLeft) break; } return hoveredComponent; } y += fontRenderer.FONT_HEIGHT; } return null; }
private List<ITextComponent> resizeContent(List<String> lines) { List<ITextComponent> ret = new ArrayList<ITextComponent>(); for (String line : lines) { if (line == null) { ret.add(null); continue; } ITextComponent chat = ForgeHooks.newChatWithLinks(line, false); ret.addAll(GuiUtilRenderComponents.splitText(chat, this.listWidth-8, GuiCustomizeWorld.this.fontRenderer, false, true)); } return ret; }
@Override public int getHeight(int virtualWidth) { return GuiUtilRenderComponents.splitText(text, virtualWidth - 20, fontRenderer, false, false).size() * fontRenderer.FONT_HEIGHT; }
public static List<ITextComponent> split(ITextComponent chat, int width) { FontRenderer fr = Minecraft.getMinecraft().fontRenderer; return GuiUtilRenderComponents.splitText(chat, width, fr, false, false); }