Search in sources :

Example 1 with IProgWidget

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

the class GuiProgrammer method onIGWAction.

@Optional.Method(modid = ModIds.IGWMOD)
private void onIGWAction() {
    int x = lastMouseX;
    int y = lastMouseY;
    IProgWidget hoveredWidget = programmerUnit.getHoveredWidget(x, y);
    if (hoveredWidget != null) {
        GuiWiki gui = new GuiWiki();
        FMLClientHandler.instance().showGuiScreen(gui);
        gui.setCurrentFile("pneumaticcraft:progwidget/" + hoveredWidget.getWidgetString());
    }
    for (IProgWidget widget : visibleSpawnWidgets) {
        if (widget != draggingWidget && x - guiLeft >= widget.getX() && y - guiTop >= widget.getY() && x - guiLeft <= widget.getX() + widget.getWidth() / 2 && y - guiTop <= widget.getY() + widget.getHeight() / 2) {
            GuiWiki gui = new GuiWiki();
            FMLClientHandler.instance().showGuiScreen(gui);
            gui.setCurrentFile("pneumaticcraft:progwidget/" + widget.getWidgetString());
        }
    }
}
Also used : IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) GuiWiki(igwmod.gui.GuiWiki) Point(java.awt.Point)

Example 2 with IProgWidget

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

the class GuiProgrammer method drawGuiContainerForegroundLayer.

@Override
protected void drawGuiContainerForegroundLayer(int x, int y) {
    super.drawGuiContainerForegroundLayer(x, y);
    boolean igwLoaded = Loader.isModLoaded(ModIds.IGWMOD);
    fontRendererObj.drawString(widgetPage + 1 + "/" + (maxPage + 1), 305, 175, 0xFF000000);
    fontRendererObj.drawString(I18n.format("gui.programmer.difficulty"), 263, 190, 0xFF000000);
    if (showingWidgetProgress == 0) {
        programmerUnit.renderForeground(x, y, draggingWidget);
    }
    for (IProgWidget widget : visibleSpawnWidgets) {
        if (widget != draggingWidget && x - guiLeft >= widget.getX() && y - guiTop >= widget.getY() && x - guiLeft <= widget.getX() + widget.getWidth() / 2 && y - guiTop <= widget.getY() + widget.getHeight() / 2) {
            List<String> tooltip = new ArrayList<String>();
            widget.getTooltip(tooltip);
            if (igwLoaded)
                tooltip.add(I18n.format("gui.programmer.pressIForInfo"));
            if (tooltip.size() > 0)
                drawHoveringString(tooltip, x - guiLeft, y - guiTop, fontRendererObj);
        }
    }
}
Also used : IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) ArrayList(java.util.ArrayList)

Example 3 with IProgWidget

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

the class GuiProgrammer method deleteConnectingWidgets.

private void deleteConnectingWidgets(IProgWidget widget) {
    te.progWidgets.remove(widget);
    IProgWidget[] connectingWidgets = widget.getConnectedParameters();
    if (connectingWidgets != null) {
        for (IProgWidget widg : connectingWidgets) {
            if (widg != null)
                deleteConnectingWidgets(widg);
        }
    }
    IProgWidget outputWidget = widget.getOutputWidget();
    if (outputWidget != null)
        deleteConnectingWidgets(outputWidget);
}
Also used : IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget)

Example 4 with IProgWidget

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

the class GuiProgrammer method updateConvertRelativeState.

private void updateConvertRelativeState() {
    convertToRelativeButton.enabled = false;
    List<String> tooltip = new ArrayList<String>();
    tooltip.add("gui.programmer.button.convertToRelative.desc");
    boolean startFound = false;
    for (IProgWidget startWidget : te.progWidgets) {
        if (startWidget instanceof ProgWidgetStart) {
            startFound = true;
            IProgWidget widget = startWidget.getOutputWidget();
            if (widget instanceof ProgWidgetCoordinateOperator) {
                ProgWidgetCoordinateOperator operatorWidget = (ProgWidgetCoordinateOperator) widget;
                if (!operatorWidget.getVariable().equals("")) {
                    try {
                        if (generateRelativeOperators(operatorWidget, tooltip, true)) {
                            convertToRelativeButton.enabled = true;
                        } else {
                            tooltip.add("gui.programmer.button.convertToRelative.notEnoughRoom");
                        }
                    } catch (NullPointerException e) {
                        tooltip.add("gui.programmer.button.convertToRelative.cantHaveVariables");
                    }
                } else {
                    tooltip.add("gui.programmer.button.convertToRelative.noVariableName");
                }
            } else {
                tooltip.add("gui.programmer.button.convertToRelative.noBaseCoordinate");
            }
        }
    }
    if (!startFound)
        tooltip.add("gui.programmer.button.convertToRelative.noStartPiece");
    List<String> localizedTooltip = new ArrayList<String>();
    for (String s : tooltip) {
        localizedTooltip.addAll(PneumaticCraftUtils.convertStringIntoList(I18n.format(s), 40));
    }
    convertToRelativeButton.setTooltipText(localizedTooltip);
}
Also used : IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) ProgWidgetCoordinateOperator(pneumaticCraft.common.progwidgets.ProgWidgetCoordinateOperator) ArrayList(java.util.ArrayList) ProgWidgetStart(pneumaticCraft.common.progwidgets.ProgWidgetStart)

Example 5 with IProgWidget

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

the class GuiProgrammer method generateRelativeOperators.

/**
     * 
     * @param baseWidget
     * @param simulate
     * @return true if successful
     */
private boolean generateRelativeOperators(ProgWidgetCoordinateOperator baseWidget, List<String> tooltip, boolean simulate) {
    ChunkPosition baseCoord = ProgWidgetCoordinateOperator.calculateCoordinate(baseWidget, 0, baseWidget.getOperator());
    Map<ChunkPosition, String> offsetToVariableNames = new HashMap<ChunkPosition, String>();
    for (IProgWidget widget : te.progWidgets) {
        if (widget instanceof ProgWidgetArea) {
            ProgWidgetArea area = (ProgWidgetArea) widget;
            if (area.getCoord1Variable().equals("") && (area.x1 != 0 || area.y1 != 0 || area.z1 != 0)) {
                ChunkPosition offset = new ChunkPosition(area.x1 - baseCoord.chunkPosX, area.y1 - baseCoord.chunkPosY, area.z1 - baseCoord.chunkPosZ);
                String var = getOffsetVariable(offsetToVariableNames, baseWidget.getVariable(), offset);
                if (!simulate)
                    area.setCoord1Variable(var);
            }
            if (area.getCoord2Variable().equals("") && (area.x2 != 0 || area.y2 != 0 || area.z2 != 0)) {
                ChunkPosition offset = new ChunkPosition(area.x2 - baseCoord.chunkPosX, area.y2 - baseCoord.chunkPosY, area.z2 - baseCoord.chunkPosZ);
                String var = getOffsetVariable(offsetToVariableNames, baseWidget.getVariable(), offset);
                if (!simulate)
                    area.setCoord2Variable(var);
            }
        } else if (widget instanceof ProgWidgetCoordinate && baseWidget.getConnectedParameters()[0] != widget) {
            ProgWidgetCoordinate coordinate = (ProgWidgetCoordinate) widget;
            if (!coordinate.isUsingVariable()) {
                ChunkPosition c = coordinate.getCoordinate();
                String chunkString = "(" + c.chunkPosX + ", " + c.chunkPosY + ", " + c.chunkPosZ + ")";
                if (PneumaticCraftUtils.distBetween(c, 0, 0, 0) < 64) {
                    //When the coordinate value is close to 0, there's a low chance it means a position, and rather an offset.
                    if (tooltip != null)
                        tooltip.add(I18n.format("gui.programmer.button.convertToRelative.coordIsNotChangedWarning", chunkString));
                } else {
                    if (tooltip != null)
                        tooltip.add(I18n.format("gui.programmer.button.convertToRelative.coordIsChangedWarning", chunkString));
                    if (!simulate) {
                        ChunkPosition offset = new ChunkPosition(c.chunkPosX - baseCoord.chunkPosX, c.chunkPosY - baseCoord.chunkPosY, c.chunkPosZ - baseCoord.chunkPosZ);
                        String var = getOffsetVariable(offsetToVariableNames, baseWidget.getVariable(), offset);
                        if (!simulate) {
                            coordinate.setVariable(var);
                            coordinate.setUsingVariable(true);
                        }
                    }
                }
            }
        }
    }
    if (offsetToVariableNames.size() > 0) {
        ProgWidgetCoordinateOperator firstOperator = null;
        ProgWidgetCoordinateOperator prevOperator = baseWidget;
        int x = baseWidget.getX();
        for (Map.Entry<ChunkPosition, String> entry : offsetToVariableNames.entrySet()) {
            ProgWidgetCoordinateOperator operator = new ProgWidgetCoordinateOperator();
            operator.setVariable(entry.getValue());
            int y = prevOperator.getY() + prevOperator.getHeight() / 2;
            operator.setX(x);
            operator.setY(y);
            if (!isValidPlaced(operator))
                return false;
            ProgWidgetCoordinate coordinatePiece1 = new ProgWidgetCoordinate();
            coordinatePiece1.setX(x + prevOperator.getWidth() / 2);
            coordinatePiece1.setY(y);
            coordinatePiece1.setVariable(baseWidget.getVariable());
            coordinatePiece1.setUsingVariable(true);
            if (!isValidPlaced(coordinatePiece1))
                return false;
            ProgWidgetCoordinate coordinatePiece2 = new ProgWidgetCoordinate();
            coordinatePiece2.setX(x + prevOperator.getWidth() / 2 + coordinatePiece1.getWidth() / 2);
            coordinatePiece2.setY(y);
            coordinatePiece2.setCoordinate(entry.getKey());
            if (!isValidPlaced(coordinatePiece2))
                return false;
            if (!simulate) {
                te.progWidgets.add(operator);
                te.progWidgets.add(coordinatePiece1);
                te.progWidgets.add(coordinatePiece2);
            }
            if (firstOperator == null)
                firstOperator = operator;
            prevOperator = operator;
        }
        if (!simulate) {
            NetworkHandler.sendToServer(new PacketProgrammerUpdate(te));
            TileEntityProgrammer.updatePuzzleConnections(te.progWidgets);
        }
        return true;
    } else {
        //When there's nothing to place there's always room.
        return true;
    }
}
Also used : IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) HashMap(java.util.HashMap) ChunkPosition(net.minecraft.world.ChunkPosition) ProgWidgetArea(pneumaticCraft.common.progwidgets.ProgWidgetArea) ProgWidgetCoordinateOperator(pneumaticCraft.common.progwidgets.ProgWidgetCoordinateOperator) PacketProgrammerUpdate(pneumaticCraft.common.network.PacketProgrammerUpdate) ProgWidgetCoordinate(pneumaticCraft.common.progwidgets.ProgWidgetCoordinate) Map(java.util.Map) HashMap(java.util.HashMap) Point(java.awt.Point)

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