implings plugin: use npc indicators for impling overlay

This commit is contained in:
Adam
2021-08-22 14:49:52 -04:00
parent ec7af70da4
commit e9665f3504
5 changed files with 57 additions and 194 deletions

View File

@@ -1,82 +0,0 @@
/*
* Copyright (c) 2018, Seth <http://github.com/sethtroll>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.implings;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.util.List;
import javax.inject.Inject;
import net.runelite.api.NPC;
import net.runelite.api.Point;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayUtil;
public class ImplingMinimapOverlay extends Overlay
{
private final ImplingsPlugin plugin;
private final ImplingsConfig config;
@Inject
private ImplingMinimapOverlay(ImplingsPlugin plugin, ImplingsConfig config)
{
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_WIDGETS);
this.plugin = plugin;
this.config = config;
}
@Override
public Dimension render(Graphics2D graphics)
{
List<NPC> imps = plugin.getImplings();
if (imps.isEmpty())
{
return null;
}
for (NPC imp : imps)
{
Point impLocation = imp.getMinimapLocation();
Color color = plugin.npcToColor(imp);
if (!plugin.showNpc(imp) || impLocation == null || color == null)
{
continue;
}
OverlayUtil.renderMinimapLocation(graphics, impLocation, color);
if (config.showName())
{
Point textLocation = new Point(impLocation.getX() + 1, impLocation.getY());
OverlayUtil.renderTextLocation(graphics, textLocation, imp.getName(), color);
}
}
return null;
}
}

View File

@@ -31,13 +31,11 @@ import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
import net.runelite.client.config.ConfigSection;
/**
*
* @author robin
*/
@ConfigGroup("implings")
@ConfigGroup(ImplingsConfig.GROUP)
public interface ImplingsConfig extends Config
{
String GROUP = "implings";
enum ImplingMode
{
NONE,

View File

@@ -28,13 +28,10 @@ import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.util.List;
import javax.inject.Inject;
import net.runelite.api.Actor;
import net.runelite.api.Client;
import net.runelite.api.NPC;
import net.runelite.api.Point;
import net.runelite.api.Perspective;
import net.runelite.api.Point;
import net.runelite.api.coords.LocalPoint;
import net.runelite.api.coords.WorldPoint;
import net.runelite.client.ui.overlay.Overlay;
@@ -42,10 +39,7 @@ import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayUtil;
/**
* @author robin
*/
public class ImplingsOverlay extends Overlay
class ImplingsOverlay extends Overlay
{
private final Client client;
private final ImplingsConfig config;
@@ -64,25 +58,6 @@ public class ImplingsOverlay extends Overlay
@Override
public Dimension render(Graphics2D graphics)
{
List<NPC> implings = plugin.getImplings();
if (implings.isEmpty())
{
return null;
}
for (NPC imp : implings)
{
Color color = plugin.npcToColor(imp);
if (!plugin.showNpc(imp) || color == null)
{
continue;
}
drawImp(graphics, imp, imp.getName(), color);
}
//Draw static spawns
if (config.showSpawn())
{
for (ImplingSpawn spawn : ImplingSpawn.values())
@@ -126,20 +101,4 @@ public class ImplingsOverlay extends Overlay
OverlayUtil.renderTextLocation(graphics, textPoint, text, color);
}
}
private void drawImp(Graphics2D graphics, Actor actor, String text, Color color)
{
Polygon poly = actor.getCanvasTilePoly();
if (poly != null)
{
OverlayUtil.renderPolygon(graphics, poly, color);
}
Point textLocation = actor.getCanvasTextLocation(graphics, text, actor.getLogicalHeight());
if (textLocation != null)
{
OverlayUtil.renderTextLocation(graphics, textLocation, text, color);
}
}
}

View File

@@ -26,22 +26,22 @@ package net.runelite.client.plugins.implings;
import com.google.inject.Provides;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import javax.inject.Inject;
import lombok.AccessLevel;
import lombok.Getter;
import net.runelite.api.GameState;
import net.runelite.api.NPC;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.NpcChanged;
import net.runelite.api.events.NpcDespawned;
import net.runelite.api.events.NpcSpawned;
import net.runelite.client.Notifier;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.ConfigChanged;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDependency;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.npchighlight.HighlightedNpc;
import net.runelite.client.plugins.npchighlight.NpcIndicatorsPlugin;
import net.runelite.client.plugins.npchighlight.NpcIndicatorsService;
import net.runelite.client.ui.overlay.OverlayManager;
@PluginDescriptor(
@@ -49,26 +49,45 @@ import net.runelite.client.ui.overlay.OverlayManager;
description = "Highlight nearby implings on the minimap and on-screen",
tags = {"hunter", "minimap", "overlay", "imp"}
)
@PluginDependency(NpcIndicatorsPlugin.class)
public class ImplingsPlugin extends Plugin
{
@Getter(AccessLevel.PACKAGE)
private final List<NPC> implings = new ArrayList<>();
@Inject
private OverlayManager overlayManager;
@Inject
private ImplingsOverlay overlay;
@Inject
private ImplingMinimapOverlay minimapOverlay;
@Inject
private ImplingsConfig config;
@Inject
private Notifier notifier;
@Inject
private NpcIndicatorsService npcIndicatorsService;
@Inject
private ClientThread clientThread;
public final Function<NPC, HighlightedNpc> isTarget = (npc) ->
{
Impling impling = Impling.findImpling(npc.getId());
if (impling != null && showImpling(impling))
{
Color color = implingColor(impling);
return HighlightedNpc.builder()
.npc(npc)
.highlightColor(color)
.fillColor(new Color(0, 0, 0, 50))
.tile(true)
.name(true)
.nameOnMinimap(config.showName())
.build();
}
return null;
};
@Provides
ImplingsConfig getConfig(ConfigManager configManager)
{
@@ -79,15 +98,25 @@ public class ImplingsPlugin extends Plugin
protected void startUp()
{
overlayManager.add(overlay);
overlayManager.add(minimapOverlay);
npcIndicatorsService.registerHighlighter(isTarget);
}
@Override
protected void shutDown()
{
implings.clear();
npcIndicatorsService.unregisterHighlighter(isTarget);
overlayManager.remove(overlay);
overlayManager.remove(minimapOverlay);
}
@Subscribe
private void onConfigChanged(ConfigChanged event)
{
if (!event.getGroup().equals(ImplingsConfig.GROUP))
{
return;
}
clientThread.invoke(npcIndicatorsService::rebuild);
}
@Subscribe
@@ -102,8 +131,6 @@ public class ImplingsPlugin extends Plugin
{
notifier.notify(impling.getImplingType().getName() + " impling is in the area");
}
implings.add(npc);
}
}
@@ -119,43 +146,11 @@ public class ImplingsPlugin extends Plugin
{
notifier.notify(impling.getImplingType().getName() + " impling is in the area");
}
if (!implings.contains(npc))
{
implings.add(npc);
}
}
}
@Subscribe
public void onGameStateChanged(GameStateChanged event)
private boolean showImpling(Impling impling)
{
if (event.getGameState() == GameState.LOGIN_SCREEN || event.getGameState() == GameState.HOPPING)
{
implings.clear();
}
}
@Subscribe
public void onNpcDespawned(NpcDespawned npcDespawned)
{
if (implings.isEmpty())
{
return;
}
NPC npc = npcDespawned.getNpc();
implings.remove(npc);
}
boolean showNpc(NPC npc)
{
Impling impling = Impling.findImpling(npc.getId());
if (impling == null)
{
return false;
}
ImplingsConfig.ImplingMode impMode = showImplingType(impling.getImplingType());
return impMode == ImplingsConfig.ImplingMode.HIGHLIGHT || impMode == ImplingsConfig.ImplingMode.NOTIFY;
}
@@ -193,17 +188,10 @@ public class ImplingsPlugin extends Plugin
}
}
Color npcToColor(NPC npc)
private Color implingColor(Impling impling)
{
Impling impling = Impling.findImpling(npc.getId());
if (impling == null)
{
return null;
}
switch (impling.getImplingType())
{
case BABY:
return config.getBabyColor();
case YOUNG:
@@ -229,7 +217,7 @@ public class ImplingsPlugin extends Plugin
case LUCKY:
return config.getLuckyColor();
default:
return null;
throw new IllegalArgumentException();
}
}
}

