Search in sources :

Example 1 with GuiElementText

use of buildcraft.lib.gui.elem.GuiElementText in project BuildCraft by BuildCraft.

the class ElementHelpInfo method addGuiElements.

@SideOnly(Side.CLIENT)
public void addGuiElements(GuiElementContainerHelp container) {
    BuildCraftGui gui = container.gui;
    int y = 20;
    for (String key : localeKeys) {
        if (key == null) {
            y += Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT + 5;
            continue;
        }
        String localized = LocaleUtil.localize(key);
        List<String> lines = StringUtilBC.splitIntoLines(localized);
        for (String line : lines) {
            GuiElementText elemText = new GuiElementText(gui, container.offset(0, y), line, 0);
            container.add(elemText);
            y += elemText.getHeight() + 5;
        }
    }
}
Also used : BuildCraftGui(buildcraft.lib.gui.BuildCraftGui) GuiElementText(buildcraft.lib.gui.elem.GuiElementText) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with GuiElementText

use of buildcraft.lib.gui.elem.GuiElementText in project BuildCraft by BuildCraft.

the class GuiAbstractButton method createTextElement.

public GuiElementText createTextElement(Supplier<String> text) {
    FontRenderer fr = gui.mc.fontRenderer;
    DoubleSupplier x = () -> -fr.getStringWidth(text.get()) / 2;
    DoubleSupplier y = () -> -fr.FONT_HEIGHT / 2;
    IGuiPosition pos = getCenter().offset(x, y);
    return new GuiElementText(gui, pos, text, this::getColourForText);
}
Also used : DoubleSupplier(java.util.function.DoubleSupplier) GuiElementText(buildcraft.lib.gui.elem.GuiElementText) FontRenderer(net.minecraft.client.gui.FontRenderer) IGuiPosition(buildcraft.lib.gui.pos.IGuiPosition)

Example 3 with GuiElementText

use of buildcraft.lib.gui.elem.GuiElementText in project BuildCraft by BuildCraft.

the class ElementTypeText method deserialize0.

// pos: the position of the text
// text: The text to be drawn. Will be localised first, and used as a fallback
// expression: A replacement for text -- uses an expression rather than as a literal.
// colour: Default colour to be drawn
// centered: If true then the text will be centered around pos
@Override
public IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
    FunctionContext ctx = createContext(json);
    IGuiPosition pos = resolvePosition(json, "pos", parent, ctx);
    INodeObject<String> text;
    String prop;
    if ((prop = json.properties.get("text")) != null) {
        String localized = LocaleUtil.localize(prop);
        text = new NodeConstantObject<>(String.class, localized);
    } else if ((prop = json.properties.get("expression")) != null) {
        try {
            text = GenericExpressionCompiler.compileExpressionString(prop, ctx);
        } catch (InvalidExpressionException e) {
            throw new JsonSyntaxException("Invalid expression for '" + json.name + "'", e);
        }
    } else {
        throw new JsonSyntaxException("Require either 'text' or 'expression'!");
    }
    int colour;
    if (json.properties.containsKey("colour")) {
        colour = resolveEquationInt(json, "colour", ctx);
    } else {
        colour = resolveEquationInt(json, "color", ctx);
    }
    GuiElementText element = new GuiElementText(gui, pos, text, colour);
    element.setCentered("true".equals(json.properties.get("centered")));
    element.setDropShadow("true".equals(json.properties.get("shadow")));
    element.setForeground("true".equals(json.properties.get("foreground")));
    return element;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) InvalidExpressionException(buildcraft.lib.expression.api.InvalidExpressionException) GuiElementText(buildcraft.lib.gui.elem.GuiElementText) FunctionContext(buildcraft.lib.expression.FunctionContext) IGuiPosition(buildcraft.lib.gui.pos.IGuiPosition)

Aggregations

GuiElementText (buildcraft.lib.gui.elem.GuiElementText)3 IGuiPosition (buildcraft.lib.gui.pos.IGuiPosition)2 FunctionContext (buildcraft.lib.expression.FunctionContext)1 InvalidExpressionException (buildcraft.lib.expression.api.InvalidExpressionException)1 BuildCraftGui (buildcraft.lib.gui.BuildCraftGui)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 DoubleSupplier (java.util.function.DoubleSupplier)1 FontRenderer (net.minecraft.client.gui.FontRenderer)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1