use of pneumaticCraft.common.network.PacketProgrammerUpdate in project PneumaticCraft by MineMaarten.
the class GuiProgrammer method initGui.
@Override
public void initGui() {
if (pastebinGui != null && pastebinGui.outputTag != null) {
te.readProgWidgetsFromNBT(pastebinGui.outputTag);
pastebinGui = null;
NetworkHandler.sendToServer(new PacketProgrammerUpdate(te));
}
super.initGui();
if (programmerUnit != null) {
te.translatedX = programmerUnit.getTranslatedX();
te.translatedY = programmerUnit.getTranslatedY();
te.zoomState = programmerUnit.getLastZoom();
}
programmerUnit = new GuiUnitProgrammer(te.progWidgets, fontRendererObj, guiLeft, guiTop, xSize, width, height, PROGRAMMING_START_X, PROGRAMMING_START_Y, PROGRAMMING_WIDTH, PROGRAMMING_HEIGHT, te.translatedX, te.translatedY, te.zoomState);
addWidget(programmerUnit.getScrollBar());
int xStart = (width - xSize) / 2;
int yStart = (height - ySize) / 2;
// addProgWidgetTabs(xStart, yStart);
importButton = new GuiButtonSpecial(1, xStart + 301, yStart + 3, 20, 15, "<--");
importButton.setTooltipText("Import program");
buttonList.add(importButton);
exportButton = new GuiButtonSpecial(2, xStart + 301, yStart + 20, 20, 15, "-->");
buttonList.add(exportButton);
buttonList.add(new GuiButton(3, xStart + 294, yStart + 174, 10, 10, "-"));
buttonList.add(new GuiButton(4, xStart + 335, yStart + 174, 10, 10, "+"));
allWidgetsButton = new GuiButtonSpecial(8, xStart + 321, yStart + 159, 10, 10, "<");
allWidgetsButton.setTooltipText(I18n.format("gui.programmer.button.openPanel.tooltip"));
addWidget(allWidgetsButton);
difficultyButtons = new ArrayList<GuiRadioButton>();
for (int i = 0; i < IProgWidget.WidgetDifficulty.values().length; i++) {
GuiRadioButton radioButton = new GuiRadioButton(i, xStart + 263, yStart + 200 + i * 12, 0xFF000000, IProgWidget.WidgetDifficulty.values()[i].getLocalizedName());
radioButton.checked = Config.getProgrammerDifficulty() == i;
addWidget(radioButton);
difficultyButtons.add(radioButton);
radioButton.otherChoices = difficultyButtons;
if (i == 1)
radioButton.setTooltip(I18n.format("gui.programmer.difficulty.medium.tooltip"));
if (i == 2)
radioButton.setTooltip(I18n.format("gui.programmer.difficulty.advanced.tooltip"));
}
buttonList.add(new GuiButton(5, xStart + 5, yStart + 175, 87, 20, I18n.format("gui.programmer.button.showStart")));
buttonList.add(new GuiButton(6, xStart + 5, yStart + 197, 87, 20, I18n.format("gui.programmer.button.showLatest")));
addWidget(showInfo = new GuiCheckBox(-1, xStart + 5, yStart + 220, 0xFF000000, "gui.programmer.checkbox.showInfo").setChecked(te.showInfo));
addWidget(showFlow = new GuiCheckBox(-1, xStart + 5, yStart + 232, 0xFF000000, "gui.programmer.checkbox.showFlow").setChecked(te.showFlow));
GuiButtonSpecial pastebinButton = new GuiButtonSpecial(7, guiLeft - 24, guiTop + 44, 20, 20, "");
pastebinButton.setTooltipText(I18n.format("gui.remote.button.pastebinButton"));
pastebinButton.setRenderedIcon(Textures.GUI_PASTEBIN_ICON_LOCATION);
buttonList.add(pastebinButton);
undoButton = new GuiButtonSpecial(9, guiLeft - 24, guiTop + 2, 20, 20, "");
redoButton = new GuiButtonSpecial(10, guiLeft - 24, guiTop + 23, 20, 20, "");
GuiButtonSpecial clearAllButton = new GuiButtonSpecial(11, guiLeft - 24, guiTop + 65, 20, 20, "");
convertToRelativeButton = new GuiButtonSpecial(12, guiLeft - 24, guiTop + 86, 20, 20, "Rel");
undoButton.setRenderedIcon(Textures.GUI_UNDO_ICON_LOCATION);
redoButton.setRenderedIcon(Textures.GUI_REDO_ICON_LOCATION);
clearAllButton.setRenderedIcon(Textures.GUI_DELETE_ICON_LOCATION);
undoButton.setTooltipText(I18n.format("gui.programmer.button.undoButton.tooltip"));
redoButton.setTooltipText(I18n.format("gui.programmer.button.redoButton.tooltip"));
clearAllButton.setTooltipText(I18n.format("gui.programmer.button.clearAllButton.tooltip"));
buttonList.add(undoButton);
buttonList.add(redoButton);
buttonList.add(clearAllButton);
buttonList.add(convertToRelativeButton);
String containerName = te.hasCustomInventoryName() ? te.getInventoryName() : StatCollector.translateToLocal(te.getInventoryName() + ".name");
addLabel(containerName, guiLeft + 7, guiTop + 5);
nameField = new WidgetTextField(fontRendererObj, guiLeft + 200, guiTop + 5, 98, fontRendererObj.FONT_HEIGHT);
addWidget(nameField);
String name = I18n.format("gui.programmer.name");
addLabel(name, guiLeft + 197 - fontRendererObj.getStringWidth(name), guiTop + 5);
updateVisibleProgWidgets();
}
use of pneumaticCraft.common.network.PacketProgrammerUpdate 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;
}
}
use of pneumaticCraft.common.network.PacketProgrammerUpdate in project PneumaticCraft by MineMaarten.
the class GuiProgrammer method keyTyped.
@Override
protected void keyTyped(char key, int keyCode) {
super.keyTyped(key, keyCode);
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) {
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));
}
}
use of pneumaticCraft.common.network.PacketProgrammerUpdate in project PneumaticCraft by MineMaarten.
the class GuiProgrammer method actionPerformed.
/**
* Fired when a control is clicked. This is the equivalent of
* ActionListener.actionPerformed(ActionEvent e).
*/
@Override
protected void actionPerformed(GuiButton button) {
switch(button.id) {
case // redstone button
0:
// redstoneBehaviourStat.closeWindow();
break;
case 3:
if (--widgetPage < 0)
widgetPage = maxPage;
updateVisibleProgWidgets();
return;
case 4:
if (++widgetPage > maxPage)
widgetPage = 0;
updateVisibleProgWidgets();
return;
case 5:
for (IProgWidget widget : te.progWidgets) {
if (widget instanceof ProgWidgetStart) {
programmerUnit.gotoPiece(widget);
break;
}
}
return;
case 6:
if (te.progWidgets.size() > 0) {
programmerUnit.gotoPiece(te.progWidgets.get(te.progWidgets.size() - 1));
}
return;
case 7:
NBTTagCompound mainTag = new NBTTagCompound();
te.writeProgWidgetsToNBT(mainTag);
FMLClientHandler.instance().showGuiScreen(pastebinGui = new GuiPastebin(this, mainTag));
break;
case 11:
te.progWidgets.clear();
NetworkHandler.sendToServer(new PacketProgrammerUpdate(te));
break;
case 12:
for (IProgWidget widget : te.progWidgets) {
if (widget instanceof ProgWidgetStart) {
generateRelativeOperators((ProgWidgetCoordinateOperator) widget.getOutputWidget(), null, false);
break;
}
}
break;
}
NetworkHandler.sendToServer(new PacketGuiButton(button.id));
}
use of pneumaticCraft.common.network.PacketProgrammerUpdate in project PneumaticCraft by MineMaarten.
the class GuiProgrammer method drawGuiContainerBackgroundLayer.
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int x, int y) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
bindGuiTexture();
int xStart = (width - xSize) / 2;
int yStart = (height - ySize) / 2;
func_146110_a(xStart, yStart, 0, 0, xSize, ySize, xSize, ySize);
programmerUnit.getScrollBar().setEnabled(showingWidgetProgress == 0);
super.drawGuiContainerBackgroundLayer(partialTicks, x, y);
if (showingWidgetProgress > 0)
programmerUnit.getScrollBar().setCurrentState(programmerUnit.getLastZoom());
programmerUnit.render(x, y, showFlow.checked, showInfo.checked && showingWidgetProgress == 0, draggingWidget == null);
int origX = x;
int origY = y;
x -= programmerUnit.getTranslatedX();
y -= programmerUnit.getTranslatedY();
float scale = programmerUnit.getScale();
x = (int) (x / scale);
y = (int) (y / scale);
if (showingWidgetProgress > 0) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
bindGuiTexture();
int width = oldShowingWidgetProgress + (int) ((showingWidgetProgress - oldShowingWidgetProgress) * partialTicks);
for (int i = 0; i < width; i++) {
func_146110_a(xStart + 320 - i, yStart + 36, 323, 36, 1, 136, xSize, ySize);
}
func_146110_a(xStart + 319 - width, yStart + 36, 319, 36, 2, 136, xSize, ySize);
if (showingAllWidgets && draggingWidget != null)
toggleShowWidgets();
}
GL11.glEnable(GL11.GL_TEXTURE_2D);
for (IProgWidget widget : visibleSpawnWidgets) {
GL11.glPushMatrix();
GL11.glTranslated(widget.getX() + guiLeft, widget.getY() + guiTop, 0);
GL11.glScaled(0.5, 0.5, 1);
widget.render();
GL11.glPopMatrix();
}
GL11.glPushMatrix();
GL11.glTranslated(programmerUnit.getTranslatedX(), programmerUnit.getTranslatedY(), 0);
GL11.glScaled(scale, scale, 1);
if (draggingWidget != null) {
GL11.glPushMatrix();
GL11.glTranslated(draggingWidget.getX() + guiLeft, draggingWidget.getY() + guiTop, 0);
GL11.glScaled(0.5, 0.5, 1);
draggingWidget.render();
GL11.glPopMatrix();
}
GL11.glPopMatrix();
boolean isLeftClicking = Mouse.isButtonDown(0);
boolean isMiddleClicking = GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindPickBlock);
if (draggingWidget != null) {
setConnectingWidgetsToXY(draggingWidget, x - dragMouseStartX + dragWidgetStartX - guiLeft, y - dragMouseStartY + dragWidgetStartY - guiTop);
}
if (isLeftClicking && !wasClicking) {
for (IProgWidget widget : visibleSpawnWidgets) {
if (origX >= widget.getX() + guiLeft && origY >= widget.getY() + guiTop && origX <= widget.getX() + guiLeft + widget.getWidth() / 2 && origY <= widget.getY() + guiTop + widget.getHeight() / 2) {
draggingWidget = widget.copy();
te.progWidgets.add(draggingWidget);
dragMouseStartX = x - (int) (guiLeft / scale);
dragMouseStartY = y - (int) (guiTop / scale);
dragWidgetStartX = (int) ((widget.getX() - programmerUnit.getTranslatedX()) / scale);
dragWidgetStartY = (int) ((widget.getY() - programmerUnit.getTranslatedY()) / scale);
break;
}
}
if (draggingWidget == null && showingWidgetProgress == 0) {
IProgWidget widget = programmerUnit.getHoveredWidget(origX, origY);
if (widget != null) {
draggingWidget = widget;
dragMouseStartX = x - guiLeft;
dragMouseStartY = y - guiTop;
dragWidgetStartX = widget.getX();
dragWidgetStartY = widget.getY();
}
}
} else if (isMiddleClicking && !wasClicking && showingWidgetProgress == 0) {
IProgWidget widget = programmerUnit.getHoveredWidget(origX, origY);
if (widget != null) {
draggingWidget = widget.copy();
te.progWidgets.add(draggingWidget);
dragMouseStartX = 0;
dragMouseStartY = 0;
dragWidgetStartX = widget.getX() - (x - guiLeft);
dragWidgetStartY = widget.getY() - (y - guiTop);
if (PneumaticCraft.proxy.isSneakingInGui())
copyAndConnectConnectingWidgets(widget, draggingWidget);
}
}
if (!isLeftClicking && !isMiddleClicking && draggingWidget != null) {
if (programmerUnit.isOutsideProgrammingArea(draggingWidget)) {
deleteConnectingWidgets(draggingWidget);
} else {
handlePuzzleMargins();
if (!isValidPlaced(draggingWidget)) {
setConnectingWidgetsToXY(draggingWidget, dragWidgetStartX, dragWidgetStartY);
if (programmerUnit.isOutsideProgrammingArea(draggingWidget))
deleteConnectingWidgets(draggingWidget);
}
}
NetworkHandler.sendToServer(new PacketProgrammerUpdate(te));
TileEntityProgrammer.updatePuzzleConnections(te.progWidgets);
draggingWidget = null;
}
wasClicking = isLeftClicking || isMiddleClicking;
lastMouseX = origX;
lastMouseY = origY;
}
Aggregations