Merge remote-tracking branch 'runelite/master'

This commit is contained in:
Owain van Brakel
2021-09-07 07:48:07 +02:00
16 changed files with 413 additions and 360 deletions

View File

@@ -22,10 +22,12 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.runelite.client.plugins.npchighlight; package net.runelite.client.game.npcoverlay;
import java.awt.Color; import java.awt.Color;
import java.util.function.Predicate;
import lombok.Builder; import lombok.Builder;
import lombok.NonNull;
import lombok.Value; import lombok.Value;
import net.runelite.api.NPC; import net.runelite.api.NPC;
@@ -33,13 +35,20 @@ import net.runelite.api.NPC;
@Builder @Builder
public class HighlightedNpc public class HighlightedNpc
{ {
@NonNull
NPC npc; NPC npc;
@NonNull
Color highlightColor; Color highlightColor;
Color fillColor; @Builder.Default
Color fillColor = new Color(0, 0, 0, 50);
boolean hull; boolean hull;
boolean tile; boolean tile;
boolean swTile; boolean swTile;
boolean outline; boolean outline;
boolean name; boolean name;
boolean nameOnMinimap; boolean nameOnMinimap;
@Builder.Default
float borderWidth = 2.0f;
int outlineFeather;
Predicate<NPC> render;
} }

View File

