BravoTaco Posted September 15, 2019 Share Posted September 15, 2019 (edited) This will paint all the loot that is on the screen and will condense same items together if the items are in the same loot pile. To Use, simply call Painter.paintGroundItems() in your onPaint() Method. It takes 4 parameters: Graphics2D Color - This will be the color of Tile Outline Color - This will be the color of the Loot Text Script Example Usage: Spoiler Painter.paintGroundItems(g, Color.orange, Color.magenta, this) Picture: Spoiler Code: Spoiler Painter.java Spoiler import org.osbot.rs07.api.map.Position; import org.osbot.rs07.api.model.GroundItem; import org.osbot.rs07.script.Script; import java.awt.*; public abstract class Painter { private static Font textFont = new Font("TimesNewRoman", Font.BOLD, 10); public static void paintGroundItems(Graphics2D g, Color tileOutlineColor, Color itemTextColor, Script script) { g.setFont(textFont); CustomGroundItemsList customGroundItemsList = new CustomGroundItemsList(); Position position = new Position(0, 0, 0); int currentY = 15; for (GroundItem groundItem : script.getGroundItems().getAll()) { if (groundItem.isOnScreen()) { Rectangle groundItemBounds = groundItem.getPosition().getPolygon(script.getBot()).getBounds(); Position groundItemPosition = groundItem.getPosition(); CustomGroundItem customGroundItem = new CustomGroundItem(groundItem.getName(), groundItemPosition, groundItem.getAmount(), currentY, groundItemBounds); if (position.equals(groundItem.getPosition()) && !customGroundItemsList.listContainsCustomGroundItem(customGroundItem)) { currentY += 15; customGroundItem.setYOffset(currentY); customGroundItemsList.add(customGroundItem); } else if (!position.equals(groundItem.getPosition()) && !customGroundItemsList.listContainsCustomGroundItem(customGroundItem)) { currentY = 15; customGroundItem.setYOffset(currentY); customGroundItemsList.add(customGroundItem); } else if (position.equals(groundItem.getPosition()) && customGroundItemsList.listContainsCustomGroundItem(customGroundItem)) { customGroundItem.setYOffset(currentY); customGroundItemsList.add(customGroundItem); } } position = groundItem.getPosition(); } for (CustomGroundItem customGroundItem : customGroundItemsList.getCustomGroundItems()) { g.setColor(tileOutlineColor); g.drawString(customGroundItem.toString(), customGroundItem.getBounds().x, customGroundItem.getBounds().y - customGroundItem.getYOffset()); g.setColor(itemTextColor); g.draw(customGroundItem.getPosition().getPolygon(script.getBot())); } } } CustomGroundItem.java Spoiler import org.osbot.rs07.api.map.Position; import java.awt.*; public class CustomGroundItem { private String name; private Position position; private int amount; private int yOffset; private Rectangle bounds; public CustomGroundItem(String name, Position position, int amount, int yOffset, Rectangle bounds) { this.name = name; this.position = position; this.amount = amount; this.yOffset = yOffset; this.bounds = bounds; } public boolean equals(CustomGroundItem customGroundItemToCompare) { return customGroundItemToCompare.getName().equals(this.getName()) && customGroundItemToCompare.getPosition().equals(this.getPosition()); } public Position getPosition() { return position; } public void addAmount(int amount) { this.amount += amount; } public int getAmount() { return amount; } public String getName() { return name; } public int getYOffset() { return yOffset; } public void setYOffset(int yOffset) { this.yOffset = yOffset; } public Rectangle getBounds() { return bounds; } @Override public String toString() { return this.name + " [" + this.amount + "]"; } } CustomGroundItemsList.java Spoiler import java.util.ArrayList; public class CustomGroundItemsList { private ArrayList<CustomGroundItem> customGroundItems; public CustomGroundItemsList() { this.customGroundItems = new ArrayList<>(); } public ArrayList<CustomGroundItem> getCustomGroundItems() { return customGroundItems; } public boolean listContainsCustomGroundItem(CustomGroundItem customGroundItemToCompare) { for (CustomGroundItem customGroundItem : customGroundItems) { if (customGroundItem.equals(customGroundItemToCompare)) { return true; } } return false; } public void add(CustomGroundItem customGroundItem) { boolean needsToLoop = true; boolean broke = false; int index = 0; while (needsToLoop) { for (int i = 0; i < customGroundItems.size(); i++) { if (customGroundItem.equals(customGroundItems.get(i))) { customGroundItem.addAmount(customGroundItems.get(i).getAmount()); customGroundItem.setYOffset(customGroundItems.get(i).getYOffset()); index = i; customGroundItems.remove(i); broke = true; break; } } if (!broke) { customGroundItems.add(index, customGroundItem); needsToLoop = false; } else { broke = false; } } } } Edited September 17, 2019 by BravoTaco Quote Link to comment Share on other sites More sharing options...
Heist Posted September 15, 2019 Share Posted September 15, 2019 Nice little snippet! Quote Link to comment Share on other sites More sharing options...
BravoTaco Posted September 15, 2019 Author Share Posted September 15, 2019 2 hours ago, Heist said: Nice little snippet! Thanks! If you find any problems or have any suggestions with it, let me know. Quote Link to comment Share on other sites More sharing options...
Czar Posted September 16, 2019 Share Posted September 16, 2019 Excellent job! Refreshing to see a utility snippet here ^^ Quote Link to comment Share on other sites More sharing options...