Search in sources :

Example 11 with IProgWidget

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

the class GuiProgrammer method drawGuiContainerForegroundLayer.

@Override
protected void drawGuiContainerForegroundLayer(int x, int y) {
    super.drawGuiContainerForegroundLayer(x, y);
    boolean igwLoaded = Loader.isModLoaded(ModIds.IGWMOD);
    fontRenderer.drawString(widgetPage + 1 + "/" + (maxPage + 1), 305, 175, 0xFF000000);
    fontRenderer.drawString(I18n.format("gui.programmer.difficulty"), 263, 191, 0xFF000000);
    if (showingWidgetProgress == 0) {
        programmerUnit.renderForeground(x, y, draggingWidget);
    }
    for (int i = 0; i < visibleSpawnWidgets.size(); i++) {
        IProgWidget widget = visibleSpawnWidgets.get(i);
        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 && (!showingAllWidgets || filteredSpawnWidgets == null || filteredSpawnWidgets.get(i))) {
            List<String> tooltip = new ArrayList<>();
            widget.getTooltip(tooltip);
            if (igwLoaded)
                tooltip.add(I18n.format("gui.programmer.pressIForInfo"));
            if (tooltip.size() > 0)
                drawHoveringString(tooltip, x - guiLeft, y - guiTop, fontRenderer);
        }
    }
}
Also used : IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) ArrayList(java.util.ArrayList) Point(java.awt.Point)

Example 12 with IProgWidget

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

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) {
        WikiRegistry.getWikiHooks().showWikiGui("pneumaticcraft:progwidget/" + CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, 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) {
            WikiRegistry.getWikiHooks().showWikiGui("pneumaticcraft:progwidget/" + CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, widget.getWidgetString()));
        }
    }
}
Also used : IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) Point(java.awt.Point)

Example 13 with IProgWidget

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

the class GuiProgrammer method generateRelativeOperators.

/**
 * @param baseWidget
 * @param simulate
 * @return true if successful
 */
private boolean generateRelativeOperators(ProgWidgetCoordinateOperator baseWidget, List<String> tooltip, boolean simulate) {
    BlockPos baseCoord = ProgWidgetCoordinateOperator.calculateCoordinate(baseWidget, 0, baseWidget.getOperator());
    Map<BlockPos, String> offsetToVariableNames = new HashMap<>();
    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)) {
                BlockPos offset = new BlockPos(area.x1 - baseCoord.getX(), area.y1 - baseCoord.getY(), area.z1 - baseCoord.getZ());
                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)) {
                BlockPos offset = new BlockPos(area.x2 - baseCoord.getX(), area.y2 - baseCoord.getY(), area.z2 - baseCoord.getZ());
                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()) {
                BlockPos c = coordinate.getCoordinate();
                String chunkString = "(" + c.getX() + ", " + c.getY() + ", " + c.getZ() + ")";
                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) {
                        BlockPos offset = new BlockPos(c.getX() - baseCoord.getX(), c.getY() - baseCoord.getY(), c.getZ() - baseCoord.getZ());
                        String var = getOffsetVariable(offsetToVariableNames, baseWidget.getVariable(), offset);
                        coordinate.setVariable(var);
                        coordinate.setUsingVariable(true);
                    }
                }
            }
        }
    }
    if (offsetToVariableNames.size() > 0) {
        ProgWidgetCoordinateOperator firstOperator = null;
        ProgWidgetCoordinateOperator prevOperator = baseWidget;
        int x = baseWidget.getX();
        for (Map.Entry<BlockPos, 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(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) HashMap(java.util.HashMap) ProgWidgetArea(me.desht.pneumaticcraft.common.progwidgets.ProgWidgetArea) ProgWidgetCoordinateOperator(me.desht.pneumaticcraft.common.progwidgets.ProgWidgetCoordinateOperator) BlockPos(net.minecraft.util.math.BlockPos) PacketProgrammerUpdate(me.desht.pneumaticcraft.common.network.PacketProgrammerUpdate) ProgWidgetCoordinate(me.desht.pneumaticcraft.common.progwidgets.ProgWidgetCoordinate) Map(java.util.Map) HashMap(java.util.HashMap) Point(java.awt.Point)

Example 14 with IProgWidget

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

the class GuiProgrammer method updateVisibleProgWidgets.

private void updateVisibleProgWidgets() {
    int y = 0, page = 0;
    int x = WIDGET_TRAY_RIGHT - maxPage * WIDGET_X_SPACING;
    boolean showAllWidgets = showingWidgetProgress == WIDGET_X_SPACING * maxPage && showingAllWidgets;
    filterField.setVisible(showAllWidgets);
    maxPage = 0;
    visibleSpawnWidgets.clear();
    int difficulty = 0;
    for (int i = 0; i < difficultyButtons.size(); i++) {
        if (difficultyButtons.get(i).checked) {
            difficulty = i;
            break;
        }
    }
    for (IProgWidget widget : WidgetRegistrator.registeredWidgets) {
        if (difficulty >= widget.getDifficulty().ordinal()) {
            widget.setY(y + 40);
            widget.setX(showAllWidgets ? x : WIDGET_TRAY_RIGHT);
            int widgetHeight = widget.getHeight() / 2 + (widget.hasStepOutput() ? 5 : 0) + 1;
            y += widgetHeight;
            if (showAllWidgets || page == widgetPage) {
                visibleSpawnWidgets.add(widget);
            }
            if (y > ySize - 160) {
                y = 0;
                x += WIDGET_X_SPACING;
                page++;
                maxPage++;
            }
        }
    }
    filterField.x = guiLeft + WIDGET_TRAY_RIGHT - (maxPage * WIDGET_X_SPACING) - 2;
    filterSpawnWidgets();
    if (widgetPage > maxPage) {
        widgetPage = maxPage;
        updateVisibleProgWidgets();
    }
}
Also used : IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) Point(java.awt.Point)

Example 15 with IProgWidget

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

the class GuiProgrammer method filterSpawnWidgets.

private void filterSpawnWidgets() {
    String filterText = filterField.getText().trim();
    if (!visibleSpawnWidgets.isEmpty() && !filterText.isEmpty()) {
        filteredSpawnWidgets = new BitSet(visibleSpawnWidgets.size());
        for (int i = 0; i < visibleSpawnWidgets.size(); i++) {
            IProgWidget widget = visibleSpawnWidgets.get(i);
            String widgetName = I18n.format("programmingPuzzle." + widget.getWidgetString() + ".name");
            filteredSpawnWidgets.set(i, widgetName.toLowerCase().contains(filterText.toLowerCase()));
        }
    } else {
        filteredSpawnWidgets = null;
    }
}
Also used : IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) BitSet(java.util.BitSet) 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