/** * 2D & 3D projected overlay rendering utilities for plugins and scripts. * Renders directly into the current DrawingArea buffer. */ public class PluginGraphics { private final Game game; public PluginGraphics(Game game) { this.game = game; } public int getViewportWidth() { return DrawingArea.width; } public int getViewportHeight() { return DrawingArea.height; } public void fillRect(int x, int y, int w, int h, int rgb, int alpha) { if (alpha >= 255) { DrawingArea.fillArea(h, y, rgb, w, x); } else if (alpha > 0) { DrawingArea.fillArea(rgb, y, w, h, alpha, x); } } public void drawRect(int x, int y, int w, int h, int rgb) { DrawingArea.fillPixels(y, h, rgb, x, w); } public void drawHorizontalLine(int x, int y, int length, int rgb) { DrawingArea.drawHorizontalLine(y, rgb, length, x); } public void drawVerticalLine(int x, int y, int length, int rgb) { DrawingArea.drawVerticalLine(y, rgb, length, x); } /** * Draws a RuneLite-style RS translucent panel with border and optional header. */ public void drawPanel(int x, int y, int w, int h, String title) { // Dark translucent background fillRect(x, y, w, h, 0x121212, 190); // Outer dark stone border drawRect(x, y, w, h, 0x5a5243); drawRect(x + 1, y + 1, w - 2, h - 2, 0x2b271f); if (title != null && !title.isEmpty()) { fillRect(x + 2, y + 2, w - 4, 18, 0x2b271f, 220); drawHorizontalLine(x + 1, y + 20, w - 2, 0x5a5243); if (game.aTextDrawingArea_1271 != null) { game.aTextDrawingArea_1271.textLeft(RSColors.WHITE_DARKER, title, y + 15, x + 6); } } } public void drawString(String text, int x, int y, int rgb, boolean shadow) { if (text == null || text.isEmpty() || game == null) return; TextDrawingArea font = game.aTextDrawingArea_1270 != null ? game.aTextDrawingArea_1270 : game.aTextDrawingArea_1271; if (font != null) { if (shadow) { font.textLeftShadow(true, x, rgb, text, y); } else { font.textLeft(rgb, text, y, x); } } } public void drawStringBold(String text, int x, int y, int rgb, boolean shadow) { if (text == null || text.isEmpty() || game == null) return; TextDrawingArea font = game.aTextDrawingArea_1271 != null ? game.aTextDrawingArea_1271 : game.aTextDrawingArea_1270; if (font != null) { if (shadow) { font.textLeftShadow(true, x, rgb, text, y); } else { font.textLeft(rgb, text, y, x); } } } public void drawCenteredString(String text, int x, int y, int rgb) { drawCenteredString(text, x, y, rgb, 255); } public void drawCenteredString(String text, int x, int y, int rgb, int alpha) { if (text == null || text.isEmpty() || game == null || alpha <= 0) return; TextDrawingArea font = game.aTextDrawingArea_1270 != null ? game.aTextDrawingArea_1270 : game.aTextDrawingArea_1271; if (font != null) { if (alpha >= 255) { font.textCenter(rgb, text, y, x); } else { font.textCenterAlpha(rgb, text, y, x, alpha, false); } } } public void drawRightString(String text, int rightX, int y, int rgb) { if (text == null || text.isEmpty() || game == null) return; TextDrawingArea font = game.aTextDrawingArea_1270 != null ? game.aTextDrawingArea_1270 : game.aTextDrawingArea_1271; if (font != null) { font.textRight(rgb, text, y, rightX); } } public int getTextWidth(String text) { if (text == null || text.isEmpty()) return 0; if (game == null) return text.length() * 6; TextDrawingArea font = game.aTextDrawingArea_1270 != null ? game.aTextDrawingArea_1270 : game.aTextDrawingArea_1271; return font != null ? font.getTextWidth(text) : text.length() * 6; } public int getTextWidthBold(String text) { if (text == null || text.isEmpty()) return 0; if (game == null) return text.length() * 7; TextDrawingArea font = game.aTextDrawingArea_1271 != null ? game.aTextDrawingArea_1271 : game.aTextDrawingArea_1270; return font != null ? font.getTextWidth(text) : text.length() * 7; } public void drawStringTruncated(String text, int x, int y, int maxWidth, int rgb, boolean shadow) { if (text == null || text.isEmpty() || maxWidth <= 0) return; if (getTextWidth(text) <= maxWidth) { drawString(text, x, y, rgb, shadow); return; } String ellipsis = "..."; int ellipsisW = getTextWidth(ellipsis); if (maxWidth <= ellipsisW) return; int targetW = maxWidth - ellipsisW; int len = text.length(); while (len > 0 && getTextWidth(text.substring(0, len)) > targetW) { len--; } if (len > 0) { drawString(text.substring(0, len).trim() + ellipsis, x, y, rgb, shadow); } } public void drawStringBoldTruncated(String text, int x, int y, int maxWidth, int rgb, boolean shadow) { if (text == null || text.isEmpty() || maxWidth <= 0) return; if (getTextWidthBold(text) <= maxWidth) { drawStringBold(text, x, y, rgb, shadow); return; } String ellipsis = "..."; int ellipsisW = getTextWidthBold(ellipsis); if (maxWidth <= ellipsisW) return; int targetW = maxWidth - ellipsisW; int len = text.length(); while (len > 0 && getTextWidthBold(text.substring(0, len)) > targetW) { len--; } if (len > 0) { drawStringBold(text.substring(0, len).trim() + ellipsis, x, y, rgb, shadow); } } /** * Projects world coordinate to screen (viewport) coordinate. * @return int[] {screenX, screenY} or null if not on screen. */ public int[] worldToScreen(int worldX, int worldY, int heightOffset) { int localX = worldX - game.baseX; int localY = worldY - game.baseY; if (localX < 0 || localX >= 104 || localY < 0 || localY >= 104) { return null; } int sceneX = localX * 128 + 64; int sceneY = localY * 128 + 64; game.calcEntityScreenPos(sceneX, heightOffset, sceneY); if (game.spriteDrawX < 0 || game.spriteDrawY < 0) { return null; } return new int[]{game.spriteDrawX, game.spriteDrawY}; } /** * Draws a tile highlight marker and label in the 3D world. */ public void drawTileOverlay(int worldX, int worldY, int rgb, String label) { int[] center = worldToScreen(worldX, worldY, 0); if (center == null) return; // Draw cross/diamond at tile center int cx = center[0]; int cy = center[1]; drawHorizontalLine(cx - 5, cy, 11, rgb); drawVerticalLine(cx, cy - 5, 11, rgb); if (label != null && !label.isEmpty()) { int w = getTextWidth(label); fillRect(cx - (w / 2) - 3, cy - 16, w + 6, 12, 0x000000, 160); drawCenteredString(label, cx, cy - 7, rgb); } } /** * Draws a vertical radiant lootbeam rising from the ground tile into the sky. */ public void drawLootbeam(int worldX, int worldY, int rgb) { int[] ground = worldToScreen(worldX, worldY, 0); int[] sky = worldToScreen(worldX, worldY, 160); if (ground == null || sky == null) return; int gx = ground[0]; int gy = ground[1]; int sy = sky[1]; if (gy <= sy) return; int height = gy - sy; // Outer radiant glow fillRect(gx - 2, sy, 5, height, rgb, 90); // Inner intense beam fillRect(gx - 1, sy, 3, height, rgb, 180); fillRect(gx, sy, 1, height, 0xffffff, 240); // Ground target highlight drawHorizontalLine(gx - 6, gy, 13, rgb); drawVerticalLine(gx, gy - 6, 13, rgb); drawHorizontalLine(gx - 3, gy + 1, 7, rgb); } /** * Renders a list of world {x, y} path tiles as step markers on screen. */ public void drawPathOverlay(java.util.List path, int rgb) { if (path == null || path.isEmpty()) return; for (int i = 0; i < path.size(); i++) { int[] tile = path.get(i); if (tile == null || tile.length < 2) continue; String label = (i == path.size() - 1) ? "Goal" : null; drawTileOverlay(tile[0], tile[1], rgb, label); } } /** * Renders the four corners and center label of a WorldArea in the 3D viewport. */ public void drawAreaOverlay(PluginContext.WorldArea area, int rgb, String label) { if (area == null) return; drawTileOverlay(area.minX, area.minY, rgb, null); drawTileOverlay(area.maxX, area.minY, rgb, null); drawTileOverlay(area.minX, area.maxY, rgb, null); drawTileOverlay(area.maxX, area.maxY, rgb, null); if (label != null && !label.isEmpty()) { drawTileOverlay(area.centerX(), area.centerY(), rgb, label); } } }