Search in sources :

Example 6 with ProgramCardInstance

use of mcjty.rftoolscontrol.logic.grid.ProgramCardInstance in project RFToolsControl by McJty.

the class GuiProgrammer method handleClipboard.

private boolean handleClipboard(int keyCode) {
    if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL)) {
        if (keyCode == Keyboard.KEY_A) {
            selectAll();
        } else if (keyCode == Keyboard.KEY_C) {
            if (!checkSelection()) {
                GuiTools.showMessage(mc, this, getWindowManager(), 50, 50, TextFormatting.RED + "Nothing is selected!");
            } else {
                ProgramCardInstance instance = makeGridInstance(true);
                String json = instance.writeToJson();
                try {
                    StringSelection selection = new StringSelection(json);
                    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
                    clipboard.setContents(selection, selection);
                } catch (Exception e) {
                    GuiTools.showMessage(mc, this, getWindowManager(), 50, 50, TextFormatting.RED + "Error copying to clipboard!");
                }
            }
            return true;
        } else if (keyCode == Keyboard.KEY_Z) {
            if (undoProgram != null) {
                ProgramCardInstance curProgram = makeGridInstance(false);
                clearGrid(false);
                loadProgram(undoProgram);
                undoProgram = curProgram;
            }
            return true;
        } else if (keyCode == Keyboard.KEY_X) {
            if (!checkSelection()) {
                GuiTools.showMessage(mc, this, getWindowManager(), 50, 50, TextFormatting.RED + "Nothing is selected!");
            } else {
                ProgramCardInstance instance = makeGridInstance(true);
                String json = instance.writeToJson();
                try {
                    StringSelection selection = new StringSelection(json);
                    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
                    clipboard.setContents(selection, selection);
                    undoProgram = makeGridInstance(false);
                    clearGrid(checkSelection());
                } catch (Exception e) {
                    GuiTools.showMessage(mc, this, getWindowManager(), 50, 50, TextFormatting.RED + "Error copying to clipboard!");
                }
            }
            return true;
        } else if (keyCode == Keyboard.KEY_V) {
            try {
                Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
                String data = (String) clipboard.getData(DataFlavor.stringFlavor);
                ProgramCardInstance program = ProgramCardInstance.readFromJson(data);
                undoProgram = makeGridInstance(false);
                mergeProgram(program, getSelectedGridHolder());
            } catch (UnsupportedFlavorException e) {
                GuiTools.showMessage(mc, this, getWindowManager(), 50, 50, TextFormatting.RED + "Clipboard does not contain program!");
            } catch (Exception e) {
                GuiTools.showMessage(mc, this, getWindowManager(), 50, 50, TextFormatting.RED + "Error reading from clipboard!");
            }
        }
    }
    return false;
}
Also used : ProgramCardInstance(mcjty.rftoolscontrol.logic.grid.ProgramCardInstance) Clipboard(java.awt.datatransfer.Clipboard) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException) StringSelection(java.awt.datatransfer.StringSelection)

Example 7 with ProgramCardInstance

use of mcjty.rftoolscontrol.logic.grid.ProgramCardInstance in project RFToolsControl by McJty.

the class GuiProgrammer method validateAndHilight.

private void validateAndHilight() {
    ProgramCardInstance instance = makeGridInstance(false);
    for (int x = 0; x < GRID_WIDTH; x++) {
        for (int y = 0; y < GRID_HEIGHT; y++) {
            IconHolder h = getHolder(x, y);
            if (h.getIcon() != null) {
                h.getIcon().removeOverlay("E1");
                h.getIcon().removeOverlay("E2");
            }
        }
    }
    long time = System.currentTimeMillis();
    List<Pair<GridPos, String>> errors = ProgramValidator.validate(instance);
    for (Pair<GridPos, String> entry : errors) {
        GridPos p = entry.getKey();
        IconHolder h = getHolder(p.getX(), p.getY());
        h.getIcon().addOverlay((time % 2000) < 1000 ? errorIcon1 : errorIcon2);
    }
}
Also used : ProgramCardInstance(mcjty.rftoolscontrol.logic.grid.ProgramCardInstance) GridPos(mcjty.rftoolscontrol.logic.grid.GridPos) Pair(org.apache.commons.lang3.tuple.Pair)

Example 8 with ProgramCardInstance

use of mcjty.rftoolscontrol.logic.grid.ProgramCardInstance in project RFToolsControl by McJty.

the class GuiProgrammer method saveProgram.

private void saveProgram(int slot, String name) {
    ItemStack card = tileEntity.getStackInSlot(slot);
    if (card.isEmpty()) {
        return;
    }
    if (name != null) {
        ProgramCardItem.setCardName(card, name);
    }
    ProgramCardInstance instance = makeGridInstance(false);
    instance.writeToNBT(card);
    RFToolsCtrlMessages.INSTANCE.sendToServer(new PacketUpdateNBTItemInventoryProgrammer(tileEntity.getPos(), slot, card.getTagCompound()));
}
Also used : ProgramCardInstance(mcjty.rftoolscontrol.logic.grid.ProgramCardInstance) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ProgramCardInstance (mcjty.rftoolscontrol.logic.grid.ProgramCardInstance)8 GridPos (mcjty.rftoolscontrol.logic.grid.GridPos)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ItemStack (net.minecraft.item.ItemStack)2 ITextComponent (net.minecraft.util.text.ITextComponent)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 Pair (org.apache.commons.lang3.tuple.Pair)2 Clipboard (java.awt.datatransfer.Clipboard)1 StringSelection (java.awt.datatransfer.StringSelection)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 IOException (java.io.IOException)1 Window (mcjty.lib.gui.Window)1 SelectionEvent (mcjty.lib.gui.events.SelectionEvent)1 IIcon (mcjty.lib.gui.icons.IIcon)1 VerticalLayout (mcjty.lib.gui.layout.VerticalLayout)1 Button (mcjty.lib.gui.widgets.Button)1 Label (mcjty.lib.gui.widgets.Label)1 Panel (mcjty.lib.gui.widgets.Panel)1 Opcode (mcjty.rftoolscontrol.api.code.Opcode)1 Parameter (mcjty.rftoolscontrol.api.parameters.Parameter)1