Search in sources :

Example 16 with IProgWidget

use of me.desht.pneumaticcraft.common.progwidgets.IProgWidget in project pnc-repressurized by TeamPneumatic.

the class ClientEventHandler method handleProgrammableTooltip.

private void handleProgrammableTooltip(ItemTooltipEvent event) {
    IProgrammable programmable = (IProgrammable) event.getItemStack().getItem();
    if (programmable.canProgram(event.getItemStack()) && programmable.showProgramTooltip()) {
        boolean hasInvalidPrograms = false;
        List<String> addedEntries = new ArrayList<>();
        List<IProgWidget> widgets = TileEntityProgrammer.getProgWidgets(event.getItemStack());
        Map<String, Integer> widgetMap = getPuzzleSummary(widgets);
        for (Map.Entry<String, Integer> entry : widgetMap.entrySet()) {
            IProgWidget widget = ItemProgrammingPuzzle.getWidgetForName(entry.getKey());
            String prefix = "";
            GuiScreen curScreen = Minecraft.getMinecraft().currentScreen;
            if (curScreen instanceof IGuiDrone) {
                if (!((IGuiDrone) curScreen).getDrone().isProgramApplicable(widget)) {
                    prefix = TextFormatting.RED + "";
                    hasInvalidPrograms = true;
                }
            }
            addedEntries.add(prefix + "- " + entry.getValue() + "x " + I18n.format("programmingPuzzle." + entry.getKey() + ".name"));
        }
        if (hasInvalidPrograms) {
            event.getToolTip().add(TextFormatting.RED + I18n.format("gui.tooltip.programmable.invalidPieces"));
        }
        Collections.sort(addedEntries);
        event.getToolTip().addAll(addedEntries);
        if (PneumaticCraftRepressurized.proxy.isSneakingInGui() && !widgets.isEmpty()) {
            Map<Integer, Integer> widgetColorMap = TileEntityProgrammer.getPuzzleSummary(widgets);
            event.getToolTip().add(TextFormatting.WHITE + I18n.format("gui.tooltip.programmable.requiredPieces"));
            for (int color : widgetColorMap.keySet()) {
                ItemStack stack = ItemProgrammingPuzzle.getStackForColor(color);
                stack.setCount(widgetColorMap.get(color));
                event.getToolTip().add("- " + widgetColorMap.get(color) + " x " + stack.getDisplayName());
            }
        }
    }
}
Also used : IProgrammable(me.desht.pneumaticcraft.api.item.IProgrammable) IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) IGuiDrone(me.desht.pneumaticcraft.client.gui.IGuiDrone) GuiScreen(net.minecraft.client.gui.GuiScreen) ItemStack(net.minecraft.item.ItemStack)

Example 17 with IProgWidget

use of me.desht.pneumaticcraft.common.progwidgets.IProgWidget in project pnc-repressurized by TeamPneumatic.

the class DroneAIManager method setActiveWidget.

private void setActiveWidget(IProgWidget widget) {
    EntityAIBase targetAI = null;
    EntityAIBase ai = null;
    if (widget != null) {
        boolean first = widget instanceof ProgWidgetStart;
        targetAI = widget.getWidgetTargetAI(drone, widget);
        ai = widget.getWidgetAI(drone, widget);
        // Prevent endless loops
        Set<IProgWidget> visitedWidgets = new HashSet<IProgWidget>();
        while (!visitedWidgets.contains(widget) && targetAI == null && ai == null) {
            visitedWidgets.add(widget);
            IProgWidget oldWidget = widget;
            widget = widget.getOutputWidget(drone, progWidgets);
            if (widget == null) {
                if (first) {
                    return;
                } else {
                    if (stopWhenEndReached) {
                        setActiveWidget(null);
                    } else {
                        gotoFirstWidget();
                    }
                    return;
                }
            } else if (oldWidget.getOutputWidget() != widget) {
                if (addJumpBackWidget(oldWidget))
                    return;
            }
            targetAI = widget.getWidgetTargetAI(drone, widget);
            ai = widget.getWidgetAI(drone, widget);
        }
        drone.setActiveProgram(widget);
    } else {
        setLabel("Stopped");
    }
    curActiveWidget = widget;
    if (curWidgetAI != null)
        removeTask(curWidgetAI);
    if (curWidgetTargetAI != null)
        drone.getTargetAI().removeTask(curWidgetTargetAI);
    if (ai != null)
        addTask(2, ai);
    if (targetAI != null)
        drone.getTargetAI().addTask(2, targetAI);
    curWidgetAI = ai;
    curWidgetTargetAI = targetAI;
}
Also used : IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) EntityAIBase(net.minecraft.entity.ai.EntityAIBase) ProgWidgetStart(me.desht.pneumaticcraft.common.progwidgets.ProgWidgetStart)

