Search in sources :

Example 21 with Point

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

the class RSWidgetMixin method getWidgetItem.

@Inject
@Override
public WidgetItem getWidgetItem(int index) {
    int[] itemIds = getItemIds();
    int[] itemQuantities = getItemQuantities();
    if (itemIds == null || itemQuantities == null) {
        return null;
    }
    // the number of item slot columns is stored here
    int columns = getWidth();
    int paddingX = getPaddingX();
    int paddingY = getPaddingY();
    int itemId = itemIds[index];
    int itemQuantity = itemQuantities[index];
    Point widgetCanvasLocation = getCanvasLocation();
    if (itemId <= 0 || itemQuantity <= 0 || columns <= 0) {
        return null;
    }
    int row = index / columns;
    int col = index % columns;
    int itemX = widgetCanvasLocation.getX() + ((ITEM_SLOT_SIZE + paddingX) * col);
    int itemY = widgetCanvasLocation.getY() + ((ITEM_SLOT_SIZE + paddingY) * row);
    Rectangle bounds = new Rectangle(itemX - 1, itemY - 1, ITEM_SLOT_SIZE, ITEM_SLOT_SIZE);
    return new WidgetItem(itemId - 1, itemQuantity, index, bounds);
}
Also used : Rectangle(java.awt.Rectangle) WidgetItem(net.runelite.api.widgets.WidgetItem) Point(net.runelite.api.Point) Point(net.runelite.api.Point) Inject(net.runelite.api.mixins.Inject)

Example 22 with Point

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

the class JarvisTest method test.

@Test
public void test() {
    Point[] points = { new Point(0, 3), new Point(1, 1), new Point(2, 2), new Point(4, 4), new Point(0, 0), new Point(1, 2), new Point(3, 1), new Point(3, 3) };
    List<Point> result = Jarvis.convexHull(Arrays.asList(points));
    Assert.assertEquals(4, result.size());
    Assert.assertEquals(new Point(0, 0), result.get(0));
    Assert.assertEquals(new Point(0, 3), result.get(1));
    Assert.assertEquals(new Point(4, 4), result.get(2));
    Assert.assertEquals(new Point(3, 1), result.get(3));
}
Also used : Point(net.runelite.api.Point) Test(org.junit.Test)

Example 23 with Point

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

the class Jarvis method convexHull.

/**
 * compute the convex hull of a given set of points
 *
 * @param points
 * @return
 */
public static List<Point> convexHull(List<Point> points) {
    if (points.size() < 3) {
        return null;
    }
    List<Point> ch = new ArrayList<>();
    // find the left most point
    Point left = findLeftMost(points);
    // current point we are on
    Point current = left;
    do {
        ch.add(current);
        // the next point - all points are to the right of the
        // line between current and next
        Point next = null;
        for (Point p : points) {
            if (next == null) {
                next = p;
                continue;
            }
            int cp = crossProduct(current, p, next);
            if (cp > 0 || (cp == 0 && current.distanceTo(p) > current.distanceTo(next))) {
                next = p;
            }
        }
        // Points can be null if they are behind or very close to the camera.
        if (next == null) {
            return null;
        }
        assert ch.size() <= points.size() : "hull has more points than graph";
        current = next;
    } while (current != left);
    return ch;
}
Also used : ArrayList(java.util.ArrayList) Point(net.runelite.api.Point) Point(net.runelite.api.Point)

Example 24 with Point

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

the class ImplingsOverlay method drawImp.

private void drawImp(Graphics2D graphics, Actor actor, String text, Color color) {
    Polygon poly = actor.getCanvasTilePoly();
    if (poly != null) {
        OverlayUtil.renderPolygon(graphics, poly, color);
    }
    Point textLocation = actor.getCanvasTextLocation(graphics, text, actor.getLogicalHeight());
    if (textLocation != null) {
        OverlayUtil.renderTextLocation(graphics, textLocation, text, color);
    }
}
Also used : Point(net.runelite.api.Point) Polygon(java.awt.Polygon)

Example 25 with Point

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

the class KourendLibraryOverlay method render.

