Search in sources :

Example 1 with WidgetListSlot

use of buildcraft.core.list.ContainerList.WidgetListSlot 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)

Aggregations

WidgetListSlot (buildcraft.core.list.ContainerList.WidgetListSlot)1 IGuiElement (buildcraft.lib.gui.IGuiElement)1 GuiImageButton (buildcraft.lib.gui.button.GuiImageButton)1 GuiRectangle (buildcraft.lib.gui.pos.GuiRectangle)1 IGuiArea (buildcraft.lib.gui.pos.IGuiArea)1 Nonnull (javax.annotation.Nonnull)1 GuiTextField (net.minecraft.client.gui.GuiTextField)1 ItemStack (net.minecraft.item.ItemStack)1 NonNullList (net.minecraft.util.NonNullList)1