use of net.runelite.api.Player in project runelite by runelite.
the class GroundItemsOverlay method render.
@Override
public Dimension render(Graphics2D graphics) {
final FontMetrics fm = graphics.getFontMetrics();
final Player player = client.getLocalPlayer();
if (player == null || client.getViewportWidget() == null) {
return null;
}
plugin.checkItems();
offsetMap.clear();
final LocalPoint localLocation = player.getLocalLocation();
for (GroundItem item : plugin.getCollectedGroundItems().values()) {
final LocalPoint groundPoint = LocalPoint.fromWorld(client, item.getLocation());
if (groundPoint == null || localLocation.distanceTo(groundPoint) > MAX_DISTANCE) {
continue;
}
final boolean highlighted = plugin.isHighlighted(item.getName());
if (!plugin.isHotKeyPressed() && !highlighted && ((item.getGePrice() > 0 && item.getGePrice() < config.getHideUnderGeValue()) || item.getHaPrice() < config.getHideUnderHAValue())) {
continue;
}
final boolean hidden = plugin.isHidden(item.getName());
final Color color = getCostColor(item.getGePrice() > 0 ? item.getGePrice() : item.getHaPrice(), highlighted, hidden);
itemStringBuilder.append(item.getName());
if (item.getQuantity() > 1) {
if (item.getQuantity() >= MAX_QUANTITY) {
itemStringBuilder.append(" (Lots!)");
} else {
itemStringBuilder.append(" (").append(item.getQuantity()).append(")");
}
}
if (config.showGEPrice() && item.getGePrice() > 0) {
itemStringBuilder.append(" (EX: ").append(StackFormatter.quantityToStackSize(item.getGePrice())).append(" gp)");
}
if (config.showHAValue() && item.getHaPrice() > 0) {
itemStringBuilder.append(" (HA: ").append(StackFormatter.quantityToStackSize(item.getHaPrice())).append(" gp)");
}
final String itemString = itemStringBuilder.toString();
itemStringBuilder.setLength(0);
final Point textPoint = Perspective.getCanvasTextLocation(client, graphics, groundPoint, itemString, OFFSET_Z);
if (textPoint == null) {
continue;
}
final int offset = offsetMap.compute(item.getLocation(), (k, v) -> v != null ? v + 1 : 0);
final int textX = textPoint.getX();
final int textY = textPoint.getY() - (STRING_GAP * offset);
textComponent.setText(itemString);
textComponent.setColor(color);
textComponent.setPosition(new java.awt.Point(textX, textY));
textComponent.render(graphics);
if (plugin.isHotKeyPressed()) {
final int stringWidth = fm.stringWidth(itemString);
final int stringHeight = fm.getHeight();
final int descent = fm.getDescent();
// Hidden box
final Rectangle itemHiddenBox = new Rectangle(textX + stringWidth, textY - (stringHeight / 2) - descent, RECTANGLE_SIZE, stringHeight / 2);
plugin.getHiddenBoxes().put(itemHiddenBox, item.getName());
// Highlight box
final Rectangle itemHighlightBox = new Rectangle(textX + stringWidth + RECTANGLE_SIZE + 2, textY - (stringHeight / 2) - descent, RECTANGLE_SIZE, stringHeight / 2);
plugin.getHighlightBoxes().put(itemHighlightBox, item.getName());
final Point mousePos = client.getMouseCanvasPosition();
boolean mouseInHiddenBox = itemHiddenBox.contains(mousePos.getX(), mousePos.getY());
boolean mouseInHighlightBox = itemHighlightBox.contains(mousePos.getX(), mousePos.getY());
// Draw hidden box
drawRectangle(graphics, itemHiddenBox, mouseInHiddenBox ? Color.RED : color, hidden, true);
// Draw highlight box
drawRectangle(graphics, itemHighlightBox, mouseInHighlightBox ? Color.GREEN : color, highlighted, false);
}
}
return null;
}
use of net.runelite.api.Player in project runelite by runelite.
the class GroundItemsPlugin method checkItems.
void checkItems() {
final Player player = client.getLocalPlayer();
if (!dirty || player == null || client.getViewportWidget() == null) {
return;
}
dirty = false;
final Region region = client.getRegion();
final Tile[][][] tiles = region.getTiles();
final int z = client.getPlane();
final LocalPoint from = player.getLocalLocation();
final int lowerX = Math.max(0, from.getRegionX() - MAX_RANGE);
final int lowerY = Math.max(0, from.getRegionY() - MAX_RANGE);
final int upperX = Math.min(from.getRegionX() + MAX_RANGE, REGION_SIZE - 1);
final int upperY = Math.min(from.getRegionY() + MAX_RANGE, REGION_SIZE - 1);
groundItems.clear();
for (int x = lowerX; x <= upperX; ++x) {
for (int y = lowerY; y <= upperY; ++y) {
Tile tile = tiles[z][x][y];
if (tile == null) {
continue;
}
ItemLayer itemLayer = tile.getItemLayer();
if (itemLayer == null) {
continue;
}
Node current = itemLayer.getBottom();
// adds the items on the ground to the ArrayList to be drawn
while (current instanceof Item) {
final Item item = (Item) current;
// Continue iteration
current = current.getNext();
// Build ground item
final GroundItem groundItem = buildGroundItem(tile, item);
if (groundItem != null) {
groundItems.add(groundItem);
}
}
}
}
// Group ground items together and sort them properly
collectedGroundItems.clear();
Lists.reverse(groundItems).stream().collect(groundItemMapCollector);
}
Aggregations