* fix(audio,client): start music immediately on login/track change and remove non-HD tooltip jitter Eliminates artificial client-side music start and fade-out delays across all platforms, prioritizes music packets at the start of server login, and replaces jittery non-HD hover tooltips in Game.java. ### Core & Client Rendering - 2006Scape Client/src/main/java/Game.java: - Updated method49() to call method853(musicVolume2, is, aBoolean995) directly on all platforms instead of routing through method684/method899 fade-out queues. - Reset anInt720 to 0 in constructMusic(), method853(), and method368() when stopped so the initial track and post-login music start without a 20-tick (~400ms) delay. - Replaced the non-HD chatTextDrawingArea.method390(..., loopCycle / 1000, ...) fallback with chatTextDrawingArea.textLeftShadow(...) so Walk here and hover tooltips render crisply with HD disabled. ### Server Login Audio - 2006Scape Server/src/main/java/com/rs2/net/PacketSender.java: - Moved music/sound volume configs (168, 169), player.getPlayList().sendMusicConfigs(), and Music.playMusic(player) to run right after frame 249 and duplicate-login checks in loginPlayer(), flushing the login song before quest, skill, sidebar, and equipment packets. * refactor(ui): use ClientSettings.SERVER_NAME in Plugin Hub modal title Replaces the hardcoded RUNELITE prefix in the Plugin Hub modal header with ClientSettings.SERVER_NAME so the UI branding stays consistent with the configured server name. ### UI & Styling - 2006Scape Client/src/main/java/PluginPanelUI.java: - Updated drawViewportModal title formatting to use ClientSettings.SERVER_NAME + " PLUGIN & SCRIPT HUB" (and " PLUGIN HUB" when scripts are unavailable). * feat(client): migrate Ground Items and Menu Entry Swapper plugins to online repository Removes the built-in `GroundItemsOverlayPlugin` and `MenuEntrySwapperPlugin` classes from the client bundle so players install them manually from the Online Repo tab (`2006scape-plugins`), and adds minimal `ScriptInterpreter`, `PluginContext`, and `PluginGraphics` host support so both plugins run natively in the interpreted plugin dialect. ### Plugin Host Infrastructure - `ScriptInterpreter.java`: - Added `@defaultEnabled` metadata parsing (`ScriptMetadata.defaultEnabled`) and overrode `InterpretedPlugin.isEnabledByDefault()`. - Registered `MenuEntry.class` in `compile(String)` so interpreted plugins can invoke `MenuEntry.stripColorTags(...)` and menu entry helpers. - Overrode `InterpretedPlugin.onCommand(String, String[])` to forward chat commands (`command`, joined `args`) to interpreted plugins. - `PluginContext.java`: - Added `createList()` and `createMap()` collection helpers for interpreted plugins. - `PluginGraphics.java`: - Added `worldToScreenList(int, int, int)` returning a 2-element `List<Integer>` for array-free coordinate projection. ### Cleanups & Deprecations - `PluginManager.java`: - Removed `MenuEntrySwapperPlugin` and `GroundItemsOverlayPlugin` registrations from `registerBuiltIns()`, leaving `Hd317Plugin`. - `MenuEntrySwapperPlugin.java`, `GroundItemsOverlayPlugin.java`: - Removed built-in plugin classes (migrated to `2006scape-plugins/plugins/MenuEntrySwapper.java` and `GroundItems.java`). * perf(plugins): optimize ScriptInterpreter/PluginContext and fix Web Online Repo SHA lookup Improve script/plugin execution speed for TeaVM/Web and Desktop/Android, add throttled in-game chat error reporting, and fix Online Repo commit SHA resolution on Web. ### Script & Plugin Engine - `PluginContext.java` - Added `getGroundItems(int radius)` to scan only `[plx - radius, plx + radius]` x `[ply - radius, ply + radius]` instead of the full 104x104 tile grid, with a `game == null` fallback to `getGroundItems()` for unit test mocks. - `ScriptInterpreter.java` - Pre-parsed `FunctionDef` bodies into `List<Stmt>` (`parseBlock`, `parseIfStatement`, `parseSimpleStatement`) at compile time, removing per-execution substring scanning in `executeStmts`. - Added `METHOD_CACHE` (`getCachedMethods`) to index public methods by lowercase name per `Class<?>`, eliminating repeated `clazz.getMethods()` scans in `invokeReflectiveMethod`. - Added `Environment.reportedErrors` and `reportRuntimeError` to surface the first uncaught runtime error per function to in-game chat. - `PluginManager.java` - Added `reportedPluginErrors` (cleared on `reloadExternal()`) and `reportPluginError` across `onGameTick`, `onPostBuildMenu`, and `onRenderOverlays` to surface the first error per plugin/phase to in-game chat. ### Online Repository - `PluginRepoClient.java` - Added `REPO_COMMIT_API_URL` using `PLUGIN_REPO_SLUG` (`2006-Scape/Client-Extensions`) and `PLUGIN_REPO_BRANCH` (`main`) as a CORS-friendly fallback in `resolveLatestMainSha()` when `.git/info/refs` is unavailable in the browser. * perf(graphics): add native drawTileLabelBatches for ground item overlays Move per-frame ground item tile and label rendering loops from interpreted script execution into compiled Java on `PluginGraphics` to eliminate per-frame TeaVM reflection and AST overhead. ### Graphics Pipeline - `PluginGraphics.java` - Added `drawTileLabelBatches(List<?>, int, int)` to project cached tile coordinates (`worldToScreen` with `worldToScreenList` fallback for unit test mocks), lazily cache `getTextWidth`, render lootbeams, and draw label boxes/text in compiled Java. * perf(plugins): add ground item signature and native tile batch builder to PluginContext Eliminate periodic stutters caused by `GroundItems` rebuilding its tile cache in `ScriptInterpreter` every 500ms by providing a zero-allocation ground item fingerprint and compiled batch builder. ### Plugin API - `PluginContext.java` - Added `getGroundItemsSignature(int radius)` to compute a lightweight FNV-1a fingerprint of ground items within `radius` tiles without allocating `GroundItemWrapper` objects or looking up `ItemDef`. - Added `buildGroundItemTiles(...)` to perform wildcard filtering, duplicate collapsing, sorting, label/quantity/value formatting, and border/lootbeam preparation in compiled Java. * refactor(plugins): remove GroundItems-specific buildGroundItemTiles from PluginContext Keep `PluginContext` limited to generic client API primitives (`getGroundItems(int)` and `getGroundItemsSignature(int)`) while moving Ground Items-specific grouping, tier coloring, and label formatting back into the plugin. ### Cleanups & Deprecations - `PluginContext.java` - Removed `buildGroundItemTiles(...)` and its private helpers (`matchesAnyPattern`, `getGroundItemColor`, `formatItemQuantity`, `formatItemValue`) along with unused `Map`/`HashMap`/`LinkedHashMap` imports. * feat(scripts): add ternary, modulo, compound assignments, constructors, list literals, and indexing Expand `ScriptInterpreter` expression and statement support to simplify plugin and script authoring across Desktop, Android, and Web. ### Script & Plugin Engine - `ScriptInterpreter.java` - Added short-circuiting ternary (`cond ? a : b` with `findMatchingTernaryColon`), `%` modulo operator, and unified `+=`, `-=`, `*=`, `/=`, `%=` compound assignments. - Added `target[index]` reads and `target[index] = value` writes for `List`, `Map`, arrays, and `String`, plus bracket-aware `findTopLevelOp` and `parseArguments`. - Added `[a, b, c]` list literals and `new ClassName(...)` constructors (`ArrayList`, `HashMap`, `LinkedHashMap`, `HashSet`, `StringBuilder`, `WorldArea`, `MenuEntry`, plus reflective constructor fallback). - Fast-pathed `StringBuilder` (`append`, `toString`, `length`, `setLength`) in `invokeMethod` and fixed `findMethodOpenParen` to ignore parentheses inside string literals. - `ScriptInterpreterTest.java` - Added `evaluatesTernaryModuloConstructorsAndIndexing` covering ternary, `%`, `*=`, `/=`, `%=`, list literals, `new HashMap()`, `new StringBuilder()`, indexing, and unbalanced parentheses inside strings. * fix(scripts): support long literals with L suffix in ScriptInterpreter Parse integer literals ending in `l` or `L` (e.g. `0L`) as `Long` instead of returning `null`. ### Bug Fixes & Edge Cases - `ScriptInterpreter.java` - Added `^-?\d+[lL]$` literal handling in `evalExpression` before standard integer literal parsing. * feat(scripts): add for/for-each/switch/break/continue, braceless blocks, and TeaVM fast-paths Expand `ScriptInterpreter` control-flow support and add direct non-reflective fast-paths for `PluginContext`, `PluginGraphics`, `MenuEntry`, and `GroundItemWrapper` to eliminate TeaVM `Class.getMethods()` `ReferenceError`s and per-tick reflection overhead. ### Script & Plugin Engine - `ScriptInterpreter.java` - Added `for (init; cond; update)`, enhanced `for (var : iterable)`, `switch`/`case`/`default`, `break`/`continue` (`BreakSignal`, `ContinueSignal`), and braceless single-statement bodies (`parseBodyOrSingleStatement`) for `if`, `else`, `while`, and `for`. - Added direct fast-paths in `invokeMethod` for `PluginContext` (`isLoggedIn`, `getGroundItems`, `getGroundItemsSignature`, `createList`, `createMap`, `sendClientMessage`, `getPlayerX`, `getPlayerY`, `getPlayerAnim`, `isBankOpen`, `getInventoryCount`, `walkTo`), `PluginContext.GroundItemWrapper` (`getDistance`), `MenuEntry` (`stripColorTags`, `matches`, `getAction`, `getTarget`, `getRawText`, `setRawText`), and `PluginGraphics` (`drawTileLabelBatches`, `fillRect`, `drawRect`, `drawCenteredString`, `drawString`, `drawStringBold`, `getTextWidth`, `getTextWidthBold`, `worldToScreenList`, `drawLootbeam`, `getViewportWidth`, `getViewportHeight`). - Added `try/catch` guard around `clazz.getMethods()` in `getCachedMethods` and included `[expr|phase]` diagnostics in `reportRuntimeError`. ### Unit Tests - `ScriptInterpreterTest.java` - Added `evaluatesForLoopsBreakContinueBracelessAndSwitch` covering `for`, `for-each`, `break`, `continue`, braceless `if`, `switch` fallthrough/default, and `MenuEntry` fast-paths. * feat(plugin-hub): add multi-line STRING config editor overlay and localStorage config seeding Replaces the non-editable "(Edit in .properties or chat)" placeholder in Plugin Hub settings with an interactive multi-line text editor overlay supporting cursor navigation and click positioning. Also seeds plugin settings on first boot and adds live localStorage reload support for web/cross-platform storage editing. ### Command Infrastructure - `PluginManager.java`: - Added `reloadStorage()` and `applyConfigToPlugin(...)` so external storage edits hot-reload `2006scape_plugin_settings` and `2006scape_script_*` entries into active plugins and scripts. - Updated `loadConfig()` to call `saveConfig()` when `DesktopHooks.loadPluginConfig()` returns `null`, seeding `2006scape_plugin_settings` on first boot. - `RSApplet.java`: - Queued Left (`1`) and Right (`2`) arrow keys into `charQueue` when `PluginPanelUI.isSearchFocused()` is true so arrow-key cursor movement reaches the modal editor without affecting normal gameplay. ### UI & Edge Cases - `PluginPanelUI.java`: - Replaced `(Edit in .properties or chat)` with a `220px` preview box in `drawConfigEditor` and `handleConfigTab`. - Added `drawConfigStringEditorOverlay`, `getStringEditorBounds`, and `wrapTextForWidth` to render a focused multi-line wrapped editor (up to 1,024 chars) with Clear, Cancel, and Save buttons. - Added `editingStringCursor` with Left/Right arrow, Home/End, mid-string insert/backspace, vertical gold caret rendering, auto-scroll to keep the cursor line visible, and pixel-accurate click-to-place-cursor support. - Added `commitStringEdit(PluginManager)` to auto-commit on blur, Back, or Close.
345 lines
13 KiB
Java
345 lines
13 KiB
Java
/**
|
|
* 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};
|
|
}
|
|
|
|
/**
|
|
* Projects world coordinate to screen (viewport) coordinate as a 2-element List [x, y], or null if off-screen.
|
|
*/
|
|
public java.util.List<Integer> worldToScreenList(int worldX, int worldY, int heightOffset) {
|
|
int[] pos = worldToScreen(worldX, worldY, heightOffset);
|
|
if (pos == null) return null;
|
|
java.util.List<Integer> list = new java.util.ArrayList<>(2);
|
|
list.add(pos[0]);
|
|
list.add(pos[1]);
|
|
return list;
|
|
}
|
|
|
|
/**
|
|
* 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 pre-computed ground item tile batches in compiled Java, avoiding per-frame
|
|
* script loop and reflection overhead (critical for TeaVM/Web performance).
|
|
*/
|
|
@SuppressWarnings("unchecked")
|
|
public void drawTileLabelBatches(java.util.List<?> tiles, int boxOpacity, int textOpacity) {
|
|
if (tiles == null || tiles.isEmpty()) return;
|
|
for (int t = 0; t < tiles.size(); t++) {
|
|
Object tileObj = tiles.get(t);
|
|
if (!(tileObj instanceof java.util.Map)) continue;
|
|
java.util.Map<Object, Object> tile = (java.util.Map<Object, Object>) tileObj;
|
|
|
|
int tileX = toIntValue(tile.get("x"), 0);
|
|
int tileY = toIntValue(tile.get("y"), 0);
|
|
|
|
Object beamFlag = tile.get("hasBeam");
|
|
if (beamFlag instanceof Boolean && ((Boolean) beamFlag).booleanValue()) {
|
|
drawLootbeam(tileX, tileY, toIntValue(tile.get("beamColor"), 0xffffff));
|
|
}
|
|
|
|
int baseX;
|
|
int baseY;
|
|
if (game != null) {
|
|
int[] pos = worldToScreen(tileX, tileY, 20);
|
|
if (pos == null) continue;
|
|
baseX = pos[0];
|
|
baseY = pos[1];
|
|
} else {
|
|
java.util.List<Integer> screen = worldToScreenList(tileX, tileY, 20);
|
|
if (screen == null || screen.size() < 2) continue;
|
|
baseX = screen.get(0);
|
|
baseY = screen.get(1);
|
|
}
|
|
|
|
Object itemsObj = tile.get("items");
|
|
if (!(itemsObj instanceof java.util.List)) continue;
|
|
java.util.List<?> itemsOnTile = (java.util.List<?>) itemsObj;
|
|
|
|
for (int rowIdx = 0; rowIdx < itemsOnTile.size(); rowIdx++) {
|
|
Object itemObj = itemsOnTile.get(rowIdx);
|
|
if (!(itemObj instanceof java.util.Map)) continue;
|
|
java.util.Map<Object, Object> item = (java.util.Map<Object, Object>) itemObj;
|
|
|
|
int rowY = baseY - (rowIdx * 14);
|
|
int color = toIntValue(item.get("color"), 0xffffff);
|
|
int borderColor = toIntValue(item.get("borderColor"), -1);
|
|
Object labelObj = item.get("label");
|
|
String label = labelObj != null ? labelObj.toString() : "";
|
|
|
|
int textW = toIntValue(item.get("textW"), -1);
|
|
if (textW < 0) {
|
|
textW = getTextWidth(label);
|
|
item.put("textW", textW);
|
|
}
|
|
|
|
int halfW = textW / 2;
|
|
int boxX = baseX - halfW - 3;
|
|
int boxY = rowY - 11;
|
|
int boxW = textW + 6;
|
|
int boxH = 13;
|
|
|
|
if (boxOpacity > 0) {
|
|
fillRect(boxX, boxY, boxW, boxH, 0x000000, boxOpacity);
|
|
}
|
|
if (borderColor != -1) {
|
|
drawRect(boxX, boxY, boxW, boxH, borderColor);
|
|
}
|
|
drawCenteredString(label, baseX, rowY - 1, color, textOpacity);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static int toIntValue(Object val, int fallback) {
|
|
if (val instanceof Number) {
|
|
return ((Number) val).intValue();
|
|
}
|
|
return fallback;
|
|
}
|
|
|
|
/**
|
|
* Renders a list of world {x, y} path tiles as step markers on screen.
|
|
*/
|
|
public void drawPathOverlay(java.util.List<int[]> 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);
|
|
}
|
|
}
|
|
}
|