death indicator plugin: Use Item IDs for overlays

This commit is contained in:
Jordan Atwood
2018-07-18 16:27:24 -07:00
parent ecea2e28ca
commit 99e2d766d6
3 changed files with 57 additions and 55 deletions

View File

@@ -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);
}
}

View File

@@ -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");
}
}