Search in sources :

Example 16 with Widget

use of gregtech.api.gui.Widget in project GregTech by GregTechCE.

the class PipeGridElementWidget method determineConnections.

private int determineConnections() {
    ComponentGridWidget gridWidget = parentWidget;
    if (gridWidget == null) {
        return 0;
    }
    Position self = gridWidget.getWidgetOrigin(this);
    int resultConnections = 0;
    for (ElementOrientation orientation : ElementOrientation.values()) {
        Position position = new Position(self.x + orientation.offsetX, self.y + orientation.offsetY);
        Widget widget = gridWidget.getWidgetAt(position.x, position.y);
        Position origin = gridWidget.getWidgetOrigin(widget);
        Position relativePos = position.subtract(origin);
        if (widget instanceof GridElementWidget && ((GridElementWidget) widget).canConnect(orientation.getOpposite(), relativePos, connectionType)) {
            resultConnections |= 1 << orientation.ordinal();
        }
    }
    return resultConnections;
}
Also used : Position(gregtech.api.util.Position) Widget(gregtech.api.gui.Widget)

Example 17 with Widget

use of gregtech.api.gui.Widget in project GregTech by GregTechCE.

the class ScrollableListWidget method updateElementPositions.

private void updateElementPositions() {
    Position position = getPosition();
    int currentPosY = position.y - scrollOffset;
    int totalListHeight = 0;
    for (Widget widget : widgets) {
        Position childPosition = new Position(position.x, currentPosY);
        widget.setParentPosition(childPosition);
        currentPosY += widget.getSize().getHeight();
        totalListHeight += widget.getSize().getHeight();
        final Size size = getSize();
        widget.applyScissor(position.x, position.y, size.width - scrollPaneWidth, size.height);
    }
    this.totalListHeight = totalListHeight;
    this.slotHeight = widgets.isEmpty() ? 0 : totalListHeight / widgets.size();
}
Also used : Position(gregtech.api.util.Position) Size(gregtech.api.util.Size) Widget(gregtech.api.gui.Widget)

Example 18 with Widget

use of gregtech.api.gui.Widget in project GregTech by GregTechCE.

the class SimpleFluidFilter method initUI.

