Merge pull request #939 from McSwindler/npc-plugin-branch
NPC Highlight Plugin
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -5,3 +5,6 @@ nb-configuration.xml
|
|||||||
project.properties
|
project.properties
|
||||||
*.iml
|
*.iml
|
||||||
.idea/
|
.idea/
|
||||||
|
.project
|
||||||
|
.settings/
|
||||||
|
.classpath
|
||||||
@@ -68,4 +68,6 @@ public interface Actor extends Renderable
|
|||||||
* Returns the logical height of the actor's model. This is roughly where the health bar is drawn.
|
* Returns the logical height of the actor's model. This is roughly where the health bar is drawn.
|
||||||
*/
|
*/
|
||||||
int getLogicalHeight();
|
int getLogicalHeight();
|
||||||
|
|
||||||
|
Polygon getConvexHull();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,8 +56,6 @@ public interface TileObject
|
|||||||
|
|
||||||
Point getMinimapLocation();
|
Point getMinimapLocation();
|
||||||
|
|
||||||
Polygon getConvexHull(Model model, int orientation);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the on-screen clickable area of {@code object}
|
* Get the on-screen clickable area of {@code object}
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||||
|
* 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.api.events;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import net.runelite.api.NPCComposition;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class NpcActionChanged
|
||||||
|
{
|
||||||
|
private NPCComposition npcComposition;
|
||||||
|
private int idx;
|
||||||
|
}
|
||||||
@@ -32,7 +32,9 @@ import com.google.common.eventbus.Subscribe;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
@@ -40,8 +42,11 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.MenuAction;
|
import net.runelite.api.MenuAction;
|
||||||
import net.runelite.api.MenuEntry;
|
import net.runelite.api.MenuEntry;
|
||||||
|
import net.runelite.api.NPC;
|
||||||
|
import net.runelite.api.NPCComposition;
|
||||||
import net.runelite.api.events.MenuEntryAdded;
|
import net.runelite.api.events.MenuEntryAdded;
|
||||||
import net.runelite.api.events.MenuOptionClicked;
|
import net.runelite.api.events.MenuOptionClicked;
|
||||||
|
import net.runelite.api.events.NpcActionChanged;
|
||||||
import net.runelite.api.events.PlayerMenuOptionClicked;
|
import net.runelite.api.events.PlayerMenuOptionClicked;
|
||||||
import net.runelite.api.events.PlayerMenuOptionsChanged;
|
import net.runelite.api.events.PlayerMenuOptionsChanged;
|
||||||
import net.runelite.api.events.WidgetMenuOptionClicked;
|
import net.runelite.api.events.WidgetMenuOptionClicked;
|
||||||
@@ -64,6 +69,7 @@ public class MenuManager
|
|||||||
private final Map<Integer, String> playerMenuIndexMap = new HashMap<>();
|
private final Map<Integer, String> playerMenuIndexMap = new HashMap<>();
|
||||||
//Used to manage custom non-player menu options
|
//Used to manage custom non-player menu options
|
||||||
private final Multimap<Integer, WidgetMenuOption> managedMenuOptions = HashMultimap.create();
|
private final Multimap<Integer, WidgetMenuOption> managedMenuOptions = HashMultimap.create();
|
||||||
|
private final Set<String> npcMenuOptions = new HashSet<>();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public MenuManager(Provider<Client> clientProvider, EventBus eventBus)
|
public MenuManager(Provider<Client> clientProvider, EventBus eventBus)
|
||||||
@@ -72,6 +78,32 @@ public class MenuManager
|
|||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addNpcMenuOption(String option)
|
||||||
|
{
|
||||||
|
npcMenuOptions.add(option);
|
||||||
|
|
||||||
|
// add to surrounding npcs
|
||||||
|
Client client = clientProvider.get();
|
||||||
|
for (NPC npc : client.getNpcs())
|
||||||
|
{
|
||||||
|
NPCComposition composition = npc.getComposition();
|
||||||
|
addNpcOption(composition, option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeNpcMenuOption(String option)
|
||||||
|
{
|
||||||
|
npcMenuOptions.remove(npcMenuOptions);
|
||||||
|
|
||||||
|
// remove this option from all npc compositions
|
||||||
|
Client client = clientProvider.get();
|
||||||
|
for (NPC npc : client.getNpcs())
|
||||||
|
{
|
||||||
|
NPCComposition composition = npc.getComposition();
|
||||||
|
removeNpcOption(composition, option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a CustomMenuOption to the list of managed menu options.
|
* Adds a CustomMenuOption to the list of managed menu options.
|
||||||
*
|
*
|
||||||
@@ -186,6 +218,56 @@ public class MenuManager
|
|||||||
addPlayerMenuItem(newIdx, menuText);
|
addPlayerMenuItem(newIdx, menuText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onNpcActionChanged(NpcActionChanged event)
|
||||||
|
{
|
||||||
|
NPCComposition composition = event.getNpcComposition();
|
||||||
|
for (String npcOption : npcMenuOptions)
|
||||||
|
{
|
||||||
|
addNpcOption(composition, npcOption);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addNpcOption(NPCComposition composition, String npcOption)
|
||||||
|
{
|
||||||
|
String[] actions = composition.getActions();
|
||||||
|
int unused = -1;
|
||||||
|
for (int i = 0; i < actions.length; ++i)
|
||||||
|
{
|
||||||
|
if (actions[i] == null && unused == -1)
|
||||||
|
{
|
||||||
|
unused = i;
|
||||||
|
}
|
||||||
|
else if (actions[i] != null && actions[i].equals(npcOption))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (unused == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
actions[unused] = npcOption;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeNpcOption(NPCComposition composition, String npcOption)
|
||||||
|
{
|
||||||
|
String[] actions = composition.getActions();
|
||||||
|
|
||||||
|
if (composition.getActions() == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < actions.length; ++i)
|
||||||
|
{
|
||||||
|
if (actions[i] != null && actions[i].equals(npcOption))
|
||||||
|
{
|
||||||
|
actions[i] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onMenuOptionClicked(MenuOptionClicked event)
|
public void onMenuOptionClicked(MenuOptionClicked event)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ public class DevToolsOverlay extends Overlay
|
|||||||
for (NPC npc : npcs)
|
for (NPC npc : npcs)
|
||||||
{
|
{
|
||||||
NPCComposition composition = npc.getComposition();
|
NPCComposition composition = npc.getComposition();
|
||||||
if (composition.getConfigs() != null && composition.transform() != null)
|
if (composition.getConfigs() != null)
|
||||||
{
|
{
|
||||||
composition = composition.transform();
|
composition = composition.transform();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,15 +27,11 @@ package net.runelite.client.plugins.grounditems;
|
|||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import net.runelite.client.util.WildcardMatcher;
|
||||||
|
|
||||||
class WildcardMatchLoader extends CacheLoader<String, Boolean>
|
class WildcardMatchLoader extends CacheLoader<String, Boolean>
|
||||||
{
|
{
|
||||||
// Regex used for matching item names with others
|
|
||||||
private static final Pattern WILDCARD_PATTERN = Pattern.compile("(?i)[^*]+|(\\*)");
|
|
||||||
|
|
||||||
private final List<String> nameFilters;
|
private final List<String> nameFilters;
|
||||||
|
|
||||||
WildcardMatchLoader(List<String> nameFilters)
|
WildcardMatchLoader(List<String> nameFilters)
|
||||||
@@ -55,26 +51,7 @@ class WildcardMatchLoader extends CacheLoader<String, Boolean>
|
|||||||
|
|
||||||
for (final String filter : nameFilters)
|
for (final String filter : nameFilters)
|
||||||
{
|
{
|
||||||
final Matcher matcher = WILDCARD_PATTERN.matcher(filter);
|
if (WildcardMatcher.matches(filter, filteredName))
|
||||||
final StringBuffer buffer = new StringBuffer();
|
|
||||||
|
|
||||||
buffer.append("(?i)");
|
|
||||||
while (matcher.find())
|
|
||||||
{
|
|
||||||
if (matcher.group(1) != null)
|
|
||||||
{
|
|
||||||
matcher.appendReplacement(buffer, ".*");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
matcher.appendReplacement(buffer, "\\\\Q" + matcher.group(0) + "\\\\E");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
matcher.appendTail(buffer);
|
|
||||||
final String replaced = buffer.toString();
|
|
||||||
|
|
||||||
if (filteredName.matches(replaced))
|
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, James Swindle <wilingua@gmail.com>
|
||||||
|
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||||
|
* 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.BasicStroke;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Point;
|
||||||
|
import java.awt.Polygon;
|
||||||
|
import java.util.Map;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import net.runelite.api.Client;
|
||||||
|
import net.runelite.api.NPC;
|
||||||
|
import net.runelite.api.NPCComposition;
|
||||||
|
import net.runelite.client.ui.overlay.Overlay;
|
||||||
|
import net.runelite.client.ui.overlay.OverlayLayer;
|
||||||
|
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||||
|
import net.runelite.client.ui.overlay.OverlayUtil;
|
||||||
|
|
||||||
|
public class NpcClickboxOverlay extends Overlay
|
||||||
|
{
|
||||||
|
private final Client client;
|
||||||
|
private final NpcHighlightConfig config;
|
||||||
|
private final NpcHighlightPlugin plugin;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
NpcClickboxOverlay(Client client, NpcHighlightConfig config, NpcHighlightPlugin plugin)
|
||||||
|
{
|
||||||
|
this.client = client;
|
||||||
|
this.config = config;
|
||||||
|
this.plugin = plugin;
|
||||||
|
setPosition(OverlayPosition.DYNAMIC);
|
||||||
|
setLayer(OverlayLayer.ABOVE_SCENE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension render(Graphics2D graphics, Point parent)
|
||||||
|
{
|
||||||
|
Map<NPC, String> npcMap = plugin.getHighlightedNpcs();
|
||||||
|
for (NPC npc : npcMap.keySet())
|
||||||
|
{
|
||||||
|
renderNpcOverlay(graphics, npc, npcMap.get(npc), config.getNpcColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (NPC npc : plugin.getTaggedNpcs())
|
||||||
|
{
|
||||||
|
NPCComposition composition = plugin.getComposition(npc);
|
||||||
|
if (composition == null || composition.getName() == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
String name = composition.getName().replace('\u00A0', ' ');
|
||||||
|
renderNpcOverlay(graphics, npc, name, config.getTagColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderNpcOverlay(Graphics2D graphics, NPC actor, String name, Color color)
|
||||||
|
{
|
||||||
|
Polygon objectClickbox = actor.getConvexHull();
|
||||||
|
if (objectClickbox != null)
|
||||||
|
{
|
||||||
|
graphics.setColor(color);
|
||||||
|
graphics.setStroke(new BasicStroke(2));
|
||||||
|
graphics.draw(objectClickbox);
|
||||||
|
graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 20));
|
||||||
|
graphics.fill(objectClickbox);
|
||||||
|
}
|
||||||
|
|
||||||
|
net.runelite.api.Point textLocation = actor.getCanvasTextLocation(graphics, name, actor.getLogicalHeight() + 40);
|
||||||
|
|
||||||
|
if (textLocation != null)
|
||||||
|
{
|
||||||
|
OverlayUtil.renderTextLocation(graphics, textLocation, name, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, Tomas Slusny <slusnucky@gmail.com>
|
||||||
|
* 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.Color;
|
||||||
|
import net.runelite.client.config.Config;
|
||||||
|
import net.runelite.client.config.ConfigGroup;
|
||||||
|
import net.runelite.client.config.ConfigItem;
|
||||||
|
|
||||||
|
@ConfigGroup(
|
||||||
|
keyName = "npchighlight",
|
||||||
|
name = "NPC Highlight",
|
||||||
|
description = "Configuration for the NPC highlight plugin"
|
||||||
|
)
|
||||||
|
public interface NpcHighlightConfig extends Config
|
||||||
|
{
|
||||||
|
@ConfigItem(
|
||||||
|
position = 0,
|
||||||
|
keyName = "npcToHighlight",
|
||||||
|
name = "NPCs to Highlight",
|
||||||
|
description = "List of NPC names to highlight"
|
||||||
|
)
|
||||||
|
default String getNpcToHighlight()
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
position = 1,
|
||||||
|
keyName = "npcColor",
|
||||||
|
name = "Highlight Color",
|
||||||
|
description = "Color of the NPC highlight"
|
||||||
|
)
|
||||||
|
default Color getNpcColor()
|
||||||
|
{
|
||||||
|
return Color.CYAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
position = 2,
|
||||||
|
keyName = "enableTag",
|
||||||
|
name = "Enable Tag Option",
|
||||||
|
description = "Enable the NPC tag menu option"
|
||||||
|
)
|
||||||
|
default boolean isTagEnabled()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
position = 3,
|
||||||
|
keyName = "tagColor",
|
||||||
|
name = "Tag Color",
|
||||||
|
description = "Color of the NPC tag highlight"
|
||||||
|
)
|
||||||
|
default Color getTagColor()
|
||||||
|
{
|
||||||
|
return Color.CYAN;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,211 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, James Swindle <wilingua@gmail.com>
|
||||||
|
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||||
|
* 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 com.google.common.eventbus.Subscribe;
|
||||||
|
import com.google.inject.Provides;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
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.GameTick;
|
||||||
|
import net.runelite.api.events.MenuOptionClicked;
|
||||||
|
import net.runelite.client.config.ConfigManager;
|
||||||
|
import net.runelite.client.menus.MenuManager;
|
||||||
|
import net.runelite.client.plugins.Plugin;
|
||||||
|
import net.runelite.client.plugins.PluginDescriptor;
|
||||||
|
import net.runelite.client.ui.overlay.Overlay;
|
||||||
|
import net.runelite.client.util.WildcardMatcher;
|
||||||
|
|
||||||
|
@PluginDescriptor(name = "NPC Highlight")
|
||||||
|
public class NpcHighlightPlugin extends Plugin
|
||||||
|
{
|
||||||
|
// Option added to NPC menu
|
||||||
|
private static final String TAG = "Tag";
|
||||||
|
|
||||||
|
// Regex for splitting the hidden items in the config.
|
||||||
|
private static final String DELIMITER_REGEX = "\\s*,\\s*";
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Client client;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private MenuManager menuManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private NpcHighlightConfig config;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private NpcClickboxOverlay npcClickboxOverlay;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private NpcMinimapOverlay npcMinimapOverlay;
|
||||||
|
|
||||||
|
@Getter(AccessLevel.PACKAGE)
|
||||||
|
private final Set<Integer> npcTags = new HashSet<>();
|
||||||
|
|
||||||
|
@Getter(AccessLevel.PACKAGE)
|
||||||
|
private final List<NPC> taggedNpcs = new ArrayList<>();
|
||||||
|
|
||||||
|
@Getter(AccessLevel.PACKAGE)
|
||||||
|
private Map<NPC, String> highlightedNpcs = new HashMap<>();
|
||||||
|
|
||||||
|
private void toggleTag(int npcId)
|
||||||
|
{
|
||||||
|
boolean removed = npcTags.remove(npcId);
|
||||||
|
if (!removed)
|
||||||
|
npcTags.add(npcId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
NpcHighlightConfig provideConfig(ConfigManager configManager)
|
||||||
|
{
|
||||||
|
return configManager.getConfig(NpcHighlightConfig.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void startUp() throws Exception
|
||||||
|
{
|
||||||
|
if (config.isTagEnabled())
|
||||||
|
menuManager.addNpcMenuOption(TAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void shutDown() throws Exception
|
||||||
|
{
|
||||||
|
npcTags.clear();
|
||||||
|
taggedNpcs.clear();
|
||||||
|
menuManager.removeNpcMenuOption(TAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void updateConfig(ConfigChanged event)
|
||||||
|
{
|
||||||
|
if (!event.getGroup().equals("npchighlight"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (config.isTagEnabled())
|
||||||
|
menuManager.addNpcMenuOption(TAG);
|
||||||
|
else
|
||||||
|
menuManager.removeNpcMenuOption(TAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onMenuObjectClicked(MenuOptionClicked click)
|
||||||
|
{
|
||||||
|
if (click.getMenuOption().equals(TAG))
|
||||||
|
toggleTag(click.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onGameTick(GameTick tick)
|
||||||
|
{
|
||||||
|
highlightedNpcs = buildNpcsToHighlight();
|
||||||
|
taggedNpcs.clear();
|
||||||
|
if (npcTags.isEmpty() || !config.isTagEnabled())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (NPC npc : client.getNpcs())
|
||||||
|
{
|
||||||
|
if (npcTags.contains(npc.getIndex()))
|
||||||
|
{
|
||||||
|
NPCComposition composition = getComposition(npc);
|
||||||
|
if (composition == null || composition.getName() == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
taggedNpcs.add(npc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Overlay> getOverlays()
|
||||||
|
{
|
||||||
|
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())
|
||||||
|
{
|
||||||
|
NPCComposition composition = getComposition(npc);
|
||||||
|
|
||||||
|
if (npc == null || composition == null || composition.getName() == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (String highlight : highlightedNpcs)
|
||||||
|
{
|
||||||
|
String name = composition.getName().replace('\u00A0', ' ');
|
||||||
|
if (WildcardMatcher.matches(highlight, name))
|
||||||
|
{
|
||||||
|
npcMap.put(npc, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return npcMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get npc composition, account for imposters
|
||||||
|
*
|
||||||
|
* @param npc
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected NPCComposition getComposition(NPC npc)
|
||||||
|
{
|
||||||
|
if (npc == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
NPCComposition composition = npc.getComposition();
|
||||||
|
if (composition != null && composition.getConfigs() != null)
|
||||||
|
{
|
||||||
|
composition = composition.transform();
|
||||||
|
}
|
||||||
|
|
||||||
|
return composition;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, James Swindle <wilingua@gmail.com>
|
||||||
|
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||||
|
* 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.Color;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Point;
|
||||||
|
import java.util.Map;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import net.runelite.api.NPC;
|
||||||
|
import net.runelite.client.ui.overlay.Overlay;
|
||||||
|
import net.runelite.client.ui.overlay.OverlayLayer;
|
||||||
|
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||||
|
import net.runelite.client.ui.overlay.OverlayUtil;
|
||||||
|
|
||||||
|
public class NpcMinimapOverlay extends Overlay
|
||||||
|
{
|
||||||
|
private final NpcHighlightConfig config;
|
||||||
|
private final NpcHighlightPlugin plugin;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
NpcMinimapOverlay(NpcHighlightConfig config, NpcHighlightPlugin plugin)
|
||||||
|
{
|
||||||
|
this.config = config;
|
||||||
|
this.plugin = plugin;
|
||||||
|
setPosition(OverlayPosition.DYNAMIC);
|
||||||
|
setLayer(OverlayLayer.ABOVE_WIDGETS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension render(Graphics2D graphics, Point parent)
|
||||||
|
{
|
||||||
|
Map<NPC, String> npcMap = plugin.getHighlightedNpcs();
|
||||||
|
for (NPC npc : npcMap.keySet())
|
||||||
|
{
|
||||||
|
renderNpcOverlay(graphics, npc, npcMap.get(npc), config.getNpcColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderNpcOverlay(Graphics2D graphics, NPC actor, String name, Color color)
|
||||||
|
{
|
||||||
|
net.runelite.api.Point minimapLocation = actor.getMinimapLocation();
|
||||||
|
if (minimapLocation != null)
|
||||||
|
{
|
||||||
|
OverlayUtil.renderMinimapLocation(graphics, minimapLocation, color.darker());
|
||||||
|
OverlayUtil.renderTextLocation(graphics, minimapLocation, name, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||||
|
* 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.util;
|
||||||
|
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class WildcardMatcher
|
||||||
|
{
|
||||||
|
private static final Pattern WILDCARD_PATTERN = Pattern.compile("(?i)[^*]+|(\\*)");
|
||||||
|
|
||||||
|
public static boolean matches(String pattern, String text)
|
||||||
|
{
|
||||||
|
final Matcher matcher = WILDCARD_PATTERN.matcher(pattern);
|
||||||
|
final StringBuffer buffer = new StringBuffer();
|
||||||
|
|
||||||
|
buffer.append("(?i)");
|
||||||
|
while (matcher.find())
|
||||||
|
{
|
||||||
|
if (matcher.group(1) != null)
|
||||||
|
{
|
||||||
|
matcher.appendReplacement(buffer, ".*");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
matcher.appendReplacement(buffer, "\\\\Q" + matcher.group(0) + "\\\\E");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
matcher.appendTail(buffer);
|
||||||
|
final String replaced = buffer.toString();
|
||||||
|
|
||||||
|
return text.matches(replaced);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||||
|
* 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.util;
|
||||||
|
|
||||||
|
import static junit.framework.TestCase.assertTrue;
|
||||||
|
import static net.runelite.client.util.WildcardMatcher.matches;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class WildcardMatcherTest
|
||||||
|
{
|
||||||
|
@Test
|
||||||
|
public void testMatches()
|
||||||
|
{
|
||||||
|
assertTrue(matches("rune*", "rune pouch"));
|
||||||
|
assertTrue(matches("rune*", "Rune pouch"));
|
||||||
|
assertFalse(matches("Abyssal whip", "Adamant dagger"));
|
||||||
|
assertTrue(matches("rune*", "Runeite Ore"));
|
||||||
|
assertTrue(matches("Abyssal whip", "Abyssal whip"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,12 +35,12 @@ import net.runelite.api.Point;
|
|||||||
import net.runelite.api.SpritePixels;
|
import net.runelite.api.SpritePixels;
|
||||||
import net.runelite.api.coords.LocalPoint;
|
import net.runelite.api.coords.LocalPoint;
|
||||||
import net.runelite.api.coords.WorldPoint;
|
import net.runelite.api.coords.WorldPoint;
|
||||||
|
import net.runelite.api.events.AnimationChanged;
|
||||||
import net.runelite.api.events.GraphicChanged;
|
import net.runelite.api.events.GraphicChanged;
|
||||||
import net.runelite.api.mixins.FieldHook;
|
import net.runelite.api.mixins.FieldHook;
|
||||||
import net.runelite.api.mixins.Inject;
|
import net.runelite.api.mixins.Inject;
|
||||||
import net.runelite.api.mixins.Mixin;
|
import net.runelite.api.mixins.Mixin;
|
||||||
import net.runelite.api.mixins.Shadow;
|
import net.runelite.api.mixins.Shadow;
|
||||||
import net.runelite.api.events.AnimationChanged;
|
|
||||||
import static net.runelite.client.callback.Hooks.eventBus;
|
import static net.runelite.client.callback.Hooks.eventBus;
|
||||||
import net.runelite.rs.api.RSActor;
|
import net.runelite.rs.api.RSActor;
|
||||||
import net.runelite.rs.api.RSClient;
|
import net.runelite.rs.api.RSClient;
|
||||||
@@ -48,6 +48,7 @@ import net.runelite.rs.api.RSCombatInfo1;
|
|||||||
import net.runelite.rs.api.RSCombatInfo2;
|
import net.runelite.rs.api.RSCombatInfo2;
|
||||||
import net.runelite.rs.api.RSCombatInfoList;
|
import net.runelite.rs.api.RSCombatInfoList;
|
||||||
import net.runelite.rs.api.RSCombatInfoListHolder;
|
import net.runelite.rs.api.RSCombatInfoListHolder;
|
||||||
|
import net.runelite.rs.api.RSModel;
|
||||||
import net.runelite.rs.api.RSNode;
|
import net.runelite.rs.api.RSNode;
|
||||||
|
|
||||||
@Mixin(RSActor.class)
|
@Mixin(RSActor.class)
|
||||||
@@ -188,4 +189,16 @@ public abstract class RSActorMixin implements RSActor
|
|||||||
graphicChanged.setActor(this);
|
graphicChanged.setActor(this);
|
||||||
eventBus.post(graphicChanged);
|
eventBus.post(graphicChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@Override
|
||||||
|
public Polygon getConvexHull()
|
||||||
|
{
|
||||||
|
RSModel model = getModel();
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return model.getConvexHull(getX(), getY(), getOrientation());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,12 +28,13 @@ import java.awt.Polygon;
|
|||||||
import java.awt.geom.Area;
|
import java.awt.geom.Area;
|
||||||
import net.runelite.api.Model;
|
import net.runelite.api.Model;
|
||||||
import net.runelite.api.Perspective;
|
import net.runelite.api.Perspective;
|
||||||
import net.runelite.api.Renderable;
|
|
||||||
import net.runelite.api.mixins.Inject;
|
import net.runelite.api.mixins.Inject;
|
||||||
import net.runelite.api.mixins.Mixin;
|
import net.runelite.api.mixins.Mixin;
|
||||||
import net.runelite.api.mixins.Shadow;
|
import net.runelite.api.mixins.Shadow;
|
||||||
import net.runelite.rs.api.RSClient;
|
import net.runelite.rs.api.RSClient;
|
||||||
import net.runelite.rs.api.RSDecorativeObject;
|
import net.runelite.rs.api.RSDecorativeObject;
|
||||||
|
import net.runelite.rs.api.RSModel;
|
||||||
|
import net.runelite.rs.api.RSRenderable;
|
||||||
|
|
||||||
@Mixin(RSDecorativeObject.class)
|
@Mixin(RSDecorativeObject.class)
|
||||||
public abstract class RSDecorativeObjectMixin implements RSDecorativeObject
|
public abstract class RSDecorativeObjectMixin implements RSDecorativeObject
|
||||||
@@ -59,19 +60,19 @@ public abstract class RSDecorativeObjectMixin implements RSDecorativeObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Model getModel()
|
private RSModel getModel()
|
||||||
{
|
{
|
||||||
Renderable renderable = getRenderable();
|
RSRenderable renderable = getRenderable();
|
||||||
if (renderable == null)
|
if (renderable == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Model model;
|
RSModel model;
|
||||||
|
|
||||||
if (renderable instanceof Model)
|
if (renderable instanceof Model)
|
||||||
{
|
{
|
||||||
model = (Model) renderable;
|
model = (RSModel) renderable;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -92,13 +93,13 @@ public abstract class RSDecorativeObjectMixin implements RSDecorativeObject
|
|||||||
@Override
|
@Override
|
||||||
public Polygon getConvexHull()
|
public Polygon getConvexHull()
|
||||||
{
|
{
|
||||||
Model model = getModel();
|
RSModel model = getModel();
|
||||||
|
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return getConvexHull(model, getOrientation());
|
return model.getConvexHull(getX(), getY(), getOrientation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,15 +26,15 @@ package net.runelite.mixins;
|
|||||||
|
|
||||||
import java.awt.Polygon;
|
import java.awt.Polygon;
|
||||||
import java.awt.geom.Area;
|
import java.awt.geom.Area;
|
||||||
import net.runelite.api.Model;
|
|
||||||
import net.runelite.api.Perspective;
|
import net.runelite.api.Perspective;
|
||||||
import net.runelite.api.Point;
|
import net.runelite.api.Point;
|
||||||
import net.runelite.api.Renderable;
|
|
||||||
import net.runelite.api.mixins.Inject;
|
import net.runelite.api.mixins.Inject;
|
||||||
import net.runelite.api.mixins.Mixin;
|
import net.runelite.api.mixins.Mixin;
|
||||||
import net.runelite.api.mixins.Shadow;
|
import net.runelite.api.mixins.Shadow;
|
||||||
import net.runelite.rs.api.RSClient;
|
import net.runelite.rs.api.RSClient;
|
||||||
import net.runelite.rs.api.RSGameObject;
|
import net.runelite.rs.api.RSGameObject;
|
||||||
|
import net.runelite.rs.api.RSModel;
|
||||||
|
import net.runelite.rs.api.RSRenderable;
|
||||||
|
|
||||||
@Mixin(RSGameObject.class)
|
@Mixin(RSGameObject.class)
|
||||||
public abstract class RSGameObjectMixin implements RSGameObject
|
public abstract class RSGameObjectMixin implements RSGameObject
|
||||||
@@ -57,17 +57,17 @@ public abstract class RSGameObjectMixin implements RSGameObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Model getModel()
|
private RSModel getModel()
|
||||||
{
|
{
|
||||||
Renderable renderable = getRenderable();
|
RSRenderable renderable = getRenderable();
|
||||||
if (renderable == null)
|
if (renderable == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (renderable instanceof Model)
|
if (renderable instanceof RSModel)
|
||||||
{
|
{
|
||||||
return (Model) renderable;
|
return (RSModel) renderable;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -86,13 +86,13 @@ public abstract class RSGameObjectMixin implements RSGameObject
|
|||||||
@Override
|
@Override
|
||||||
public Polygon getConvexHull()
|
public Polygon getConvexHull()
|
||||||
{
|
{
|
||||||
Model model = getModel();
|
RSModel model = getModel();
|
||||||
|
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return getConvexHull(model, getOrientation());
|
return model.getConvexHull(getX(), getY(), getOrientation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,17 +24,26 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.mixins;
|
package net.runelite.mixins;
|
||||||
|
|
||||||
|
import java.awt.Polygon;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.runelite.api.model.Triangle;
|
import net.runelite.api.Perspective;
|
||||||
import net.runelite.api.model.Vertex;
|
import net.runelite.api.Point;
|
||||||
import net.runelite.api.mixins.Inject;
|
import net.runelite.api.mixins.Inject;
|
||||||
import net.runelite.api.mixins.Mixin;
|
import net.runelite.api.mixins.Mixin;
|
||||||
|
import net.runelite.api.mixins.Shadow;
|
||||||
|
import net.runelite.api.model.Jarvis;
|
||||||
|
import net.runelite.api.model.Triangle;
|
||||||
|
import net.runelite.api.model.Vertex;
|
||||||
|
import net.runelite.rs.api.RSClient;
|
||||||
import net.runelite.rs.api.RSModel;
|
import net.runelite.rs.api.RSModel;
|
||||||
|
|
||||||
@Mixin(RSModel.class)
|
@Mixin(RSModel.class)
|
||||||
public abstract class RSModelMixin implements RSModel
|
public abstract class RSModelMixin implements RSModel
|
||||||
{
|
{
|
||||||
|
@Shadow("clientInstance")
|
||||||
|
private static RSClient client;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Inject
|
@Inject
|
||||||
public List<Vertex> getVertices()
|
public List<Vertex> getVertices()
|
||||||
@@ -85,4 +94,49 @@ public abstract class RSModelMixin implements RSModel
|
|||||||
|
|
||||||
return triangles;
|
return triangles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Inject
|
||||||
|
public Polygon getConvexHull(int localX, int localY, int orientation)
|
||||||
|
{
|
||||||
|
List<Vertex> vertices = getVertices();
|
||||||
|
|
||||||
|
// rotate vertices
|
||||||
|
for (int i = 0; i < vertices.size(); ++i)
|
||||||
|
{
|
||||||
|
Vertex v = vertices.get(i);
|
||||||
|
vertices.set(i, v.rotate(orientation));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Point> points = new ArrayList<Point>();
|
||||||
|
|
||||||
|
for (Vertex v : vertices)
|
||||||
|
{
|
||||||
|
// Compute canvas location of vertex
|
||||||
|
Point p = Perspective.worldToCanvas(client,
|
||||||
|
localX - v.getX(),
|
||||||
|
localY - v.getZ(),
|
||||||
|
-v.getY());
|
||||||
|
if (p != null)
|
||||||
|
{
|
||||||
|
points.add(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run Jarvis march algorithm
|
||||||
|
points = Jarvis.convexHull(points);
|
||||||
|
if (points == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert to a polygon
|
||||||
|
Polygon p = new Polygon();
|
||||||
|
for (Point point : points)
|
||||||
|
{
|
||||||
|
p.addPoint(point.getX(), point.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||||
|
* 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.mixins;
|
||||||
|
|
||||||
|
import net.runelite.api.events.NpcActionChanged;
|
||||||
|
import net.runelite.api.mixins.FieldHook;
|
||||||
|
import net.runelite.api.mixins.Inject;
|
||||||
|
import net.runelite.api.mixins.Mixin;
|
||||||
|
import static net.runelite.client.callback.Hooks.eventBus;
|
||||||
|
import net.runelite.rs.api.RSNPCComposition;
|
||||||
|
|
||||||
|
@Mixin(RSNPCComposition.class)
|
||||||
|
public abstract class RSNpcCompositionMixin implements RSNPCComposition
|
||||||
|
{
|
||||||
|
@FieldHook("actions")
|
||||||
|
@Inject
|
||||||
|
public void actionsHook(int idx)
|
||||||
|
{
|
||||||
|
NpcActionChanged npcActionChanged = new NpcActionChanged();
|
||||||
|
npcActionChanged.setNpcComposition(this);
|
||||||
|
npcActionChanged.setIdx(idx);
|
||||||
|
eventBus.post(npcActionChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,9 +26,6 @@ package net.runelite.mixins;
|
|||||||
|
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Polygon;
|
import java.awt.Polygon;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import net.runelite.api.Model;
|
|
||||||
import net.runelite.api.Perspective;
|
import net.runelite.api.Perspective;
|
||||||
import net.runelite.api.Point;
|
import net.runelite.api.Point;
|
||||||
import net.runelite.api.TileObject;
|
import net.runelite.api.TileObject;
|
||||||
@@ -38,8 +35,6 @@ import net.runelite.api.mixins.Inject;
|
|||||||
import net.runelite.api.mixins.Mixin;
|
import net.runelite.api.mixins.Mixin;
|
||||||
import net.runelite.api.mixins.Mixins;
|
import net.runelite.api.mixins.Mixins;
|
||||||
import net.runelite.api.mixins.Shadow;
|
import net.runelite.api.mixins.Shadow;
|
||||||
import net.runelite.api.model.Jarvis;
|
|
||||||
import net.runelite.api.model.Vertex;
|
|
||||||
import net.runelite.rs.api.RSClient;
|
import net.runelite.rs.api.RSClient;
|
||||||
import net.runelite.rs.api.RSDecorativeObject;
|
import net.runelite.rs.api.RSDecorativeObject;
|
||||||
import net.runelite.rs.api.RSGameObject;
|
import net.runelite.rs.api.RSGameObject;
|
||||||
@@ -115,52 +110,4 @@ public abstract class TileObjectMixin implements TileObject
|
|||||||
{
|
{
|
||||||
return Perspective.worldToMiniMap(client, getX(), getY());
|
return Perspective.worldToMiniMap(client, getX(), getY());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Inject
|
|
||||||
public Polygon getConvexHull(Model model, int orientation)
|
|
||||||
{
|
|
||||||
int localX = getX();
|
|
||||||
int localY = getY();
|
|
||||||
|
|
||||||
List<Vertex> vertices = model.getVertices();
|
|
||||||
|
|
||||||
// rotate vertices
|
|
||||||
for (int i = 0; i < vertices.size(); ++i)
|
|
||||||
{
|
|
||||||
Vertex v = vertices.get(i);
|
|
||||||
vertices.set(i, v.rotate(orientation));
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Point> points = new ArrayList<Point>();
|
|
||||||
|
|
||||||
for (Vertex v : vertices)
|
|
||||||
{
|
|
||||||
// Compute canvas location of vertex
|
|
||||||
Point p = Perspective.worldToCanvas(client,
|
|
||||||
localX - v.getX(),
|
|
||||||
localY - v.getZ(),
|
|
||||||
-v.getY());
|
|
||||||
if (p != null)
|
|
||||||
{
|
|
||||||
points.add(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run Jarvis march algorithm
|
|
||||||
points = Jarvis.convexHull(points);
|
|
||||||
if (points == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert to a polygon
|
|
||||||
Polygon p = new Polygon();
|
|
||||||
for (Point point : points)
|
|
||||||
{
|
|
||||||
p.addPoint(point.getX(), point.getY());
|
|
||||||
}
|
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
package net.runelite.rs.api;
|
package net.runelite.rs.api;
|
||||||
|
|
||||||
import net.runelite.api.DecorativeObject;
|
import net.runelite.api.DecorativeObject;
|
||||||
import net.runelite.api.Renderable;
|
|
||||||
import net.runelite.mapping.Import;
|
import net.runelite.mapping.Import;
|
||||||
|
|
||||||
public interface RSDecorativeObject extends DecorativeObject
|
public interface RSDecorativeObject extends DecorativeObject
|
||||||
@@ -44,7 +43,7 @@ public interface RSDecorativeObject extends DecorativeObject
|
|||||||
int getOrientation();
|
int getOrientation();
|
||||||
|
|
||||||
@Import("renderable1")
|
@Import("renderable1")
|
||||||
Renderable getRenderable();
|
RSRenderable getRenderable();
|
||||||
|
|
||||||
void setPlane(int plane);
|
void setPlane(int plane);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,13 +25,12 @@
|
|||||||
package net.runelite.rs.api;
|
package net.runelite.rs.api;
|
||||||
|
|
||||||
import net.runelite.api.GameObject;
|
import net.runelite.api.GameObject;
|
||||||
import net.runelite.api.Renderable;
|
|
||||||
import net.runelite.mapping.Import;
|
import net.runelite.mapping.Import;
|
||||||
|
|
||||||
public interface RSGameObject extends GameObject
|
public interface RSGameObject extends GameObject
|
||||||
{
|
{
|
||||||
@Import("renderable")
|
@Import("renderable")
|
||||||
Renderable getRenderable();
|
RSRenderable getRenderable();
|
||||||
|
|
||||||
@Import("plane")
|
@Import("plane")
|
||||||
int getPlane();
|
int getPlane();
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.rs.api;
|
package net.runelite.rs.api;
|
||||||
|
|
||||||
|
import java.awt.Polygon;
|
||||||
import net.runelite.api.Model;
|
import net.runelite.api.Model;
|
||||||
import net.runelite.mapping.Import;
|
import net.runelite.mapping.Import;
|
||||||
|
|
||||||
@@ -52,4 +53,13 @@ public interface RSModel extends RSRenderable, Model
|
|||||||
|
|
||||||
@Import("indices3")
|
@Import("indices3")
|
||||||
int[] getTrianglesZ();
|
int[] getTrianglesZ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the convex hull of this model
|
||||||
|
* @param localX
|
||||||
|
* @param localY
|
||||||
|
* @param orientation
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Polygon getConvexHull(int localX, int localY, int orientation);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.rs.api;
|
package net.runelite.rs.api;
|
||||||
|
|
||||||
import net.runelite.api.Model;
|
|
||||||
import net.runelite.api.Renderable;
|
import net.runelite.api.Renderable;
|
||||||
import net.runelite.mapping.Import;
|
import net.runelite.mapping.Import;
|
||||||
|
|
||||||
@@ -35,5 +34,5 @@ public interface RSRenderable extends RSNode, Renderable
|
|||||||
|
|
||||||
@Import("getModel")
|
@Import("getModel")
|
||||||
@Override
|
@Override
|
||||||
Model getModel();
|
RSModel getModel();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user