use of pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.
the class GuiProgrammer method updateVisibleProgWidgets.
private void updateVisibleProgWidgets() {
int y = 0, page = 0;
int xSpacing = 22;
int x = 322 - maxPage * xSpacing;
boolean showAllWidgets = showingWidgetProgress == xSpacing * maxPage && showingAllWidgets;
maxPage = 0;
visibleSpawnWidgets.clear();
int difficulty = 0;
for (int i = 0; i < difficultyButtons.size(); i++) {
if (difficultyButtons.get(i).checked) {
difficulty = i;
break;
}
}
for (IProgWidget widget : WidgetRegistrator.registeredWidgets) {
if (difficulty >= widget.getDifficulty().ordinal()) {
widget.setY(y + 40);
widget.setX(showAllWidgets ? x : 322);
int widgetHeight = widget.getHeight() / 2 + (widget.hasStepOutput() ? 5 : 0) + 1;
y += widgetHeight;
if (showAllWidgets || page == widgetPage)
visibleSpawnWidgets.add(widget);
if (y > ySize - 160) {
y = 0;
x += xSpacing;
page++;
maxPage++;
}
}
}
if (widgetPage > maxPage) {
widgetPage = maxPage;
updateVisibleProgWidgets();
}
}
use of pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.
the class GuiProgrammer method copyAndConnectConnectingWidgets.
private void copyAndConnectConnectingWidgets(IProgWidget original, IProgWidget copy) {
IProgWidget[] connectingWidgets = original.getConnectedParameters();
if (connectingWidgets != null) {
for (int i = 0; i < connectingWidgets.length; i++) {
if (connectingWidgets[i] != null) {
IProgWidget c = connectingWidgets[i].copy();
te.progWidgets.add(c);
copy.setParameter(i, c);
copyAndConnectConnectingWidgets(connectingWidgets[i], c);
}
}
}
IProgWidget outputWidget = original.getOutputWidget();
if (outputWidget != null) {
IProgWidget c = outputWidget.copy();
te.progWidgets.add(c);
copy.setOutputWidget(c);
copyAndConnectConnectingWidgets(outputWidget, c);
}
}
use of pneumaticCraft.common.progwidgets.IProgWidget 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;
}
use of pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.
the class GuiUnitProgrammer method renderForeground.
public void renderForeground(int x, int y, IProgWidget tooltipExcludingWidget) {
IProgWidget widget = getHoveredWidget(x, y);
if (widget != null && widget != tooltipExcludingWidget) {
List<String> tooltip = new ArrayList<String>();
widget.getTooltip(tooltip);
List<String> errors = new ArrayList<String>();
widget.addErrors(errors, progWidgets);
if (errors.size() > 0) {
tooltip.add(EnumChatFormatting.RED + I18n.format("gui.programmer.errors"));
for (String s : errors) {
String[] lines = WordUtils.wrap("-" + I18n.format(s), 30).split(System.getProperty("line.separator"));
for (String line : lines) {
tooltip.add(EnumChatFormatting.RED + " " + line);
}
}
}
List<String> warnings = new ArrayList<String>();
widget.addWarnings(warnings, progWidgets);
if (warnings.size() > 0) {
tooltip.add(EnumChatFormatting.YELLOW + I18n.format("gui.programmer.warnings"));
for (String s : warnings) {
String[] lines = WordUtils.wrap("-" + I18n.format(s), 30).split(System.getProperty("line.separator"));
for (String line : lines) {
tooltip.add(EnumChatFormatting.YELLOW + " " + line);
}
}
}
addAdditionalInfoToTooltip(widget, tooltip);
if (tooltip.size() > 0)
drawHoveringText(tooltip, x - guiLeft, y - guiTop, fontRendererObj);
}
}
use of pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.
the class RenderItemProgrammingPuzzle method render.
private void render(float x, float y, float z, float scale, ItemStack stack) {
IProgWidget widget = ItemProgrammingPuzzle.getWidgetForPiece(stack);
if (widget == null)
return;
int width = widget.getWidth() + (widget.getParameters() != null && widget.getParameters().length > 0 ? 10 : 0);
int height = widget.getHeight() + (widget.hasStepOutput() ? 5 : 0);
GL11.glPushMatrix();
GL11.glTranslated(x, y, z);
// GL11.glDisable(GL11.GL_LIGHTING);
// GL11.glRotatef(-90F, 1F, 0, 0);
// Scale, Translate, Rotate
scale = scale / Math.max(height, width);
GL11.glScalef(scale, scale, 1);
GL11.glTranslatef(-width / 2, -height / 2, 0);
// GL11.glTranslatef(x, y, z);
//GL11.glRotatef(-90F, 1F, 0, 0);
widget.render();
// GL11.glEnable(GL11.GL_LIGHTING);
GL11.glPopMatrix();
}
Aggregations