Search in sources :

Example 1 with GuiElementToolTip

use of buildcraft.lib.gui.GuiElementToolTip in project BuildCraft by BuildCraft.

the class ElementTypeToolTip method deserialize0.

// Args:
// - pos[0], pos[1]: the area for help (where it will be drawn, relative to the root of the gui). Defaults
// to 0,0
// - size[0], size[1]: the size of the help area
// - area[0-3]: mapping for pos[0], pos[1], size[0], size[1]
// - text: The text to display in the tooltip
// - expression: The expression to display in the tooltip
@Override
public IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
    FunctionContext ctx = createContext(json);
    List<String> text = new ArrayList<>();
    String key = "text";
    boolean isExpression = false;
    if (json.properties.containsKey("expression") || json.properties.containsKey("expression[0]")) {
        key = "expression";
        isExpression = true;
    }
    if (json.properties.containsKey(key + "[0]")) {
        int i = 0;
        while (true) {
            String prop = json.properties.get(key + "[" + i + "]");
            if (prop == null) {
                break;
            }
            text.add(prop);
            i++;
        }
    } else {
        text.add(json.properties.getOrDefault(key, "ERROR: Text not given!"));
    }
    INodeBoolean visible = getEquationBool(json, "visible", ctx, true);
    ITooltipElement source;
    if (isExpression) {
        List<INodeObject<String>> nodes = new ArrayList<>(text.size());
        try {
            for (String s : text) {
                nodes.add(GenericExpressionCompiler.compileExpressionString(s, ctx));
            }
        } catch (InvalidExpressionException e) {
            throw new JsonSyntaxException(e);
        }
        source = (list) -> {
            if (visible.evaluate()) {
                String[] arr = new String[nodes.size()];
                for (int i = 0; i < arr.length; i++) {
                    arr[i] = nodes.get(i).evaluate();
                }
                list.add(ToolTip.createLocalized(arr));
            }
        };
    } else {
        ToolTip tooltip = ToolTip.createLocalized(text.toArray(new String[0]));
        source = (list) -> {
            if (visible.evaluate()) {
                list.add(tooltip);
            }
        };
    }
    inheritProperty(json, "pos[0]", "area[0]");
    inheritProperty(json, "pos[1]", "area[1]");
    inheritProperty(json, "size[0]", "area[2]");
    inheritProperty(json, "size[1]", "area[3]");
    IGuiArea area = resolveArea(json, "area", parent, ctx);
    return new GuiElementToolTip(gui, area, source);
}
Also used : GuiElementToolTip(buildcraft.lib.gui.GuiElementToolTip) ToolTip(buildcraft.lib.gui.elem.ToolTip) IGuiArea(buildcraft.lib.gui.pos.IGuiArea) ITooltipElement(buildcraft.lib.gui.ITooltipElement) ArrayList(java.util.ArrayList) INodeBoolean(buildcraft.lib.expression.api.IExpressionNode.INodeBoolean) FunctionContext(buildcraft.lib.expression.FunctionContext) JsonSyntaxException(com.google.gson.JsonSyntaxException) InvalidExpressionException(buildcraft.lib.expression.api.InvalidExpressionException) GuiElementToolTip(buildcraft.lib.gui.GuiElementToolTip) INodeObject(buildcraft.lib.expression.api.IExpressionNode.INodeObject)

Example 2 with GuiElementToolTip

use of buildcraft.lib.gui.GuiElementToolTip in project BuildCraft by BuildCraft.

the class GuiEmzuliPipe_BC8 method addButton.