View File

@@ -152,12 +152,12 @@ public class NpcIndicatorsPluginTest
when(npc.getName()).thenReturn("Joseph");
npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc));
assertTrue(npcIndicatorsPlugin.getHighlightedNpcs().contains(npc));
assertTrue(npcIndicatorsPlugin.getHighlightedNpcs().containsKey(npc));
when(npc.getName()).thenReturn("Werewolf");
npcIndicatorsPlugin.onNpcChanged(new NpcChanged(npc, null));
assertFalse(npcIndicatorsPlugin.getHighlightedNpcs().contains(npc));
assertFalse(npcIndicatorsPlugin.getHighlightedNpcs().containsKey(npc));
}
@Test
@@ -171,11 +171,11 @@ public class NpcIndicatorsPluginTest
when(npc.getName()).thenReturn("Joseph");
npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc));
assertFalse(npcIndicatorsPlugin.getHighlightedNpcs().contains(npc));
assertFalse(npcIndicatorsPlugin.getHighlightedNpcs().containsKey(npc));
when(npc.getName()).thenReturn("Werewolf");
npcIndicatorsPlugin.onNpcChanged(new NpcChanged(npc, null));
assertTrue(npcIndicatorsPlugin.getHighlightedNpcs().contains(npc));
assertTrue(npcIndicatorsPlugin.getHighlightedNpcs().containsKey(npc));
}
}