npc indicators: add option to highlight dead npc menu entries

This commit is contained in:
Adam
2020-06-04 22:40:27 -04:00
parent af7c833695
commit bda66e8da4
3 changed files with 95 additions and 9 deletions

View File

@@ -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});
}
}