use of pneumaticCraft.common.progwidgets.IProgWidget 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.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.
the class GuiDroneDebuggerOptions method drawScreen.
@Override
public void drawScreen(int x, int y, float partialTicks) {
if (selectedDrone != null) {
Minecraft.getMinecraft().fontRenderer.drawString("Drone name: " + selectedDrone.getCommandSenderName(), 20, screenHeight - 15, 0xFFFFFFFF, true);
Minecraft.getMinecraft().fontRenderer.drawString("Routine: " + selectedDrone.getLabel(), screenWidth / 2, screenHeight - 15, 0xFFFFFFFF, true);
}
programmerUnit.render(x, y, true, true, true);
programmerUnit.renderForeground(x, y, null);
if (selectedDrone == null) {
drawCenteredString(Minecraft.getMinecraft().fontRenderer, "Press '" + Keyboard.getKeyName(KeyHandler.getInstance().keybindDebuggingDrone.getKeyCode()) + "' on a Drone when tracked by an Entity Tracker to debug the Drone.", screenWidth / 2, screenHeight / 2, 0xFFFF0000);
}
IProgWidget widget = programmerUnit.getHoveredWidget(x, y);
if (widget == null)
widget = areaShowingWidget;
upgradeHandler.getShowingPositions().clear();
if (widget != null) {
int widgetId = selectedDrone.getProgWidgets().indexOf(widget);
for (DebugEntry entry : selectedDrone.getDebugEntries()) {
if (entry.getProgWidgetId() == widgetId && !entry.getPos().equals(new ChunkPosition(0, 0, 0))) {
upgradeHandler.getShowingPositions().add(entry.getPos());
}
}
}
}
use of pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.
the class GuiUnitProgrammer method showFlow.
private void showFlow() {
GL11.glLineWidth(1);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glBegin(GL11.GL_LINES);
for (IProgWidget widget : progWidgets) {
if (widget instanceof IJump) {
List<String> jumpLocations = ((IJump) widget).getPossibleJumpLocations();
if (jumpLocations != null) {
for (String jumpLocation : jumpLocations) {
if (jumpLocation != null) {
for (IProgWidget w : progWidgets) {
if (w instanceof ILabel) {
String label = ((ILabel) w).getLabel();
if (label != null && jumpLocation.equals(label)) {
int x1 = widget.getX() + widget.getWidth() / 4;
int y1 = widget.getY() + widget.getHeight() / 4;
int x2 = w.getX() + w.getWidth() / 4;
int y2 = w.getY() + w.getHeight() / 4;
double midX = (x2 + x1) / 2D;
double midY = (y2 + y1) / 2D;
GL11.glVertex3d(guiLeft + x1, guiTop + y1, zLevel);
GL11.glVertex3d(guiLeft + x2, guiTop + y2, zLevel);
Vec3 arrowVec = Vec3.createVectorHelper(x1 - x2, y1 - y2, 0).normalize();
float arrowAngle = (float) Math.toRadians(30);
float arrowSize = 5;
arrowVec.xCoord *= arrowSize;
arrowVec.yCoord *= arrowSize;
arrowVec.rotateAroundZ(arrowAngle);
GL11.glVertex3d(guiLeft + midX, guiTop + midY, zLevel);
GL11.glVertex3d(guiLeft + midX + arrowVec.xCoord, guiTop + midY + arrowVec.yCoord, zLevel);
arrowVec.rotateAroundZ(-2 * arrowAngle);
GL11.glVertex3d(guiLeft + midX, guiTop + midY, zLevel);
GL11.glVertex3d(guiLeft + midX + arrowVec.xCoord, guiTop + midY + arrowVec.yCoord, zLevel);
}
}
}
}
}
}
}
}
GL11.glEnd();
GL11.glEnable(GL11.GL_TEXTURE_2D);
}
use of pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.
the class GuiUnitProgrammer method render.
public void render(int x, int y, boolean showFlow, boolean showInfo, boolean translate) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int origX = x;
int origY = y;
x -= translatedX;
y -= translatedY;
float scale = getScale();
x = (int) (x / scale);
y = (int) (y / scale);
if (scaleScroll.getState() != lastZoom) {
float shift = SCALE_PER_STEP * (scaleScroll.getState() - lastZoom);
if (new Rectangle(guiLeft + startX, guiTop + startY, areaWidth, areaHeight).contains(origX, origY)) {
translatedX += shift * x;
translatedY += shift * y;
} else {
translatedX += areaWidth / 2 * shift;
translatedY += areaHeight / 2 * shift;
}
}
lastZoom = scaleScroll.getState();
ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft(), Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight);
GL11.glScissor((guiLeft + startX) * sr.getScaleFactor(), (sr.getScaledHeight() - areaHeight - (guiTop + startY)) * sr.getScaleFactor(), areaWidth * sr.getScaleFactor(), areaHeight * sr.getScaleFactor());
GL11.glEnable(GL11.GL_SCISSOR_TEST);
GL11.glPushMatrix();
GL11.glTranslated(translatedX, translatedY, 0);
GL11.glScaled(scale, scale, 1);
if (showFlow)
showFlow();
GL11.glEnable(GL11.GL_TEXTURE_2D);
for (IProgWidget widget : progWidgets) {
GL11.glPushMatrix();
GL11.glTranslated(widget.getX() + guiLeft, widget.getY() + guiTop, 0);
GL11.glScaled(0.5, 0.5, 1);
widget.render();
GL11.glPopMatrix();
}
for (IProgWidget widget : progWidgets) {
List<String> errors = new ArrayList<String>();
widget.addErrors(errors, progWidgets);
if (errors.size() > 0) {
drawBorder(widget, 0xFFFF0000);
} else {
List<String> warnings = new ArrayList<String>();
widget.addWarnings(warnings, progWidgets);
if (warnings.size() > 0) {
drawBorder(widget, 0xFFFFFF00);
}
}
}
renderAdditionally();
GL11.glColor4d(1, 1, 1, 1);
if (showInfo) {
for (IProgWidget widget : progWidgets) {
GL11.glPushMatrix();
GL11.glTranslated(widget.getX() + guiLeft, widget.getY() + guiTop, 0);
GL11.glScaled(0.5, 0.5, 1);
widget.renderExtraInfo();
GL11.glPopMatrix();
}
}
GL11.glPopMatrix();
GL11.glDisable(GL11.GL_SCISSOR_TEST);
boolean isLeftClicking = Mouse.isButtonDown(0);
if (translate && isLeftClicking && wasClicking && new Rectangle(guiLeft + startX, guiTop + startY, areaWidth, areaHeight).contains(origX, origY)) {
translatedX += origX - lastMouseX;
translatedY += origY - lastMouseY;
}
wasClicking = isLeftClicking;
lastMouseX = origX;
lastMouseY = origY;
}
use of pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.
the class DroneAIExternalProgram method doBlockInteraction.
@Override
protected boolean doBlockInteraction(ChunkPosition pos, double distToBlock) {
IInventory inv = IOHelper.getInventoryForTE(drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ));
if (inv == null)
return false;
if (curProgramTag != null) {
if (curSlot < inv.getSizeInventory()) {
ItemStack stack = inv.getStackInSlot(curSlot);
if (stack != null && curProgramTag.equals(stack.getTagCompound())) {
subAI.onUpdateTasks();
if (subAI.isIdling() || isRunningSameProgram(subAI.getCurrentAI())) {
curProgramTag = null;
curSlot++;
}
} else {
curProgramTag = null;
subAI.setWidgets(new ArrayList<IProgWidget>());
}
}
return true;
} else {
while (curSlot < inv.getSizeInventory()) {
ItemStack stack = inv.getStackInSlot(curSlot);
if (stack != null && stack.getItem() instanceof IProgrammable) {
IProgrammable programmable = (IProgrammable) stack.getItem();
if (programmable.canProgram(stack) && programmable.usesPieces(stack)) {
List<IProgWidget> widgets = TileEntityProgrammer.getProgWidgets(stack);
boolean areWidgetsValid = true;
for (IProgWidget widget : widgets) {
if (!drone.isProgramApplicable(widget)) {
areWidgetsValid = false;
break;
}
}
if (areWidgetsValid) {
if (widget.shareVariables)
mainAI.connectVariables(subAI);
subAI.getDrone().getAIManager().setLabel("Main");
subAI.setWidgets(widgets);
curProgramTag = stack.getTagCompound();
if (!subAI.isIdling()) {
return true;
}
}
}
}
curSlot++;
}
return false;
}
}
Aggregations