@Override
public Dimension render(Graphics2D g) {
    Player player = client.getLocalPlayer();
    if (player == null) {
        return null;
    }
    WorldPoint playerLoc = player.getWorldLocation();
    if (playerLoc.distanceTo2D(LIBRARY_CENTER) > ROUGH_ENABLE_DISTANCE) {
        return null;
    }
    List<Bookcase> allBookcases = library.getBookcasesOnLevel(client.getPlane());
    if (allBookcases == null) {
        return null;
    }
    for (Bookcase bookcase : allBookcases) {
        // AABB
        WorldPoint caseLoc = bookcase.getLocation();
        if (Math.abs(playerLoc.getX() - caseLoc.getX()) > MAXIMUM_DISTANCE || Math.abs(playerLoc.getY() - caseLoc.getY()) > MAXIMUM_DISTANCE) {
            continue;
        }
        LocalPoint localBookcase = LocalPoint.fromWorld(client, caseLoc);
        if (localBookcase == null) {
            continue;
        }
        Point screenBookcase = Perspective.worldToCanvas(client, localBookcase.getX(), localBookcase.getY(), caseLoc.getPlane(), 25);
        if (screenBookcase != null) {
            boolean bookIsKnown = bookcase.isBookSet();
            Book book = bookcase.getBook();
            Set<Book> possible = bookcase.getPossibleBooks();
            if (bookIsKnown && book == null) {
                for (Book b : possible) {
                    if (b != null && b.isDarkManuscript()) {
                        book = b;
                        break;
                    }
                }
            }
            if (!bookIsKnown && possible.size() == 1) {
                book = possible.iterator().next();
                bookIsKnown = true;
            }
            Color color = bookIsKnown ? Color.ORANGE : Color.WHITE;
            // Render the poly on the floor
            if (!(bookIsKnown && book == null) && (library.getState() == SolvedState.NO_DATA || book != null || possible.size() > 0)) {
                Polygon poly = getCanvasTilePoly(client, localBookcase);
                if (poly != null) {
                    OverlayUtil.renderPolygon(g, poly, color);
                }
            }
            int height = 0;
            // If the book is singled out, render the text and the book's icon
            if (bookIsKnown) {
                if (book != null) {
                    FontMetrics fm = g.getFontMetrics();
                    Rectangle2D bounds = fm.getStringBounds(book.getShortName(), g);
                    height = (int) bounds.getHeight() + book.getIcon().getHeight() + 6;
                    Point textLoc = new Point((int) (screenBookcase.getX() - (bounds.getWidth() / 2)), screenBookcase.getY() - (height / 2) + (int) bounds.getHeight());
                    OverlayUtil.renderTextLocation(g, textLoc, book.getShortName(), color);
                    g.drawImage(book.getIcon(), screenBookcase.getX() - (book.getIcon().getWidth() / 2), screenBookcase.getY() + (height / 2) - book.getIcon().getHeight(), null);
                }
            } else {
                // otherwise render up to 9 icons of the possible books in the bookcase in a square
                final int BOOK_ICON_SIZE = 32;
                Book[] books = possible.stream().filter(Objects::nonNull).limit(9).toArray(Book[]::new);
                if (books.length > 1 && books.length <= 9) {
                    int cols = (int) Math.ceil(Math.sqrt(books.length));
                    int rows = (int) Math.ceil((double) books.length / cols);
                    height = rows * BOOK_ICON_SIZE;
                    int xbase = screenBookcase.getX() - ((cols * BOOK_ICON_SIZE) / 2);
                    int ybase = screenBookcase.getY() - rows * BOOK_ICON_SIZE / 2;
                    for (int i = 0; i < books.length; i++) {
                        int col = i % cols;
                        int row = i / cols;
                        int x = col * BOOK_ICON_SIZE;
                        int y = row * BOOK_ICON_SIZE;
                        if (row == rows - 1) {
                            x += (BOOK_ICON_SIZE * (books.length % rows)) / 2;
                        }
                        g.drawImage(books[i].getIcon(), xbase + x, ybase + y, null);
                    }
                }
            }
            // Draw the bookcase's ID on top
            if (KourendLibraryPlugin.debug) {
                FontMetrics fm = g.getFontMetrics();
                String str = bookcase.getIndex().stream().map(Object::toString).collect(Collectors.joining(", "));
                Rectangle2D bounds = fm.getStringBounds(str, g);
                Point textLoc = new Point((int) (screenBookcase.getX() - (bounds.getWidth() / 2)), screenBookcase.getY() - (height / 2));
                OverlayUtil.renderTextLocation(g, textLoc, str, Color.WHITE);
            }
        }
    }
    // Render the customer's wanted book on their head and a poly under their feet
    LibraryCustomer customer = library.getCustomer();
    if (customer != null) {
        client.getNpcs().stream().filter(n -> n.getId() == customer.getId()).forEach(n -> {
            Book b = library.getCustomerBook();
            LocalPoint local = n.getLocalLocation();
            Polygon poly = getCanvasTilePoly(client, local);
            OverlayUtil.renderPolygon(g, poly, Color.WHITE);
            Point screen = Perspective.worldToCanvas(client, local.getX(), local.getY(), client.getPlane(), n.getLogicalHeight());
            if (screen != null) {
                g.drawImage(b.getIcon(), screen.getX() - (b.getIcon().getWidth() / 2), screen.getY() - b.getIcon().getHeight(), null);
            }
        });
    }
    return null;
}
Also used : Color(java.awt.Color) Polygon(java.awt.Polygon) LocalPoint(net.runelite.api.coords.LocalPoint) WorldPoint(net.runelite.api.coords.WorldPoint) OverlayLayer(net.runelite.client.ui.overlay.OverlayLayer) OverlayUtil(net.runelite.client.ui.overlay.OverlayUtil) Inject(com.google.inject.Inject) Rectangle2D(java.awt.geom.Rectangle2D) Set(java.util.Set) Player(net.runelite.api.Player) Point(net.runelite.api.Point) Client(net.runelite.api.Client) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Dimension(java.awt.Dimension) List(java.util.List) Perspective(net.runelite.api.Perspective) FontMetrics(java.awt.FontMetrics) Graphics2D(java.awt.Graphics2D) Overlay(net.runelite.client.ui.overlay.Overlay) OverlayPosition(net.runelite.client.ui.overlay.OverlayPosition) Perspective.getCanvasTilePoly(net.runelite.api.Perspective.getCanvasTilePoly) Player(net.runelite.api.Player) Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) 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) LocalPoint(net.runelite.api.coords.LocalPoint) WorldPoint(net.runelite.api.coords.WorldPoint) FontMetrics(java.awt.FontMetrics) Objects(java.util.Objects) Polygon(java.awt.Polygon)

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