Search in sources :

Example 11 with IGuiArea

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

the class GuiList method initGui.

@Override
public void initGui() {
    super.initGui();
    for (int line = 0; line < container.slots.length; line++) {
        WidgetListSlot[] arr = container.slots[line];
        for (int slot = 0; slot < arr.length; slot++) {
            final WidgetListSlot listSlot = arr[slot];
            GuiRectangle rectangle = new GuiRectangle(8 + slot * 18, 32 + line * 34, 16, 16);
            IGuiArea phantomSlotArea = rectangle.offset(mainGui.rootElement);
            mainGui.shownElements.add(listSlot.new GuiElementPhantomSlot(mainGui, phantomSlotArea) {

                @Override
                protected boolean shouldDrawHighlight() {
                    if (listSlot.slotIndex == 0) {
                        return true;
                    }
                    return !GuiList.this.container.lines[listSlot.lineIndex].isOneStackMode();
                }

                @Override
                public void drawBackground(float partialTicks) {
                    if (!shouldDrawHighlight()) {
                        ICON_HIGHLIGHT.drawAt(this);
                    }
                }

                @Nonnull
                @Override
                public ItemStack getStack() {
                    if (shouldDrawHighlight()) {
                        return super.getStack();
                    } else {
                        NonNullList<ItemStack> data = GuiList.this.getExamplesList(listSlot.lineIndex, container.lines[listSlot.lineIndex].getSortingType());
                        if (data.size() >= listSlot.slotIndex) {
                            return data.get(listSlot.slotIndex - 1);
                        } else {
                            return StackUtil.EMPTY;
                        }
                    }
                }

                @Override
                public void onMouseClicked(int button) {
                    super.onMouseClicked(button);
                    if (contains(gui.mouse)) {
                        clearExamplesCache(listSlot.lineIndex);
                    }
                }
            });
        }
    }
    buttonList.clear();
    for (int sy = 0; sy < ListHandler.HEIGHT; sy++) {
        int bOff = sy * BUTTON_COUNT;
        int bOffX = this.guiLeft + 8 + ListHandler.WIDTH * 18 - BUTTON_COUNT * 11;
        int bOffY = this.guiTop + 32 + sy * 34 + 18;
        GuiImageButton buttonPrecise = new GuiImageButton(mainGui, bOff + 0, bOffX, bOffY, 11, TEXTURE_BASE, 176, 16, 176, 28);
        buttonPrecise.setToolTip(ToolTip.createLocalized("gui.list.nbt"));
        buttonPrecise.setBehaviour(IButtonBehaviour.TOGGLE);
        mainGui.shownElements.add(buttonPrecise);
        GuiImageButton buttonType = new GuiImageButton(mainGui, bOff + 1, bOffX + 11, bOffY, 11, TEXTURE_BASE, 176, 16, 185, 28);
        buttonType.setToolTip(ToolTip.createLocalized("gui.list.metadata"));
        buttonType.setBehaviour(IButtonBehaviour.TOGGLE);
        mainGui.shownElements.add(buttonType);
        GuiImageButton buttonMaterial = new GuiImageButton(mainGui, bOff + 2, bOffX + 22, bOffY, 11, TEXTURE_BASE, 176, 16, 194, 28);
        buttonMaterial.setToolTip(ToolTip.createLocalized("gui.list.oredict"));
        buttonMaterial.setBehaviour(IButtonBehaviour.TOGGLE);
        mainGui.shownElements.add(buttonMaterial);
    }
    for (IGuiElement elem : mainGui.shownElements) {
        if (elem instanceof GuiImageButton) {
            GuiImageButton b = (GuiImageButton) elem;
            int id = Integer.parseInt(b.id);
            int lineId = id / BUTTON_COUNT;
            int buttonId = id % BUTTON_COUNT;
            if (container.lines[lineId].getOption(buttonId)) {
                b.activate();
            }
            b.registerListener(this);
        }
    }
    textField = new GuiTextField(6, this.fontRenderer, guiLeft + 10, guiTop + 10, 156, 12);
    textField.setMaxStringLength(32);
    textField.setText(BCCoreItems.list.getName(container.getListItemStack()));
    textField.setFocused(false);
}
Also used : IGuiArea(buildcraft.lib.gui.pos.IGuiArea) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) Nonnull(javax.annotation.Nonnull) GuiTextField(net.minecraft.client.gui.GuiTextField) WidgetListSlot(buildcraft.core.list.ContainerList.WidgetListSlot) GuiImageButton(buildcraft.lib.gui.button.GuiImageButton) NonNullList(net.minecraft.util.NonNullList) IGuiElement(buildcraft.lib.gui.IGuiElement) ItemStack(net.minecraft.item.ItemStack)

Example 12 with IGuiArea

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

the class ElementTypeDrawnStack method deserialize0.