Example 18 with IProgWidget

use of me.desht.pneumaticcraft.common.progwidgets.IProgWidget in project pnc-repressurized by TeamPneumatic.

the class GuiProgrammer method drawGuiContainerBackgroundLayer.

@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int x, int y) {
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    drawDefaultBackground();
    bindGuiTexture();
    int xStart = (width - xSize) / 2;
    int yStart = (height - ySize) / 2;
    drawModalRectWithCustomSizedTexture(xStart, yStart, 0, 0, xSize, ySize, xSize, ySize);
    programmerUnit.getScrollBar().setEnabled(showingWidgetProgress == 0);
    super.drawGuiContainerBackgroundLayer(partialTicks, x, y);
    if (showingWidgetProgress > 0)
        programmerUnit.getScrollBar().setCurrentState(programmerUnit.getLastZoom());
    programmerUnit.render(x, y, showFlow.checked, showInfo.checked && showingWidgetProgress == 0, draggingWidget == null);
    int origX = x;
    int origY = y;
    x -= programmerUnit.getTranslatedX();
    y -= programmerUnit.getTranslatedY();
    float scale = programmerUnit.getScale();
    x = (int) (x / scale);
    y = (int) (y / scale);
    if (showingWidgetProgress > 0) {
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        bindGuiTexture();
        int width = oldShowingWidgetProgress + (int) ((showingWidgetProgress - oldShowingWidgetProgress) * partialTicks);
        for (int i = 0; i < width; i++) {
            drawModalRectWithCustomSizedTexture(xStart + 320 - i, yStart + 36, 323, 36, 1, 136, xSize, ySize);
        }
        drawModalRectWithCustomSizedTexture(xStart + 319 - width, yStart + 36, 319, 36, 2, 136, xSize, ySize);
        if (showingAllWidgets && draggingWidget != null)
            toggleShowWidgets();
    }
    GlStateManager.enableTexture2D();
    GlStateManager.enableBlend();
    GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
    for (int i = 0; i < visibleSpawnWidgets.size(); i++) {
        IProgWidget widget = visibleSpawnWidgets.get(i);
        GlStateManager.pushMatrix();
        GlStateManager.translate(widget.getX() + guiLeft, widget.getY() + guiTop, 0);
        GlStateManager.scale(0.5, 0.5, 1);
        if (showingAllWidgets && filteredSpawnWidgets != null && !filteredSpawnWidgets.get(i)) {
            GlStateManager.color(1, 1, 1, 0.2f);
        } else {
            GlStateManager.color(1, 1, 1, 1);
        }
        widget.render();
        GlStateManager.popMatrix();
    }
    GlStateManager.disableBlend();
    GlStateManager.pushMatrix();
    GlStateManager.translate(programmerUnit.getTranslatedX(), programmerUnit.getTranslatedY(), 0);
    GlStateManager.scale(scale, scale, 1);
    if (draggingWidget != null) {
        GlStateManager.pushMatrix();
        GlStateManager.translate(draggingWidget.getX() + guiLeft, draggingWidget.getY() + guiTop, 0);
        GlStateManager.scale(0.5, 0.5, 1);
        draggingWidget.render();
        GlStateManager.popMatrix();
    }
    GlStateManager.popMatrix();
    boolean isLeftClicking = Mouse.isButtonDown(0);
    boolean isMiddleClicking = GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindPickBlock);
    if (draggingWidget != null) {
        setConnectingWidgetsToXY(draggingWidget, x - dragMouseStartX + dragWidgetStartX - guiLeft, y - dragMouseStartY + dragWidgetStartY - guiTop);
    }
    if (isLeftClicking && !wasClicking) {
        for (IProgWidget widget : visibleSpawnWidgets) {
            if (origX >= widget.getX() + guiLeft && origY >= widget.getY() + guiTop && origX <= widget.getX() + guiLeft + widget.getWidth() / 2 && origY <= widget.getY() + guiTop + widget.getHeight() / 2) {
                draggingWidget = widget.copy();
                te.progWidgets.add(draggingWidget);
                dragMouseStartX = x - (int) (guiLeft / scale);
                dragMouseStartY = y - (int) (guiTop / scale);
                dragWidgetStartX = (int) ((widget.getX() - programmerUnit.getTranslatedX()) / scale);
                dragWidgetStartY = (int) ((widget.getY() - programmerUnit.getTranslatedY()) / scale);
                break;
            }
        }
        // create area widgets straight from GPS Area Tools
        ItemStack heldItem = mc.player.inventory.getItemStack();
        ProgWidgetArea areaToolWidget = null;
        if (heldItem.hasCapability(CapabilityGPSAreaTool.INSTANCE, null)) {
            CapabilityGPSAreaTool cap = heldItem.getCapability(CapabilityGPSAreaTool.INSTANCE, null);
            areaToolWidget = cap.createWidget();
        }
        if (draggingWidget == null && showingWidgetProgress == 0) {
            IProgWidget widget = programmerUnit.getHoveredWidget(origX, origY);
            if (widget != null) {
                draggingWidget = widget;
                dragMouseStartX = x - guiLeft;
                dragMouseStartY = y - guiTop;
                dragWidgetStartX = widget.getX();
                dragWidgetStartY = widget.getY();
                if (areaToolWidget != null && widget instanceof ProgWidgetArea) {
                    NBTTagCompound tag = new NBTTagCompound();
                    areaToolWidget.writeToNBT(tag);
                    widget.readFromNBT(tag);
                } else if (heldItem.getItem() == Itemss.GPS_TOOL && widget instanceof ProgWidgetCoordinate) {
                    ((ProgWidgetCoordinate) widget).loadFromGPSTool(heldItem);
                }
            }
        }
        // Create a new widget from a GPS Area tool when nothing was selected
        if (draggingWidget == null) {
            if (areaToolWidget != null) {
                draggingWidget = areaToolWidget;
            } else if (heldItem.getItem() == Itemss.GPS_TOOL) {
                ProgWidgetCoordinate coordWidget = new ProgWidgetCoordinate();
                draggingWidget = coordWidget;
                coordWidget.loadFromGPSTool(heldItem);
            }
            if (draggingWidget != null) {
                draggingWidget.setX(Integer.MAX_VALUE);
                draggingWidget.setY(Integer.MAX_VALUE);
                te.progWidgets.add(draggingWidget);
                dragMouseStartX = draggingWidget.getWidth() / 3;
                dragMouseStartY = draggingWidget.getHeight() / 4;
                dragWidgetStartX = 0;
                dragWidgetStartY = 0;
            }
        }
    } else if (isMiddleClicking && !wasClicking && showingWidgetProgress == 0) {
        IProgWidget widget = programmerUnit.getHoveredWidget(origX, origY);
        if (widget != null) {
            draggingWidget = widget.copy();
            te.progWidgets.add(draggingWidget);
            dragMouseStartX = 0;
            dragMouseStartY = 0;
            dragWidgetStartX = widget.getX() - (x - guiLeft);
            dragWidgetStartY = widget.getY() - (y - guiTop);
            if (PneumaticCraftRepressurized.proxy.isSneakingInGui())
                copyAndConnectConnectingWidgets(widget, draggingWidget);
        }
    }
    if (!isLeftClicking && !isMiddleClicking && draggingWidget != null) {
        if (programmerUnit.isOutsideProgrammingArea(draggingWidget)) {
            deleteConnectingWidgets(draggingWidget);
        } else {
            handlePuzzleMargins();
            if (!isValidPlaced(draggingWidget)) {
                setConnectingWidgetsToXY(draggingWidget, dragWidgetStartX, dragWidgetStartY);
                if (programmerUnit.isOutsideProgrammingArea(draggingWidget))
                    deleteConnectingWidgets(draggingWidget);
            }
        }
        NetworkHandler.sendToServer(new PacketProgrammerUpdate(te));
        TileEntityProgrammer.updatePuzzleConnections(te.progWidgets);
        draggingWidget = null;
    }
    wasClicking = isLeftClicking || isMiddleClicking;
    lastMouseX = origX;
    lastMouseY = origY;
}
Also used : IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) CapabilityGPSAreaTool(me.desht.pneumaticcraft.common.capabilities.CapabilityGPSAreaTool) ProgWidgetArea(me.desht.pneumaticcraft.common.progwidgets.ProgWidgetArea) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PacketProgrammerUpdate(me.desht.pneumaticcraft.common.network.PacketProgrammerUpdate) ItemStack(net.minecraft.item.ItemStack) ProgWidgetCoordinate(me.desht.pneumaticcraft.common.progwidgets.ProgWidgetCoordinate) Point(java.awt.Point)

