npc indicators: use events for highlighted npcs
This commit is contained in:
@@ -30,7 +30,6 @@ import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Polygon;
|
||||
import java.util.Map;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.NPC;
|
||||
@@ -59,10 +58,9 @@ public class NpcClickboxOverlay extends Overlay
|
||||
@Override
|
||||
public Dimension render(Graphics2D graphics)
|
||||
{
|
||||
Map<NPC, String> npcMap = plugin.getHighlightedNpcs();
|
||||
for (NPC npc : npcMap.keySet())
|
||||
for (NPC npc : plugin.getHighlightedNpcs())
|
||||
{
|
||||
renderNpcOverlay(graphics, npc, npcMap.get(npc), config.getNpcColor());
|
||||
renderNpcOverlay(graphics, npc, npc.getName(), config.getNpcColor());
|
||||
}
|
||||
|
||||
NPC[] npcs = client.getCachedNPCs();
|
||||
|
||||
@@ -27,22 +27,23 @@ package net.runelite.client.plugins.npchighlight;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.google.inject.Provides;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.inject.Inject;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.events.ConfigChanged;
|
||||
import net.runelite.api.events.FocusChanged;
|
||||
import net.runelite.api.events.GameTick;
|
||||
import net.runelite.api.events.MenuOptionClicked;
|
||||
import net.runelite.api.events.NpcDespawned;
|
||||
import net.runelite.api.events.NpcSpawned;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.input.KeyManager;
|
||||
import net.runelite.client.menus.MenuManager;
|
||||
@@ -91,7 +92,12 @@ public class NpcIndicatorsPlugin extends Plugin
|
||||
* NPCs tagged due to highlight in the config
|
||||
*/
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private Map<NPC, String> highlightedNpcs = new HashMap<>();
|
||||
private final Set<NPC> highlightedNpcs = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Highlight strings from the configuration
|
||||
*/
|
||||
private List<String> highlights = new ArrayList<>();
|
||||
|
||||
private boolean hotKeyPressed = false;
|
||||
|
||||
@@ -112,15 +118,67 @@ public class NpcIndicatorsPlugin extends Plugin
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
keyManager.registerKeyListener(inputListener);
|
||||
highlights = getHighlights();
|
||||
rebuildNpcs();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutDown() throws Exception
|
||||
{
|
||||
npcTags.clear();
|
||||
highlightedNpcs.clear();
|
||||
keyManager.unregisterKeyListener(inputListener);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onConfigChanged(ConfigChanged configChanged)
|
||||
{
|
||||
if (!configChanged.getGroup().equals("npcindicators"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
highlights = getHighlights();
|
||||
rebuildNpcs();
|
||||
}
|
||||
|
||||
private List<String> getHighlights()
|
||||
{
|
||||
String configNpcs = config.getNpcToHighlight().toLowerCase();
|
||||
if (configNpcs.isEmpty())
|
||||
return Collections.emptyList();
|
||||
|
||||
List<String> highlightedNpcs = Arrays.asList(configNpcs.split(DELIMITER_REGEX));
|
||||
return highlightedNpcs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild highlighted npcs
|
||||
*/
|
||||
private void rebuildNpcs()
|
||||
{
|
||||
highlightedNpcs.clear();
|
||||
|
||||
for (NPC npc : client.getNpcs())
|
||||
{
|
||||
String npcName = npc.getName();
|
||||
|
||||
if (npcName == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (String highlight : highlights)
|
||||
{
|
||||
if (WildcardMatcher.matches(highlight, npcName))
|
||||
{
|
||||
highlightedNpcs.add(npc);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onFocusChanged(FocusChanged focusChanged)
|
||||
{
|
||||
@@ -139,9 +197,28 @@ public class NpcIndicatorsPlugin extends Plugin
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onGameTick(GameTick tick)
|
||||
public void onNpcSpawned(NpcSpawned npcSpawned)
|
||||
{
|
||||
highlightedNpcs = buildNpcsToHighlight();
|
||||
NPC npc = npcSpawned.getNpc();
|
||||
String npcName = npc.getName();
|
||||
if (npcName != null)
|
||||
{
|
||||
for (String highlight : highlights)
|
||||
{
|
||||
if (WildcardMatcher.matches(highlight, npcName))
|
||||
{
|
||||
highlightedNpcs.add(npc);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onNpcDespawned(NpcDespawned npcDespawned)
|
||||
{
|
||||
NPC npc = npcDespawned.getNpc();
|
||||
highlightedNpcs.remove(npc);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -150,36 +227,6 @@ public class NpcIndicatorsPlugin extends Plugin
|
||||
return Arrays.asList(npcClickboxOverlay, npcMinimapOverlay);
|
||||
}
|
||||
|
||||
private Map<NPC, String> buildNpcsToHighlight()
|
||||
{
|
||||
String configNpcs = config.getNpcToHighlight().toLowerCase();
|
||||
if (configNpcs.isEmpty())
|
||||
return Collections.EMPTY_MAP;
|
||||
|
||||
Map<NPC, String> npcMap = new HashMap<>();
|
||||
List<String> highlightedNpcs = Arrays.asList(configNpcs.split(DELIMITER_REGEX));
|
||||
|
||||
for (NPC npc : client.getNpcs())
|
||||
{
|
||||
String npcName = npc.getName();
|
||||
|
||||
if (npcName == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (String highlight : highlightedNpcs)
|
||||
{
|
||||
if (WildcardMatcher.matches(highlight, npcName))
|
||||
{
|
||||
npcMap.put(npc, npcName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return npcMap;
|
||||
}
|
||||
|
||||
void updateNpcMenuOptions(boolean pressed)
|
||||
{
|
||||
if (!config.isTagEnabled())
|
||||
|
||||
@@ -28,7 +28,6 @@ package net.runelite.client.plugins.npchighlight;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.util.Map;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.NPC;
|
||||
@@ -57,10 +56,9 @@ public class NpcMinimapOverlay extends Overlay
|
||||
@Override
|
||||
public Dimension render(Graphics2D graphics)
|
||||
{
|
||||
Map<NPC, String> npcMap = plugin.getHighlightedNpcs();
|
||||
for (NPC npc : npcMap.keySet())
|
||||
for (NPC npc : plugin.getHighlightedNpcs())
|
||||
{
|
||||
renderNpcOverlay(graphics, npc, npcMap.get(npc), config.getNpcColor());
|
||||
renderNpcOverlay(graphics, npc, npc.getName(), config.getNpcColor());
|
||||
}
|
||||
|
||||
NPC[] npcs = client.getCachedNPCs();
|
||||
|
||||
Reference in New Issue
Block a user