@@ -23,12 +23,13 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.runelite.client.plugins.npchighlight; package net.runelite.client.game.npcoverlay;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import javax.inject.Inject; import java.util.Map;
import java.util.function.Predicate;
import net.runelite.api.NPC; import net.runelite.api.NPC;
import net.runelite.api.NPCComposition; import net.runelite.api.NPCComposition;
import net.runelite.api.Point; import net.runelite.api.Point;
@@ -38,16 +39,13 @@ import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayUtil; import net.runelite.client.ui.overlay.OverlayUtil;
import net.runelite.client.util.Text; import net.runelite.client.util.Text;
public class NpcMinimapOverlay extends Overlay class NpcMinimapOverlay extends Overlay
{ {
private final NpcIndicatorsConfig config; private final Map<NPC, HighlightedNpc> highlightedNpcs;
private final NpcIndicatorsPlugin plugin;
@Inject NpcMinimapOverlay(Map<NPC, HighlightedNpc> highlightedNpcs)
NpcMinimapOverlay(NpcIndicatorsConfig config, NpcIndicatorsPlugin plugin)
{ {
this.config = config; this.highlightedNpcs = highlightedNpcs;
this.plugin = plugin;
setPosition(OverlayPosition.DYNAMIC); setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_WIDGETS); setLayer(OverlayLayer.ABOVE_WIDGETS);
} }
@@ -55,7 +53,7 @@ public class NpcMinimapOverlay extends Overlay
@Override @Override
public Dimension render(Graphics2D graphics) public Dimension render(Graphics2D graphics)
{ {
for (HighlightedNpc highlightedNpc : plugin.getHighlightedNpcs().values()) for (HighlightedNpc highlightedNpc : highlightedNpcs.values())
{ {
renderNpcOverlay(graphics, highlightedNpc); renderNpcOverlay(graphics, highlightedNpc);
} }
@@ -66,10 +64,14 @@ public class NpcMinimapOverlay extends Overlay
private void renderNpcOverlay(Graphics2D graphics, HighlightedNpc highlightedNpc) private void renderNpcOverlay(Graphics2D graphics, HighlightedNpc highlightedNpc)
{ {
NPC actor = highlightedNpc.getNpc(); NPC actor = highlightedNpc.getNpc();
String name = Text.removeTags(actor.getName());
NPCComposition npcComposition = actor.getTransformedComposition(); NPCComposition npcComposition = actor.getTransformedComposition();
if (npcComposition == null || !npcComposition.isInteractible() if (npcComposition == null || !npcComposition.isInteractible())
|| (actor.isDead() && config.ignoreDeadNpcs())) {
return;
}
Predicate<NPC> render = highlightedNpc.getRender();
if (render != null && !render.test(actor))
{ {
return; return;
} }
@@ -80,8 +82,9 @@ public class NpcMinimapOverlay extends Overlay
Color color = highlightedNpc.getHighlightColor(); Color color = highlightedNpc.getHighlightColor();
OverlayUtil.renderMinimapLocation(graphics, minimapLocation, color.darker()); OverlayUtil.renderMinimapLocation(graphics, minimapLocation, color.darker());
if (highlightedNpc.isNameOnMinimap()) if (highlightedNpc.isNameOnMinimap() && actor.getName() != null)
{ {
String name = Text.removeTags(actor.getName());
OverlayUtil.renderTextLocation(graphics, minimapLocation, name, color); OverlayUtil.renderTextLocation(graphics, minimapLocation, name, color);
} }
} }

View File

@@ -0,0 +1,147 @@
/*
* Copyright (c) 2018, James Swindle <wilingua@gmail.com>
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* 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.game.npcoverlay;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.Shape;
import java.util.Map;
import java.util.function.Predicate;
import net.runelite.api.Client;
import net.runelite.api.NPC;
import net.runelite.api.NPCComposition;
import net.runelite.api.Perspective;
import net.runelite.api.Point;
import net.runelite.api.coords.LocalPoint;
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;
import net.runelite.client.ui.overlay.outline.ModelOutlineRenderer;
import net.runelite.client.util.Text;
class NpcOverlay extends Overlay
{
private final Client client;
private final ModelOutlineRenderer modelOutlineRenderer;
private final Map<NPC, HighlightedNpc> highlightedNpcs;
NpcOverlay(Client client, ModelOutlineRenderer modelOutlineRenderer, Map<NPC, HighlightedNpc> highlightedNpcs)
{
this.client = client;
this.modelOutlineRenderer = modelOutlineRenderer;
this.highlightedNpcs = highlightedNpcs;
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_SCENE);
}
@Override
public Dimension render(Graphics2D graphics)
{
for (HighlightedNpc highlightedNpc : highlightedNpcs.values())
{
renderNpcOverlay(graphics, highlightedNpc);
}
return null;
}
private void renderNpcOverlay(Graphics2D graphics, HighlightedNpc highlightedNpc)
{
NPC actor = highlightedNpc.getNpc();
NPCComposition npcComposition = actor.getTransformedComposition();
if (npcComposition == null || !npcComposition.isInteractible())
{
return;
}
Predicate<NPC> render = highlightedNpc.getRender();
if (render != null && !render.test(actor))
{
return;
}
final Color borderColor = highlightedNpc.getHighlightColor();
float borderWidth = highlightedNpc.getBorderWidth();
final Color fillColor = highlightedNpc.getFillColor();
if (highlightedNpc.isHull())
{
Shape objectClickbox = actor.getConvexHull();
renderPoly(graphics, borderColor, borderWidth, fillColor, objectClickbox);
}
if (highlightedNpc.isTile())
{
Polygon tilePoly = actor.getCanvasTilePoly();
renderPoly(graphics, borderColor, borderWidth, fillColor, tilePoly);
}
if (highlightedNpc.isSwTile())
{
int size = npcComposition.getSize();
LocalPoint lp = actor.getLocalLocation();
int x = lp.getX() - ((size - 1) * Perspective.LOCAL_TILE_SIZE / 2);
int y = lp.getY() - ((size - 1) * Perspective.LOCAL_TILE_SIZE / 2);
Polygon southWestTilePoly = Perspective.getCanvasTilePoly(client, new LocalPoint(x, y));
renderPoly(graphics, borderColor, borderWidth, fillColor, southWestTilePoly);
}
if (highlightedNpc.isOutline())
{
modelOutlineRenderer.drawOutline(actor, (int) highlightedNpc.getBorderWidth(), borderColor, highlightedNpc.getOutlineFeather());
}
if (highlightedNpc.isName() && actor.getName() != null)
{
String npcName = Text.removeTags(actor.getName());
Point textLocation = actor.getCanvasTextLocation(graphics, npcName, actor.getLogicalHeight() + 40);
if (textLocation != null)
{
OverlayUtil.renderTextLocation(graphics, textLocation, npcName, borderColor);
}
}
}
private void renderPoly(Graphics2D graphics, Color borderColor, float borderWidth, Color fillColor, Shape polygon)
{
if (polygon != null)
{
graphics.setColor(borderColor);
graphics.setStroke(new BasicStroke(borderWidth));
graphics.draw(polygon);
graphics.setColor(fillColor);
graphics.fill(polygon);
}
}
}

View File

@@ -0,0 +1,142 @@
/*
* Copyright (c) 2018, James Swindle <wilingua@gmail.com>
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* 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.game.npcoverlay;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import javax.inject.Inject;
import javax.inject.Singleton;
import net.runelite.api.Client;
import net.runelite.api.NPC;
import net.runelite.api.events.NpcChanged;
import net.runelite.api.events.NpcDespawned;
import net.runelite.api.events.NpcSpawned;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.eventbus.EventBus;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.ui.overlay.outline.ModelOutlineRenderer;
@Singleton
public class NpcOverlayService
{
private final Client client;
private final ClientThread clientThread;
private final List<Function<NPC, HighlightedNpc>> highlightFunctions = new ArrayList<>();
private final Map<NPC, HighlightedNpc> highlightedNpcs = new HashMap<>();
@Inject
private NpcOverlayService(Client client, ClientThread clientThread,
OverlayManager overlayManager, ModelOutlineRenderer modelOutlineRenderer, EventBus eventBus)
{
this.client = client;
this.clientThread = clientThread;
overlayManager.add(new NpcOverlay(client, modelOutlineRenderer, highlightedNpcs));
overlayManager.add(new NpcMinimapOverlay(highlightedNpcs));
eventBus.register(this);
}
@Subscribe(
// Run after plugins, which typically capture NPCs on spawn and reference them in the highlight functions
priority = -1
)
private void onNpcSpawned(NpcSpawned npcSpawned)
{
final NPC npc = npcSpawned.getNpc();
for (Function<NPC, HighlightedNpc> f : highlightFunctions)
{
HighlightedNpc highlightedNpc = f.apply(npc);
if (highlightedNpc != null)
{
highlightedNpcs.put(npc, highlightedNpc);
return;
}
}
}
@Subscribe
private void onNpcDespawned(NpcDespawned npcDespawned)
{
final NPC npc = npcDespawned.getNpc();
highlightedNpcs.remove(npc);
}
@Subscribe
private void onNpcChanged(NpcChanged event)
{
final NPC npc = event.getNpc();
highlightedNpcs.remove(npc);
for (Function<NPC, HighlightedNpc> f : highlightFunctions)
{
HighlightedNpc highlightedNpc = f.apply(npc);
if (highlightedNpc != null)
{
highlightedNpcs.put(npc, highlightedNpc);
return;
}
}
}
public void rebuild()
{
clientThread.invoke(() ->
{
highlightedNpcs.clear();
outer:
for (NPC npc : client.getNpcs())
{
for (Function<NPC, HighlightedNpc> f : highlightFunctions)
{
HighlightedNpc highlightedNpc = f.apply(npc);
if (highlightedNpc != null)
{
highlightedNpcs.put(npc, highlightedNpc);
continue outer;
}
}
}
});
}
public void registerHighlighter(Function<NPC, HighlightedNpc> p)
{
highlightFunctions.add(p);
rebuild();
}
public void unregisterHighlighter(Function<NPC, HighlightedNpc> p)
{
highlightFunctions.remove(p);
rebuild();
}
}

View File

@@ -1,67 +0,0 @@
/*
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* 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.corp;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Polygon;
import javax.inject.Inject;
import net.runelite.api.NPC;
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;
class CoreOverlay extends Overlay
{
private final CorpPlugin corpPlugin;
private final CorpConfig config;
@Inject
private CoreOverlay(CorpPlugin corpPlugin, CorpConfig corpConfig)
{
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_SCENE);
this.corpPlugin = corpPlugin;
this.config = corpConfig;
}
@Override
public Dimension render(Graphics2D graphics)
{
NPC core = corpPlugin.getCore();
if (core != null && config.markDarkCore())
{
Polygon canvasTilePoly = core.getCanvasTilePoly();
if (canvasTilePoly != null)
{
OverlayUtil.renderPolygon(graphics, canvasTilePoly, Color.RED.brighter());
}
}
return null;
}
}

View File

@@ -28,9 +28,11 @@ import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup; import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem; import net.runelite.client.config.ConfigItem;
@ConfigGroup("corp") @ConfigGroup(CorpConfig.GROUP)
public interface CorpConfig extends Config public interface CorpConfig extends Config
{ {
String GROUP = "corp";
@ConfigItem( @ConfigItem(
keyName = "showDamage", keyName = "showDamage",
name = "Show damage overlay", name = "Show damage overlay",

View File

@@ -25,8 +25,10 @@
package net.runelite.client.plugins.corp; package net.runelite.client.plugins.corp;
import com.google.inject.Provides; import com.google.inject.Provides;
import java.awt.Color;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.function.Function;
import javax.inject.Inject; import javax.inject.Inject;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
@@ -50,6 +52,8 @@ import net.runelite.client.chat.ChatMessageManager;
import net.runelite.client.chat.QueuedMessage; import net.runelite.client.chat.QueuedMessage;
import net.runelite.client.config.ConfigManager; import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe; import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.game.npcoverlay.HighlightedNpc;
import net.runelite.client.game.npcoverlay.NpcOverlayService;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.ui.overlay.OverlayManager;
@@ -89,7 +93,24 @@ public class CorpPlugin extends Plugin
private CorpDamageOverlay corpOverlay; private CorpDamageOverlay corpOverlay;
@Inject @Inject
private CoreOverlay coreOverlay; private CorpConfig config;
@Inject
private NpcOverlayService npcOverlayService;
private final Function<NPC, HighlightedNpc> isCore = (npc) ->
{
if (npc == core)
{
return HighlightedNpc.builder()
.npc(npc)
.tile(true)
.highlightColor(Color.RED.brighter())
.render(n -> config.markDarkCore())
.build();
}
return null;
};
@Provides @Provides
CorpConfig getConfig(ConfigManager configManager) CorpConfig getConfig(ConfigManager configManager)
@@ -100,15 +121,15 @@ public class CorpPlugin extends Plugin
@Override @Override
protected void startUp() throws Exception protected void startUp() throws Exception
{ {
npcOverlayService.registerHighlighter(isCore);
overlayManager.add(corpOverlay); overlayManager.add(corpOverlay);
overlayManager.add(coreOverlay);
} }
@Override @Override
protected void shutDown() throws Exception protected void shutDown() throws Exception
{ {
npcOverlayService.unregisterHighlighter(isCore);
overlayManager.remove(corpOverlay); overlayManager.remove(corpOverlay);
overlayManager.remove(coreOverlay);
corp = core = null; corp = core = null;
yourDamage = 0; yourDamage = 0;

View File

@@ -32,16 +32,13 @@ import net.runelite.api.NPC;
import net.runelite.api.events.NpcChanged; import net.runelite.api.events.NpcChanged;
import net.runelite.api.events.NpcSpawned; import net.runelite.api.events.NpcSpawned;
import net.runelite.client.Notifier; import net.runelite.client.Notifier;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.ConfigManager; import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe; import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.ConfigChanged; import net.runelite.client.events.ConfigChanged;
import net.runelite.client.game.npcoverlay.HighlightedNpc;
import net.runelite.client.game.npcoverlay.NpcOverlayService;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDependency;
import net.runelite.client.plugins.PluginDescriptor; 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; import net.runelite.client.ui.overlay.OverlayManager;
@PluginDescriptor( @PluginDescriptor(
@@ -49,7 +46,6 @@ import net.runelite.client.ui.overlay.OverlayManager;
description = "Highlight nearby implings on the minimap and on-screen", description = "Highlight nearby implings on the minimap and on-screen",
tags = {"hunter", "minimap", "overlay", "imp"} tags = {"hunter", "minimap", "overlay", "imp"}
) )
@PluginDependency(NpcIndicatorsPlugin.class)
public class ImplingsPlugin extends Plugin public class ImplingsPlugin extends Plugin
{ {
@Inject @Inject
@@ -65,10 +61,7 @@ public class ImplingsPlugin extends Plugin
private Notifier notifier; private Notifier notifier;
@Inject @Inject
private NpcIndicatorsService npcIndicatorsService; private NpcOverlayService npcOverlayService;
@Inject
private ClientThread clientThread;
public final Function<NPC, HighlightedNpc> isTarget = (npc) -> public final Function<NPC, HighlightedNpc> isTarget = (npc) ->
{ {
@@ -79,7 +72,6 @@ public class ImplingsPlugin extends Plugin
return HighlightedNpc.builder() return HighlightedNpc.builder()
.npc(npc) .npc(npc)
.highlightColor(color) .highlightColor(color)
.fillColor(new Color(0, 0, 0, 50))
.tile(true) .tile(true)
.name(true) .name(true)
.nameOnMinimap(config.showName()) .nameOnMinimap(config.showName())
@@ -98,13 +90,13 @@ public class ImplingsPlugin extends Plugin
protected void startUp() protected void startUp()
{ {
overlayManager.add(overlay); overlayManager.add(overlay);
npcIndicatorsService.registerHighlighter(isTarget); npcOverlayService.registerHighlighter(isTarget);
} }
@Override @Override
protected void shutDown() protected void shutDown()
{ {
npcIndicatorsService.unregisterHighlighter(isTarget); npcOverlayService.unregisterHighlighter(isTarget);
overlayManager.remove(overlay); overlayManager.remove(overlay);
} }
@@ -116,7 +108,7 @@ public class ImplingsPlugin extends Plugin
return; return;
} }
clientThread.invoke(npcIndicatorsService::rebuild); npcOverlayService.rebuild();
} }
@Subscribe @Subscribe

View File

@@ -27,7 +27,6 @@ package net.runelite.client.plugins.npchighlight;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.inject.Binder;
import com.google.inject.Provides; import com.google.inject.Provides;
import java.awt.Color; import java.awt.Color;
import java.time.Instant; import java.time.Instant;
@@ -66,6 +65,8 @@ import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.ConfigManager; import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe; import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.ConfigChanged; import net.runelite.client.events.ConfigChanged;
import net.runelite.client.game.npcoverlay.HighlightedNpc;
import net.runelite.client.game.npcoverlay.NpcOverlayService;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.ui.overlay.OverlayManager;
@@ -79,7 +80,7 @@ import net.runelite.client.util.WildcardMatcher;
tags = {"highlight", "minimap", "npcs", "overlay", "respawn", "tags"} tags = {"highlight", "minimap", "npcs", "overlay", "respawn", "tags"}
) )
@Slf4j @Slf4j
public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService public class NpcIndicatorsPlugin extends Plugin
{ {
private static final int MAX_ACTOR_VIEW_RANGE = 15; private static final int MAX_ACTOR_VIEW_RANGE = 15;
@@ -104,14 +105,14 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
private OverlayManager overlayManager; private OverlayManager overlayManager;
@Inject @Inject
private NpcSceneOverlay npcSceneOverlay; private NpcRespawnOverlay npcRespawnOverlay;
@Inject
private NpcMinimapOverlay npcMinimapOverlay;
@Inject @Inject
private ClientThread clientThread; private ClientThread clientThread;
@Inject
private NpcOverlayService npcOverlayService;
/** /**
* NPCs to highlight * NPCs to highlight
*/ */
@@ -175,7 +176,7 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
*/ */
private boolean skipNextSpawnCheck = false; private boolean skipNextSpawnCheck = false;
private final List<Function<NPC, HighlightedNpc>> higlightPredicates = new ArrayList<>(); private final Function<NPC, HighlightedNpc> isHighlighted = highlightedNpcs::get;
@Provides @Provides
NpcIndicatorsConfig provideConfig(ConfigManager configManager) NpcIndicatorsConfig provideConfig(ConfigManager configManager)
@@ -183,17 +184,11 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
return configManager.getConfig(NpcIndicatorsConfig.class); return configManager.getConfig(NpcIndicatorsConfig.class);
} }
@Override
public void configure(Binder binder)
{
binder.bind(NpcIndicatorsService.class).toInstance(this);
}
@Override @Override
protected void startUp() throws Exception protected void startUp() throws Exception
{ {
overlayManager.add(npcSceneOverlay); npcOverlayService.registerHighlighter(isHighlighted);
overlayManager.add(npcMinimapOverlay); overlayManager.add(npcRespawnOverlay);
clientThread.invoke(() -> clientThread.invoke(() ->
{ {
skipNextSpawnCheck = true; skipNextSpawnCheck = true;
@@ -204,8 +199,8 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
@Override @Override
protected void shutDown() throws Exception protected void shutDown() throws Exception
{ {
overlayManager.remove(npcSceneOverlay); npcOverlayService.unregisterHighlighter(isHighlighted);
overlayManager.remove(npcMinimapOverlay); overlayManager.remove(npcRespawnOverlay);
clientThread.invoke(() -> clientThread.invoke(() ->
{ {
deadNpcsToDisplay.clear(); deadNpcsToDisplay.clear();
@@ -367,10 +362,13 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
} }
highlightedNpcs.put(npc, highlightedNpc(npc)); highlightedNpcs.put(npc, highlightedNpc(npc));
} }
npcOverlayService.rebuild();
} }
else else
{ {
final String name = npc.getName(); final String name = npc.getName();
// this trips a config change which triggers the overlay rebuild
updateNpcsToHighlight(name); updateNpcsToHighlight(name);
} }
@@ -404,24 +402,7 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
memorizeNpc(npc); memorizeNpc(npc);
spawnedNpcsThisTick.add(npc); spawnedNpcsThisTick.add(npc);
} }
return;
} }
for (Function<NPC, HighlightedNpc> predicate : higlightPredicates)
{
HighlightedNpc highlightedNpc = predicate.apply(npc);
if (highlightedNpc != null)
{
highlightedNpcs.put(npc, highlightedNpc);
if (!client.isInInstancedRegion())
{
memorizeNpc(npc);
spawnedNpcsThisTick.add(npc);
}
return;
}
}
} }
@Subscribe @Subscribe
@@ -454,17 +435,6 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
|| highlightMatchesNPCName(npcName)) || highlightMatchesNPCName(npcName))
{ {
highlightedNpcs.put(npc, highlightedNpc(npc)); highlightedNpcs.put(npc, highlightedNpc(npc));
return;
}
for (Function<NPC, HighlightedNpc> predicate : higlightPredicates)
{
HighlightedNpc highlightedNpc = predicate.apply(npc);
if (highlightedNpc != null)
{
highlightedNpcs.put(npc, highlightedNpc);
return;
}
} }
} }
@@ -572,8 +542,7 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
return Text.fromCSV(configNpcs); return Text.fromCSV(configNpcs);
} }
@Override void rebuild()
public void rebuild()
{ {
highlights = getHighlights(); highlights = getHighlights();
highlightedNpcs.clear(); highlightedNpcs.clear();
@@ -586,7 +555,6 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
return; return;
} }
outer:
for (NPC npc : client.getNpcs()) for (NPC npc : client.getNpcs())
{ {
final String npcName = npc.getName(); final String npcName = npc.getName();
@@ -612,23 +580,11 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
continue; continue;
} }
for (Function<NPC, HighlightedNpc> predicate : higlightPredicates)
{
HighlightedNpc highlightedNpc = predicate.apply(npc);
if (highlightedNpc != null)
{
if (!client.isInInstancedRegion())
{
memorizeNpc(npc);
}
highlightedNpcs.put(npc, highlightedNpc);
continue outer;
}
}
// NPC is not highlighted // NPC is not highlighted
memorizedNpcs.remove(npc.getIndex()); memorizedNpcs.remove(npc.getIndex());
} }
npcOverlayService.rebuild();
} }
private boolean highlightMatchesNPCName(String npcName) private boolean highlightMatchesNPCName(String npcName)
@@ -746,18 +702,9 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
.outline(config.highlightOutline()) .outline(config.highlightOutline())
.name(config.drawNames()) .name(config.drawNames())
.nameOnMinimap(config.drawMinimapNames()) .nameOnMinimap(config.drawMinimapNames())
.borderWidth((float) config.borderWidth())
.outlineFeather(config.outlineFeather())
.render(n -> !n.isDead() || !config.ignoreDeadNpcs())
.build(); .build();
} }
@Override
public void registerHighlighter(Function<NPC, HighlightedNpc> p)
{
higlightPredicates.add(p);
}
@Override
public void unregisterHighlighter(Function<NPC, HighlightedNpc> p)
{
higlightPredicates.remove(p);
}
} }