private void addButton(SlotIndex index, int x, int y) {
    Supplier<EnumDyeColor> getter = () -> container.behaviour.slotColours.get(index);
    Consumer<EnumDyeColor> setter = c -> container.paintWidgets.get(index).setColour(c);
    IGuiPosition elem = mainGui.rootElement.offset(x, y);
    GuiButtonDrawable button = new GuiButtonDrawable(mainGui, index.name(), elem, PAINT_BUTTON_BUILDER);
    button.registerListener((b, key) -> {
        final EnumDyeColor old = getter.get();
        EnumDyeColor nColour;
        switch(key) {
            case 0:
                {
                    nColour = ColourUtil.getNextOrNull(old);
                    break;
                }
            case 1:
                {
                    nColour = ColourUtil.getPrevOrNull(old);
                    break;
                }
            case 2:
                {
                    nColour = null;
                    break;
                }
            default:
                {
                    return;
                }
        }
        setter.accept(nColour);
    });
    mainGui.shownElements.add(button);
    // Button paintbrush
    IGuiArea area = new GuiRectangle(20, 20).offset(elem);
    ISimpleDrawable paintIcon = (px, py) -> {
        EnumDyeColor colour = getter.get();
        if (colour == null) {
            ICON_NO_PAINT.drawAt(px + 2, py + 2);
        } else {
            ISprite sprite = BCTransportSprites.ACTION_PIPE_COLOUR[colour.ordinal()];
            GuiIcon.drawAt(sprite, px + 2, py + 2, 16);
        }
    };
    mainGui.shownElements.add(new GuiElementDrawable(mainGui, area, paintIcon, false));
    ITooltipElement tooltips = list -> {
        EnumDyeColor colour = getter.get();
        String line;
        if (colour == null) {
            line = LocaleUtil.localize("gui.pipes.emzuli.nopaint");
        } else {
            line = LocaleUtil.localize("gui.pipes.emzuli.paint", ColourUtil.getTextFullTooltip(colour));
        }
        list.add(new ToolTip(line));
    };
    mainGui.shownElements.add(new GuiElementToolTip(mainGui, area, tooltips));
}
Also used : ITooltipElement(buildcraft.lib.gui.ITooltipElement) Supplier(java.util.function.Supplier) ISprite(buildcraft.api.core.render.ISprite) GuiIcon(buildcraft.lib.gui.GuiIcon) SlotIndex(buildcraft.transport.pipe.behaviour.PipeBehaviourEmzuli.SlotIndex) GuiBC8(buildcraft.lib.gui.GuiBC8) GuiElementDrawable(buildcraft.lib.gui.elem.GuiElementDrawable) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) BCLibSprites(buildcraft.lib.BCLibSprites) ISimpleDrawable(buildcraft.lib.gui.ISimpleDrawable) GuiElementToolTip(buildcraft.lib.gui.GuiElementToolTip) BCTransportSprites(buildcraft.transport.BCTransportSprites) LocaleUtil(buildcraft.lib.misc.LocaleUtil) PipeBehaviourEmzuli(buildcraft.transport.pipe.behaviour.PipeBehaviourEmzuli) Consumer(java.util.function.Consumer) ToolTip(buildcraft.lib.gui.elem.ToolTip) EnumDyeColor(net.minecraft.item.EnumDyeColor) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ResourceLocation(net.minecraft.util.ResourceLocation) ColourUtil(buildcraft.lib.misc.ColourUtil) ContainerEmzuliPipe_BC8(buildcraft.transport.container.ContainerEmzuliPipe_BC8) BCCoreSprites(buildcraft.core.BCCoreSprites) GuiButtonDrawable(buildcraft.lib.gui.button.GuiButtonDrawable) IGuiArea(buildcraft.lib.gui.pos.IGuiArea) IGuiPosition(buildcraft.lib.gui.pos.IGuiPosition) GuiElementToolTip(buildcraft.lib.gui.GuiElementToolTip) ToolTip(buildcraft.lib.gui.elem.ToolTip) IGuiArea(buildcraft.lib.gui.pos.IGuiArea) ISimpleDrawable(buildcraft.lib.gui.ISimpleDrawable) ITooltipElement(buildcraft.lib.gui.ITooltipElement) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) ISprite(buildcraft.api.core.render.ISprite) GuiButtonDrawable(buildcraft.lib.gui.button.GuiButtonDrawable) GuiElementDrawable(buildcraft.lib.gui.elem.GuiElementDrawable) EnumDyeColor(net.minecraft.item.EnumDyeColor) GuiElementToolTip(buildcraft.lib.gui.GuiElementToolTip) IGuiPosition(buildcraft.lib.gui.pos.IGuiPosition)

Aggregations

GuiElementToolTip (buildcraft.lib.gui.GuiElementToolTip)2 ITooltipElement (buildcraft.lib.gui.ITooltipElement)2 ToolTip (buildcraft.lib.gui.elem.ToolTip)2 IGuiArea (buildcraft.lib.gui.pos.IGuiArea)2 ISprite (buildcraft.api.core.render.ISprite)1 BCCoreSprites (buildcraft.core.BCCoreSprites)1 BCLibSprites (buildcraft.lib.BCLibSprites)1 FunctionContext (buildcraft.lib.expression.FunctionContext)1 INodeBoolean (buildcraft.lib.expression.api.IExpressionNode.INodeBoolean)1 INodeObject (buildcraft.lib.expression.api.IExpressionNode.INodeObject)1 InvalidExpressionException (buildcraft.lib.expression.api.InvalidExpressionException)1 GuiBC8 (buildcraft.lib.gui.GuiBC8)1 GuiIcon (buildcraft.lib.gui.GuiIcon)1 ISimpleDrawable (buildcraft.lib.gui.ISimpleDrawable)1 GuiButtonDrawable (buildcraft.lib.gui.button.GuiButtonDrawable)1 GuiElementDrawable (buildcraft.lib.gui.elem.GuiElementDrawable)1 GuiRectangle (buildcraft.lib.gui.pos.GuiRectangle)1 IGuiPosition (buildcraft.lib.gui.pos.IGuiPosition)1 ColourUtil (buildcraft.lib.misc.ColourUtil)1 LocaleUtil (buildcraft.lib.misc.LocaleUtil)1