use of me.desht.pneumaticcraft.common.progwidgets.ProgWidgetArea in project pnc-repressurized by TeamPneumatic.
the class ItemGPSAreaTool method addInformation.
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack stack, World worldIn, List<String> infoList, ITooltipFlag par4) {
super.addInformation(stack, worldIn, infoList, par4);
for (int index = 0; index < 2; index++) {
BlockPos pos = getGPSLocation(stack, index);
if (pos != null) {
infoList.add(String.format("\u00a72P%d: %d, %d, %d", index + 1, pos.getX(), pos.getY(), pos.getZ()));
}
String varName = getVariable(stack, index);
if (!varName.equals("")) {
infoList.add(I18n.format("gui.tooltip.gpsTool.variable", varName));
}
}
CapabilityGPSAreaTool cap = getCap(stack);
if (cap != null) {
ProgWidgetArea area = cap.getWidget();
area.addAreaTypeTooltip(infoList);
}
}
use of me.desht.pneumaticcraft.common.progwidgets.ProgWidgetArea in project pnc-repressurized by TeamPneumatic.
the class ItemLogisticsDrone method addLogisticsProgram.
private void addLogisticsProgram(BlockPos pos, List<IProgWidget> widgets) {
ProgWidgetStart start = new ProgWidgetStart();
start.setX(0);
start.setY(0);
widgets.add(start);
ProgWidgetLogistics logistics = new ProgWidgetLogistics();
logistics.setX(0);
logistics.setY(11);
widgets.add(logistics);
ProgWidgetArea area = new ProgWidgetArea();
area.setX(15);
area.setY(11);
area.x1 = pos.getX() - 16;
area.y1 = pos.getY() - 16;
area.z1 = pos.getZ() - 16;
area.x2 = pos.getX() + 16;
area.y2 = pos.getY() + 16;
area.z2 = pos.getZ() + 16;
widgets.add(area);
TileEntityProgrammer.updatePuzzleConnections(widgets);
}
use of me.desht.pneumaticcraft.common.progwidgets.ProgWidgetArea 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;
}
}
use of me.desht.pneumaticcraft.common.progwidgets.ProgWidgetArea in project pnc-repressurized by TeamPneumatic.
the class GuiProgrammer method drawGuiContainerBackgroundLayer.
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int x, int y) {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
drawDefaultBackground();
bindGuiTexture();
int xStart = (width - xSize) / 2;
int yStart = (height - ySize) / 2;
drawModalRectWithCustomSizedTexture(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) {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
bindGuiTexture();
int width = oldShowingWidgetProgress + (int) ((showingWidgetProgress - oldShowingWidgetProgress) * partialTicks);
for (int i = 0; i < width; i++) {
drawModalRectWithCustomSizedTexture(xStart + 320 - i, yStart + 36, 323, 36, 1, 136, xSize, ySize);
}
drawModalRectWithCustomSizedTexture(xStart + 319 - width, yStart + 36, 319, 36, 2, 136, xSize, ySize);
if (showingAllWidgets && draggingWidget != null)
toggleShowWidgets();
}
GlStateManager.enableTexture2D();
GlStateManager.enableBlend();
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
for (int i = 0; i < visibleSpawnWidgets.size(); i++) {
IProgWidget widget = visibleSpawnWidgets.get(i);
GlStateManager.pushMatrix();
GlStateManager.translate(widget.getX() + guiLeft, widget.getY() + guiTop, 0);
GlStateManager.scale(0.5, 0.5, 1);
if (showingAllWidgets && filteredSpawnWidgets != null && !filteredSpawnWidgets.get(i)) {
GlStateManager.color(1, 1, 1, 0.2f);
} else {
GlStateManager.color(1, 1, 1, 1);
}
widget.render();
GlStateManager.popMatrix();
}
GlStateManager.disableBlend();
GlStateManager.pushMatrix();
GlStateManager.translate(programmerUnit.getTranslatedX(), programmerUnit.getTranslatedY(), 0);
GlStateManager.scale(scale, scale, 1);
if (draggingWidget != null) {
GlStateManager.pushMatrix();
GlStateManager.translate(draggingWidget.getX() + guiLeft, draggingWidget.getY() + guiTop, 0);
GlStateManager.scale(0.5, 0.5, 1);
draggingWidget.render();
GlStateManager.popMatrix();
}
GlStateManager.popMatrix();
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;
}
}
// create area widgets straight from GPS Area Tools
ItemStack heldItem = mc.player.inventory.getItemStack();
ProgWidgetArea areaToolWidget = null;
if (heldItem.hasCapability(CapabilityGPSAreaTool.INSTANCE, null)) {
CapabilityGPSAreaTool cap = heldItem.getCapability(CapabilityGPSAreaTool.INSTANCE, null);
areaToolWidget = cap.createWidget();
}
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();
if (areaToolWidget != null && widget instanceof ProgWidgetArea) {
NBTTagCompound tag = new NBTTagCompound();
areaToolWidget.writeToNBT(tag);
widget.readFromNBT(tag);
} else if (heldItem.getItem() == Itemss.GPS_TOOL && widget instanceof ProgWidgetCoordinate) {
((ProgWidgetCoordinate) widget).loadFromGPSTool(heldItem);
}
}
}
// Create a new widget from a GPS Area tool when nothing was selected
if (draggingWidget == null) {
if (areaToolWidget != null) {
draggingWidget = areaToolWidget;
} else if (heldItem.getItem() == Itemss.GPS_TOOL) {
ProgWidgetCoordinate coordWidget = new ProgWidgetCoordinate();
draggingWidget = coordWidget;
coordWidget.loadFromGPSTool(heldItem);
}
if (draggingWidget != null) {
draggingWidget.setX(Integer.MAX_VALUE);
draggingWidget.setY(Integer.MAX_VALUE);
te.progWidgets.add(draggingWidget);
dragMouseStartX = draggingWidget.getWidth() / 3;
dragMouseStartY = draggingWidget.getHeight() / 4;
dragWidgetStartX = 0;
dragWidgetStartY = 0;
}
}
} 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 (PneumaticCraftRepressurized.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