Add sprite drawing on actors
This commit is contained in:
@@ -56,5 +56,7 @@ public interface Actor extends Renderable
|
||||
|
||||
Point getCanvasImageLocation(Graphics2D graphics, BufferedImage image, int zOffset);
|
||||
|
||||
Point getCanvasSpriteLocation(Graphics2D graphics, SpritePixels sprite, int zOffset);
|
||||
|
||||
Point getMinimapLocation();
|
||||
}
|
||||
|
||||
@@ -307,4 +307,32 @@ public class Perspective
|
||||
return new Point(xOffset, yOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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, Point 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,4 +29,8 @@ public interface SpritePixels
|
||||
int DEFAULT_SHADOW_COLOR = 3153952;
|
||||
|
||||
void drawAt(int x, int y);
|
||||
|
||||
int getWidth();
|
||||
|
||||
int getHeight();
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.awt.image.BufferedImage;
|
||||
|
||||
import net.runelite.api.Actor;
|
||||
import net.runelite.api.Point;
|
||||
import net.runelite.api.SpritePixels;
|
||||
import net.runelite.api.TileObject;
|
||||
|
||||
|
||||
@@ -78,6 +79,14 @@ public class OverlayUtil
|
||||
graphics.drawImage(image, x, y, null);
|
||||
}
|
||||
|
||||
public static void renderSpriteLocation(Graphics2D graphics, Point imgLoc, SpritePixels sprite)
|
||||
{
|
||||
int x = imgLoc.getX();
|
||||
int y = imgLoc.getY();
|
||||
|
||||
sprite.drawAt(x, y);
|
||||
}
|
||||
|
||||
public static void renderActorOverlay(Graphics2D graphics, Actor actor, String text, Color color)
|
||||
{
|
||||
Polygon poly = actor.getCanvasTilePoly();
|
||||
@@ -120,6 +129,27 @@ public class OverlayUtil
|
||||
}
|
||||
}
|
||||
|
||||
public static void renderActorOverlaySprite(Graphics2D graphics, Actor actor, SpritePixels sprite, Color color)
|
||||
{
|
||||
Polygon poly = actor.getCanvasTilePoly();
|
||||
if (poly != null)
|
||||
{
|
||||
renderPolygon(graphics, poly, color);
|
||||
}
|
||||
|
||||
Point minimapLocation = actor.getMinimapLocation();
|
||||
if (minimapLocation != null)
|
||||
{
|
||||
renderMinimapLocation(graphics, minimapLocation, color);
|
||||
}
|
||||
|
||||
Point imageLocation = actor.getCanvasSpriteLocation(graphics, sprite, actor.getModelHeight());
|
||||
if (imageLocation != null)
|
||||
{
|
||||
renderSpriteLocation(graphics, imageLocation, sprite);
|
||||
}
|
||||
}
|
||||
|
||||
public static void renderTileOverlay(Graphics2D graphics, TileObject tileObject, String text, Color color)
|
||||
{
|
||||
Polygon poly = tileObject.getCanvasTilePoly();
|
||||
|
||||
@@ -32,6 +32,7 @@ import net.runelite.api.NPC;
|
||||
import net.runelite.api.Perspective;
|
||||
import net.runelite.api.Player;
|
||||
import net.runelite.api.Point;
|
||||
import net.runelite.api.SpritePixels;
|
||||
import net.runelite.api.mixins.Inject;
|
||||
import net.runelite.api.mixins.Mixin;
|
||||
import net.runelite.api.mixins.Shadow;
|
||||
@@ -143,6 +144,13 @@ public abstract class RSActorMixin implements RSActor
|
||||
return Perspective.getCanvasImageLocation(client, graphics, getLocalLocation(), image, zOffset);
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public Point getCanvasSpriteLocation(Graphics2D graphics, SpritePixels sprite, int zOffset)
|
||||
{
|
||||
return Perspective.getCanvasSpriteLocation(client, graphics, getLocalLocation(), sprite, zOffset);
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public Point getMinimapLocation()
|
||||
|
||||
@@ -32,4 +32,12 @@ public interface RSSpritePixels extends SpritePixels
|
||||
@Import("drawAt")
|
||||
@Override
|
||||
void drawAt(int x, int y);
|
||||
|
||||
@Import("height")
|
||||
@Override
|
||||
int getHeight();
|
||||
|
||||
@Import("width")
|
||||
@Override
|
||||
int getWidth();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user