From 9874b3af433eb7b76ec9ce31700e15c5ede1d1fb Mon Sep 17 00:00:00 2001 From: semtexerror Date: Wed, 28 Feb 2018 18:28:18 -0500 Subject: [PATCH] cannon plugin: draw npc double hit spots --- .../client/plugins/cannon/CannonConfig.java | 21 ++++++++ .../client/plugins/cannon/CannonOverlay.java | 48 +++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonConfig.java index e07567616a..dede24adbe 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonConfig.java @@ -24,6 +24,7 @@ */ package net.runelite.client.plugins.cannon; +import java.awt.Color; import net.runelite.client.config.Config; import net.runelite.client.config.ConfigGroup; import net.runelite.client.config.ConfigItem; @@ -54,4 +55,24 @@ public interface CannonConfig extends Config { return false; } + + @ConfigItem( + keyName = "showDoubleHitSpot", + name = "Show double hit spots", + description = "Configures whether to show the NPC double hit spot" + ) + default boolean showDoubleHitSpot() + { + return false; + } + + @ConfigItem( + keyName = "highlightDoubleHitColor", + name = "Color of double hit spots", + description = "Configures the highlight color of double hit spots" + ) + default Color highlightDoubleHitColor() + { + return Color.RED; + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonOverlay.java index f3402789ac..930c4c7995 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonOverlay.java @@ -24,16 +24,20 @@ */ package net.runelite.client.plugins.cannon; +import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.Point; +import java.awt.Polygon; import javax.inject.Inject; import net.runelite.api.Client; import net.runelite.api.Perspective; +import static net.runelite.api.Perspective.LOCAL_TILE_SIZE; import net.runelite.api.widgets.Widget; import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.OverlayPriority; +import net.runelite.client.ui.overlay.OverlayUtil; import net.runelite.client.ui.overlay.components.TextComponent; class CannonOverlay extends Overlay @@ -93,6 +97,50 @@ class CannonOverlay extends Overlay textComponent.render(graphics, parent); } + if (config.showDoubleHitSpot()) + { + Color color = config.highlightDoubleHitColor(); + drawDoubleHitSpots(graphics, plugin.getCannon().getLocalLocation(), color); + } + return null; } + + + /** + * Draw the double hit spots on a 6 by 6 grid around the cannon + * @param startTile The position of the cannon + */ + private void drawDoubleHitSpots(Graphics2D graphics, net.runelite.api.Point startTile, Color color) + { + for (int x = -3; x <= 3; x++) + { + for (int y = -3; y <= 3; y++) + { + if (y != 1 && x != 1 && y != -1 && x != -1) + { + continue; + } + + //Ignore center square + if (y >= -1 && y <= 1 && x >= -1 && x <= 1) + { + continue; + } + + int xPos = startTile.getX() - (x * LOCAL_TILE_SIZE); + int yPos = startTile.getY() - (y * LOCAL_TILE_SIZE); + + net.runelite.api.Point marker = new net.runelite.api.Point(xPos, yPos); + Polygon poly = Perspective.getCanvasTilePoly(client, marker); + + if (poly == null) + { + continue; + } + + OverlayUtil.renderPolygon(graphics, poly, color); + } + } + } } \ No newline at end of file