Example 19 with IProgWidget

use of me.desht.pneumaticcraft.common.progwidgets.IProgWidget in project pnc-repressurized by TeamPneumatic.

the class GuiProgrammer method isValidPlaced.

private boolean isValidPlaced(IProgWidget widget1) {
    Rectangle draggingRect = new Rectangle(widget1.getX(), widget1.getY(), widget1.getWidth() / 2, widget1.getHeight() / 2);
    for (IProgWidget widget : te.progWidgets) {
        if (widget != widget1) {
            if (draggingRect.intersects(widget.getX(), widget.getY(), widget.getWidth() / 2, widget.getHeight() / 2)) {
                return false;
            }
        }
    }
    IProgWidget[] parameters = widget1.getConnectedParameters();
    if (parameters != null) {
        for (IProgWidget widget : parameters) {
            if (widget != null && !isValidPlaced(widget))
                return false;
        }
    }
    IProgWidget outputWidget = widget1.getOutputWidget();
    return !(outputWidget != null && !isValidPlaced(outputWidget));
}
Also used : IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) Rectangle(java.awt.Rectangle)

Example 20 with IProgWidget

use of me.desht.pneumaticcraft.common.progwidgets.IProgWidget in project pnc-repressurized by TeamPneumatic.

the class GuiProgrammer method copyAndConnectConnectingWidgets.

