Search in sources :

Example 1 with ToolTip

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

the class GuiArchitectOld method initGui.

@SuppressWarnings("unchecked")
@Override
public void initGui() {
    super.initGui();
    Keyboard.enableRepeatEvents(true);
    optionRotate = new GuiBetterButton(0, guiLeft + 5, guiTop + 30, 79, "");
    buttonList.add(optionRotate);
    optionExcavate = new GuiBetterButton(1, guiLeft + 5, guiTop + 55, 79, "");
    buttonList.add(optionExcavate);
    optionAllowCreative = new GuiBetterButton(2, guiLeft + 5, guiTop + 80, 79, "");
    optionAllowCreative.setToolTip(new ToolTip(500, new ToolTipLine(LocaleUtil.localize("tile.architect.tooltip.allowCreative.1")), new ToolTipLine(LocaleUtil.localize("tile.architect.tooltip.allowCreative.2"))));
    buttonList.add(optionAllowCreative);
    textField = new GuiTextField(0, this.fontRendererObj, TEXT_X, TEXT_Y, TEXT_WIDTH, TEXT_HEIGHT);
    textField.setMaxStringLength(DefaultProps.MAX_NAME_SIZE);
    textField.setText(architect.name);
    textField.setFocused(true);
    updateButtons();
}
Also used : ToolTip(buildcraft.lib.gui.elem.ToolTip) ToolTipLine(buildcraft.core.lib.gui.tooltips.ToolTipLine) GuiBetterButton(buildcraft.lib.gui.button.GuiBetterButton) GuiTextField(net.minecraft.client.gui.GuiTextField)

Example 2 with ToolTip

use of buildcraft.lib.gui.elem.ToolTip 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 3 with ToolTip

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

the class GuiBuildCraft method drawToolTips.

private void drawToolTips(Collection<?> objects, int mouseX, int mouseY, int offsetX, int offsetY) {
    for (Object obj : objects) {
        if (!(obj instanceof IToolTipProvider)) {
            continue;
        }
        IToolTipProvider provider = (IToolTipProvider) obj;
        if (!provider.isToolTipVisible()) {
            continue;
        }
        ToolTip tips = provider.getToolTip();
        if (tips == null) {
            continue;
        }
        boolean mouseOver = provider.isMouseOver(mouseX, mouseY);
        tips.onTick(mouseOver);
        if (mouseOver && tips.isReady()) {
            tips.refresh();
            drawToolTips(tips, mouseX + offsetX, mouseY + offsetY);
        }
    }
}
Also used : ToolTip(buildcraft.lib.gui.elem.ToolTip) IToolTipProvider(buildcraft.core.lib.gui.tooltips.IToolTipProvider)

Example 4 with ToolTip

use of buildcraft.lib.gui.elem.ToolTip 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)

Example 5 with ToolTip

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

the class GuiUtil method createToolTip.

public static ToolTip createToolTip(Supplier<ItemStack> stackRef) {
    return new ToolTip() {

        @Override
        public void refresh() {
            delegate().clear();
            ItemStack stack = stackRef.get();
            if (!stack.isEmpty()) {
                delegate().addAll(GuiUtil.getFormattedTooltip(stack));
            }
        }
    };
}
Also used : ToolTip(buildcraft.lib.gui.elem.ToolTip) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ToolTip (buildcraft.lib.gui.elem.ToolTip)6 ToolTipLine (buildcraft.core.lib.gui.tooltips.ToolTipLine)2 GuiElementToolTip (buildcraft.lib.gui.GuiElementToolTip)2 ITooltipElement (buildcraft.lib.gui.ITooltipElement)2 GuiBetterButton (buildcraft.lib.gui.button.GuiBetterButton)2 IGuiArea (buildcraft.lib.gui.pos.IGuiArea)2 GuiTextField (net.minecraft.client.gui.GuiTextField)2 ISprite (buildcraft.api.core.render.ISprite)1 BCCoreSprites (buildcraft.core.BCCoreSprites)1 IToolTipProvider (buildcraft.core.lib.gui.tooltips.IToolTipProvider)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