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;
|
2018-02-02 05:25:00 -05:00
|
|
|
import java.io.File;
|
2018-01-31 09:05:34 -05:00
|
|
|
import java.io.IOException;
|
2018-01-31 08:12:02 -05:00
|
|
|
|
2018-02-02 05:25:00 -05:00
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
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
|
|
|
|
2018-02-02 00:49:19 -05:00
|
|
|
public static final int NUM_ROWS = 4;
|
|
|
|
public static final int NUM_COLUMNS = 7;
|
|
|
|
|
2018-01-31 09:05:34 -05:00
|
|
|
Robot robot;
|
2018-02-02 00:49:19 -05:00
|
|
|
Rectangle inventoryRectangleToCapture;
|
2018-01-31 08:12:02 -05:00
|
|
|
InventorySlot[][] inventorySlots;
|
2018-02-02 00:49:19 -05:00
|
|
|
InventoryItems items;
|
2018-01-31 08:12:02 -05:00
|
|
|
|
2018-02-02 00:49:19 -05:00
|
|
|
public Inventory() throws AWTException, IOException {
|
|
|
|
initializeInventoryRectangle();
|
2018-01-31 09:05:34 -05:00
|
|
|
initializeInventorySlots();
|
2018-02-02 00:49:19 -05:00
|
|
|
initializeItems();
|
2018-01-31 09:05:34 -05:00
|
|
|
robot = new Robot();
|
2018-02-02 00:49:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private void initializeInventoryRectangle() {
|
|
|
|
inventoryRectangleToCapture = new Rectangle(INVENTORY_OFFSET_WIDTH, INVENTORY_OFFSET_HEIGHT, INVENTORY_WIDTH, INVENTORY_HEIGHT);
|
2018-01-31 09:05:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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-02-02 00:49:19 -05:00
|
|
|
private void initializeItems() throws IOException {
|
|
|
|
items = new InventoryItems("/home/dpapp/Desktop/RunescapeAIPics/Items/");
|
|
|
|
}
|
|
|
|
|
2018-01-31 09:05:34 -05:00
|
|
|
public void update() throws IOException {
|
2018-02-02 00:49:19 -05:00
|
|
|
BufferedImage image = robot.createScreenCapture(this.inventoryRectangleToCapture);
|
2018-02-02 05:25:00 -05:00
|
|
|
ImageIO.write(image, "png", new File(getImageName()));
|
2018-01-31 09:05:34 -05:00
|
|
|
updateAllInventorySlots(image);
|
|
|
|
}
|
2018-02-02 05:25:00 -05:00
|
|
|
|
|
|
|
private String getImageName() {
|
|
|
|
return ("/home/dpapp/Desktop/RunescapeAIPics/Tests/Inventory/inventory.png");
|
|
|
|
}
|
2018-02-02 00:49:19 -05:00
|
|
|
|
|
|
|
public void updateWithFakeImageForTests(BufferedImage testImage) throws IOException {
|
|
|
|
updateAllInventorySlots(testImage);
|
|
|
|
}
|
|
|
|
|
2018-01-31 09:05:34 -05:00
|
|
|
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-02-02 05:25:00 -05:00
|
|
|
//inventorySlots[row][column].writeInventorySlotImage(image, row, column);
|
2018-01-31 09:05:34 -05:00
|
|
|
}
|
|
|
|
}
|
2018-01-31 08:12:02 -05:00
|
|
|
}
|
2018-02-02 00:49:19 -05:00
|
|
|
|
|
|
|
public String getItemNameInInventorySlot(int row, int column) {
|
|
|
|
return inventorySlots[row][column].getItemNameInInventorySlot(items);
|
|
|
|
}
|
|
|
|
|
2018-02-02 05:25:00 -05:00
|
|
|
/*public boolean isInventoryFull() {
|
2018-02-02 00:49:19 -05:00
|
|
|
for (int row = 0; row < 4; row++) {
|
|
|
|
for (int column = 0; column < 7; column++) {
|
|
|
|
if (!inventorySlots[row][column].isInventorySlotEmpty(items)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2018-02-02 05:25:00 -05:00
|
|
|
}*/
|
2018-01-31 08:12:02 -05:00
|
|
|
}
|