private void copyAndConnectConnectingWidgets(IProgWidget original, IProgWidget copy) {
    IProgWidget[] connectingWidgets = original.getConnectedParameters();
    if (connectingWidgets != null) {
        for (int i = 0; i < connectingWidgets.length; i++) {
            if (connectingWidgets[i] != null) {
                IProgWidget c = connectingWidgets[i].copy();
                te.progWidgets.add(c);
                copy.setParameter(i, c);
                copyAndConnectConnectingWidgets(connectingWidgets[i], c);
            }
        }
    }
    IProgWidget outputWidget = original.getOutputWidget();
    if (outputWidget != null) {
        IProgWidget c = outputWidget.copy();
        te.progWidgets.add(c);
        copy.setOutputWidget(c);
        copyAndConnectConnectingWidgets(outputWidget, c);
    }
}
Also used : IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) Point(java.awt.Point)

Aggregations

IProgWidget (me.desht.pneumaticcraft.common.progwidgets.IProgWidget)33 Point (java.awt.Point)10 ItemStack (net.minecraft.item.ItemStack)7 ArrayList (java.util.ArrayList)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 PacketProgrammerUpdate (me.desht.pneumaticcraft.common.network.PacketProgrammerUpdate)4 ProgWidgetStart (me.desht.pneumaticcraft.common.progwidgets.ProgWidgetStart)4 GuiScreen (net.minecraft.client.gui.GuiScreen)3 BlockPos (net.minecraft.util.math.BlockPos)3 IProgrammable (me.desht.pneumaticcraft.api.item.IProgrammable)2 EntityDrone (me.desht.pneumaticcraft.common.entity.living.EntityDrone)2 PacketGuiButton (me.desht.pneumaticcraft.common.network.PacketGuiButton)2 PacketUpdateTextfield (me.desht.pneumaticcraft.common.network.PacketUpdateTextfield)2 IVariableWidget (me.desht.pneumaticcraft.common.progwidgets.IVariableWidget)2 ProgWidgetArea (me.desht.pneumaticcraft.common.progwidgets.ProgWidgetArea)2 ProgWidgetCoordinate (me.desht.pneumaticcraft.common.progwidgets.ProgWidgetCoordinate)2 ProgWidgetCoordinateOperator (me.desht.pneumaticcraft.common.progwidgets.ProgWidgetCoordinateOperator)2 Entity (net.minecraft.entity.Entity)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 Rectangle (java.awt.Rectangle)1