Merge pull request #2426 from Adam-/npcindicators
Cleanup npcindicators
This commit is contained in:
@@ -30,7 +30,6 @@ import java.awt.Color;
|
|||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Polygon;
|
import java.awt.Polygon;
|
||||||
import java.util.Map;
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.NPC;
|
import net.runelite.api.NPC;
|
||||||
@@ -59,16 +58,19 @@ public class NpcClickboxOverlay extends Overlay
|
|||||||
@Override
|
@Override
|
||||||
public Dimension render(Graphics2D graphics)
|
public Dimension render(Graphics2D graphics)
|
||||||
{
|
{
|
||||||
Map<NPC, String> npcMap = plugin.getHighlightedNpcs();
|
for (NPC npc : plugin.getHighlightedNpcs())
|
||||||
for (NPC npc : npcMap.keySet())
|
|
||||||
{
|
{
|
||||||
renderNpcOverlay(graphics, npc, npcMap.get(npc), config.getNpcColor());
|
renderNpcOverlay(graphics, npc, npc.getName(), config.getNpcColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (NPC npc : plugin.getTaggedNpcs())
|
NPC[] npcs = client.getCachedNPCs();
|
||||||
|
for (int npcId : plugin.getNpcTags())
|
||||||
{
|
{
|
||||||
String npcName = npc.getName();
|
NPC npc = npcs[npcId];
|
||||||
renderNpcOverlay(graphics, npc, npcName, config.getTagColor());
|
if (npc != null && npc.getName() != null)
|
||||||
|
{
|
||||||
|
renderNpcOverlay(graphics, npc, npc.getName(), config.getTagColor());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -31,19 +31,19 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.NPC;
|
import net.runelite.api.NPC;
|
||||||
|
import net.runelite.api.events.ConfigChanged;
|
||||||
import net.runelite.api.events.FocusChanged;
|
import net.runelite.api.events.FocusChanged;
|
||||||
import net.runelite.api.events.GameTick;
|
|
||||||
import net.runelite.api.events.MenuOptionClicked;
|
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.config.ConfigManager;
|
||||||
import net.runelite.client.input.KeyManager;
|
import net.runelite.client.input.KeyManager;
|
||||||
import net.runelite.client.menus.MenuManager;
|
import net.runelite.client.menus.MenuManager;
|
||||||
@@ -82,14 +82,22 @@ public class NpcIndicatorsPlugin extends Plugin
|
|||||||
@Inject
|
@Inject
|
||||||
private KeyManager keyManager;
|
private KeyManager keyManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NPCs tagged with the Tag option
|
||||||
|
*/
|
||||||
@Getter(AccessLevel.PACKAGE)
|
@Getter(AccessLevel.PACKAGE)
|
||||||
private final Set<Integer> npcTags = new HashSet<>();
|
private final Set<Integer> npcTags = new HashSet<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NPCs tagged due to highlight in the config
|
||||||
|
*/
|
||||||
@Getter(AccessLevel.PACKAGE)
|
@Getter(AccessLevel.PACKAGE)
|
||||||
private final List<NPC> taggedNpcs = new ArrayList<>();
|
private final Set<NPC> highlightedNpcs = new HashSet<>();
|
||||||
|
|
||||||
@Getter(AccessLevel.PACKAGE)
|
/**
|
||||||
private Map<NPC, String> highlightedNpcs = new HashMap<>();
|
* Highlight strings from the configuration
|
||||||
|
*/
|
||||||
|
private List<String> highlights = new ArrayList<>();
|
||||||
|
|
||||||
private boolean hotKeyPressed = false;
|
private boolean hotKeyPressed = false;
|
||||||
|
|
||||||
@@ -110,16 +118,67 @@ public class NpcIndicatorsPlugin extends Plugin
|
|||||||
protected void startUp() throws Exception
|
protected void startUp() throws Exception
|
||||||
{
|
{
|
||||||
keyManager.registerKeyListener(inputListener);
|
keyManager.registerKeyListener(inputListener);
|
||||||
|
highlights = getHighlights();
|
||||||
|
rebuildNpcs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void shutDown() throws Exception
|
protected void shutDown() throws Exception
|
||||||
{
|
{
|
||||||
npcTags.clear();
|
npcTags.clear();
|
||||||
taggedNpcs.clear();
|
highlightedNpcs.clear();
|
||||||
keyManager.unregisterKeyListener(inputListener);
|
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
|
@Subscribe
|
||||||
public void onFocusChanged(FocusChanged focusChanged)
|
public void onFocusChanged(FocusChanged focusChanged)
|
||||||
{
|
{
|
||||||
@@ -138,59 +197,36 @@ public class NpcIndicatorsPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onGameTick(GameTick tick)
|
public void onNpcSpawned(NpcSpawned npcSpawned)
|
||||||
{
|
{
|
||||||
highlightedNpcs = buildNpcsToHighlight();
|
NPC npc = npcSpawned.getNpc();
|
||||||
taggedNpcs.clear();
|
String npcName = npc.getName();
|
||||||
if (npcTags.isEmpty() || !config.isTagEnabled())
|
if (npcName != null)
|
||||||
{
|
{
|
||||||
return;
|
for (String highlight : highlights)
|
||||||
}
|
|
||||||
for (NPC npc : client.getNpcs())
|
|
||||||
{
|
|
||||||
if (npcTags.contains(npc.getIndex()) && npc.getName() != null)
|
|
||||||
{
|
{
|
||||||
taggedNpcs.add(npc);
|
if (WildcardMatcher.matches(highlight, npcName))
|
||||||
|
{
|
||||||
|
highlightedNpcs.add(npc);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onNpcDespawned(NpcDespawned npcDespawned)
|
||||||
|
{
|
||||||
|
NPC npc = npcDespawned.getNpc();
|
||||||
|
highlightedNpcs.remove(npc);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Overlay> getOverlays()
|
public Collection<Overlay> getOverlays()
|
||||||
{
|
{
|
||||||
return Arrays.asList(npcClickboxOverlay, npcMinimapOverlay);
|
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)
|
void updateNpcMenuOptions(boolean pressed)
|
||||||
{
|
{
|
||||||
if (!config.isTagEnabled())
|
if (!config.isTagEnabled())
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ package net.runelite.client.plugins.npchighlight;
|
|||||||
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 java.util.Map;
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.NPC;
|
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;
|
||||||
@@ -39,12 +39,14 @@ import net.runelite.client.ui.overlay.OverlayUtil;
|
|||||||
|
|
||||||
public class NpcMinimapOverlay extends Overlay
|
public class NpcMinimapOverlay extends Overlay
|
||||||
{
|
{
|
||||||
|
private final Client client;
|
||||||
private final NpcIndicatorsConfig config;
|
private final NpcIndicatorsConfig config;
|
||||||
private final NpcIndicatorsPlugin plugin;
|
private final NpcIndicatorsPlugin plugin;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
NpcMinimapOverlay(NpcIndicatorsConfig config, NpcIndicatorsPlugin plugin)
|
NpcMinimapOverlay(Client client, NpcIndicatorsConfig config, NpcIndicatorsPlugin plugin)
|
||||||
{
|
{
|
||||||
|
this.client = client;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
setPosition(OverlayPosition.DYNAMIC);
|
setPosition(OverlayPosition.DYNAMIC);
|
||||||
@@ -54,15 +56,19 @@ public class NpcMinimapOverlay extends Overlay
|
|||||||
@Override
|
@Override
|
||||||
public Dimension render(Graphics2D graphics)
|
public Dimension render(Graphics2D graphics)
|
||||||
{
|
{
|
||||||
Map<NPC, String> npcMap = plugin.getHighlightedNpcs();
|
for (NPC npc : plugin.getHighlightedNpcs())
|
||||||
for (NPC npc : npcMap.keySet())
|
|
||||||
{
|
{
|
||||||
renderNpcOverlay(graphics, npc, npcMap.get(npc), config.getNpcColor());
|
renderNpcOverlay(graphics, npc, npc.getName(), config.getNpcColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (NPC npc : plugin.getTaggedNpcs())
|
NPC[] npcs = client.getCachedNPCs();
|
||||||
|
for (int npcId : plugin.getNpcTags())
|
||||||
{
|
{
|
||||||
renderNpcOverlay(graphics, npc, npc.getName(), config.getTagColor());
|
NPC npc = npcs[npcId];
|
||||||
|
if (npc != null && npc.getName() != null)
|
||||||
|
{
|
||||||
|
renderNpcOverlay(graphics, npc, npc.getName(), config.getTagColor());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user