Search in sources :

Example 21 with IProgWidget

use of pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.

the class GuiDroneDebuggerOptions method initGui.

@Override
public void initGui(IGuiScreen gui) {
    GuiScreen guiScreen = (GuiScreen) gui;
    screenWidth = guiScreen.width;
    screenHeight = guiScreen.height;
    if (PneumaticCraft.proxy.getPlayer() != null) {
        ItemStack helmet = PneumaticCraft.proxy.getPlayer().getCurrentArmor(3);
        if (helmet != null) {
            int entityId = NBTUtil.getInteger(helmet, NBTKeys.PNEUMATIC_HELMET_DEBUGGING_DRONE);
            Entity entity = PneumaticCraft.proxy.getClientWorld().getEntityByID(entityId);
            if (entity instanceof EntityDrone) {
                selectedDrone = (EntityDrone) entity;
            }
        }
    }
    int spacing = 20;
    programmingStartX = spacing;
    programmingWidth = guiScreen.width - spacing * 2;
    programmingHeight = guiScreen.height - spacing - PROGRAMMING_START_Y;
    programmerUnit = new DebugInfoProgrammerUnit(selectedDrone != null ? selectedDrone.getProgWidgets() : new ArrayList<IProgWidget>(), gui.getFontRenderer(), 0, 0, guiScreen.width, guiScreen.height, 100, programmingStartX, PROGRAMMING_START_Y, programmingWidth, programmingHeight, 0, 0, 0);
    if (selectedDrone != null) {
        for (IProgWidget widget : selectedDrone.getProgWidgets()) {
            if (widget instanceof ProgWidgetStart) {
                programmerUnit.gotoPiece(widget);
                break;
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) EntityDrone(pneumaticCraft.common.entity.living.EntityDrone) IGuiScreen(pneumaticCraft.api.client.pneumaticHelmet.IGuiScreen) GuiScreen(net.minecraft.client.gui.GuiScreen) ItemStack(net.minecraft.item.ItemStack) ProgWidgetStart(pneumaticCraft.common.progwidgets.ProgWidgetStart)

Example 22 with IProgWidget

use of pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.

the class GuiProgrammer method setConnectingWidgetsToXY.

private void setConnectingWidgetsToXY(IProgWidget widget, int x, int y) {
    widget.setX(x);
    widget.setY(y);
    IProgWidget[] connectingWidgets = widget.getConnectedParameters();
    if (connectingWidgets != null) {
        for (int i = 0; i < connectingWidgets.length; i++) {
            if (connectingWidgets[i] != null) {
                if (i < connectingWidgets.length / 2) {
                    setConnectingWidgetsToXY(connectingWidgets[i], x + widget.getWidth() / 2, y + i * 11);
                } else {
                    int totalWidth = 0;
                    IProgWidget branch = connectingWidgets[i];
                    while (branch != null) {
                        totalWidth += branch.getWidth() / 2;
                        branch = branch.getConnectedParameters()[0];
                    }
                    setConnectingWidgetsToXY(connectingWidgets[i], x - totalWidth, y + (i - connectingWidgets.length / 2) * 11);
                }
            }
        }
    }
    IProgWidget outputWidget = widget.getOutputWidget();
    if (outputWidget != null)
        setConnectingWidgetsToXY(outputWidget, x, y + widget.getHeight() / 2);
}
Also used : IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) Point(java.awt.Point)

Example 23 with IProgWidget

use of pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.

the class GuiProgrammer method actionPerformed.

/**
     * Fired when a control is clicked. This is the equivalent of
     * ActionListener.actionPerformed(ActionEvent e).
     */
@Override
protected void actionPerformed(GuiButton button) {
    switch(button.id) {
        case // redstone button
        0:
            //          redstoneBehaviourStat.closeWindow();
            break;
        case 3:
            if (--widgetPage < 0)
                widgetPage = maxPage;
            updateVisibleProgWidgets();
            return;
        case 4:
            if (++widgetPage > maxPage)
                widgetPage = 0;
            updateVisibleProgWidgets();
            return;
        case 5:
            for (IProgWidget widget : te.progWidgets) {
                if (widget instanceof ProgWidgetStart) {
                    programmerUnit.gotoPiece(widget);
                    break;
                }
            }
            return;
        case 6:
            if (te.progWidgets.size() > 0) {
                programmerUnit.gotoPiece(te.progWidgets.get(te.progWidgets.size() - 1));
            }
            return;
        case 7:
            NBTTagCompound mainTag = new NBTTagCompound();
            te.writeProgWidgetsToNBT(mainTag);
            FMLClientHandler.instance().showGuiScreen(pastebinGui = new GuiPastebin(this, mainTag));
            break;
        case 11:
            te.progWidgets.clear();
            NetworkHandler.sendToServer(new PacketProgrammerUpdate(te));
            break;
        case 12:
            for (IProgWidget widget : te.progWidgets) {
                if (widget instanceof ProgWidgetStart) {
                    generateRelativeOperators((ProgWidgetCoordinateOperator) widget.getOutputWidget(), null, false);
                    break;
                }
            }
            break;
    }
    NetworkHandler.sendToServer(new PacketGuiButton(button.id));
}
Also used : IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) PacketGuiButton(pneumaticCraft.common.network.PacketGuiButton) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PacketProgrammerUpdate(pneumaticCraft.common.network.PacketProgrammerUpdate) ProgWidgetStart(pneumaticCraft.common.progwidgets.ProgWidgetStart)

Example 24 with IProgWidget

use of pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.

the class GuiProgrammer method updateScreen.

@Override
public void updateScreen() {
    super.updateScreen();
    undoButton.enabled = te.canUndo;
    redoButton.enabled = te.canRedo;
    updateConvertRelativeState();
    ItemStack programmedItem = te.getStackInSlot(TileEntityProgrammer.PROGRAM_SLOT);
    oldShowingWidgetProgress = showingWidgetProgress;
    if (showingAllWidgets) {
        int maxProgress = maxPage * 22;
        if (showingWidgetProgress < maxProgress) {
            showingWidgetProgress += 30;
            if (showingWidgetProgress >= maxProgress) {
                showingWidgetProgress = maxProgress;
                updateVisibleProgWidgets();
            }
        }
    } else {
        showingWidgetProgress -= 30;
        if (showingWidgetProgress < 0)
            showingWidgetProgress = 0;
    }
    List<String> errors = new ArrayList<String>();
    List<String> warnings = new ArrayList<String>();
    for (IProgWidget w : te.progWidgets) {
        w.addErrors(errors, te.progWidgets);
        w.addWarnings(warnings, te.progWidgets);
    }
    boolean isDeviceInserted = programmedItem != null;
    importButton.enabled = isDeviceInserted;
    exportButton.enabled = isDeviceInserted && errors.size() == 0;
    List<String> exportButtonTooltip = new ArrayList<String>();
    exportButtonTooltip.add("Export program");
    exportButtonTooltip.add(I18n.format("gui.programmer.button.export.programmingWhen", I18n.format("gui.programmer.button.export." + (te.redstoneMode == 0 ? "pressingButton" : "onItemInsert"))));
    exportButtonTooltip.add(I18n.format("gui.programmer.button.export.pressRToChange"));
    if (programmedItem != null) {
        List<ItemStack> requiredPieces = te.getRequiredPuzzleStacks();
        List<ItemStack> returnedPieces = te.getReturnedPuzzleStacks();
        if (!requiredPieces.isEmpty() || !returnedPieces.isEmpty())
            exportButtonTooltip.add("");
        if (!requiredPieces.isEmpty()) {
            exportButtonTooltip.add("Required Programming Puzzles:");
            if (player.capabilities.isCreativeMode)
                exportButtonTooltip.add("(Creative mode, so the following is free)");
            for (ItemStack stack : requiredPieces) {
                String prefix;
                if (te.hasEnoughPuzzleStacks(player, stack)) {
                    prefix = EnumChatFormatting.GREEN.toString();
                } else {
                    prefix = EnumChatFormatting.RED.toString();
                    exportButton.enabled = player.capabilities.isCreativeMode && errors.size() == 0;
                }
                exportButtonTooltip.add(prefix + "-" + stack.stackSize + "x " + stack.getDisplayName());
            }
        }
        if (!returnedPieces.isEmpty()) {
            exportButtonTooltip.add("Returned Programming Puzzles:");
            if (player.capabilities.isCreativeMode)
                exportButtonTooltip.add("(Creative mode, nothing's given)");
            for (ItemStack stack : returnedPieces) {
                exportButtonTooltip.add("-" + stack.stackSize + "x " + stack.getDisplayName());
            }
        }
    } else {
        exportButtonTooltip.add("No programmable item inserted.");
    }
    if (errors.size() > 0)
        exportButtonTooltip.add(EnumChatFormatting.RED + I18n.format("gui.programmer.errorCount", errors.size()));
    if (warnings.size() > 0)
        exportButtonTooltip.add(EnumChatFormatting.YELLOW + I18n.format("gui.programmer.warningCount", warnings.size()));
    exportButton.setTooltipText(exportButtonTooltip);
    if (programmedItem != null) {
        nameField.setEnabled(true);
        if (!nameField.isFocused()) {
            if (wasFocused) {
                programmedItem.setStackDisplayName(nameField.getText());
                NetworkHandler.sendToServer(new PacketUpdateTextfield(te, 0));
            }
            nameField.setText(programmedItem.getDisplayName());
            wasFocused = false;
        } else {
            wasFocused = true;
        }
    } else {
        nameField.setEnabled(false);
        nameField.setText("");
        wasFocused = false;
    }
}
Also used : PacketUpdateTextfield(pneumaticCraft.common.network.PacketUpdateTextfield) IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) Point(java.awt.Point)

