Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Draws the rectangle bounds of the inventory items includes item names +
- * item id's in the middle of the bounds
- *
- * @Param g - g relates to the parameter of the OSBot painter interface
- * Visibility of this method public as it's in it's own class script is the
- * instance of the MethodProvider
- */
- public void paintInventory(Graphics g) {
- // Declaring the inventory
- Inventory inventory = script.client.getInventory();
- // Grabbing the items on the inventory interface
- Item[] inventoryItems = inventory.getItems();
- // Opening a list to keep track of the slot locations of items
- ArrayList<Integer> slots = new ArrayList<Integer>();
- // Opening a list to keep track of the slot's rectangle bounds
- ArrayList<Rectangle> rectangleDestinations = new ArrayList<Rectangle>();
- // Null check + length check
- if (inventoryItems != null && inventoryItems.length > 0) {
- // Illiterating through the array of items
- for (int i = 0; i < inventoryItems.length; i++) {
- // Null checking the item
- if (inventoryItems[i] != null)
- // Adding the slot to the list we opened before
- slots.add(inventory.getSlotForId(inventoryItems[i].getId()));
- }
- }
- // Null check + length check on the slots of the inventory
- if (slots != null && slots.size() > 0) {
- // Illiterating through the inventory slots
- for (int i : slots) {
- // Adding the rectangle bounds of the slots to the list
- rectangleDestinations.add(inventory.getDestinationForSlot(i));
- }
- }
- // Null + Length check on the rectangle bounds of slots
- if (rectangleDestinations != null && rectangleDestinations.size() > 0) {
- // Illiterating through the rectangle bound list
- for (Rectangle r : rectangleDestinations) {
- // Illiterating through the inventory items
- for (Item item : inventoryItems) {
- // Null check of the rectangle bounds
- if (r != null) {
- // Setting a easily visible colour
- g.setColor(Color.BLACK);
- // Drawing the rectangle bounds
- g.drawRect(r.x, r.y, r.width, r.height);
- }
- // Null check of the item and checking that the slot of item
- // is equal to r
- if (item != null
- && (inventory.getDestinationForSlot(inventory
- .getSlotForId(item.getId())).equals(r))) {
- // Setting to another easily visible colour
- g.setColor(Color.WHITE);
- // Constructing a font with bold text
- Font font = new Font(Font.SANS_SERIF, Font.PLAIN, 10);
- // Setting the font we just constructed
- g.setFont(font);
- // Null check of the item's name
- if (item.getName() != null) {
- // Drawing the text in the middle of the rectangle
- g.drawString("" + item.getName(), r.x
- + (r.width / 2), r.y + (r.height / 2));
- }
- // Checking if the item has an ID
- if (item.getId() != 0) {
- // Drawing the Item ID under the item name
- // - 8 on the x due to the font metrics
- g.drawString("" + item.getId(),
- r.x + (r.width / 2), r.y - 5
- + (r.height / 2) - 10);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement