Search in sources :

Example 16 with Player

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;
}
Also used : Player(net.runelite.api.Player) LocalPoint(net.runelite.api.coords.LocalPoint) FontMetrics(java.awt.FontMetrics) Color(java.awt.Color) Rectangle(java.awt.Rectangle) LocalPoint(net.runelite.api.coords.LocalPoint) WorldPoint(net.runelite.api.coords.WorldPoint) Point(net.runelite.api.Point) LocalPoint(net.runelite.api.coords.LocalPoint) WorldPoint(net.runelite.api.coords.WorldPoint) Point(net.runelite.api.Point)

Example 17 with Player

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);
}
Also used : ItemLayer(net.runelite.api.ItemLayer) Item(net.runelite.api.Item) Player(net.runelite.api.Player) LocalPoint(net.runelite.api.coords.LocalPoint) Node(net.runelite.api.Node) Region(net.runelite.api.Region) Tile(net.runelite.api.Tile) LocalPoint(net.runelite.api.coords.LocalPoint)

Aggregations

Player (net.runelite.api.Player)17 Subscribe (com.google.common.eventbus.Subscribe)6 LocalPoint (net.runelite.api.coords.LocalPoint)6 Point (net.runelite.api.Point)4 Color (java.awt.Color)3 WorldPoint (net.runelite.api.coords.WorldPoint)3 FontMetrics (java.awt.FontMetrics)2 GameObject (net.runelite.api.GameObject)2 NPC (net.runelite.api.NPC)2 Region (net.runelite.api.Region)2 Tile (net.runelite.api.Tile)2 Inject (net.runelite.api.mixins.Inject)2 Inject (com.google.inject.Inject)1 Dimension (java.awt.Dimension)1 Graphics2D (java.awt.Graphics2D)1 Polygon (java.awt.Polygon)1 Rectangle (java.awt.Rectangle)1 Rectangle2D (java.awt.geom.Rectangle2D)1 IOException (java.io.IOException)1 Duration (java.time.Duration)1