Merge pull request #2882 from deathbeam/unify-highlight-tag
Unify Highlight and Tag colors for NPC indicators, cleanup code
This commit is contained in:
@@ -60,17 +60,7 @@ public class NpcClickboxOverlay extends Overlay
|
|||||||
{
|
{
|
||||||
for (NPC npc : plugin.getHighlightedNpcs())
|
for (NPC npc : plugin.getHighlightedNpcs())
|
||||||
{
|
{
|
||||||
renderNpcOverlay(graphics, npc, npc.getName(), config.getNpcColor());
|
renderNpcOverlay(graphics, npc, npc.getName(), config.getHighlightColor());
|
||||||
}
|
|
||||||
|
|
||||||
NPC[] npcs = client.getCachedNPCs();
|
|
||||||
for (int npcId : plugin.getNpcTags())
|
|
||||||
{
|
|
||||||
NPC npc = npcs[npcId];
|
|
||||||
if (npc != null && npc.getName() != null)
|
|
||||||
{
|
|
||||||
renderNpcOverlay(graphics, npc, npc.getName(), config.getTagColor());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public interface NpcIndicatorsConfig extends Config
|
|||||||
name = "Highlight Color",
|
name = "Highlight Color",
|
||||||
description = "Color of the NPC highlight"
|
description = "Color of the NPC highlight"
|
||||||
)
|
)
|
||||||
default Color getNpcColor()
|
default Color getHighlightColor()
|
||||||
{
|
{
|
||||||
return Color.CYAN;
|
return Color.CYAN;
|
||||||
}
|
}
|
||||||
@@ -82,17 +82,6 @@ public interface NpcIndicatorsConfig extends Config
|
|||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
position = 4,
|
position = 4,
|
||||||
keyName = "tagColor",
|
|
||||||
name = "Tag Color",
|
|
||||||
description = "Color of the NPC tag highlight"
|
|
||||||
)
|
|
||||||
default Color getTagColor()
|
|
||||||
{
|
|
||||||
return Color.CYAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ConfigItem(
|
|
||||||
position = 5,
|
|
||||||
keyName = "drawNames",
|
keyName = "drawNames",
|
||||||
name = "Draw names above NPC",
|
name = "Draw names above NPC",
|
||||||
description = "Configures whether or not NPC names should be drawn above the NPC"
|
description = "Configures whether or not NPC names should be drawn above the NPC"
|
||||||
@@ -103,7 +92,7 @@ public interface NpcIndicatorsConfig extends Config
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
position = 6,
|
position = 5,
|
||||||
keyName = "drawMinimapNames",
|
keyName = "drawMinimapNames",
|
||||||
name = "Draw names on minimap",
|
name = "Draw names on minimap",
|
||||||
description = "Configures whether or not NPC names should be drawn on the minimap"
|
description = "Configures whether or not NPC names should be drawn on the minimap"
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.npchighlight;
|
package net.runelite.client.plugins.npchighlight;
|
||||||
|
|
||||||
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -34,6 +35,7 @@ import java.util.Collections;
|
|||||||
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.regex.Pattern;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -61,7 +63,7 @@ public class NpcIndicatorsPlugin extends Plugin
|
|||||||
private static final String TAG = "Tag";
|
private static final String TAG = "Tag";
|
||||||
|
|
||||||
// Regex for splitting the hidden items in the config.
|
// Regex for splitting the hidden items in the config.
|
||||||
private static final String DELIMITER_REGEX = "\\s*,\\s*";
|
private static final Splitter COMMA_SPLITTER = Splitter.on(Pattern.compile("\\s*,\\s*")).trimResults();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Client client;
|
private Client client;
|
||||||
@@ -85,13 +87,7 @@ public class NpcIndicatorsPlugin extends Plugin
|
|||||||
private KeyManager keyManager;
|
private KeyManager keyManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NPCs tagged with the Tag option
|
* NPCs to highlight
|
||||||
*/
|
|
||||||
@Getter(AccessLevel.PACKAGE)
|
|
||||||
private final Set<Integer> npcTags = new HashSet<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NPCs tagged due to highlight in the config
|
|
||||||
*/
|
*/
|
||||||
@Getter(AccessLevel.PACKAGE)
|
@Getter(AccessLevel.PACKAGE)
|
||||||
private final Set<NPC> highlightedNpcs = new HashSet<>();
|
private final Set<NPC> highlightedNpcs = new HashSet<>();
|
||||||
@@ -101,14 +97,12 @@ public class NpcIndicatorsPlugin extends Plugin
|
|||||||
*/
|
*/
|
||||||
private List<String> highlights = new ArrayList<>();
|
private List<String> highlights = new ArrayList<>();
|
||||||
|
|
||||||
private boolean hotKeyPressed = false;
|
/**
|
||||||
|
* NPC ids marked with the Tag option
|
||||||
|
*/
|
||||||
|
private final Set<Integer> npcTags = new HashSet<>();
|
||||||
|
|
||||||
private void toggleTag(int npcId)
|
private boolean hotKeyPressed = false;
|
||||||
{
|
|
||||||
boolean removed = npcTags.remove(npcId);
|
|
||||||
if (!removed)
|
|
||||||
npcTags.add(npcId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
NpcIndicatorsConfig provideConfig(ConfigManager configManager)
|
NpcIndicatorsConfig provideConfig(ConfigManager configManager)
|
||||||
@@ -121,7 +115,7 @@ public class NpcIndicatorsPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
keyManager.registerKeyListener(inputListener);
|
keyManager.registerKeyListener(inputListener);
|
||||||
highlights = getHighlights();
|
highlights = getHighlights();
|
||||||
rebuildNpcs();
|
rebuildAllNpcs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -150,44 +144,7 @@ public class NpcIndicatorsPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
highlights = getHighlights();
|
highlights = getHighlights();
|
||||||
rebuildNpcs();
|
rebuildAllNpcs();
|
||||||
}
|
|
||||||
|
|
||||||
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
|
||||||
@@ -204,16 +161,41 @@ public class NpcIndicatorsPlugin extends Plugin
|
|||||||
public void onMenuObjectClicked(MenuOptionClicked click)
|
public void onMenuObjectClicked(MenuOptionClicked click)
|
||||||
{
|
{
|
||||||
if (click.getMenuOption().equals(TAG))
|
if (click.getMenuOption().equals(TAG))
|
||||||
toggleTag(click.getId());
|
{
|
||||||
|
final int id = click.getId();
|
||||||
|
final boolean removed = npcTags.remove(id);
|
||||||
|
final NPC[] cachedNPCs = client.getCachedNPCs();
|
||||||
|
final NPC npc = cachedNPCs[id];
|
||||||
|
|
||||||
|
if (npc != null && npc.getName() != null)
|
||||||
|
{
|
||||||
|
if (removed)
|
||||||
|
{
|
||||||
|
highlightedNpcs.remove(npc);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
npcTags.add(id);
|
||||||
|
highlightedNpcs.add(npc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onNpcSpawned(NpcSpawned npcSpawned)
|
public void onNpcSpawned(NpcSpawned npcSpawned)
|
||||||
{
|
{
|
||||||
NPC npc = npcSpawned.getNpc();
|
final NPC npc = npcSpawned.getNpc();
|
||||||
String npcName = npc.getName();
|
final String npcName = npc.getName();
|
||||||
|
|
||||||
if (npcName != null)
|
if (npcName != null)
|
||||||
{
|
{
|
||||||
|
if (npcTags.contains(npc.getIndex()))
|
||||||
|
{
|
||||||
|
highlightedNpcs.add(npc);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (String highlight : highlights)
|
for (String highlight : highlights)
|
||||||
{
|
{
|
||||||
if (WildcardMatcher.matches(highlight, npcName))
|
if (WildcardMatcher.matches(highlight, npcName))
|
||||||
@@ -228,8 +210,7 @@ public class NpcIndicatorsPlugin extends Plugin
|
|||||||
@Subscribe
|
@Subscribe
|
||||||
public void onNpcDespawned(NpcDespawned npcDespawned)
|
public void onNpcDespawned(NpcDespawned npcDespawned)
|
||||||
{
|
{
|
||||||
NPC npc = npcDespawned.getNpc();
|
highlightedNpcs.remove(npcDespawned.getNpc());
|
||||||
highlightedNpcs.remove(npc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -256,4 +237,47 @@ public class NpcIndicatorsPlugin extends Plugin
|
|||||||
|
|
||||||
hotKeyPressed = pressed;
|
hotKeyPressed = pressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<String> getHighlights()
|
||||||
|
{
|
||||||
|
final String configNpcs = config.getNpcToHighlight().toLowerCase();
|
||||||
|
|
||||||
|
if (configNpcs.isEmpty())
|
||||||
|
{
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
return COMMA_SPLITTER.splitToList(configNpcs);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void rebuildAllNpcs()
|
||||||
|
{
|
||||||
|
highlightedNpcs.clear();
|
||||||
|
|
||||||
|
for (NPC npc : client.getNpcs())
|
||||||
|
{
|
||||||
|
String npcName = npc.getName();
|
||||||
|
|
||||||
|
if (npcName == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (npcTags.contains(npc.getIndex()))
|
||||||
|
{
|
||||||
|
highlightedNpcs.add(npc);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String highlight : highlights)
|
||||||
|
{
|
||||||
|
if (WildcardMatcher.matches(highlight, npcName))
|
||||||
|
{
|
||||||
|
highlightedNpcs.add(npc);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,17 +58,7 @@ public class NpcMinimapOverlay extends Overlay
|
|||||||
{
|
{
|
||||||
for (NPC npc : plugin.getHighlightedNpcs())
|
for (NPC npc : plugin.getHighlightedNpcs())
|
||||||
{
|
{
|
||||||
renderNpcOverlay(graphics, npc, npc.getName(), config.getNpcColor());
|
renderNpcOverlay(graphics, npc, npc.getName(), config.getHighlightColor());
|
||||||
}
|
|
||||||
|
|
||||||
NPC[] npcs = client.getCachedNPCs();
|
|
||||||
for (int npcId : plugin.getNpcTags())
|
|
||||||
{
|
|
||||||
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