Search in sources :

Example 6 with IGuiArea

use of buildcraft.lib.gui.pos.IGuiArea in project BuildCraft by BuildCraft.

the class ElementType method resolveArea.

public static IGuiArea resolveArea(JsonGuiElement json, String name, IGuiPosition parent, FunctionContext ctx) {
    String eqn = json.properties.get(name);
    if (eqn == null) {
        INodeDouble x = getEquationDouble(json, name + "[0]", ctx);
        INodeDouble y = getEquationDouble(json, name + "[1]", ctx);
        INodeDouble w = getEquationDouble(json, name + "[2]", ctx);
        INodeDouble h = getEquationDouble(json, name + "[3]", ctx);
        return IGuiArea.create(x, y, w, h).offset(parent);
    }
    try {
        return GenericExpressionCompiler.compileExpressionObject(IGuiArea.class, eqn, ctx).evaluate();
    } catch (InvalidExpressionException e) {
        throw new JsonSyntaxException("Failed to resolve an area for " + json.fullName, e);
    }
}
Also used : IGuiArea(buildcraft.lib.gui.pos.IGuiArea) JsonSyntaxException(com.google.gson.JsonSyntaxException) InvalidExpressionException(buildcraft.lib.expression.api.InvalidExpressionException) INodeDouble(buildcraft.lib.expression.api.IExpressionNode.INodeDouble)

Example 7 with IGuiArea

use of buildcraft.lib.gui.pos.IGuiArea in project BuildCraft by BuildCraft.

the class ElementTypeContainer method deserialize0.

@Override
protected IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
    FunctionContext ctx = createContext(json);
    boolean scissor = resolveEquationBool(json, "limit", ctx, false);
    if (scissor) {
        IGuiArea area = resolveArea(json, "area", parent, ctx);
        return new GuiElementContainerScissor(gui, area);
    } else {
        IGuiPosition pos = resolvePosition(json, "pos", parent, ctx);
        return new GuiElementContainerResizing(gui, pos);
    }
}
Also used : IGuiArea(buildcraft.lib.gui.pos.IGuiArea) GuiElementContainerScissor(buildcraft.lib.gui.elem.GuiElementContainerScissor) GuiElementContainerResizing(buildcraft.lib.gui.elem.GuiElementContainerResizing) FunctionContext(buildcraft.lib.expression.FunctionContext) IGuiPosition(buildcraft.lib.gui.pos.IGuiPosition)

Example 8 with IGuiArea

use of buildcraft.lib.gui.pos.IGuiArea in project BuildCraft by BuildCraft.

the class GuiGuide method drawOpen.

private void drawOpen(float partialTicks) {
    // Draw the pages
    mc.renderEngine.bindTexture(LEFT_PAGE);
    PAGE_LEFT.drawAt(minX, minY);
    mc.renderEngine.bindTexture(RIGHT_PAGE);
    PAGE_RIGHT.drawAt(minX + PAGE_LEFT.width, minY);
    isOverHover = PEN_HIDDEN_AREA.offset(minX, minY).contains(mouse);
    // Now draw the actual contents of the book
    String title = currentPage.getTitle();
    if (title != null) {
        int x = /* this.minX + */
        (width - currentFont.getStringWidth(title)) / 2;
        currentFont.drawString(title, x, minY + 12, 0);
    }
    tooltipStack = null;
    tooltip.clear();
    setupFontRenderer();
    for (GuideChapter chapter : chapters) {
        chapter.reset();
    }
    currentPage.renderFirstPage(minX + (int) PAGE_LEFT_TEXT.x, minY + (int) PAGE_LEFT_TEXT.y, (int) PAGE_LEFT_TEXT.width, (int) PAGE_LEFT_TEXT.height);
    currentPage.renderSecondPage(minX + PAGE_LEFT.width + (int) PAGE_RIGHT_TEXT.x, minY + (int) PAGE_RIGHT_TEXT.y, (int) PAGE_RIGHT_TEXT.width, (int) PAGE_RIGHT_TEXT.height);
    int chapterIndex = 0;
    for (GuideChapter chapter : chapters) {
        chapter.draw(chapterIndex, partialTicks);
        chapterIndex++;
    }
    // Draw the back button if there are any pages on the stack
    if (!pages.isEmpty()) {
        GuiIcon icon = BACK;
        IGuiArea position = BACK_POSITION.offset(minX, minY);
        if (position.contains(mouse)) {
            icon = BACK_HOVERED;
        }
        icon.drawAt(position);
    }
    // Reset the colour for the pen
    GlStateManager.color(1, 1, 1);
    // Draw the pen
    if (isEditing) {
        mc.renderEngine.bindTexture(ICONS_2);
        if (isOverHover) {
            PEN_UP.drawAt(mouse.getX() - PEN_UP.width / 2, mouse.getY() - PEN_UP.height);
        } else {
            PEN_ANGLED.drawAt(mouse.getX() - 2, mouse.getY() - PEN_ANGLED.height - 2);
        }
    } else {
        int h = (int) (hoverStageLast * (1 - partialTicks) + hoverStageNext * partialTicks);
        // Draw pen
        mc.renderEngine.bindTexture(ICONS_2);
        drawTexturedModalRect(minX + PAGE_LEFT.width - PEN_HIDDEN_WIDTH / 2, minY - h, PEN_HIDDEN_X, PEN_HIDDEN_Y, PEN_HIDDEN_WIDTH, h);
        if (tooltipStack != null) {
            renderToolTip(tooltipStack, (int) mouse.getX(), (int) mouse.getY());
        } else if (!tooltip.isEmpty()) {
            drawHoveringText(tooltip, (int) mouse.getX(), (int) mouse.getY());
        }
    }
}
Also used : GuideChapter(buildcraft.lib.client.guide.parts.GuideChapter) IGuiArea(buildcraft.lib.gui.pos.IGuiArea) GuiIcon(buildcraft.lib.gui.GuiIcon)

