Merge pull request #10875 from devLotto/issue-8633
player-indicators: highlight the 'Walk here' menu entry too
This commit is contained in:
@@ -273,9 +273,6 @@ public enum MenuAction
|
||||
*/
|
||||
RUNELITE_OVERLAY_CONFIG(1502),
|
||||
|
||||
FOLLOW(2046),
|
||||
TRADE(2047),
|
||||
|
||||
/**
|
||||
* Menu action triggered when the id is not defined in this class.
|
||||
*/
|
||||
|
||||
@@ -27,13 +27,14 @@ package net.runelite.client.plugins.playerindicators;
|
||||
import com.google.inject.Provides;
|
||||
import java.awt.Color;
|
||||
import javax.inject.Inject;
|
||||
import lombok.Value;
|
||||
import net.runelite.api.ClanMemberRank;
|
||||
import static net.runelite.api.ClanMemberRank.UNRANKED;
|
||||
import net.runelite.api.Client;
|
||||
import static net.runelite.api.MenuAction.*;
|
||||
import net.runelite.api.MenuEntry;
|
||||
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.eventbus.Subscribe;
|
||||
import net.runelite.client.game.ClanManager;
|
||||
@@ -93,93 +94,141 @@ public class PlayerIndicatorsPlugin extends Plugin
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
if (type == WALK.getId()
|
||||
|| type == SPELL_CAST_ON_PLAYER.getId()
|
||||
|| type == ITEM_USE_ON_PLAYER.getId()
|
||||
|| type == PLAYER_FIRST_OPTION.getId()
|
||||
|| type == PLAYER_SECOND_OPTION.getId()
|
||||
|| type == PLAYER_THIRD_OPTION.getId()
|
||||
|| type == PLAYER_FOURTH_OPTION.getId()
|
||||
|| type == PLAYER_FIFTH_OPTION.getId()
|
||||
|| type == PLAYER_SIXTH_OPTION.getId()
|
||||
|| type == PLAYER_SEVENTH_OPTION.getId()
|
||||
|| type == PLAYER_EIGTH_OPTION.getId()
|
||||
|| type == RUNELITE.getId())
|
||||
{
|
||||
Player[] players = client.getCachedPlayers();
|
||||
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)
|
||||
{
|
||||
player = players[identifier];
|
||||
}
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Decorations decorations = getDecorations(player);
|
||||
|
||||
if (decorations == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
String oldTarget = entry.getTarget();
|
||||
String newTarget = decorateTarget(oldTarget, decorations);
|
||||
|
||||
entry.setTarget(newTarget);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
int identifier = menuEntryAdded.getIdentifier();
|
||||
if (type == FOLLOW.getId() || type == TRADE.getId()
|
||||
|| type == SPELL_CAST_ON_PLAYER.getId() || type == ITEM_USE_ON_PLAYER.getId()
|
||||
|| type == PLAYER_FIRST_OPTION.getId()
|
||||
|| type == PLAYER_SECOND_OPTION.getId()
|
||||
|| type == PLAYER_THIRD_OPTION.getId()
|
||||
|| type == PLAYER_FOURTH_OPTION.getId()
|
||||
|| type == PLAYER_FIFTH_OPTION.getId()
|
||||
|| type == PLAYER_SIXTH_OPTION.getId()
|
||||
|| type == PLAYER_SEVENTH_OPTION.getId()
|
||||
|| type == PLAYER_EIGTH_OPTION.getId()
|
||||
|| type == RUNELITE.getId())
|
||||
if (modified)
|
||||
{
|
||||
final Player localPlayer = client.getLocalPlayer();
|
||||
Player[] players = client.getCachedPlayers();
|
||||
Player player = null;
|
||||
|
||||
if (identifier >= 0 && identifier < players.length)
|
||||
{
|
||||
player = players[identifier];
|
||||
}
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int image = -1;
|
||||
Color color = null;
|
||||
|
||||
if (config.highlightFriends() && player.isFriend())
|
||||
{
|
||||
color = config.getFriendColor();
|
||||
}
|
||||
else if (config.drawClanMemberNames() && player.isClanMember())
|
||||
{
|
||||
color = config.getClanMemberColor();
|
||||
|
||||
ClanMemberRank rank = clanManager.getRank(player.getName());
|
||||
if (rank != UNRANKED)
|
||||
{
|
||||
image = clanManager.getIconNumber(rank);
|
||||
}
|
||||
}
|
||||
else if (config.highlightTeamMembers() && player.getTeam() > 0 && localPlayer.getTeam() == player.getTeam())
|
||||
{
|
||||
color = config.getTeamMemberColor();
|
||||
}
|
||||
else if (config.highlightNonClanMembers() && !player.isClanMember())
|
||||
{
|
||||
color = config.getNonClanMemberColor();
|
||||
}
|
||||
|
||||
if (image != -1 || color != null)
|
||||
{
|
||||
MenuEntry[] menuEntries = client.getMenuEntries();
|
||||
MenuEntry lastEntry = menuEntries[menuEntries.length - 1];
|
||||
|
||||
if (color != null && config.colorPlayerMenu())
|
||||
{
|
||||
// strip out existing <col...
|
||||
String target = lastEntry.getTarget();
|
||||
int idx = target.indexOf('>');
|
||||
if (idx != -1)
|
||||
{
|
||||
target = target.substring(idx + 1);
|
||||
}
|
||||
|
||||
lastEntry.setTarget(ColorUtil.prependColorTag(target, color));
|
||||
}
|
||||
|
||||
if (image != -1 && config.showClanRanks())
|
||||
{
|
||||
lastEntry.setTarget("<img=" + image + ">" + lastEntry.getTarget());
|
||||
}
|
||||
|
||||
client.setMenuEntries(menuEntries);
|
||||
}
|
||||
client.setMenuEntries(menuEntries);
|
||||
}
|
||||
}
|
||||
|
||||
private Decorations getDecorations(Player player)
|
||||
{
|
||||
int image = -1;
|
||||
Color color = null;
|
||||
|
||||
if (config.highlightFriends() && player.isFriend())
|
||||
{
|
||||
color = config.getFriendColor();
|
||||
}
|
||||
else if (config.drawClanMemberNames() && player.isClanMember())
|
||||
{
|
||||
color = config.getClanMemberColor();
|
||||
|
||||
ClanMemberRank rank = clanManager.getRank(player.getName());
|
||||
if (rank != UNRANKED)
|
||||
{
|
||||
image = clanManager.getIconNumber(rank);
|
||||
}
|
||||
}
|
||||
else if (config.highlightTeamMembers()
|
||||
&& player.getTeam() > 0 && client.getLocalPlayer().getTeam() == player.getTeam())
|
||||
{
|
||||
color = config.getTeamMemberColor();
|
||||
}
|
||||
else if (config.highlightNonClanMembers() && !player.isClanMember())
|
||||
{
|
||||
color = config.getNonClanMemberColor();
|
||||
}
|
||||
|
||||
if (image == -1 && color == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
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...
|
||||
int idx = oldTarget.indexOf('>');
|
||||
if (idx != -1)
|
||||
{
|
||||
newTarget = oldTarget.substring(idx + 1);
|
||||
}
|
||||
|
||||
newTarget = ColorUtil.prependColorTag(newTarget, decorations.getColor());
|
||||
}
|
||||
|
||||
if (decorations.getImage() != -1 && config.showClanRanks())
|
||||
{
|
||||
newTarget = "<img=" + decorations.getImage() + ">" + newTarget;
|
||||
}
|
||||
|
||||
return newTarget;
|
||||
}
|
||||
|
||||
@Value
|
||||
private static class Decorations
|
||||
{
|
||||
private final int image;
|
||||
private final Color color;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user