use of pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.
the class GuiDroneDebuggerOptions method initGui.
@Override
public void initGui(IGuiScreen gui) {
GuiScreen guiScreen = (GuiScreen) gui;
screenWidth = guiScreen.width;
screenHeight = guiScreen.height;
if (PneumaticCraft.proxy.getPlayer() != null) {
ItemStack helmet = PneumaticCraft.proxy.getPlayer().getCurrentArmor(3);
if (helmet != null) {
int entityId = NBTUtil.getInteger(helmet, NBTKeys.PNEUMATIC_HELMET_DEBUGGING_DRONE);
Entity entity = PneumaticCraft.proxy.getClientWorld().getEntityByID(entityId);
if (entity instanceof EntityDrone) {
selectedDrone = (EntityDrone) entity;
}
}
}
int spacing = 20;
programmingStartX = spacing;
programmingWidth = guiScreen.width - spacing * 2;
programmingHeight = guiScreen.height - spacing - PROGRAMMING_START_Y;
programmerUnit = new DebugInfoProgrammerUnit(selectedDrone != null ? selectedDrone.getProgWidgets() : new ArrayList<IProgWidget>(), gui.getFontRenderer(), 0, 0, guiScreen.width, guiScreen.height, 100, programmingStartX, PROGRAMMING_START_Y, programmingWidth, programmingHeight, 0, 0, 0);
if (selectedDrone != null) {
for (IProgWidget widget : selectedDrone.getProgWidgets()) {
if (widget instanceof ProgWidgetStart) {
programmerUnit.gotoPiece(widget);
break;
}
}
}
}
use of pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.
the class GuiProgrammer method setConnectingWidgetsToXY.
private void setConnectingWidgetsToXY(IProgWidget widget, int x, int y) {
widget.setX(x);
widget.setY(y);
IProgWidget[] connectingWidgets = widget.getConnectedParameters();
if (connectingWidgets != null) {
for (int i = 0; i < connectingWidgets.length; i++) {
if (connectingWidgets[i] != null) {
if (i < connectingWidgets.length / 2) {
setConnectingWidgetsToXY(connectingWidgets[i], x + widget.getWidth() / 2, y + i * 11);
} else {
int totalWidth = 0;
IProgWidget branch = connectingWidgets[i];
while (branch != null) {
totalWidth += branch.getWidth() / 2;
branch = branch.getConnectedParameters()[0];
}
setConnectingWidgetsToXY(connectingWidgets[i], x - totalWidth, y + (i - connectingWidgets.length / 2) * 11);
}
}
}
}
IProgWidget outputWidget = widget.getOutputWidget();
if (outputWidget != null)
setConnectingWidgetsToXY(outputWidget, x, y + widget.getHeight() / 2);
}
use of pneumaticCraft.common.progwidgets.IProgWidget 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.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.
the class GuiProgrammer method updateScreen.
@Override
public void updateScreen() {
super.updateScreen();
undoButton.enabled = te.canUndo;
redoButton.enabled = te.canRedo;
updateConvertRelativeState();
ItemStack programmedItem = te.getStackInSlot(TileEntityProgrammer.PROGRAM_SLOT);
oldShowingWidgetProgress = showingWidgetProgress;
if (showingAllWidgets) {
int maxProgress = maxPage * 22;
if (showingWidgetProgress < maxProgress) {
showingWidgetProgress += 30;
if (showingWidgetProgress >= maxProgress) {
showingWidgetProgress = maxProgress;
updateVisibleProgWidgets();
}
}
} else {
showingWidgetProgress -= 30;
if (showingWidgetProgress < 0)
showingWidgetProgress = 0;
}
List<String> errors = new ArrayList<String>();
List<String> warnings = new ArrayList<String>();
for (IProgWidget w : te.progWidgets) {
w.addErrors(errors, te.progWidgets);
w.addWarnings(warnings, te.progWidgets);
}
boolean isDeviceInserted = programmedItem != null;
importButton.enabled = isDeviceInserted;
exportButton.enabled = isDeviceInserted && errors.size() == 0;
List<String> exportButtonTooltip = new ArrayList<String>();
exportButtonTooltip.add("Export program");
exportButtonTooltip.add(I18n.format("gui.programmer.button.export.programmingWhen", I18n.format("gui.programmer.button.export." + (te.redstoneMode == 0 ? "pressingButton" : "onItemInsert"))));
exportButtonTooltip.add(I18n.format("gui.programmer.button.export.pressRToChange"));
if (programmedItem != null) {
List<ItemStack> requiredPieces = te.getRequiredPuzzleStacks();
List<ItemStack> returnedPieces = te.getReturnedPuzzleStacks();
if (!requiredPieces.isEmpty() || !returnedPieces.isEmpty())
exportButtonTooltip.add("");
if (!requiredPieces.isEmpty()) {
exportButtonTooltip.add("Required Programming Puzzles:");
if (player.capabilities.isCreativeMode)
exportButtonTooltip.add("(Creative mode, so the following is free)");
for (ItemStack stack : requiredPieces) {
String prefix;
if (te.hasEnoughPuzzleStacks(player, stack)) {
prefix = EnumChatFormatting.GREEN.toString();
} else {
prefix = EnumChatFormatting.RED.toString();
exportButton.enabled = player.capabilities.isCreativeMode && errors.size() == 0;
}
exportButtonTooltip.add(prefix + "-" + stack.stackSize + "x " + stack.getDisplayName());
}
}
if (!returnedPieces.isEmpty()) {
exportButtonTooltip.add("Returned Programming Puzzles:");
if (player.capabilities.isCreativeMode)
exportButtonTooltip.add("(Creative mode, nothing's given)");
for (ItemStack stack : returnedPieces) {
exportButtonTooltip.add("-" + stack.stackSize + "x " + stack.getDisplayName());
}
}
} else {
exportButtonTooltip.add("No programmable item inserted.");
}
if (errors.size() > 0)
exportButtonTooltip.add(EnumChatFormatting.RED + I18n.format("gui.programmer.errorCount", errors.size()));
if (warnings.size() > 0)
exportButtonTooltip.add(EnumChatFormatting.YELLOW + I18n.format("gui.programmer.warningCount", warnings.size()));
exportButton.setTooltipText(exportButtonTooltip);
if (programmedItem != null) {
nameField.setEnabled(true);
if (!nameField.isFocused()) {
if (wasFocused) {
programmedItem.setStackDisplayName(nameField.getText());
NetworkHandler.sendToServer(new PacketUpdateTextfield(te, 0));
}
nameField.setText(programmedItem.getDisplayName());
wasFocused = false;
} else {
wasFocused = true;
}
} else {
nameField.setEnabled(false);
nameField.setText("");
wasFocused = false;
}
}
use of pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.
the class GuiProgrammer method isValidPlaced.
private boolean isValidPlaced(IProgWidget widget1) {
Rectangle draggingRect = new Rectangle(widget1.getX(), widget1.getY(), widget1.getWidth() / 2, widget1.getHeight() / 2);
for (IProgWidget widget : te.progWidgets) {
if (widget != widget1) {
if (draggingRect.intersects(widget.getX(), widget.getY(), widget.getWidth() / 2, widget.getHeight() / 2)) {
return false;
}
}
}
IProgWidget[] parameters = widget1.getConnectedParameters();
if (parameters != null) {
for (IProgWidget widget : parameters) {
if (widget != null && !isValidPlaced(widget))
return false;
}
}
IProgWidget outputWidget = widget1.getOutputWidget();
if (outputWidget != null && !isValidPlaced(outputWidget))
return false;
return true;
}
Aggregations