use of net.minecraft.util.text.ITextProperties in project SophisticatedBackpacks by P3pp3rF1y.
the class BackpackScreen method renderErrorMessage.
private void renderErrorMessage(MatrixStack matrixStack, ITextComponent overlayErrorMessage) {
RenderSystem.pushMatrix();
RenderSystem.disableDepthTest();
RenderSystem.translatef((float) width / 2, topPos + inventoryLabelY + 4, 300F);
FontRenderer fontrenderer = Minecraft.getInstance().font;
int tooltipWidth = font.width(overlayErrorMessage);
List<ITextProperties> wrappedTextLines = new ArrayList<>();
int maxLineWidth = 260;
if (tooltipWidth > maxLineWidth) {
int wrappedTooltipWidth = 0;
List<ITextProperties> wrappedLine = font.getSplitter().splitLines(overlayErrorMessage, maxLineWidth, Style.EMPTY);
for (ITextProperties line : wrappedLine) {
int lineWidth = font.width(line);
if (lineWidth > wrappedTooltipWidth) {
wrappedTooltipWidth = lineWidth;
}
wrappedTextLines.add(line);
}
tooltipWidth = wrappedTooltipWidth;
} else {
wrappedTextLines.add(overlayErrorMessage);
}
int tooltipHeight = 8;
if (wrappedTextLines.size() > 1) {
tooltipHeight += 2 + (wrappedTextLines.size() - 1) * 10;
}
Matrix4f matrix4f = matrixStack.last().pose();
float leftX = (float) -tooltipWidth / 2;
GuiHelper.renderTooltipBackground(matrix4f, tooltipWidth, (int) leftX, 0, tooltipHeight, ERROR_BACKGROUND_COLOR, ERROR_BORDER_COLOR, ERROR_BORDER_COLOR);
IRenderTypeBuffer.Impl renderTypeBuffer = IRenderTypeBuffer.immediate(Tessellator.getInstance().getBuilder());
matrixStack.translate(0.0D, 0.0D, 400.0D);
GuiHelper.writeTooltipLines(wrappedTextLines, fontrenderer, leftX, 0, matrix4f, renderTypeBuffer, DyeColor.RED.getColorValue());
renderTypeBuffer.endBatch();
RenderSystem.popMatrix();
}
use of net.minecraft.util.text.ITextProperties in project SophisticatedBackpacks by P3pp3rF1y.
the class GuiHelper method renderTooltip.
public static void renderTooltip(Minecraft minecraft, MatrixStack matrixStack, List<? extends ITextProperties> textLines, int mouseX, int mouseY, ITooltipRenderPart additionalRender, @Nullable FontRenderer tooltipRenderFont, ItemStack stack, int maxTextWidth) {
FontRenderer font = tooltipRenderFont == null ? minecraft.font : tooltipRenderFont;
int windowWidth = minecraft.getWindow().getGuiScaledWidth();
int windowHeight = minecraft.getWindow().getGuiScaledHeight();
int tooltipWidth = getMaxLineWidth(textLines, font);
if (maxTextWidth > 0 && tooltipWidth > maxTextWidth) {
tooltipWidth = maxTextWidth;
}
int wrappedTooltipWidth = 0;
List<ITextProperties> wrappedTextLines = new ArrayList<>();
for (ITextProperties textLine : textLines) {
List<ITextProperties> wrappedLine = font.getSplitter().splitLines(textLine, tooltipWidth, Style.EMPTY);
for (ITextProperties line : wrappedLine) {
int lineWidth = font.width(line);
if (lineWidth > wrappedTooltipWidth) {
wrappedTooltipWidth = lineWidth;
}
wrappedTextLines.add(line);
}
}
tooltipWidth = wrappedTooltipWidth;
tooltipWidth = Math.max(tooltipWidth, additionalRender.getWidth());
textLines = wrappedTextLines;
int leftX = mouseX + 12;
if (leftX + tooltipWidth > windowWidth) {
leftX -= 28 + tooltipWidth;
}
int topY = mouseY - 12;
int tooltipHeight = 8;
if (textLines.size() > 1) {
tooltipHeight += 2 + (textLines.size() - 1) * 10;
}
tooltipHeight += additionalRender.getHeight();
if (topY + tooltipHeight + 6 > windowHeight) {
topY = windowHeight - tooltipHeight - 6;
}
int backgroundColor = GuiUtils.DEFAULT_BACKGROUND_COLOR;
int borderColorStart = GuiUtils.DEFAULT_BORDER_COLOR_START;
int borderColorEnd = GuiUtils.DEFAULT_BORDER_COLOR_END;
RenderTooltipEvent.Color colorEvent = new RenderTooltipEvent.Color(stack, textLines, matrixStack, leftX, topY, font, backgroundColor, borderColorStart, borderColorEnd);
MinecraftForge.EVENT_BUS.post(colorEvent);
backgroundColor = colorEvent.getBackground();
borderColorStart = colorEvent.getBorderStart();
borderColorEnd = colorEvent.getBorderEnd();
matrixStack.pushPose();
Matrix4f matrix4f = matrixStack.last().pose();
renderTooltipBackground(matrix4f, tooltipWidth, leftX, topY, tooltipHeight, backgroundColor, borderColorStart, borderColorEnd);
MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostBackground(stack, textLines, matrixStack, leftX, topY, font, tooltipWidth, tooltipHeight));
IRenderTypeBuffer.Impl renderTypeBuffer = IRenderTypeBuffer.immediate(Tessellator.getInstance().getBuilder());
matrixStack.translate(0.0D, 0.0D, 400.0D);
topY = writeTooltipLines(textLines, font, leftX, topY, matrix4f, renderTypeBuffer, -1);
renderTypeBuffer.endBatch();
additionalRender.render(matrixStack, leftX, topY, font);
matrixStack.popPose();
MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostText(stack, textLines, matrixStack, leftX, topY, font, tooltipWidth, tooltipHeight));
}
use of net.minecraft.util.text.ITextProperties in project SophisticatedBackpacks by P3pp3rF1y.
the class GuiHelper method writeTooltipLines.
public static int writeTooltipLines(List<? extends ITextProperties> textLines, FontRenderer font, float leftX, int topY, Matrix4f matrix4f, IRenderTypeBuffer.Impl renderTypeBuffer, int color) {
for (int i = 0; i < textLines.size(); ++i) {
ITextProperties line = textLines.get(i);
if (line != null) {
font.drawInBatch(LanguageMap.getInstance().getVisualOrder(line), leftX, topY, color, true, matrix4f, renderTypeBuffer, false, 0, 15728880);
}
if (i == 0) {
topY += 2;
}
topY += 10;
}
return topY;
}
use of net.minecraft.util.text.ITextProperties in project SophisticatedBackpacks by P3pp3rF1y.
the class BatteryInventoryPart method renderTooltip.
private void renderTooltip(int mouseX, int mouseY, int energyStored, int maxEnergyStored) {
int screenX = screen.getGuiLeft() + pos.getX() + 10;
int screenY = screen.getGuiTop() + pos.getY() + 1;
if (mouseX >= screenX && mouseX < screenX + 16 && mouseY >= screenY && mouseY < screenY + height - 2) {
List<ITextProperties> tooltip = new ArrayList<>();
tooltip.add(new TranslationTextComponent(TranslationHelper.translUpgradeKey("battery.contents_tooltip"), String.format("%,d", energyStored), String.format("%,d", maxEnergyStored)));
GuiHelper.setTooltipToRender(tooltip);
}
}
use of net.minecraft.util.text.ITextProperties in project VariousOddities by Lyinginbedmon.
the class ScreenCharacterSheet method renderActionSet.
private void renderActionSet(MatrixStack matrixStack, int mouseX, int mouseY) {
EnumCreatureType.Action hovered = null;
int count = EnumCreatureType.Action.values().length;
int iconX = this.listPassives.getLeft() - ACTION_ICON_SEP - ACTION_ICON_SIZE;
int iconY = (this.height - (count * ACTION_ICON_SIZE + count - 1 * ACTION_ICON_SEP)) / 2;
for (EnumCreatureType.Action action : EnumCreatureType.Action.values()) {
if (renderAction(matrixStack, iconX, iconY, mouseX, mouseY, action, this.actionSet.contains(action)))
hovered = action;
iconY += ACTION_ICON_SIZE + ACTION_ICON_SEP;
}
if (hovered != null) {
List<ITextProperties> tooltip = Lists.newArrayList();
String translated = hovered.translated().getString().toLowerCase();
if (this.actionSet.contains(hovered)) {
tooltip.add(new TranslationTextComponent("enum.varodd.type_action.does", translated));
if (hovered == EnumCreatureType.Action.BREATHES)
this.fluids.forEach((fluid) -> {
String name = "air";
if (fluid != null)
name = fluid.getName().getPath();
tooltip.add(new StringTextComponent(" " + name));
});
} else
tooltip.add(new TranslationTextComponent("enum.varodd.type_action.doesnt", translated));
renderWrappedToolTip(matrixStack, tooltip, mouseX, mouseY, this.font);
}
}
Aggregations