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;
}
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);
}
}
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()));
}
Aggregations