Search in sources :

Example 16 with LocalPoint

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

the class PohOverlay method render.

@Override
public Dimension render(Graphics2D graphics) {
    LocalPoint localLocation = client.getLocalPlayer().getLocalLocation();
    plugin.getPohObjects().forEach((object, tile) -> {
        LocalPoint location = object.getLocalLocation();
        if (tile.getPlane() == client.getPlane() && localLocation.distanceTo(location) <= MAX_DISTANCE) {
            PohIcons icon = PohIcons.getIcon(object.getId());
            if (icon != null && iconList.contains(icon)) {
                net.runelite.api.Point minimapLoc = Perspective.getMiniMapImageLocation(client, object.getLocalLocation(), icon.getImage());
                if (minimapLoc != null) {
                    graphics.drawImage(icon.getImage(), minimapLoc.getX(), minimapLoc.getY(), null);
                }
            }
        }
    });
    return null;
}
Also used : LocalPoint(net.runelite.api.coords.LocalPoint)

Example 17 with LocalPoint

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

the class TitheFarmPlantOverlay method render.

@Override
public Dimension render(Graphics2D graphics) {
    Widget viewport = client.getViewportWidget();
    for (TitheFarmPlant plant : plugin.getPlants()) {
        LocalPoint localLocation = LocalPoint.fromWorld(client, plant.getWorldLocation());
        net.runelite.api.Point canvasLocation = Perspective.worldToCanvas(client, localLocation.getX(), localLocation.getY(), client.getPlane());
        if (viewport != null && localLocation != null) {
            switch(plant.getState()) {
                case UNWATERED:
                    drawTimerOnPlant(graphics, plant, canvasLocation, config.getColorUnwatered());
                    break;
                case WATERED:
                    drawTimerOnPlant(graphics, plant, canvasLocation, config.getColorWatered());
                    break;
                case GROWN:
                    drawTimerOnPlant(graphics, plant, canvasLocation, config.getColorGrown());
                    break;
            }
        }
    }
    return null;
}
Also used : LocalPoint(net.runelite.api.coords.LocalPoint) Widget(net.runelite.api.widgets.Widget)

Example 18 with LocalPoint

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

the class BarrowsOverlay method renderBarrowsBrothers.

private void renderBarrowsBrothers(Graphics2D graphics) {
    for (BarrowsBrothers brother : BarrowsBrothers.values()) {
        LocalPoint localLocation = LocalPoint.fromWorld(client, brother.getLocation());
        if (localLocation == null) {
            continue;
        }
        net.runelite.api.Point minimapText = Perspective.getCanvasTextMiniMapLocation(client, graphics, localLocation, brother.getName());
        if (minimapText != null) {
            graphics.setColor(Color.black);
            graphics.drawString(brother.getName(), minimapText.getX() + 1, minimapText.getY() + 1);
            graphics.setColor(Color.cyan);
            graphics.drawString(brother.getName(), minimapText.getX(), minimapText.getY());
        }
    }
}
Also used : LocalPoint(net.runelite.api.coords.LocalPoint)

Example 19 with LocalPoint

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

the class Perspective method getCanvasTextMiniMapLocation.

/**
 * Calculates text position and centers on minimap depending on string length.
 *
 * @param client
 * @param graphics
 * @param localLocation local location of the tile
 * @param text string for width measurement
 * @return a {@link Point} on screen corresponding to the given
 * localLocation.
 */
public static Point getCanvasTextMiniMapLocation(Client client, Graphics2D graphics, LocalPoint localLocation, String text) {
    Point p = Perspective.worldToMiniMap(client, localLocation.getX(), localLocation.getY());
    if (p == null) {
        return null;
    }
    FontMetrics fm = graphics.getFontMetrics();
    Rectangle2D bounds = fm.getStringBounds(text, graphics);
    int xOffset = p.getX() - (int) (bounds.getWidth() / 2);
    int yOffset = p.getY() - (int) (bounds.getHeight() / 2) + fm.getAscent();
    return new Point(xOffset, yOffset);
}
Also used : FontMetrics(java.awt.FontMetrics) Rectangle2D(java.awt.geom.Rectangle2D) LocalPoint(net.runelite.api.coords.LocalPoint) LocalPoint(net.runelite.api.coords.LocalPoint)

Example 20 with LocalPoint

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

the class Perspective method getCanvasSpriteLocation.

/**
 * Calculates sprite position and centers depending on sprite size.
 *
 * @param client
 * @param graphics
 * @param localLocation local location of the tile
 * @param sprite SpritePixel for size measurement
 * @param zOffset offset from ground plane
 * @return a {@link Point} on screen corresponding to the given
 * localLocation.
 */
public static Point getCanvasSpriteLocation(Client client, Graphics2D graphics, LocalPoint localLocation, SpritePixels sprite, int zOffset) {
    int plane = client.getPlane();
    Point p = Perspective.worldToCanvas(client, localLocation.getX(), localLocation.getY(), plane, zOffset);
    if (p == null) {
        return null;
    }
    int xOffset = p.getX() - sprite.getWidth() / 2;
    int yOffset = p.getY() - sprite.getHeight() / 2;
    return new Point(xOffset, yOffset);
}
Also used : LocalPoint(net.runelite.api.coords.LocalPoint) LocalPoint(net.runelite.api.coords.LocalPoint)

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