Search in sources :

Example 31 with LocalPoint

use of net.runelite.api.coords.LocalPoint 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 32 with LocalPoint

use of net.runelite.api.coords.LocalPoint 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)

Example 33 with LocalPoint

use of net.runelite.api.coords.LocalPoint in project runelite by runelite.

the class CannonSpotOverlay method renderCannonSpot.

private void renderCannonSpot(Graphics2D graphics, Client client, LocalPoint point, BufferedImage image, Color color) {
    // Render tile
    Polygon poly = Perspective.getCanvasTilePoly(client, point);
    if (poly != null) {
        OverlayUtil.renderPolygon(graphics, poly, color);
    }
    // Render icon
    Point imageLoc = Perspective.getCanvasImageLocation(client, graphics, point, image, 0);
    if (imageLoc != null) {
        OverlayUtil.renderImageLocation(graphics, imageLoc, image);
    }
}
Also used : LocalPoint(net.runelite.api.coords.LocalPoint) WorldPoint(net.runelite.api.coords.WorldPoint) Point(net.runelite.api.Point) Polygon(java.awt.Polygon)

Aggregations

LocalPoint (net.runelite.api.coords.LocalPoint)33 Point (net.runelite.api.Point)8 Polygon (java.awt.Polygon)7 Color (java.awt.Color)5 WorldPoint (net.runelite.api.coords.WorldPoint)5 FontMetrics (java.awt.FontMetrics)4 GameObject (net.runelite.api.GameObject)4 Rectangle2D (java.awt.geom.Rectangle2D)3 Player (net.runelite.api.Player)3 Tile (net.runelite.api.Tile)3 Area (java.awt.geom.Area)2 Region (net.runelite.api.Region)2 ProgressPie (net.runelite.client.ui.overlay.components.ProgressPie)2 Subscribe (com.google.common.eventbus.Subscribe)1 Inject (com.google.inject.Inject)1 Dimension (java.awt.Dimension)1 Graphics2D (java.awt.Graphics2D)1 Rectangle (java.awt.Rectangle)1 Instant (java.time.Instant)1 HashMap (java.util.HashMap)1