@Override
public void initUI(Consumer<Widget> widgetGroup) {
    for (int i = 0; i < 9; ++i) {
        int index = i;
        widgetGroup.accept((new PhantomFluidWidget(10 + 18 * (i % 3), 18 * (i / 3), 18, 18, () -> getFluidInSlot(index), (newFluid) -> setFluidInSlot(index, newFluid))).setBackgroundTexture(GuiTextures.SLOT));
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Consumer(java.util.function.Consumer) NBTTagList(net.minecraft.nbt.NBTTagList) Widget(gregtech.api.gui.Widget) NBTBase(net.minecraft.nbt.NBTBase) PhantomFluidWidget(gregtech.api.gui.widgets.PhantomFluidWidget) FluidStack(net.minecraftforge.fluids.FluidStack) GuiTextures(gregtech.api.gui.GuiTextures) Nullable(javax.annotation.Nullable) PhantomFluidWidget(gregtech.api.gui.widgets.PhantomFluidWidget)

Example 19 with Widget

use of gregtech.api.gui.Widget in project GregTech by GregTechCE.

the class RecipeMapCategory method drawExtras.

@Override
public void drawExtras(Minecraft minecraft) {
    for (Widget widget : modularUI.guiWidgets.values()) {
        widget.drawInBackground(0, 0, new IRenderContext() {
        });
        widget.drawInForeground(0, 0);
    }
}
Also used : IRenderContext(gregtech.api.gui.IRenderContext) Widget(gregtech.api.gui.Widget) TankWidget(gregtech.api.gui.widgets.TankWidget) SlotWidget(gregtech.api.gui.widgets.SlotWidget)

Example 20 with Widget

use of gregtech.api.gui.Widget in project GregTech by GregTechCE.

the class RecipeMapCategory method setRecipe.

@Override
public void setRecipe(IRecipeLayout recipeLayout, GTRecipeWrapper recipeWrapper, IIngredients ingredients) {
    IGuiItemStackGroup itemStackGroup = recipeLayout.getItemStacks();
    IGuiFluidStackGroup fluidStackGroup = recipeLayout.getFluidStacks();
    for (Widget uiWidget : modularUI.guiWidgets.values()) {
        if (uiWidget instanceof SlotWidget) {
            SlotWidget slotWidget = (SlotWidget) uiWidget;
            if (!(slotWidget.getHandle() instanceof SlotItemHandler)) {
                continue;
            }
            SlotItemHandler handle = (SlotItemHandler) slotWidget.getHandle();
            if (handle.getItemHandler() == importItems) {
                // this is input item stack slot widget, so add it to item group
                itemStackGroup.init(handle.getSlotIndex(), true, slotWidget.getPosition().x, slotWidget.getPosition().y);
            } else if (handle.getItemHandler() == exportItems) {
                // this is output item stack slot widget, so add it to item group
                itemStackGroup.init(importItems.getSlots() + handle.getSlotIndex(), false, slotWidget.getPosition().x, slotWidget.getPosition().y);
            }
        } else if (uiWidget instanceof TankWidget) {
            TankWidget tankWidget = (TankWidget) uiWidget;
            if (importFluids.getFluidTanks().contains(tankWidget.fluidTank)) {
                int importIndex = importFluids.getFluidTanks().indexOf(tankWidget.fluidTank);
                List<List<FluidStack>> inputsList = ingredients.getInputs(FluidStack.class);
                int fluidAmount = 0;
                if (inputsList.size() > importIndex && !inputsList.get(importIndex).isEmpty())
                    fluidAmount = inputsList.get(importIndex).get(0).amount;
                // this is input tank widget, so add it to fluid group
                fluidStackGroup.init(importIndex, true, tankWidget.getPosition().x + tankWidget.fluidRenderOffset, tankWidget.getPosition().y + tankWidget.fluidRenderOffset, tankWidget.getSize().width - (2 * tankWidget.fluidRenderOffset), tankWidget.getSize().height - (2 * tankWidget.fluidRenderOffset), fluidAmount, false, null);
            } else if (exportFluids.getFluidTanks().contains(tankWidget.fluidTank)) {
                int exportIndex = exportFluids.getFluidTanks().indexOf(tankWidget.fluidTank);
                List<List<FluidStack>> inputsList = ingredients.getOutputs(FluidStack.class);
                int fluidAmount = 0;
                if (inputsList.size() > exportIndex && !inputsList.get(exportIndex).isEmpty())
                    fluidAmount = inputsList.get(exportIndex).get(0).amount;
                // this is output tank widget, so add it to fluid group
                fluidStackGroup.init(importFluids.getFluidTanks().size() + exportIndex, false, tankWidget.getPosition().x + tankWidget.fluidRenderOffset, tankWidget.getPosition().y + tankWidget.fluidRenderOffset, tankWidget.getSize().width - (2 * tankWidget.fluidRenderOffset), tankWidget.getSize().height - (2 * tankWidget.fluidRenderOffset), fluidAmount, false, null);
            }
        }
    }
    itemStackGroup.addTooltipCallback(recipeWrapper::addTooltip);
    fluidStackGroup.addTooltipCallback(recipeWrapper::addTooltip);
    itemStackGroup.set(ingredients);
    fluidStackGroup.set(ingredients);
}
Also used : TankWidget(gregtech.api.gui.widgets.TankWidget) SlotWidget(gregtech.api.gui.widgets.SlotWidget) FluidStack(net.minecraftforge.fluids.FluidStack) IGuiFluidStackGroup(mezz.jei.api.gui.IGuiFluidStackGroup) IGuiItemStackGroup(mezz.jei.api.gui.IGuiItemStackGroup) Widget(gregtech.api.gui.Widget) TankWidget(gregtech.api.gui.widgets.TankWidget) SlotWidget(gregtech.api.gui.widgets.SlotWidget) FluidTankList(gregtech.api.capability.impl.FluidTankList) List(java.util.List) SlotItemHandler(net.minecraftforge.items.SlotItemHandler)

Aggregations

Widget (gregtech.api.gui.Widget)20 INativeWidget (gregtech.api.gui.INativeWidget)9 Position (gregtech.api.util.Position)4 Consumer (java.util.function.Consumer)3 ScrollableListWidget (gregtech.api.gui.widgets.ScrollableListWidget)2 SlotWidget (gregtech.api.gui.widgets.SlotWidget)2 TankWidget (gregtech.api.gui.widgets.TankWidget)2 PacketUIWidgetUpdate (gregtech.api.net.PacketUIWidgetUpdate)2 Size (gregtech.api.util.Size)2 ItemStack (net.minecraft.item.ItemStack)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 FluidTankList (gregtech.api.capability.impl.FluidTankList)1 GuiTextures (gregtech.api.gui.GuiTextures)1 IRenderContext (gregtech.api.gui.IRenderContext)1 ModularUI (gregtech.api.gui.ModularUI)1 IGhostIngredientTarget (gregtech.api.gui.igredient.IGhostIngredientTarget)1 IIngredientSlot (gregtech.api.gui.igredient.IIngredientSlot)1 IRecipeTransferHandlerWidget (gregtech.api.gui.igredient.IRecipeTransferHandlerWidget)1 LabelWidget (gregtech.api.gui.widgets.LabelWidget)1