Search in sources :

Example 21 with IProgWidget

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

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(me.desht.pneumaticcraft.common.progwidgets.IProgWidget)

Example 22 with IProgWidget

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

the class GuiProgrammer method updateConvertRelativeState.

private void updateConvertRelativeState() {
    convertToRelativeButton.enabled = false;
    List<String> tooltip = new ArrayList<>();
    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<>();
    for (String s : tooltip) {
        localizedTooltip.addAll(PneumaticCraftUtils.convertStringIntoList(I18n.format(s), 40));
    }
    convertToRelativeButton.setTooltipText(localizedTooltip);
}
Also used : IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) ProgWidgetCoordinateOperator(me.desht.pneumaticcraft.common.progwidgets.ProgWidgetCoordinateOperator) ArrayList(java.util.ArrayList) ProgWidgetStart(me.desht.pneumaticcraft.common.progwidgets.ProgWidgetStart)

Example 23 with IProgWidget

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

the class GuiProgrammer method keyTyped.

@Override
protected void keyTyped(char key, int keyCode) throws IOException {
    super.keyTyped(key, keyCode);
    if (nameField.isFocused() || filterField.isFocused() && keyCode != Keyboard.KEY_TAB) {
        return;
    }
    if (Keyboard.KEY_I == keyCode && Loader.isModLoaded(ModIds.IGWMOD)) {
        onIGWAction();
    }
    if (Keyboard.KEY_R == keyCode) {
        if (exportButton.getBounds().contains(lastMouseX, lastMouseY)) {
            NetworkHandler.sendToServer(new PacketGuiButton(0));
        }
    }
    if (Keyboard.KEY_SPACE == keyCode || Keyboard.KEY_TAB == keyCode) {
        toggleShowWidgets();
    }
    if (Keyboard.KEY_DELETE == keyCode) {
        IProgWidget widget = programmerUnit.getHoveredWidget(lastMouseX, lastMouseY);
        if (widget != null) {
            te.progWidgets.remove(widget);
            NetworkHandler.sendToServer(new PacketProgrammerUpdate(te));
        }
    }
    if (Keyboard.KEY_Z == keyCode) {
        NetworkHandler.sendToServer(new PacketGuiButton(undoButton.id));
    }
    if (Keyboard.KEY_Y == keyCode) {
        NetworkHandler.sendToServer(new PacketGuiButton(redoButton.id));
    }
}
Also used : IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) PacketGuiButton(me.desht.pneumaticcraft.common.network.PacketGuiButton) PacketProgrammerUpdate(me.desht.pneumaticcraft.common.network.PacketProgrammerUpdate)

Example 24 with IProgWidget

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

the class GuiProgrammer method updateScreen.

@Override
public void updateScreen() {
    super.updateScreen();
    undoButton.enabled = te.canUndo;
    redoButton.enabled = te.canRedo;
    updateConvertRelativeState();
    ItemStack programmedItem = te.getIteminProgrammingSlot();
    oldShowingWidgetProgress = showingWidgetProgress;
    if (showingAllWidgets) {
        int maxProgress = maxPage * WIDGET_X_SPACING;
        if (showingWidgetProgress < maxProgress) {
            showingWidgetProgress += 60;
            if (showingWidgetProgress >= maxProgress) {
                showingWidgetProgress = maxProgress;
                updateVisibleProgWidgets();
            }
        }
    } else {
        showingWidgetProgress -= 60;
        if (showingWidgetProgress < 0)
            showingWidgetProgress = 0;
    }
    List<String> errors = new ArrayList<>();
    List<String> warnings = new ArrayList<>();
    for (IProgWidget w : te.progWidgets) {
        w.addErrors(errors, te.progWidgets);
        w.addWarnings(warnings, te.progWidgets);
    }
    boolean isDeviceInserted = !programmedItem.isEmpty();
    importButton.enabled = isDeviceInserted;
    exportButton.enabled = isDeviceInserted && errors.size() == 0;
    List<String> exportButtonTooltip = new ArrayList<>();
    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.isEmpty()) {
        List<ItemStack> requiredPieces = te.getRequiredPuzzleStacks();
        List<ItemStack> returnedPieces = te.getReturnedPuzzleStacks();
        if (!requiredPieces.isEmpty() || !returnedPieces.isEmpty())
            exportButtonTooltip.add("");
        if (!requiredPieces.isEmpty()) {
            exportButtonTooltip.add(I18n.format("gui.tooltip.programmable.requiredPieces"));
            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 = TextFormatting.GREEN.toString();
                } else {
                    prefix = TextFormatting.RED.toString();
                    exportButton.enabled = player.capabilities.isCreativeMode && errors.size() == 0;
                }
                exportButtonTooltip.add(prefix + "-" + stack.getCount() + "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.getCount() + "x " + stack.getDisplayName());
            }
        }
    } else {
        exportButtonTooltip.add("No programmable item inserted.");
    }
    if (errors.size() > 0)
        exportButtonTooltip.add(TextFormatting.RED + I18n.format("gui.programmer.errorCount", errors.size()));
    if (warnings.size() > 0)
        exportButtonTooltip.add(TextFormatting.YELLOW + I18n.format("gui.programmer.warningCount", warnings.size()));
    exportButton.setTooltipText(exportButtonTooltip);
    if (!programmedItem.isEmpty()) {
        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(me.desht.pneumaticcraft.common.network.PacketUpdateTextfield) IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) Point(java.awt.Point)

Example 25 with IProgWidget

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

the class GuiProgrammer method mouseClicked.

@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
    ItemStack programmedItem = te.getIteminProgrammingSlot();
    if (nameField.isFocused() && !programmedItem.isEmpty()) {
        programmedItem.setStackDisplayName(nameField.getText());
        NetworkHandler.sendToServer(new PacketUpdateTextfield(te, 0));
    }
    super.mouseClicked(mouseX, mouseY, mouseButton);
    if (mouseButton == 1 && showingWidgetProgress == 0) {
        IProgWidget widget = programmerUnit.getHoveredWidget(mouseX, mouseY);
        if (widget != null) {
            GuiScreen screen = widget.getOptionWindow(this);
            if (screen != null)
                mc.displayGuiScreen(screen);
        }
    }
}
Also used : PacketUpdateTextfield(me.desht.pneumaticcraft.common.network.PacketUpdateTextfield) IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) GuiScreen(net.minecraft.client.gui.GuiScreen) ItemStack(net.minecraft.item.ItemStack)

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