@Override
protected IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
    FunctionContext ctx = createContext(json);
    IGuiPosition pos = resolvePosition(json, "pos", parent, ctx);
    INodeBoolean visible = getEquationBool(json, "visible", ctx, true);
    boolean foreground = resolveEquationBool(json, "foreground", ctx, false);
    Item item = JsonUtils.getItem(json.json, "id");
    int meta = resolveEquationInt(json, "meta", ctx);
    ItemStack stack = new ItemStack(item, 1, meta);
    ISimpleDrawable icon = new GuiStack(stack);
    IGuiArea area = IGuiArea.create(pos, 16, 16);
    return new GuiElementDrawable(gui, area, icon, foreground, visible);
}
Also used : Item(net.minecraft.item.Item) IGuiArea(buildcraft.lib.gui.pos.IGuiArea) ISimpleDrawable(buildcraft.lib.gui.ISimpleDrawable) GuiElementDrawable(buildcraft.lib.gui.elem.GuiElementDrawable) INodeBoolean(buildcraft.lib.expression.api.IExpressionNode.INodeBoolean) ItemStack(net.minecraft.item.ItemStack) GuiStack(buildcraft.lib.gui.GuiStack) FunctionContext(buildcraft.lib.expression.FunctionContext) IGuiPosition(buildcraft.lib.gui.pos.IGuiPosition)

Example 13 with IGuiArea

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

the class ElementTypeSprite method deserialize0.

@Override
public IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
    FunctionContext ctx = createContext(json);
    inheritProperty(json, "pos[0]", "area[0]");
    inheritProperty(json, "pos[1]", "area[1]");
    inheritProperty(json, "size[0]", "area[2]");
    inheritProperty(json, "size[1]", "area[3]");
    inheritProperty(json, "source.pos[0]", "source.area[0]");
    inheritProperty(json, "source.pos[1]", "source.area[1]");
    inheritProperty(json, "source.size[0]", "source.area[2]");
    inheritProperty(json, "source.size[1]", "source.area[3]");
    inheritProperty(json, "area", "source.area");
    inheritProperty(json, "area[0]", "source.area[0]");
    inheritProperty(json, "area[1]", "source.area[1]");
    inheritProperty(json, "area[2]", "source.area[2]");
    inheritProperty(json, "area[3]", "source.area[3]");
    IGuiArea area = resolveArea(json, "area", parent, ctx);
    IGuiArea srcArea = resolveArea(json, "source.area", PositionAbsolute.ORIGIN, ctx);
    INodeBoolean visible = getEquationBool(json, "visible", ctx, true);
    boolean foreground = resolveEquationBool(json, "foreground", ctx, false);
    // TODO: Allow the source sprite to be changing as well!
    SrcTexture tex = resolveTexture(info, json, "source");
    String origin = tex.origin;
    int texSize = tex.texSize;
    if (// 
    !json.properties.containsKey("source.area[2]") && // 
    !json.properties.containsKey("source.area[3]") && !json.properties.containsKey("source.area")) {
        srcArea = new GuiRectangle(texSize, texSize);
    }
    ISprite sprite = gui.properties.get(origin, ISprite.class);
    if (sprite == null) {
        ResourceLocation loc = SpriteUtil.transformLocation(new ResourceLocation(origin));
        sprite = new SpriteRaw(loc, 0, 0, 1, 1);
    }
    if (srcArea instanceof GuiRectangle) {
        double u = srcArea.getX();
        double v = srcArea.getY();
        double uSize = srcArea.getWidth();
        double vSize = srcArea.getHeight();
        sprite = GuiUtil.subRelative(sprite, u, v, uSize, vSize, texSize);
    } else {
        final IGuiArea a = srcArea;
        INodeDouble u = () -> a.getX() / texSize;
        INodeDouble v = () -> a.getY() / texSize;
        INodeDouble uSize = () -> a.getEndX() / texSize;
        INodeDouble vSize = () -> a.getEndY() / texSize;
        sprite = new SubSpriteChanging(sprite, u, v, uSize, vSize);
    }
    ISimpleDrawable icon = new GuiSpriteScaled(sprite, area.offsetToOrigin());
    GuiElementDrawable element = new GuiElementDrawable(gui, area, icon, foreground, visible);
    return element;
}
Also used : IGuiArea(buildcraft.lib.gui.pos.IGuiArea) ISimpleDrawable(buildcraft.lib.gui.ISimpleDrawable) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) ISprite(buildcraft.api.core.render.ISprite) GuiElementDrawable(buildcraft.lib.gui.elem.GuiElementDrawable) INodeBoolean(buildcraft.lib.expression.api.IExpressionNode.INodeBoolean) FunctionContext(buildcraft.lib.expression.FunctionContext) SubSpriteChanging(buildcraft.lib.client.sprite.SubSpriteChanging) INodeDouble(buildcraft.lib.expression.api.IExpressionNode.INodeDouble) ResourceLocation(net.minecraft.util.ResourceLocation) GuiSpriteScaled(buildcraft.lib.gui.GuiSpriteScaled) SpriteRaw(buildcraft.lib.client.sprite.SpriteRaw)

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