2018-01-31 09:05:34 -05:00
|
|
|
import java.awt.AWTException;
|
|
|
|
import java.awt.Rectangle;
|
|
|
|
import java.awt.Robot;
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
import java.io.IOException;
|
2018-01-31 08:12:02 -05:00
|
|
|
|
|
|
|
public class Inventory {
|
|
|
|
|
2018-01-31 23:38:32 -05:00
|
|
|
public static final int INVENTORY_OFFSET_WIDTH = 655; //top left corner of inventory, fromm top left corner of screen
|
|
|
|
public static final int INVENTORY_OFFSET_HEIGHT = 290;
|
2018-01-31 09:05:34 -05:00
|
|
|
public static final int INVENTORY_WIDTH = 820 - 649;// 820
|
2018-01-31 23:38:32 -05:00
|
|
|
public static final int INVENTORY_HEIGHT = 350; // 530
|
2018-01-31 09:05:34 -05:00
|
|
|
|
|
|
|
Robot robot;
|
|
|
|
Rectangle inventoryAreaToCapture;
|
2018-01-31 08:12:02 -05:00
|
|
|
InventorySlot[][] inventorySlots;
|
|
|
|
|
2018-01-31 09:05:34 -05:00
|
|
|
public Inventory() throws AWTException {
|
|
|
|
initializeInventorySlots();
|
|
|
|
robot = new Robot();
|
|
|
|
this.inventoryAreaToCapture = new Rectangle(INVENTORY_OFFSET_WIDTH, INVENTORY_OFFSET_HEIGHT, INVENTORY_WIDTH, INVENTORY_HEIGHT);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initializeInventorySlots() {
|
2018-01-31 08:12:02 -05:00
|
|
|
inventorySlots = new InventorySlot[4][7];
|
2018-01-31 09:05:34 -05:00
|
|
|
for (int row = 0; row < 4; row++) {
|
|
|
|
for (int column = 0; column < 7; column++) {
|
|
|
|
inventorySlots[row][column] = new InventorySlot(row, column);
|
2018-01-31 08:12:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-31 09:05:34 -05:00
|
|
|
public void update() throws IOException {
|
|
|
|
BufferedImage image = robot.createScreenCapture(this.inventoryAreaToCapture);
|
|
|
|
updateAllInventorySlots(image);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateAllInventorySlots(BufferedImage image) throws IOException {
|
|
|
|
for (int row = 0; row < 4; row++) {
|
|
|
|
for (int column = 0; column < 7; column++) {
|
2018-02-01 22:39:57 -05:00
|
|
|
inventorySlots[row][column].updateInventorySlot(image);
|
2018-01-31 09:05:34 -05:00
|
|
|
}
|
|
|
|
}
|
2018-01-31 08:12:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|