Example 9 with IGuiArea

use of buildcraft.lib.gui.pos.IGuiArea in project BuildCraft by BuildCraft.

the class ElementTypeHelp 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]
// - colour: The colour for the help element (overlay)
// - title: The name of the help element
@Override
public IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
    FunctionContext ctx = createContext(json);
    String title = json.properties.get("title");
    List<String> text = new ArrayList<>();
    if (json.properties.containsKey("text[0]")) {
        int i = 0;
        while (true) {
            String prop = json.properties.get("text[" + i + "]");
            if (prop == null) {
                break;
            }
            text.add(prop);
            i++;
        }
    } else {
        text.add(json.properties.getOrDefault("text", "ERROR: Help not given!"));
    }
    int colour = resolveEquationInt(json, "colour", ctx);
    ElementHelpInfo help = new ElementHelpInfo(title, colour, text.toArray(new String[0]));
    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 DummyHelpElement(area, help);
}
Also used : IGuiArea(buildcraft.lib.gui.pos.IGuiArea) DummyHelpElement(buildcraft.lib.gui.help.DummyHelpElement) ArrayList(java.util.ArrayList) ElementHelpInfo(buildcraft.lib.gui.help.ElementHelpInfo) FunctionContext(buildcraft.lib.expression.FunctionContext)

Example 10 with IGuiArea

use of buildcraft.lib.gui.pos.IGuiArea 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

IGuiArea (buildcraft.lib.gui.pos.IGuiArea)13 FunctionContext (buildcraft.lib.expression.FunctionContext)7 GuiRectangle (buildcraft.lib.gui.pos.GuiRectangle)4 JsonSyntaxException (com.google.gson.JsonSyntaxException)4 INodeBoolean (buildcraft.lib.expression.api.IExpressionNode.INodeBoolean)3 ISimpleDrawable (buildcraft.lib.gui.ISimpleDrawable)3 GuiElementDrawable (buildcraft.lib.gui.elem.GuiElementDrawable)3 IGuiPosition (buildcraft.lib.gui.pos.IGuiPosition)3 ArrayList (java.util.ArrayList)3 ISprite (buildcraft.api.core.render.ISprite)2 INodeDouble (buildcraft.lib.expression.api.IExpressionNode.INodeDouble)2 InvalidExpressionException (buildcraft.lib.expression.api.InvalidExpressionException)2 GuiElementToolTip (buildcraft.lib.gui.GuiElementToolTip)2 GuiIcon (buildcraft.lib.gui.GuiIcon)2 IGuiElement (buildcraft.lib.gui.IGuiElement)2 ITooltipElement (buildcraft.lib.gui.ITooltipElement)2 ToolTip (buildcraft.lib.gui.elem.ToolTip)2 ItemStack (net.minecraft.item.ItemStack)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 IStatementContainer (buildcraft.api.statements.IStatementContainer)1