From 517d986845289c7bf276159502a46491df591b77 Mon Sep 17 00:00:00 2001 From: XrioBtw <33559295+XrioBtw@users.noreply.github.com> Date: Tue, 24 Nov 2020 17:01:38 +0100 Subject: [PATCH 1/3] Tile number drawing and config option --- src/main/java/shortestpath/PathTileOverlay.java | 13 +++++++++++-- src/main/java/shortestpath/ShortestPathConfig.java | 5 +++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/shortestpath/PathTileOverlay.java b/src/main/java/shortestpath/PathTileOverlay.java index ed47d060..a40e3735 100644 --- a/src/main/java/shortestpath/PathTileOverlay.java +++ b/src/main/java/shortestpath/PathTileOverlay.java @@ -68,8 +68,9 @@ public Dimension render(Graphics2D graphics) { } if (config.drawTiles() && plugin.path != null) { + int i = 0; for (WorldPoint point : plugin.path) { - drawTile(graphics, point, new Color(255, 0, 0, 128)); + drawTile(graphics, point, ++i, new Color(255, 0, 0, 128)); } } @@ -77,7 +78,7 @@ public Dimension render(Graphics2D graphics) { return null; } - private void drawTile(Graphics2D graphics, WorldPoint point, Color color) { + private void drawTile(Graphics2D graphics, WorldPoint point, int i, Color color) { if (point.getPlane() != client.getPlane()) { return; } @@ -94,5 +95,13 @@ private void drawTile(Graphics2D graphics, WorldPoint point, Color color) { graphics.setColor(color); graphics.fill(poly); + + if (config.drawTileNumbers()) { + String s = "" + i; + graphics.setColor(Color.WHITE); + int stringX = (int) (poly.getBounds().getCenterX() - graphics.getFontMetrics().getStringBounds(s, graphics).getWidth() / 2); + int stringY = (int) poly.getBounds().getCenterY(); + graphics.drawString(s, stringX, stringY); + } } } diff --git a/src/main/java/shortestpath/ShortestPathConfig.java b/src/main/java/shortestpath/ShortestPathConfig.java index ae15ab9a..21a98834 100644 --- a/src/main/java/shortestpath/ShortestPathConfig.java +++ b/src/main/java/shortestpath/ShortestPathConfig.java @@ -12,6 +12,11 @@ default boolean drawTiles() { return true; } + @ConfigItem(keyName = "drawTileNumbers", name = "Draw tile numbers on tiles", description = "Whether the tile number should be drawn on the game tiles") + default boolean drawTileNumbers() { + return true; + } + @ConfigItem(keyName = "drawMinimap", name = "Draw path on minimap", description = "Whether the path should be drawn on the minimap") default boolean drawMinimap() { return true; From 5dfdd9ff2c3e253139c80a08b88355549ba6fd68 Mon Sep 17 00:00:00 2001 From: XrioBtw <33559295+XrioBtw@users.noreply.github.com> Date: Sun, 10 Jan 2021 19:38:16 +0100 Subject: [PATCH 2/3] Resolve conflicts --- .../java/shortestpath/PathTileOverlay.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/main/java/shortestpath/PathTileOverlay.java b/src/main/java/shortestpath/PathTileOverlay.java index a40e3735..3a6441c7 100644 --- a/src/main/java/shortestpath/PathTileOverlay.java +++ b/src/main/java/shortestpath/PathTileOverlay.java @@ -33,6 +33,25 @@ public Dimension render(Graphics2D graphics) { if (config.drawDebugInfo()) { Tile[][] tiles = client.getScene().getTiles()[client.getPlane()]; + + for (WorldPoint a : plugin.transports.keySet()) { + drawTile(graphics, a, new Color(0, 255, 0, 128)); + + Point ca = tileCenter(a); + + if (ca == null) { + continue; + } + + for (WorldPoint b : plugin.transports.get(a)) { + Point cb = tileCenter(b); + + if (cb != null) { + graphics.drawLine(ca.x, ca.y, cb.x, cb.y); + } + } + } + for (Tile[] row : tiles) { for (Tile tile : row) { if (tile == null) { @@ -78,6 +97,26 @@ public Dimension render(Graphics2D graphics) { return null; } + private Point tileCenter(WorldPoint b) { + if (b.getPlane() != client.getPlane()) { + return null; + } + + LocalPoint lp = LocalPoint.fromWorld(client, b); + if (lp == null) { + return null; + } + + Polygon poly = Perspective.getCanvasTilePoly(client, lp); + if (poly == null) { + return null; + } + + int cx = poly.getBounds().x + poly.getBounds().width / 2; + int cy = poly.getBounds().y + poly.getBounds().height / 2; + return new Point(cx, cy); + } + private void drawTile(Graphics2D graphics, WorldPoint point, int i, Color color) { if (point.getPlane() != client.getPlane()) { return; From 17ea311f854fa8d63757cd1116e3b4ee84558b96 Mon Sep 17 00:00:00 2001 From: XrioBtw <33559295+XrioBtw@users.noreply.github.com> Date: Thu, 21 Jan 2021 17:28:19 +0100 Subject: [PATCH 3/3] Add tile counter drawing --- src/main/java/shortestpath/PathTileOverlay.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/shortestpath/PathTileOverlay.java b/src/main/java/shortestpath/PathTileOverlay.java index afafdcbb..3a6441c7 100644 --- a/src/main/java/shortestpath/PathTileOverlay.java +++ b/src/main/java/shortestpath/PathTileOverlay.java @@ -87,8 +87,9 @@ public Dimension render(Graphics2D graphics) { } if (config.drawTiles() && plugin.path != null) { + int i = 0; for (WorldPoint point : plugin.path) { - drawTile(graphics, point, new Color(255, 0, 0, 128)); + drawTile(graphics, point, ++i, new Color(255, 0, 0, 128)); } } @@ -116,7 +117,7 @@ private Point tileCenter(WorldPoint b) { return new Point(cx, cy); } - private void drawTile(Graphics2D graphics, WorldPoint point, Color color) { + private void drawTile(Graphics2D graphics, WorldPoint point, int i, Color color) { if (point.getPlane() != client.getPlane()) { return; } @@ -133,5 +134,13 @@ private void drawTile(Graphics2D graphics, WorldPoint point, Color color) { graphics.setColor(color); graphics.fill(poly); + + if (config.drawTileNumbers()) { + String s = "" + i; + graphics.setColor(Color.WHITE); + int stringX = (int) (poly.getBounds().getCenterX() - graphics.getFontMetrics().getStringBounds(s, graphics).getWidth() / 2); + int stringY = (int) poly.getBounds().getCenterY(); + graphics.drawString(s, stringX, stringY); + } } }