Search in sources :

Example 11 with IGuiElement

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

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

the class BuildCraftJsonGui method load.

public final void load() {
    ResourceLoaderContext loadHistory = new ResourceLoaderContext();
    try (InputStreamReader reader = loadHistory.startLoading(jsonGuiDefinition)) {
        JsonObject obj = new Gson().fromJson(reader, JsonObject.class);
        JsonGuiInfo info = new JsonGuiInfo(obj, context, loadHistory);
        sizeX = (int) GenericExpressionCompiler.compileExpressionLong(info.sizeX, context).evaluate();
        sizeY = (int) GenericExpressionCompiler.compileExpressionLong(info.sizeY, context).evaluate();
        varData.setNodes(info.createTickableNodes());
        for (JsonGuiElement elem : info.elements) {
            String typeName = elem.properties.get("type");
            ElementType type = JsonGuiTypeRegistry.TYPES.get(typeName);
            if (type == null) {
                BCLog.logger.warn("Unknown type " + typeName);
            } else {
                IGuiElement e = type.deserialize(this, rootElement, info, elem);
                String parent = elem.properties.get("parent");
                IContainingElement p = properties.get("custom." + parent, IContainingElement.class);
                properties.put("custom." + elem.name, e);
                if (p == null) {
                    shownElements.add(e);
                } else {
                    p.getChildElements().add(e);
                    p.calculateSizes();
                }
            }
        }
    } catch (InvalidExpressionException iee) {
        throw new JsonSyntaxException("Failed to resolve the size of " + jsonGuiDefinition, iee);
    } catch (IOException e) {
        throw new Error(e);
    }
    loadHistory.finishLoading();
}
Also used : ResourceLoaderContext(buildcraft.lib.client.model.ResourceLoaderContext) InputStreamReader(java.io.InputStreamReader) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) IOException(java.io.IOException) IContainingElement(buildcraft.lib.gui.IContainingElement) JsonSyntaxException(com.google.gson.JsonSyntaxException) InvalidExpressionException(buildcraft.lib.expression.api.InvalidExpressionException) IGuiElement(buildcraft.lib.gui.IGuiElement)

Example 13 with IGuiElement

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

the class GuiElementStatementDrag method onMouseClicked.

// IInteractableElement
@Override
public void onMouseClicked(int button) {
    if (button != 1) {
        return;
    }
    for (IGuiElement element : gui.getElementsAt(gui.mouse.getX(), gui.mouse.getY())) {
        if (element instanceof IReference<?>) {
            IReference<?> ref = (IReference<?>) element;
            Object obj = ref.get();
            if (obj == null || obj instanceof IGuiSlot) {
                startDragging((IGuiSlot) obj);
                break;
            }
        }
    }
}
Also used : IGuiSlot(buildcraft.api.statements.IGuiSlot) IGuiElement(buildcraft.lib.gui.IGuiElement) IReference(buildcraft.lib.misc.data.IReference)

Example 14 with IGuiElement

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

the class GuiElementStatementDrag method onMouseReleased.

@Override
public void onMouseReleased(int button) {
    if (!isDragging) {
        return;
    }
    for (IGuiElement element : gui.getElementsAt(gui.mouse.getX(), gui.mouse.getY())) {
        if (element instanceof IReference<?>) {
            IReference<?> ref = (IReference<?>) element;
            ref.setIfCan(dragging);
        }
    }
    isDragging = false;
    dragging = null;
    if (gui.currentMenu == this) {
        gui.currentMenu = null;
    }
}
Also used : IGuiElement(buildcraft.lib.gui.IGuiElement) IReference(buildcraft.lib.misc.data.IReference)

Aggregations

IGuiElement (buildcraft.lib.gui.IGuiElement)14 IReference (buildcraft.lib.misc.data.IReference)3 ArrayList (java.util.ArrayList)3 ISprite (buildcraft.api.core.render.ISprite)2 SpriteNineSliced (buildcraft.lib.client.sprite.SpriteNineSliced)2 IContainingElement (buildcraft.lib.gui.IContainingElement)2 HelpPosition (buildcraft.lib.gui.help.ElementHelpInfo.HelpPosition)2 IGuiArea (buildcraft.lib.gui.pos.IGuiArea)2 AutoGlScissor (buildcraft.lib.misc.GuiUtil.AutoGlScissor)2 EnumPipePart (buildcraft.api.core.EnumPipePart)1 IGuiSlot (buildcraft.api.statements.IGuiSlot)1 IStatementParameter (buildcraft.api.statements.IStatementParameter)1 WidgetListSlot (buildcraft.core.list.ContainerList.WidgetListSlot)1 ResourceLoaderContext (buildcraft.lib.client.model.ResourceLoaderContext)1 InvalidExpressionException (buildcraft.lib.expression.api.InvalidExpressionException)1 GuiElementSimple (buildcraft.lib.gui.GuiElementSimple)1 GuiIcon (buildcraft.lib.gui.GuiIcon)1 IInteractionElement (buildcraft.lib.gui.IInteractionElement)1 GuiImageButton (buildcraft.lib.gui.button.GuiImageButton)1 GuiElementContainerHelp (buildcraft.lib.gui.elem.GuiElementContainerHelp)1