From 99e2d766d6b8d33095b58b8c14e60d18ae439c88 Mon Sep 17 00:00:00 2001 From: Jordan Atwood Date: Wed, 18 Jul 2018 16:27:24 -0700 Subject: [PATCH] death indicator plugin: Use Item IDs for overlays --- .../deathindicator/DeathIndicatorPlugin.java | 58 ++++++++++++------ .../deathindicator/DeathWorldMapPoint.java | 54 ++++++---------- .../client/plugins/deathindicator/bones.png | Bin 574 -> 0 bytes 3 files changed, 57 insertions(+), 55 deletions(-) delete mode 100644 runelite-client/src/main/resources/net/runelite/client/plugins/deathindicator/bones.png diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/deathindicator/DeathIndicatorPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/deathindicator/DeathIndicatorPlugin.java index a739568db1..b2ab4fd7a0 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/deathindicator/DeathIndicatorPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/deathindicator/DeathIndicatorPlugin.java @@ -39,6 +39,7 @@ import lombok.extern.slf4j.Slf4j; import static net.runelite.api.AnimationID.DEATH; import net.runelite.api.Client; import net.runelite.api.GameState; +import net.runelite.api.ItemID; import net.runelite.api.Player; import net.runelite.api.coords.WorldPoint; import net.runelite.api.events.AnimationChanged; @@ -46,6 +47,7 @@ import net.runelite.api.events.ConfigChanged; import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.GameTick; import net.runelite.client.config.ConfigManager; +import net.runelite.client.game.ItemManager; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.ui.overlay.infobox.InfoBoxManager; @@ -66,7 +68,6 @@ public class DeathIndicatorPlugin extends Plugin 12342, // Edgeville 11062 // Camelot ); - static BufferedImage BONES; @Inject private Client client; @@ -80,27 +81,17 @@ public class DeathIndicatorPlugin extends Plugin @Inject private InfoBoxManager infoBoxManager; + @Inject + private ItemManager itemManager; + + private BufferedImage mapArrow; + private Timer deathTimer; private WorldPoint lastDeath; private Instant lastDeathTime; private int lastDeathWorld; - static - { - try - { - synchronized (ImageIO.class) - { - BONES = ImageIO.read(DeathIndicatorPlugin.class.getResourceAsStream("bones.png")); - } - } - catch (IOException e) - { - throw new RuntimeException(e); - } - } - @Provides DeathIndicatorConfig deathIndicatorConfig(ConfigManager configManager) { @@ -133,7 +124,7 @@ public class DeathIndicatorPlugin extends Plugin if (config.showDeathOnWorldMap()) { worldMapPointManager.removeIf(DeathWorldMapPoint.class::isInstance); - worldMapPointManager.add(new DeathWorldMapPoint(new WorldPoint(config.deathLocationX(), config.deathLocationY(), config.deathLocationPlane()))); + worldMapPointManager.add(new DeathWorldMapPoint(new WorldPoint(config.deathLocationX(), config.deathLocationY(), config.deathLocationPlane()), this)); } } @@ -204,7 +195,7 @@ public class DeathIndicatorPlugin extends Plugin if (config.showDeathOnWorldMap()) { worldMapPointManager.removeIf(DeathWorldMapPoint.class::isInstance); - worldMapPointManager.add(new DeathWorldMapPoint(lastDeath)); + worldMapPointManager.add(new DeathWorldMapPoint(lastDeath, this)); } resetInfobox(); @@ -290,7 +281,7 @@ public class DeathIndicatorPlugin extends Plugin if (config.showDeathOnWorldMap()) { worldMapPointManager.removeIf(DeathWorldMapPoint.class::isInstance); - worldMapPointManager.add(new DeathWorldMapPoint(deathPoint)); + worldMapPointManager.add(new DeathWorldMapPoint(deathPoint, this)); } } else @@ -328,10 +319,37 @@ public class DeathIndicatorPlugin extends Plugin Duration timeLeft = Duration.ofHours(1).minus(Duration.between(config.timeOfDeath(), now)); if (!timeLeft.isNegative() && !timeLeft.isZero()) { - deathTimer = new Timer(timeLeft.getSeconds(), ChronoUnit.SECONDS, BONES, this); + deathTimer = new Timer(timeLeft.getSeconds(), ChronoUnit.SECONDS, getBonesImage(), this); deathTimer.setTooltip("Died on world: " + config.deathWorld()); infoBoxManager.addInfoBox(deathTimer); } } } + + BufferedImage getMapArrow() + { + if (mapArrow != null) + { + return mapArrow; + } + + try + { + synchronized (ImageIO.class) + { + mapArrow = ImageIO.read(getClass().getResourceAsStream("/util/clue_arrow.png")); + } + } + catch (IOException e) + { + throw new RuntimeException(e); + } + + return mapArrow; + } + + BufferedImage getBonesImage() + { + return itemManager.getImage(ItemID.BONES); + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/deathindicator/DeathWorldMapPoint.java b/runelite-client/src/main/java/net/runelite/client/plugins/deathindicator/DeathWorldMapPoint.java index 2ef3557965..e6368d87ce 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/deathindicator/DeathWorldMapPoint.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/deathindicator/DeathWorldMapPoint.java @@ -26,56 +26,40 @@ package net.runelite.client.plugins.deathindicator; import java.awt.Graphics; import java.awt.image.BufferedImage; -import java.io.IOException; -import javax.imageio.ImageIO; import net.runelite.api.Point; import net.runelite.api.coords.WorldPoint; -import static net.runelite.client.plugins.deathindicator.DeathIndicatorPlugin.BONES; import net.runelite.client.ui.overlay.worldmap.WorldMapPoint; class DeathWorldMapPoint extends WorldMapPoint { - private static final BufferedImage WORLDMAP_HINT_ARROW; - private static final Point WORLDMAP_HINT_ARROW_POINT; + private final DeathIndicatorPlugin plugin; + private final BufferedImage worldmapHintArrow; + private final Point worldmapHintArrowPoint; - static - { - BufferedImage MAP_ARROW; - try - { - synchronized (ImageIO.class) - { - MAP_ARROW = ImageIO.read(DeathWorldMapPoint.class.getResourceAsStream("/util/clue_arrow.png")); - } - } - catch (IOException e) - { - throw new RuntimeException(e); - } - - WORLDMAP_HINT_ARROW = new BufferedImage(MAP_ARROW.getWidth(), - MAP_ARROW.getHeight(), BufferedImage.TYPE_INT_ARGB); - - Graphics graphics = WORLDMAP_HINT_ARROW.getGraphics(); - graphics.drawImage(MAP_ARROW, 0, 0, null); - graphics.drawImage(BONES, 0, 1, null); - WORLDMAP_HINT_ARROW_POINT = new Point(WORLDMAP_HINT_ARROW.getWidth() / 2, WORLDMAP_HINT_ARROW.getHeight()); - } - - DeathWorldMapPoint(final WorldPoint worldPoint) + DeathWorldMapPoint(final WorldPoint worldPoint, final DeathIndicatorPlugin plugin) { super(worldPoint, null); + + worldmapHintArrow = new BufferedImage(plugin.getMapArrow().getWidth(), plugin.getMapArrow().getHeight(), BufferedImage.TYPE_INT_ARGB); + Graphics graphics = worldmapHintArrow.getGraphics(); + graphics.drawImage(plugin.getMapArrow(), 0, 0, null); + graphics.drawImage(plugin.getBonesImage(), 0, 0, null); + worldmapHintArrowPoint = new Point( + worldmapHintArrow.getWidth() / 2, + worldmapHintArrow.getHeight()); + + this.plugin = plugin; this.setSnapToEdge(true); this.setJumpOnClick(true); - this.setImage(WORLDMAP_HINT_ARROW); - this.setImagePoint(WORLDMAP_HINT_ARROW_POINT); + this.setImage(worldmapHintArrow); + this.setImagePoint(worldmapHintArrowPoint); this.setTooltip("Death Location"); } @Override public void onEdgeSnap() { - this.setImage(BONES); + this.setImage(plugin.getBonesImage()); this.setImagePoint(null); this.setTooltip(null); } @@ -83,8 +67,8 @@ class DeathWorldMapPoint extends WorldMapPoint @Override public void onEdgeUnsnap() { - this.setImage(WORLDMAP_HINT_ARROW); - this.setImagePoint(WORLDMAP_HINT_ARROW_POINT); + this.setImage(worldmapHintArrow); + this.setImagePoint(worldmapHintArrowPoint); this.setTooltip("Death Location"); } } diff --git a/runelite-client/src/main/resources/net/runelite/client/plugins/deathindicator/bones.png b/runelite-client/src/main/resources/net/runelite/client/plugins/deathindicator/bones.png deleted file mode 100644 index 90ff52f20862eb2c32088c42aa0ab0b219c1f75a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 574 zcmV-E0>S->P)5|4b-0j3OF+upz7{opp4X1 z{#?;&e_J)tCIJqs6}s^;$?xNh4MaYZa1j6f9o(0fI5!&EvZlME3rN|hl#-fR*;%d z&`BNoKGxsI2iaX&hG~C~Roq^fk5W5sE2CeO%1;d`XCGNaR{`BuWrc-uOkHe9(L$QQ zSV5MCTHt#tJuNK}K;e^