npc indicators: allow plugins to specify highlight styles
After changing the slayer plugin to use npc indicators for the outline style, some users request being able to set the color of slayer highlights to be unique in order to identify marked npcs such as superiors while slaying. This readds the previous target color config and adds new highlight style options to the slayer plugin.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.awt.Color;
|
||||
import lombok.Builder;
|
||||
import lombok.Value;
|
||||
import net.runelite.api.NPC;
|
||||
|
||||
@Value
|
||||
@Builder
|
||||
public class HighlightedNpc
|
||||
{
|
||||
NPC npc;
|
||||
Color highlightColor;
|
||||
Color fillColor;
|
||||
boolean hull;
|
||||
boolean tile;
|
||||
boolean swTile;
|
||||
boolean outline;
|
||||
boolean name;
|
||||
boolean nameOnMinimap;
|
||||
}
|
||||
@@ -39,7 +39,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Function;
|
||||
import javax.inject.Inject;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
@@ -116,7 +116,7 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
|
||||
* NPCs to highlight
|
||||
*/
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private final Set<NPC> highlightedNpcs = new HashSet<>();
|
||||
private final Map<NPC, HighlightedNpc> highlightedNpcs = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Dead NPCs that should be displayed with a respawn indicator if the config is on.
|
||||
@@ -175,7 +175,7 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
|
||||
*/
|
||||
private boolean skipNextSpawnCheck = false;
|
||||
|
||||
private final List<Predicate<NPC>> higlightPredicates = new ArrayList<>();
|
||||
private final List<Function<NPC, HighlightedNpc>> higlightPredicates = new ArrayList<>();
|
||||
|
||||
@Provides
|
||||
NpcIndicatorsConfig provideConfig(ConfigManager configManager)
|
||||
@@ -265,7 +265,7 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
|
||||
color = config.deadNpcMenuColor();
|
||||
}
|
||||
|
||||
if (color == null && highlightedNpcs.contains(npc) && config.highlightMenuNames() && (!npc.isDead() || !config.ignoreDeadNpcs()))
|
||||
if (color == null && highlightedNpcs.containsKey(npc) && config.highlightMenuNames() && (!npc.isDead() || !config.ignoreDeadNpcs()))
|
||||
{
|
||||
color = config.highlightColor();
|
||||
}
|
||||
@@ -365,7 +365,7 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
|
||||
memorizeNpc(npc);
|
||||
npcTags.add(id);
|
||||
}
|
||||
highlightedNpcs.add(npc);
|
||||
highlightedNpcs.put(npc, highlightedNpc(npc));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -391,14 +391,14 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
|
||||
if (npcTags.contains(npc.getIndex()))
|
||||
{
|
||||
memorizeNpc(npc);
|
||||
highlightedNpcs.add(npc);
|
||||
highlightedNpcs.put(npc, highlightedNpc(npc));
|
||||
spawnedNpcsThisTick.add(npc);
|
||||
return;
|
||||
}
|
||||
|
||||
if (highlightMatchesNPCName(npcName))
|
||||
{
|
||||
highlightedNpcs.add(npc);
|
||||
highlightedNpcs.put(npc, highlightedNpc(npc));
|
||||
if (!client.isInInstancedRegion())
|
||||
{
|
||||
memorizeNpc(npc);
|
||||
@@ -407,11 +407,12 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
|
||||
return;
|
||||
}
|
||||
|
||||
for (Predicate<NPC> predicate : higlightPredicates)
|
||||
for (Function<NPC, HighlightedNpc> predicate : higlightPredicates)
|
||||
{
|
||||
if (predicate.test(npc))
|
||||
HighlightedNpc highlightedNpc = predicate.apply(npc);
|
||||
if (highlightedNpc != null)
|
||||
{
|
||||
highlightedNpcs.add(npc);
|
||||
highlightedNpcs.put(npc, highlightedNpc);
|
||||
if (!client.isInInstancedRegion())
|
||||
{
|
||||
memorizeNpc(npc);
|
||||
@@ -452,7 +453,18 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
|
||||
if (npcTags.contains(npc.getIndex())
|
||||
|| highlightMatchesNPCName(npcName))
|
||||
{
|
||||
highlightedNpcs.add(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -586,7 +598,7 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
|
||||
|
||||
if (npcTags.contains(npc.getIndex()))
|
||||
{
|
||||
highlightedNpcs.add(npc);
|
||||
highlightedNpcs.put(npc, highlightedNpc(npc));
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -596,19 +608,20 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
|
||||
{
|
||||
memorizeNpc(npc);
|
||||
}
|
||||
highlightedNpcs.add(npc);
|
||||
highlightedNpcs.put(npc, highlightedNpc(npc));
|
||||
continue;
|
||||
}
|
||||
|
||||
for (Predicate<NPC> predicate : higlightPredicates)
|
||||
for (Function<NPC, HighlightedNpc> predicate : higlightPredicates)
|
||||
{
|
||||
if (predicate.test(npc))
|
||||
HighlightedNpc highlightedNpc = predicate.apply(npc);
|
||||
if (highlightedNpc != null)
|
||||
{
|
||||
if (!client.isInInstancedRegion())
|
||||
{
|
||||
memorizeNpc(npc);
|
||||
}
|
||||
highlightedNpcs.add(npc);
|
||||
highlightedNpcs.put(npc, highlightedNpc);
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
@@ -721,14 +734,29 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
|
||||
teleportGraphicsObjectSpawnedThisTick.clear();
|
||||
}
|
||||
|
||||
private HighlightedNpc highlightedNpc(NPC npc)
|
||||
{
|
||||
return HighlightedNpc.builder()
|
||||
.npc(npc)
|
||||
.highlightColor(config.highlightColor())
|
||||
.fillColor(config.fillColor())
|
||||
.hull(config.highlightHull())
|
||||
.tile(config.highlightTile())
|
||||
.swTile(config.highlightSouthWestTile())
|
||||
.outline(config.highlightOutline())
|
||||
.name(config.drawNames())
|
||||
.nameOnMinimap(config.drawMinimapNames())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerHighlighter(Predicate<NPC> p)
|
||||
public void registerHighlighter(Function<NPC, HighlightedNpc> p)
|
||||
{
|
||||
higlightPredicates.add(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterHighlighter(Predicate<NPC> p)
|
||||
public void unregisterHighlighter(Function<NPC, HighlightedNpc> p)
|
||||
{
|
||||
higlightPredicates.remove(p);
|
||||
}
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.npchighlight;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Function;
|
||||
import net.runelite.api.NPC;
|
||||
|
||||
public interface NpcIndicatorsService
|
||||
{
|
||||
void registerHighlighter(Predicate<NPC> p);
|
||||
void unregisterHighlighter(Predicate<NPC> p);
|
||||
void registerHighlighter(Function<NPC, HighlightedNpc> p);
|
||||
void unregisterHighlighter(Function<NPC, HighlightedNpc> p);
|
||||
void rebuild();
|
||||
}
|
||||
|
||||
@@ -55,16 +55,18 @@ public class NpcMinimapOverlay extends Overlay
|
||||
@Override
|
||||
public Dimension render(Graphics2D graphics)
|
||||
{
|
||||
for (NPC npc : plugin.getHighlightedNpcs())
|
||||
for (HighlightedNpc highlightedNpc : plugin.getHighlightedNpcs().values())
|
||||
{
|
||||
renderNpcOverlay(graphics, npc, Text.removeTags(npc.getName()), config.highlightColor());
|
||||
renderNpcOverlay(graphics, highlightedNpc);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void renderNpcOverlay(Graphics2D graphics, NPC actor, String name, Color color)
|
||||
private void renderNpcOverlay(Graphics2D graphics, HighlightedNpc highlightedNpc)
|
||||
{
|
||||
NPC actor = highlightedNpc.getNpc();
|
||||
String name = Text.removeTags(actor.getName());
|
||||
NPCComposition npcComposition = actor.getTransformedComposition();
|
||||
if (npcComposition == null || !npcComposition.isInteractible()
|
||||
|| (actor.isDead() && config.ignoreDeadNpcs()))
|
||||
@@ -75,9 +77,10 @@ public class NpcMinimapOverlay extends Overlay
|
||||
Point minimapLocation = actor.getMinimapLocation();
|
||||
if (minimapLocation != null)
|
||||
{
|
||||
Color color = highlightedNpc.getHighlightColor();
|
||||
OverlayUtil.renderMinimapLocation(graphics, minimapLocation, color.darker());
|
||||
|
||||
if (config.drawMinimapNames())
|
||||
if (highlightedNpc.isNameOnMinimap())
|
||||
{
|
||||
OverlayUtil.renderTextLocation(graphics, minimapLocation, name, color);
|
||||
}
|
||||
|
||||
@@ -89,9 +89,9 @@ public class NpcSceneOverlay extends Overlay
|
||||
plugin.getDeadNpcsToDisplay().forEach((id, npc) -> renderNpcRespawn(npc, graphics));
|
||||
}
|
||||
|
||||
for (NPC npc : plugin.getHighlightedNpcs())
|
||||
for (HighlightedNpc highlightedNpc : plugin.getHighlightedNpcs().values())
|
||||
{
|
||||
renderNpcOverlay(graphics, npc);
|
||||
renderNpcOverlay(graphics, highlightedNpc);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -141,8 +141,9 @@ public class NpcSceneOverlay extends Overlay
|
||||
}
|
||||
}
|
||||
|
||||
private void renderNpcOverlay(Graphics2D graphics, NPC actor)
|
||||
private void renderNpcOverlay(Graphics2D graphics, HighlightedNpc highlightedNpc)
|
||||
{
|
||||
NPC actor = highlightedNpc.getNpc();
|
||||
NPCComposition npcComposition = actor.getTransformedComposition();
|
||||
if (npcComposition == null || !npcComposition.isInteractible()
|
||||
|| (actor.isDead() && config.ignoreDeadNpcs()))
|
||||
@@ -150,16 +151,16 @@ public class NpcSceneOverlay extends Overlay
|
||||
return;
|
||||
}
|
||||
|
||||
final Color borderColor = config.highlightColor();
|
||||
final Color fillColor = config.fillColor();
|
||||
final Color borderColor = highlightedNpc.getHighlightColor();
|
||||
final Color fillColor = highlightedNpc.getFillColor();
|
||||
|
||||
if (config.highlightHull())
|
||||
if (highlightedNpc.isHull())
|
||||
{
|
||||
Shape objectClickbox = actor.getConvexHull();
|
||||
renderPoly(graphics, borderColor, fillColor, objectClickbox);
|
||||
}
|
||||
|
||||
if (config.highlightTile())
|
||||
if (highlightedNpc.isTile())
|
||||
{
|
||||
int size = npcComposition.getSize();
|
||||
LocalPoint lp = actor.getLocalLocation();
|
||||
@@ -168,7 +169,7 @@ public class NpcSceneOverlay extends Overlay
|
||||
renderPoly(graphics, borderColor, fillColor, tilePoly);
|
||||
}
|
||||
|
||||
if (config.highlightSouthWestTile())
|
||||
if (highlightedNpc.isSwTile())
|
||||
{
|
||||
int size = npcComposition.getSize();
|
||||
LocalPoint lp = actor.getLocalLocation();
|
||||
@@ -181,12 +182,12 @@ public class NpcSceneOverlay extends Overlay
|
||||
renderPoly(graphics, borderColor, fillColor, southWestTilePoly);
|
||||
}
|
||||
|
||||
if (config.highlightOutline())
|
||||
if (highlightedNpc.isOutline())
|
||||
{
|
||||
modelOutlineRenderer.drawOutline(actor, (int)config.borderWidth(), borderColor, config.outlineFeather());
|
||||
}
|
||||
|
||||
if (config.drawNames() && actor.getName() != null)
|
||||
if (highlightedNpc.isName() && actor.getName() != null)
|
||||
{
|
||||
String npcName = Text.removeTags(actor.getName());
|
||||
Point textLocation = actor.getCanvasTextLocation(graphics, npcName, actor.getLogicalHeight() + 40);
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.slayer;
|
||||
|
||||
import java.awt.Color;
|
||||
import net.runelite.client.config.Alpha;
|
||||
import net.runelite.client.config.Config;
|
||||
import net.runelite.client.config.ConfigGroup;
|
||||
import net.runelite.client.config.ConfigItem;
|
||||
@@ -90,17 +92,51 @@ public interface SlayerConfig extends Config
|
||||
|
||||
@ConfigItem(
|
||||
position = 5,
|
||||
keyName = "highlightTargets",
|
||||
name = "Highlight Targets",
|
||||
description = "Highlight monsters you can kill for your current slayer assignment"
|
||||
keyName = "highlightHull",
|
||||
name = "Highlight hull",
|
||||
description = "Configures whether the NPC hull should be highlighted"
|
||||
)
|
||||
default boolean highlightTargets()
|
||||
default boolean highlightHull()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 6,
|
||||
keyName = "highlightTile",
|
||||
name = "Highlight tile",
|
||||
description = "Configures whether the NPC tile should be highlighted"
|
||||
)
|
||||
default boolean highlightTile()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 7,
|
||||
keyName = "highlightOutline",
|
||||
name = "Highlight outline",
|
||||
description = "Configures whether or not the NPC outline should be highlighted"
|
||||
)
|
||||
default boolean highlightOutline()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Alpha
|
||||
@ConfigItem(
|
||||
position = 8,
|
||||
keyName = "targetColor",
|
||||
name = "Target color",
|
||||
description = "Color of the highlighted targets"
|
||||
)
|
||||
default Color getTargetColor()
|
||||
{
|
||||
return Color.RED;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 9,
|
||||
keyName = "weaknessPrompt",
|
||||
name = "Show Monster Weakness",
|
||||
description = "Show an overlay on a monster when it is weak enough to finish off (Only Lizards, Gargoyles & Rockslugs)"
|
||||
@@ -111,7 +147,7 @@ public interface SlayerConfig extends Config
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 8,
|
||||
position = 10,
|
||||
keyName = "taskCommand",
|
||||
name = "Task Command",
|
||||
description = "Configures whether the slayer task command is enabled<br> !task"
|
||||
|
||||
@@ -39,7 +39,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.inject.Inject;
|
||||
@@ -86,6 +86,7 @@ import net.runelite.client.game.ItemManager;
|
||||
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;
|
||||
@@ -210,7 +211,23 @@ public class SlayerPlugin extends Plugin
|
||||
private boolean loginFlag;
|
||||
private final List<String> targetNames = new ArrayList<>();
|
||||
|
||||
public final Predicate<NPC> isTarget = (n) -> config.highlightTargets() && targets.contains(n);
|
||||
public final Function<NPC, HighlightedNpc> isTarget = (n) ->
|
||||
{
|
||||
if ((config.highlightHull() || config.highlightTile() || config.highlightOutline()) && targets.contains(n))
|
||||
{
|
||||
Color color = config.getTargetColor();
|
||||
return HighlightedNpc.builder()
|
||||
.npc(n)
|
||||
.highlightColor(color)
|
||||
.fillColor(ColorUtil.colorWithAlpha(color, color.getAlpha() / 12))
|
||||
.hull(config.highlightHull())
|
||||
.tile(config.highlightTile())
|
||||
.outline(config.highlightOutline())
|
||||
.build();
|
||||
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void startUp() throws Exception
|
||||
@@ -603,7 +620,7 @@ public class SlayerPlugin extends Plugin
|
||||
}
|
||||
else
|
||||
{
|
||||
npcIndicatorsService.rebuild();
|
||||
clientThread.invoke(npcIndicatorsService::rebuild);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user