Search in sources :

Example 1 with IGuiPosition

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

the class ElementTypeSlot method deserialize0.

// pos: the position of the slot
// slot: The slot to be moved
// index: If the slot was an InventorySlotHolder then this is the index of the slot in the list
// visible: If false then the slot won't be visible
@Override
protected IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
    FunctionContext ctx = createContext(json);
    String slotName = json.properties.get("slot");
    IGuiPosition pos = resolvePosition(json, "pos", parent, ctx);
    Slot slot = gui.properties.get(slotName, Slot.class);
    INodeBoolean visible = getEquationBool(json, "visible", ctx, true);
    if (slot != null) {
        return new GuiElementSlotMover(gui, pos, visible, slot);
    }
    InventorySlotHolder holder = gui.properties.get(slotName, InventorySlotHolder.class);
    if (holder == null) {
        throw new JsonSyntaxException("Unknown slot '" + slotName + "'");
    }
    int index = resolveEquationInt(json, "index", ctx);
    if (index < 0 || index >= holder.slots.length) {
        throw new JsonSyntaxException("Invalid slot index! (" + index + ", min = 0, max = " + (holder.slots.length - 1) + ")");
    }
    return new GuiElementSlotMover(gui, pos, visible, holder.slots[index]);
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) Slot(net.minecraft.inventory.Slot) INodeBoolean(buildcraft.lib.expression.api.IExpressionNode.INodeBoolean) FunctionContext(buildcraft.lib.expression.FunctionContext) IGuiPosition(buildcraft.lib.gui.pos.IGuiPosition) GuiElementSlotMover(buildcraft.lib.gui.elem.GuiElementSlotMover)

Example 2 with IGuiPosition

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

the class ElementType method resolvePosition.

public static IGuiPosition resolvePosition(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);
        return IGuiPosition.create(x, y).offset(parent);
    }
    try {
        return GenericExpressionCompiler.compileExpressionObject(IGuiPosition.class, eqn, ctx).evaluate();
    } catch (InvalidExpressionException e) {
        throw new JsonSyntaxException("Failed to resolve a position for " + json.fullName, e);
    }
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) InvalidExpressionException(buildcraft.lib.expression.api.InvalidExpressionException) INodeDouble(buildcraft.lib.expression.api.IExpressionNode.INodeDouble) IGuiPosition(buildcraft.lib.gui.pos.IGuiPosition)

Example 3 with IGuiPosition

use of buildcraft.lib.gui.pos.IGuiPosition 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 4 with IGuiPosition

use of buildcraft.lib.gui.pos.IGuiPosition 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 5 with IGuiPosition

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

the class Ledger_Neptune method drawBackground.

@Override
public void drawBackground(float partialTicks) {
    double startX = getX();
    double startY = getY();
    final SpriteNineSliced split;
    interpWidth = interp(lastWidth, currentWidth, partialTicks);
    interpHeight = interp(lastHeight, currentHeight, partialTicks);
    if (expandPositive) {
        split = SPRITE_SPLIT_POS;
    } else {
        split = SPRITE_SPLIT_NEG;
    }
    RenderUtil.setGLColorFromIntPlusAlpha(colour);
    split.draw(startX, startY, interpWidth, interpHeight);
    GlStateManager.color(1, 1, 1, 1);
    IGuiPosition pos2;
    if (expandPositive) {
        pos2 = positionLedgerIconStart;
    } else {
        pos2 = positionLedgerIconStart;
    }
    try (AutoGlScissor a = GuiUtil.scissor(pos2.getX(), pos2.getY(), interpWidth - 4, interpHeight - 8)) {
        for (IGuiElement element : closedElements) {
            element.drawBackground(partialTicks);
        }
        if (shouldDrawOpen()) {
            for (IGuiElement element : openElements) {
                element.drawBackground(partialTicks);
            }
        }
    }
}
Also used : AutoGlScissor(buildcraft.lib.misc.GuiUtil.AutoGlScissor) IGuiElement(buildcraft.lib.gui.IGuiElement) SpriteNineSliced(buildcraft.lib.client.sprite.SpriteNineSliced) IGuiPosition(buildcraft.lib.gui.pos.IGuiPosition)

Aggregations

IGuiPosition (buildcraft.lib.gui.pos.IGuiPosition)9 FunctionContext (buildcraft.lib.expression.FunctionContext)4 IGuiArea (buildcraft.lib.gui.pos.IGuiArea)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)3 INodeBoolean (buildcraft.lib.expression.api.IExpressionNode.INodeBoolean)2 InvalidExpressionException (buildcraft.lib.expression.api.InvalidExpressionException)2 ISimpleDrawable (buildcraft.lib.gui.ISimpleDrawable)2 GuiElementDrawable (buildcraft.lib.gui.elem.GuiElementDrawable)2 GuiElementText (buildcraft.lib.gui.elem.GuiElementText)2 DoubleSupplier (java.util.function.DoubleSupplier)2 ISprite (buildcraft.api.core.render.ISprite)1 BCCoreSprites (buildcraft.core.BCCoreSprites)1 BCLibSprites (buildcraft.lib.BCLibSprites)1 SpriteNineSliced (buildcraft.lib.client.sprite.SpriteNineSliced)1 INodeDouble (buildcraft.lib.expression.api.IExpressionNode.INodeDouble)1 GuiBC8 (buildcraft.lib.gui.GuiBC8)1 GuiElementToolTip (buildcraft.lib.gui.GuiElementToolTip)1 GuiIcon (buildcraft.lib.gui.GuiIcon)1 GuiStack (buildcraft.lib.gui.GuiStack)1 IGuiElement (buildcraft.lib.gui.IGuiElement)1