Search in sources :

Example 1 with ITextProperties

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();
}
Also used : Matrix4f(net.minecraft.util.math.vector.Matrix4f) ITextProperties(net.minecraft.util.text.ITextProperties) IRenderTypeBuffer(net.minecraft.client.renderer.IRenderTypeBuffer) ArrayList(java.util.ArrayList) FontRenderer(net.minecraft.client.gui.FontRenderer)

Example 2 with ITextProperties

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));
}
Also used : ITextProperties(net.minecraft.util.text.ITextProperties) ArrayList(java.util.ArrayList) Matrix4f(net.minecraft.util.math.vector.Matrix4f) RenderTooltipEvent(net.minecraftforge.client.event.RenderTooltipEvent) IRenderTypeBuffer(net.minecraft.client.renderer.IRenderTypeBuffer) FontRenderer(net.minecraft.client.gui.FontRenderer)

Example 3 with ITextProperties

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;
}
Also used : ITextProperties(net.minecraft.util.text.ITextProperties)

Example 4 with ITextProperties

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);
    }
}
Also used : ITextProperties(net.minecraft.util.text.ITextProperties) ArrayList(java.util.ArrayList) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent)

Example 5 with ITextProperties

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);
    }
}
Also used : AbilityRegistry(com.lying.variousoddities.species.abilities.AbilityRegistry) Style(net.minecraft.util.text.Style) IFormattableTextComponent(net.minecraft.util.text.IFormattableTextComponent) LivingData(com.lying.variousoddities.capabilities.LivingData) Action(net.minecraft.util.text.event.HoverEvent.Action) ITextComponent(net.minecraft.util.text.ITextComponent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Lists(com.google.common.collect.Lists) Minecraft(net.minecraft.client.Minecraft) Types(com.lying.variousoddities.species.types.Types) StringTextComponent(net.minecraft.util.text.StringTextComponent) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) Ability(com.lying.variousoddities.species.abilities.Ability) Template(com.lying.variousoddities.species.Template) PlayerEntity(net.minecraft.entity.player.PlayerEntity) AbilityModifier(com.lying.variousoddities.species.abilities.AbilityModifier) AbilityModifierCon(com.lying.variousoddities.species.abilities.AbilityModifierCon) ITextProperties(net.minecraft.util.text.ITextProperties) Reference(com.lying.variousoddities.reference.Reference) AbilityNaturalArmour(com.lying.variousoddities.species.abilities.AbilityNaturalArmour) ITag(net.minecraft.tags.ITag) ActionSet(com.lying.variousoddities.species.types.EnumCreatureType.ActionSet) List(java.util.List) Screen(net.minecraft.client.gui.screen.Screen) HoverEvent(net.minecraft.util.text.event.HoverEvent) EnumCreatureType(com.lying.variousoddities.species.types.EnumCreatureType) Fluid(net.minecraft.fluid.Fluid) EnumCreatureType(com.lying.variousoddities.species.types.EnumCreatureType) ITextProperties(net.minecraft.util.text.ITextProperties) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) StringTextComponent(net.minecraft.util.text.StringTextComponent)

Aggregations

ITextProperties (net.minecraft.util.text.ITextProperties)36 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)19 StringTextComponent (net.minecraft.util.text.StringTextComponent)13 ArrayList (java.util.ArrayList)9 FontRenderer (net.minecraft.client.gui.FontRenderer)7 IReorderingProcessor (net.minecraft.util.IReorderingProcessor)7 List (java.util.List)6 Matrix4f (net.minecraft.util.math.vector.Matrix4f)6 IRenderTypeBuffer (net.minecraft.client.renderer.IRenderTypeBuffer)4 ITextComponent (net.minecraft.util.text.ITextComponent)4 ItemStack (net.minecraft.item.ItemStack)3 RenderTooltipEvent (net.minecraftforge.client.event.RenderTooltipEvent)3 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)2 MoonPhase (hellfirepvp.astralsorcery.common.base.MoonPhase)2 IWeakConstellation (hellfirepvp.astralsorcery.common.constellation.IWeakConstellation)2 PerkStatistic (hellfirepvp.astralsorcery.common.perk.reader.PerkStatistic)2 LinkedList (java.util.LinkedList)2 Minecraft (net.minecraft.client.Minecraft)2 Lists (com.google.common.collect.Lists)1 LivingData (com.lying.variousoddities.capabilities.LivingData)1