Merge pull request #10875 from devLotto/issue-8633

player-indicators: highlight the 'Walk here' menu entry too
This commit is contained in:
Adam
2020-04-02 14:45:24 -04:00
committed by GitHub
2 changed files with 131 additions and 85 deletions

View File

@@ -273,9 +273,6 @@ public enum MenuAction
*/ */
RUNELITE_OVERLAY_CONFIG(1502), RUNELITE_OVERLAY_CONFIG(1502),
FOLLOW(2046),
TRADE(2047),
/** /**
* Menu action triggered when the id is not defined in this class. * Menu action triggered when the id is not defined in this class.
*/ */

View File

@@ -27,13 +27,14 @@ package net.runelite.client.plugins.playerindicators;
import com.google.inject.Provides; import com.google.inject.Provides;
import java.awt.Color; import java.awt.Color;
import javax.inject.Inject; import javax.inject.Inject;
import lombok.Value;
import net.runelite.api.ClanMemberRank; import net.runelite.api.ClanMemberRank;
import static net.runelite.api.ClanMemberRank.UNRANKED; import static net.runelite.api.ClanMemberRank.UNRANKED;
import net.runelite.api.Client; import net.runelite.api.Client;
import static net.runelite.api.MenuAction.*; import static net.runelite.api.MenuAction.*;
import net.runelite.api.MenuEntry; import net.runelite.api.MenuEntry;
import net.runelite.api.Player; import net.runelite.api.Player;
import net.runelite.api.events.MenuEntryAdded; import net.runelite.api.events.ClientTick;
import net.runelite.client.config.ConfigManager; import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe; import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.game.ClanManager; import net.runelite.client.game.ClanManager;
@@ -93,18 +94,23 @@ public class PlayerIndicatorsPlugin extends Plugin
} }
@Subscribe @Subscribe
public void onMenuEntryAdded(MenuEntryAdded menuEntryAdded) public void onClientTick(ClientTick clientTick)
{ {
int type = menuEntryAdded.getType(); MenuEntry[] menuEntries = client.getMenuEntries();
boolean modified = false;
if (type >= 2000) for (MenuEntry entry : menuEntries)
{ {
type -= 2000; int type = entry.getType();
if (type >= MENU_ACTION_DEPRIORITIZE_OFFSET)
{
type -= MENU_ACTION_DEPRIORITIZE_OFFSET;
} }
int identifier = menuEntryAdded.getIdentifier(); if (type == WALK.getId()
if (type == FOLLOW.getId() || type == TRADE.getId() || type == SPELL_CAST_ON_PLAYER.getId()
|| type == SPELL_CAST_ON_PLAYER.getId() || type == ITEM_USE_ON_PLAYER.getId() || type == ITEM_USE_ON_PLAYER.getId()
|| type == PLAYER_FIRST_OPTION.getId() || type == PLAYER_FIRST_OPTION.getId()
|| type == PLAYER_SECOND_OPTION.getId() || type == PLAYER_SECOND_OPTION.getId()
|| type == PLAYER_THIRD_OPTION.getId() || type == PLAYER_THIRD_OPTION.getId()
@@ -115,10 +121,18 @@ public class PlayerIndicatorsPlugin extends Plugin
|| type == PLAYER_EIGTH_OPTION.getId() || type == PLAYER_EIGTH_OPTION.getId()
|| type == RUNELITE.getId()) || type == RUNELITE.getId())
{ {
final Player localPlayer = client.getLocalPlayer();
Player[] players = client.getCachedPlayers(); Player[] players = client.getCachedPlayers();
Player player = null; Player player = null;
int identifier = entry.getIdentifier();
// 'Walk here' identifiers are offset by 1 because the default
// identifier for this option is 0, which is also a player index.
if (type == WALK.getId())
{
identifier--;
}
if (identifier >= 0 && identifier < players.length) if (identifier >= 0 && identifier < players.length)
{ {
player = players[identifier]; player = players[identifier];
@@ -126,9 +140,32 @@ public class PlayerIndicatorsPlugin extends Plugin
if (player == null) if (player == null)
{ {
return; continue;
} }
Decorations decorations = getDecorations(player);
if (decorations == null)
{
continue;
}
String oldTarget = entry.getTarget();
String newTarget = decorateTarget(oldTarget, decorations);
entry.setTarget(newTarget);
modified = true;
}
}
if (modified)
{
client.setMenuEntries(menuEntries);
}
}
private Decorations getDecorations(Player player)
{
int image = -1; int image = -1;
Color color = null; Color color = null;
@@ -146,7 +183,8 @@ public class PlayerIndicatorsPlugin extends Plugin
image = clanManager.getIconNumber(rank); image = clanManager.getIconNumber(rank);
} }
} }
else if (config.highlightTeamMembers() && player.getTeam() > 0 && localPlayer.getTeam() == player.getTeam()) else if (config.highlightTeamMembers()
&& player.getTeam() > 0 && client.getLocalPlayer().getTeam() == player.getTeam())
{ {
color = config.getTeamMemberColor(); color = config.getTeamMemberColor();
} }
@@ -155,31 +193,42 @@ public class PlayerIndicatorsPlugin extends Plugin
color = config.getNonClanMemberColor(); color = config.getNonClanMemberColor();
} }
if (image != -1 || color != null) if (image == -1 && color == null)
{ {
MenuEntry[] menuEntries = client.getMenuEntries(); return null;
MenuEntry lastEntry = menuEntries[menuEntries.length - 1]; }
if (color != null && config.colorPlayerMenu()) return new Decorations(image, color);
}
private String decorateTarget(String oldTarget, Decorations decorations)
{
String newTarget = oldTarget;
if (decorations.getColor() != null && config.colorPlayerMenu())
{ {
// strip out existing <col... // strip out existing <col...
String target = lastEntry.getTarget(); int idx = oldTarget.indexOf('>');
int idx = target.indexOf('>');
if (idx != -1) if (idx != -1)
{ {
target = target.substring(idx + 1); newTarget = oldTarget.substring(idx + 1);
} }
lastEntry.setTarget(ColorUtil.prependColorTag(target, color)); newTarget = ColorUtil.prependColorTag(newTarget, decorations.getColor());
} }
if (image != -1 && config.showClanRanks()) if (decorations.getImage() != -1 && config.showClanRanks())
{ {
lastEntry.setTarget("<img=" + image + ">" + lastEntry.getTarget()); newTarget = "<img=" + decorations.getImage() + ">" + newTarget;
} }
client.setMenuEntries(menuEntries); return newTarget;
} }
}
@Value
private static class Decorations
{
private final int image;
private final Color color;
} }
} }