View File

@@ -1,35 +0,0 @@
/*
* Copyright (c) 2021, Adam <Adam@sigterm.info>
* 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.npchighlight;
import java.util.function.Function;
import net.runelite.api.NPC;
public interface NpcIndicatorsService
{
void registerHighlighter(Function<NPC, HighlightedNpc> p);
void unregisterHighlighter(Function<NPC, HighlightedNpc> p);
void rebuild();
}

View File

@@ -38,8 +38,6 @@ import java.util.Locale;
import javax.inject.Inject; import javax.inject.Inject;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.Constants; import net.runelite.api.Constants;
import net.runelite.api.NPC;
import net.runelite.api.NPCComposition;
import net.runelite.api.Perspective; import net.runelite.api.Perspective;
import net.runelite.api.Point; import net.runelite.api.Point;
import net.runelite.api.coords.LocalPoint; import net.runelite.api.coords.LocalPoint;
@@ -48,10 +46,8 @@ import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer; import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayUtil; import net.runelite.client.ui.overlay.OverlayUtil;
import net.runelite.client.ui.overlay.outline.ModelOutlineRenderer;
import net.runelite.client.util.Text;
public class NpcSceneOverlay extends Overlay class NpcRespawnOverlay extends Overlay
{ {
// Anything but white text is quite hard to see since it is drawn on // Anything but white text is quite hard to see since it is drawn on
// a dark background // a dark background
@@ -67,16 +63,13 @@ public class NpcSceneOverlay extends Overlay
private final Client client; private final Client client;
private final NpcIndicatorsConfig config; private final NpcIndicatorsConfig config;
private final NpcIndicatorsPlugin plugin; private final NpcIndicatorsPlugin plugin;
private final ModelOutlineRenderer modelOutlineRenderer;
@Inject @Inject
NpcSceneOverlay(Client client, NpcIndicatorsConfig config, NpcIndicatorsPlugin plugin, NpcRespawnOverlay(Client client, NpcIndicatorsConfig config, NpcIndicatorsPlugin plugin)
ModelOutlineRenderer modelOutlineRenderer)
{ {
this.client = client; this.client = client;
this.config = config; this.config = config;
this.plugin = plugin; this.plugin = plugin;
this.modelOutlineRenderer = modelOutlineRenderer;
setPosition(OverlayPosition.DYNAMIC); setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_SCENE); setLayer(OverlayLayer.ABOVE_SCENE);
} }
@@ -89,11 +82,6 @@ public class NpcSceneOverlay extends Overlay
plugin.getDeadNpcsToDisplay().forEach((id, npc) -> renderNpcRespawn(npc, graphics)); plugin.getDeadNpcsToDisplay().forEach((id, npc) -> renderNpcRespawn(npc, graphics));
} }
for (HighlightedNpc highlightedNpc : plugin.getHighlightedNpcs().values())
{
renderNpcOverlay(graphics, highlightedNpc);
}
return null; return null;
} }
@@ -141,61 +129,6 @@ public class NpcSceneOverlay extends Overlay
} }
} }
private void renderNpcOverlay(Graphics2D graphics, HighlightedNpc highlightedNpc)
{
NPC actor = highlightedNpc.getNpc();
NPCComposition npcComposition = actor.getTransformedComposition();
if (npcComposition == null || !npcComposition.isInteractible()
|| (actor.isDead() && config.ignoreDeadNpcs()))
{
return;
}
final Color borderColor = highlightedNpc.getHighlightColor();
final Color fillColor = highlightedNpc.getFillColor();
if (highlightedNpc.isHull())
{
Shape objectClickbox = actor.getConvexHull();
renderPoly(graphics, borderColor, fillColor, objectClickbox);
}
if (highlightedNpc.isTile())
{
Polygon tilePoly = actor.getCanvasTilePoly();
renderPoly(graphics, borderColor, fillColor, tilePoly);
}
if (highlightedNpc.isSwTile())
{
int size = npcComposition.getSize();
LocalPoint lp = actor.getLocalLocation();
int x = lp.getX() - ((size - 1) * Perspective.LOCAL_TILE_SIZE / 2);
int y = lp.getY() - ((size - 1) * Perspective.LOCAL_TILE_SIZE / 2);
Polygon southWestTilePoly = Perspective.getCanvasTilePoly(client, new LocalPoint(x, y));
renderPoly(graphics, borderColor, fillColor, southWestTilePoly);
}
if (highlightedNpc.isOutline())
{
modelOutlineRenderer.drawOutline(actor, (int)config.borderWidth(), borderColor, config.outlineFeather());
}
if (highlightedNpc.isName() && actor.getName() != null)
{
String npcName = Text.removeTags(actor.getName());
Point textLocation = actor.getCanvasTextLocation(graphics, npcName, actor.getLogicalHeight() + 40);
if (textLocation != null)
{
OverlayUtil.renderTextLocation(graphics, textLocation, npcName, borderColor);
}
}
}
private void renderPoly(Graphics2D graphics, Color borderColor, Color fillColor, Shape polygon) private void renderPoly(Graphics2D graphics, Color borderColor, Color fillColor, Shape polygon)
{ {
if (polygon != null) if (polygon != null)

View File

@@ -24,20 +24,18 @@
*/ */
package net.runelite.client.plugins.runecraft; package net.runelite.client.plugins.runecraft;
import java.awt.Color;
import java.awt.Polygon;
import java.awt.Shape;
import com.google.inject.Inject; import com.google.inject.Inject;
import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Shape;
import java.util.Set;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.DecorativeObject; import net.runelite.api.DecorativeObject;
import net.runelite.api.NPC;
import net.runelite.api.Point; import net.runelite.api.Point;
import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer; import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayUtil;
class AbyssOverlay extends Overlay class AbyssOverlay extends Overlay
{ {
@@ -58,44 +56,20 @@ class AbyssOverlay extends Overlay
@Override @Override
public Dimension render(Graphics2D graphics) public Dimension render(Graphics2D graphics)
{ {
if (config.showRifts() && config.showClickBox()) Set<DecorativeObject> abyssObjects = plugin.getAbyssObjects();
if (abyssObjects.isEmpty() || !config.showRifts() || !config.showClickBox())
{ {
for (DecorativeObject object : plugin.getAbyssObjects()) return null;
{
renderRift(graphics, object);
}
} }
if (config.hightlightDarkMage()) for (DecorativeObject object : abyssObjects)
{ {
highlightDarkMage(graphics); renderRift(graphics, object);
} }
return null; return null;
} }
private void highlightDarkMage(Graphics2D graphics)
{
if (!plugin.isDegradedPouchInInventory())
{
return;
}
NPC darkMage = plugin.getDarkMage();
if (darkMage == null)
{
return;
}
Polygon tilePoly = darkMage.getCanvasTilePoly();
if (tilePoly == null)
{
return;
}
OverlayUtil.renderPolygon(graphics, tilePoly, Color.green);
}
private void renderRift(Graphics2D graphics, DecorativeObject object) private void renderRift(Graphics2D graphics, DecorativeObject object)
{ {
AbyssRifts rift = AbyssRifts.getRift(object.getId()); AbyssRifts rift = AbyssRifts.getRift(object.getId());

View File

@@ -26,10 +26,12 @@ package net.runelite.client.plugins.runecraft;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.inject.Provides; import com.google.inject.Provides;
import java.awt.Color;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.function.Function;
import java.util.stream.Stream; import java.util.stream.Stream;
import javax.inject.Inject; import javax.inject.Inject;
import lombok.AccessLevel; import lombok.AccessLevel;
@@ -47,12 +49,12 @@ import net.runelite.api.events.DecorativeObjectDespawned;
import net.runelite.api.events.DecorativeObjectSpawned; import net.runelite.api.events.DecorativeObjectSpawned;
import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.ItemContainerChanged; import net.runelite.api.events.ItemContainerChanged;
import net.runelite.api.events.NpcDespawned;
import net.runelite.api.events.NpcSpawned;
import net.runelite.client.Notifier; import net.runelite.client.Notifier;
import net.runelite.client.config.ConfigManager; import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe; import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.ConfigChanged; import net.runelite.client.events.ConfigChanged;
import net.runelite.client.game.npcoverlay.HighlightedNpc;
import net.runelite.client.game.npcoverlay.NpcOverlayService;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.ui.overlay.OverlayManager;
@@ -78,12 +80,8 @@ public class RunecraftPlugin extends Plugin
@Getter(AccessLevel.PACKAGE) @Getter(AccessLevel.PACKAGE)
private final Set<AbyssRifts> rifts = new HashSet<>(); private final Set<AbyssRifts> rifts = new HashSet<>();
@Getter(AccessLevel.PACKAGE)
private boolean degradedPouchInInventory; private boolean degradedPouchInInventory;
@Getter(AccessLevel.PACKAGE)
private NPC darkMage;
@Inject @Inject
private OverlayManager overlayManager; private OverlayManager overlayManager;
@@ -99,6 +97,11 @@ public class RunecraftPlugin extends Plugin
@Inject @Inject
private Notifier notifier; private Notifier notifier;
@Inject
private NpcOverlayService npcOverlayService;
private final Function<NPC, HighlightedNpc> highlightDarkMage = this::highlightDarkMage;
@Provides @Provides
RunecraftConfig getConfig(ConfigManager configManager) RunecraftConfig getConfig(ConfigManager configManager)
{ {
@@ -108,6 +111,7 @@ public class RunecraftPlugin extends Plugin
@Override @Override
protected void startUp() throws Exception protected void startUp() throws Exception
{ {
npcOverlayService.registerHighlighter(highlightDarkMage);
overlayManager.add(abyssOverlay); overlayManager.add(abyssOverlay);
overlayManager.add(abyssMinimapOverlay); overlayManager.add(abyssMinimapOverlay);
updateRifts(); updateRifts();
@@ -116,10 +120,10 @@ public class RunecraftPlugin extends Plugin
@Override @Override
protected void shutDown() throws Exception protected void shutDown() throws Exception
{ {
npcOverlayService.unregisterHighlighter(highlightDarkMage);
overlayManager.remove(abyssOverlay); overlayManager.remove(abyssOverlay);
overlayManager.remove(abyssMinimapOverlay); overlayManager.remove(abyssMinimapOverlay);
abyssObjects.clear(); abyssObjects.clear();
darkMage = null;
degradedPouchInInventory = false; degradedPouchInInventory = false;
} }
@@ -170,16 +174,9 @@ public class RunecraftPlugin extends Plugin
public void onGameStateChanged(GameStateChanged event) public void onGameStateChanged(GameStateChanged event)
{ {
GameState gameState = event.getGameState(); GameState gameState = event.getGameState();
switch (gameState) if (gameState == GameState.LOADING)
{ {
case LOADING: abyssObjects.clear();
abyssObjects.clear();
break;
case CONNECTION_LOST:
case HOPPING:
case LOGIN_SCREEN:
darkMage = null;
break;
} }
} }
@@ -195,24 +192,18 @@ public class RunecraftPlugin extends Plugin
degradedPouchInInventory = Stream.of(items).anyMatch(i -> DEGRADED_POUCHES.contains(i.getId())); degradedPouchInInventory = Stream.of(items).anyMatch(i -> DEGRADED_POUCHES.contains(i.getId()));
} }
@Subscribe private HighlightedNpc highlightDarkMage(NPC npc)
public void onNpcSpawned(NpcSpawned event)
{ {
final NPC npc = event.getNpc();
if (npc.getId() == NpcID.DARK_MAGE) if (npc.getId() == NpcID.DARK_MAGE)
{ {
darkMage = npc; return HighlightedNpc.builder()
} .npc(npc)
} .tile(true)
.highlightColor(Color.GREEN)
@Subscribe .render(n -> config.hightlightDarkMage() && degradedPouchInInventory)
public void onNpcDespawned(NpcDespawned event) .build();
{
final NPC npc = event.getNpc();
if (npc == darkMage)
{
darkMage = null;
} }
return null;
} }
private void updateRifts() private void updateRifts()

View File

@@ -83,12 +83,10 @@ import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.ChatInput; import net.runelite.client.events.ChatInput;
import net.runelite.client.events.ConfigChanged; import net.runelite.client.events.ConfigChanged;
import net.runelite.client.game.ItemManager; import net.runelite.client.game.ItemManager;
import net.runelite.client.game.npcoverlay.HighlightedNpc;
import net.runelite.client.game.npcoverlay.NpcOverlayService;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDependency;
import net.runelite.client.plugins.PluginDescriptor; 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; import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager; import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
import net.runelite.client.util.ColorUtil; import net.runelite.client.util.ColorUtil;
@@ -101,7 +99,6 @@ import org.apache.commons.lang3.ArrayUtils;
description = "Show additional slayer task related information", description = "Show additional slayer task related information",
tags = {"combat", "notifications", "overlay", "tasks"} tags = {"combat", "notifications", "overlay", "tasks"}
) )
@PluginDependency(NpcIndicatorsPlugin.class)
@Slf4j @Slf4j
public class SlayerPlugin extends Plugin public class SlayerPlugin extends Plugin
{ {
@@ -176,7 +173,7 @@ public class SlayerPlugin extends Plugin
private ChatClient chatClient; private ChatClient chatClient;
@Inject @Inject
private NpcIndicatorsService npcIndicatorsService; private NpcOverlayService npcOverlayService;
@Getter(AccessLevel.PACKAGE) @Getter(AccessLevel.PACKAGE)
private final List<NPC> targets = new ArrayList<>(); private final List<NPC> targets = new ArrayList<>();
@@ -233,7 +230,7 @@ public class SlayerPlugin extends Plugin
protected void startUp() throws Exception protected void startUp() throws Exception
{ {
chatCommandManager.registerCommandAsync(TASK_COMMAND_STRING, this::taskLookup, this::taskSubmit); chatCommandManager.registerCommandAsync(TASK_COMMAND_STRING, this::taskLookup, this::taskSubmit);
npcIndicatorsService.registerHighlighter(isTarget); npcOverlayService.registerHighlighter(isTarget);
overlayManager.add(overlay); overlayManager.add(overlay);
overlayManager.add(targetWeaknessOverlay); overlayManager.add(targetWeaknessOverlay);
@@ -259,8 +256,7 @@ public class SlayerPlugin extends Plugin
protected void shutDown() throws Exception protected void shutDown() throws Exception
{ {
chatCommandManager.unregisterCommand(TASK_COMMAND_STRING); chatCommandManager.unregisterCommand(TASK_COMMAND_STRING);
npcIndicatorsService.unregisterHighlighter(isTarget); npcOverlayService.unregisterHighlighter(isTarget);
npcIndicatorsService.rebuild();
overlayManager.remove(overlay); overlayManager.remove(overlay);
overlayManager.remove(targetWeaknessOverlay); overlayManager.remove(targetWeaknessOverlay);
@@ -350,10 +346,7 @@ public class SlayerPlugin extends Plugin
setProfileConfig(SlayerConfig.TASK_LOC_KEY, taskLocation); setProfileConfig(SlayerConfig.TASK_LOC_KEY, taskLocation);
} }
@Subscribe( @Subscribe
// Run prior to npc indicators plugin so targets is populated before the isTarget predicate is checked
priority = 1
)
public void onNpcSpawned(NpcSpawned npcSpawned) public void onNpcSpawned(NpcSpawned npcSpawned)
{ {
NPC npc = npcSpawned.getNpc(); NPC npc = npcSpawned.getNpc();
@@ -620,7 +613,7 @@ public class SlayerPlugin extends Plugin
} }
else else
{ {
clientThread.invoke(npcIndicatorsService::rebuild); npcOverlayService.rebuild();
} }
} }
@@ -746,7 +739,7 @@ public class SlayerPlugin extends Plugin
Task task = Task.getTask(name); Task task = Task.getTask(name);
rebuildTargetNames(task); rebuildTargetNames(task);
rebuildTargetList(); rebuildTargetList();
npcIndicatorsService.rebuild(); npcOverlayService.rebuild();
} }
private void addCounter() private void addCounter()

View File

@@ -79,6 +79,7 @@ public class NpcIndicatorsPluginTest
public void setUp() public void setUp()
{ {
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this); Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
when(npcIndicatorsConfig.highlightColor()).thenReturn(Color.RED);
} }
@Test @Test

View File

@@ -56,7 +56,7 @@ import net.runelite.client.chat.ChatCommandManager;
import net.runelite.client.chat.ChatMessageManager; import net.runelite.client.chat.ChatMessageManager;
import net.runelite.client.config.ConfigManager; import net.runelite.client.config.ConfigManager;
import net.runelite.client.game.ItemManager; import net.runelite.client.game.ItemManager;
import net.runelite.client.plugins.npchighlight.NpcIndicatorsService; import net.runelite.client.game.npcoverlay.NpcOverlayService;
import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager; import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
import net.runelite.http.api.chat.ChatClient; import net.runelite.http.api.chat.ChatClient;
@@ -176,7 +176,7 @@ public class SlayerPluginTest
@Mock @Mock
@Bind @Bind
NpcIndicatorsService npcIndicatorsService; NpcOverlayService npcOverlayService;
@Inject @Inject
SlayerPlugin slayerPlugin; SlayerPlugin slayerPlugin;