Search in sources :

Example 26 with Point

use of net.runelite.api.Point 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 27 with Point

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

Example 28 with Point

use of net.runelite.api.Point in project runelite by runelite.

the class GrandExchangePlugin method startUp.

@Override
protected void startUp() throws IOException {
    panel = injector.getInstance(GrandExchangePanel.class);
    BufferedImage icon;
    synchronized (ImageIO.class) {
        icon = ImageIO.read(getClass().getResourceAsStream("ge_icon.png"));
    }
    button = NavigationButton.builder().name("GE Offers").icon(icon).panel(panel).build();
    pluginToolbar.addNavigation(button);
    itemClick = new MouseListener() {

        @Override
        public MouseEvent mouseClicked(MouseEvent e) {
            // Check if left click + alt
            if (e.getButton() == MouseEvent.BUTTON1 && e.isAltDown()) {
                Point mousePosition = client.getMouseCanvasPosition();
                Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY);
                if (inventoryWidget != null && !inventoryWidget.isHidden()) {
                    for (WidgetItem item : inventoryWidget.getWidgetItems()) {
                        if (item.getCanvasBounds().contains(mousePosition.getX(), mousePosition.getY())) {
                            ItemComposition itemComp = client.getItemDefinition(item.getId());
                            if (itemComp != null) {
                                e.consume();
                                SwingUtilities.invokeLater(() -> {
                                    panel.showSearch();
                                    if (!button.isSelected()) {
                                        button.getOnSelect().run();
                                    }
                                    panel.getSearchPanel().priceLookup(itemComp.getName());
                                });
                            }
                            break;
                        }
                    }
                }
            }
            return super.mouseClicked(e);
        }
    };
    if (config.quickLookup()) {
        mouseManager.registerMouseListener(itemClick);
    }
}
Also used : MouseListener(net.runelite.client.input.MouseListener) MouseEvent(java.awt.event.MouseEvent) Widget(net.runelite.api.widgets.Widget) ItemComposition(net.runelite.api.ItemComposition) WidgetItem(net.runelite.api.widgets.WidgetItem) Point(net.runelite.api.Point) BufferedImage(java.awt.image.BufferedImage) ImageIO(javax.imageio.ImageIO)

Aggregations

Point (net.runelite.api.Point)28 LocalPoint (net.runelite.api.coords.LocalPoint)12 Polygon (java.awt.Polygon)9 Color (java.awt.Color)6 BufferedImage (java.awt.image.BufferedImage)5 Inject (net.runelite.api.mixins.Inject)4 FontMetrics (java.awt.FontMetrics)3 Rectangle (java.awt.Rectangle)3 Area (java.awt.geom.Area)3 ArrayList (java.util.ArrayList)3 WorldPoint (net.runelite.api.coords.WorldPoint)3 WidgetItem (net.runelite.api.widgets.WidgetItem)3 ImageIO (javax.imageio.ImageIO)2 Player (net.runelite.api.Player)2 Vertex (net.runelite.api.model.Vertex)2 Test (org.junit.Test)2 Inject (com.google.inject.Inject)1 Dimension (java.awt.Dimension)1 Graphics (java.awt.Graphics)1 Graphics2D (java.awt.Graphics2D)1