npc indicators: add option to highlight dead npc menu entries
This commit is contained in:
@@ -118,4 +118,12 @@ public interface NpcIndicatorsConfig extends Config
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 7,
|
||||
keyName = "deadNpcMenuColor",
|
||||
name = "Dead NPC menu color",
|
||||
description = "Color of the NPC menus for dead NPCs"
|
||||
)
|
||||
Color deadNpcMenuColor();
|
||||
}
|
||||
@@ -28,6 +28,7 @@ package net.runelite.client.plugins.npchighlight;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Provides;
|
||||
import java.awt.Color;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -259,17 +260,33 @@ public class NpcIndicatorsPlugin extends Plugin
|
||||
type -= MENU_ACTION_DEPRIORITIZE_OFFSET;
|
||||
}
|
||||
|
||||
if (config.highlightMenuNames() &&
|
||||
NPC_MENU_ACTIONS.contains(MenuAction.of(type)) &&
|
||||
highlightedNpcs.stream().anyMatch(npc -> npc.getIndex() == event.getIdentifier() && (!npc.isDead() || !config.ignoreDeadNpcs())))
|
||||
final MenuAction menuAction = MenuAction.of(type);
|
||||
|
||||
if (NPC_MENU_ACTIONS.contains(menuAction))
|
||||
{
|
||||
MenuEntry[] menuEntries = client.getMenuEntries();
|
||||
final MenuEntry menuEntry = menuEntries[menuEntries.length - 1];
|
||||
final String target = ColorUtil.prependColorTag(Text.removeTags(event.getTarget()), config.getHighlightColor());
|
||||
menuEntry.setTarget(target);
|
||||
client.setMenuEntries(menuEntries);
|
||||
NPC npc = client.getCachedNPCs()[event.getIdentifier()];
|
||||
|
||||
Color color = null;
|
||||
if (npc.isDead())
|
||||
{
|
||||
color = config.deadNpcMenuColor();
|
||||
}
|
||||
|
||||
if (color == null && highlightedNpcs.contains(npc) && config.highlightMenuNames() && (!npc.isDead() || !config.ignoreDeadNpcs()))
|
||||
{
|
||||
color = config.getHighlightColor();
|
||||
}
|
||||
|
||||
if (color != null)
|
||||
{
|
||||
MenuEntry[] menuEntries = client.getMenuEntries();
|
||||
final MenuEntry menuEntry = menuEntries[menuEntries.length - 1];
|
||||
final String target = ColorUtil.prependColorTag(Text.removeTags(event.getTarget()), color);
|
||||
menuEntry.setTarget(target);
|
||||
client.setMenuEntries(menuEntries);
|
||||
}
|
||||
}
|
||||
else if (hotKeyPressed && type == MenuAction.EXAMINE_NPC.getId())
|
||||
else if (hotKeyPressed && menuAction == MenuAction.EXAMINE_NPC)
|
||||
{
|
||||
// Add tag option
|
||||
MenuEntry[] menuEntries = client.getMenuEntries();
|
||||
|
||||
@@ -27,17 +27,26 @@ package net.runelite.client.plugins.npchighlight;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.testing.fieldbinder.Bind;
|
||||
import com.google.inject.testing.fieldbinder.BoundFieldModule;
|
||||
import java.awt.Color;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.MenuAction;
|
||||
import net.runelite.api.MenuEntry;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.events.MenuEntryAdded;
|
||||
import net.runelite.api.events.NpcSpawned;
|
||||
import net.runelite.client.events.ConfigChanged;
|
||||
import net.runelite.client.ui.overlay.OverlayManager;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@@ -81,4 +90,56 @@ public class NpcIndicatorsPluginTest
|
||||
assertEquals("zulrah", iterator.next());
|
||||
assertEquals("*wyvern", iterator.next());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeadNpcMenuHighlight()
|
||||
{
|
||||
when(npcIndicatorsConfig.getNpcToHighlight()).thenReturn("goblin");
|
||||
when(npcIndicatorsConfig.deadNpcMenuColor()).thenReturn(Color.RED);
|
||||
|
||||
ConfigChanged configChanged = new ConfigChanged();
|
||||
configChanged.setGroup("npcindicators");
|
||||
npcIndicatorsPlugin.onConfigChanged(configChanged);
|
||||
|
||||
NPC npc = mock(NPC.class);
|
||||
when(npc.getName()).thenReturn("Goblin");
|
||||
when(npc.isDead()).thenReturn(true);
|
||||
npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc));
|
||||
|
||||
when(client.getCachedNPCs()).thenReturn(new NPC[]{npc}); // id 0
|
||||
|
||||
when(client.getMenuEntries()).thenReturn(new MenuEntry[]{new MenuEntry()});
|
||||
MenuEntryAdded menuEntryAdded = new MenuEntryAdded("", "Goblin", MenuAction.NPC_FIRST_OPTION.getId(), 0, -1, -1);
|
||||
npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded);
|
||||
|
||||
MenuEntry target = new MenuEntry();
|
||||
target.setTarget("<col=ff0000>Goblin"); // red
|
||||
verify(client).setMenuEntries(new MenuEntry[]{target});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAliveNpcMenuHighlight()
|
||||
{
|
||||
when(npcIndicatorsConfig.getNpcToHighlight()).thenReturn("goblin");
|
||||
when(npcIndicatorsConfig.highlightMenuNames()).thenReturn(true);
|
||||
when(npcIndicatorsConfig.getHighlightColor()).thenReturn(Color.BLUE);
|
||||
|
||||
ConfigChanged configChanged = new ConfigChanged();
|
||||
configChanged.setGroup("npcindicators");
|
||||
npcIndicatorsPlugin.onConfigChanged(configChanged);
|
||||
|
||||
NPC npc = mock(NPC.class);
|
||||
when(npc.getName()).thenReturn("Goblin");
|
||||
npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc));
|
||||
|
||||
when(client.getCachedNPCs()).thenReturn(new NPC[]{npc}); // id 0
|
||||
|
||||
when(client.getMenuEntries()).thenReturn(new MenuEntry[]{new MenuEntry()});
|
||||
MenuEntryAdded menuEntryAdded = new MenuEntryAdded("", "Goblin", MenuAction.NPC_FIRST_OPTION.getId(), 0, -1, -1);
|
||||
npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded);
|
||||
|
||||
MenuEntry target = new MenuEntry();
|
||||
target.setTarget("<col=0000ff>Goblin"); // blue
|
||||
verify(client).setMenuEntries(new MenuEntry[]{target});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user