Example 25 with IProgWidget

use of pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.

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();
    if (outputWidget != null && !isValidPlaced(outputWidget))
        return false;
    return true;
}
Also used : IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) Rectangle(java.awt.Rectangle)

Aggregations

IProgWidget (pneumaticCraft.common.progwidgets.IProgWidget)36 Point (java.awt.Point)8 ProgWidgetStart (pneumaticCraft.common.progwidgets.ProgWidgetStart)8 ArrayList (java.util.ArrayList)6 ItemStack (net.minecraft.item.ItemStack)6 EntityDrone (pneumaticCraft.common.entity.living.EntityDrone)6 ProgWidgetArea (pneumaticCraft.common.progwidgets.ProgWidgetArea)5 PacketProgrammerUpdate (pneumaticCraft.common.network.PacketProgrammerUpdate)4 ProgWidgetGoToLocation (pneumaticCraft.common.progwidgets.ProgWidgetGoToLocation)4 ProgWidgetSuicide (pneumaticCraft.common.progwidgets.ProgWidgetSuicide)4 HashSet (java.util.HashSet)3 GuiScreen (net.minecraft.client.gui.GuiScreen)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 ChunkPosition (net.minecraft.world.ChunkPosition)3 Rectangle (java.awt.Rectangle)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Entity (net.minecraft.entity.Entity)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 IProgrammable (pneumaticCraft.api.item.IProgrammable)2