npc indicator: add shift right click to add tag option
currently, npc tagging causes some npc's to have the tag option as left click which can cause missclicks. This adds the ability to add the "tag" option only when shift is being pressed
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Seth <http://github.com/sethtroll>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.client.plugins.npchighlight;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.client.input.KeyListener;
|
||||
|
||||
public class NpcIndicatorsInput implements KeyListener
|
||||
{
|
||||
private static final int HOTKEY = KeyEvent.VK_SHIFT;
|
||||
|
||||
@Inject
|
||||
private NpcIndicatorsPlugin plugin;
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e)
|
||||
{
|
||||
if (e.getKeyCode() == HOTKEY)
|
||||
{
|
||||
plugin.updateNpcMenuOptions(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e)
|
||||
{
|
||||
if (e.getKeyCode() == HOTKEY)
|
||||
{
|
||||
plugin.updateNpcMenuOptions(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,10 +42,11 @@ import lombok.Getter;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.NPCComposition;
|
||||
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.client.config.ConfigManager;
|
||||
import net.runelite.client.input.KeyManager;
|
||||
import net.runelite.client.menus.MenuManager;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
@@ -76,6 +77,12 @@ public class NpcIndicatorsPlugin extends Plugin
|
||||
@Inject
|
||||
private NpcMinimapOverlay npcMinimapOverlay;
|
||||
|
||||
@Inject
|
||||
private NpcIndicatorsInput inputListener;
|
||||
|
||||
@Inject
|
||||
private KeyManager keyManager;
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private final Set<Integer> npcTags = new HashSet<>();
|
||||
|
||||
@@ -85,6 +92,8 @@ public class NpcIndicatorsPlugin extends Plugin
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private Map<NPC, String> highlightedNpcs = new HashMap<>();
|
||||
|
||||
private boolean hotKeyPressed = false;
|
||||
|
||||
private void toggleTag(int npcId)
|
||||
{
|
||||
boolean removed = npcTags.remove(npcId);
|
||||
@@ -101,8 +110,7 @@ public class NpcIndicatorsPlugin extends Plugin
|
||||
@Override
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
if (config.isTagEnabled())
|
||||
menuManager.addNpcMenuOption(TAG);
|
||||
keyManager.registerKeyListener(inputListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -110,19 +118,17 @@ public class NpcIndicatorsPlugin extends Plugin
|
||||
{
|
||||
npcTags.clear();
|
||||
taggedNpcs.clear();
|
||||
menuManager.removeNpcMenuOption(TAG);
|
||||
keyManager.unregisterKeyListener(inputListener);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void updateConfig(ConfigChanged event)
|
||||
public void onFocusChanged(FocusChanged focusChanged)
|
||||
{
|
||||
if (!event.getGroup().equals("npcindicators"))
|
||||
return;
|
||||
|
||||
if (config.isTagEnabled())
|
||||
menuManager.addNpcMenuOption(TAG);
|
||||
else
|
||||
menuManager.removeNpcMenuOption(TAG);
|
||||
// If you somehow manage to right click while holding shift, then click off screen
|
||||
if (!focusChanged.isFocused() && hotKeyPressed)
|
||||
{
|
||||
updateNpcMenuOptions(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -208,4 +214,23 @@ public class NpcIndicatorsPlugin extends Plugin
|
||||
|
||||
return composition;
|
||||
}
|
||||
|
||||
void updateNpcMenuOptions(boolean pressed)
|
||||
{
|
||||
if (!config.isTagEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (pressed)
|
||||
{
|
||||
menuManager.addNpcMenuOption(TAG);
|
||||
}
|
||||
else
|
||||
{
|
||||
menuManager.removeNpcMenuOption(TAG);
|
||||
}
|
||||
|
||||
hotKeyPressed = pressed;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user