player indicators: add clans

This commit is contained in:
Adam
2021-05-26 15:21:20 -04:00
parent 1c75a97df5
commit 7de3b61860
4 changed files with 126 additions and 38 deletions

View File

@@ -95,7 +95,7 @@ public interface PlayerIndicatorsConfig extends Config
description = "Configures if friends chat members should be highlighted",
section = highlightSection
)
default boolean drawFriendsChatMemberNames()
default boolean highlightFriendsChat()
{
return true;
}
@@ -138,6 +138,30 @@ public interface PlayerIndicatorsConfig extends Config
@ConfigItem(
position = 8,
keyName = "drawClanChatMemberNames",
name = "Highlight clan members",
description = "Configures whether or not clan members should be highlighted",
section = highlightSection
)
default boolean highlightClanMembers()
{
return true;
}
@ConfigItem(
position = 9,
keyName = "clanChatMemberColor",
name = "Clan member",
description = "Color of clan members",
section = highlightSection
)
default Color getClanMemberColor()
{
return new Color(36, 15, 171);
}
@ConfigItem(
position = 10,
keyName = "drawNonClanMemberNames",
name = "Highlight others",
description = "Configures whether or not other players should be highlighted",
@@ -149,7 +173,7 @@ public interface PlayerIndicatorsConfig extends Config
}
@ConfigItem(
position = 9,
position = 11,
keyName = "nonClanMemberColor",
name = "Others",
description = "Color of other players names",
@@ -214,4 +238,15 @@ public interface PlayerIndicatorsConfig extends Config
{
return true;
}
@ConfigItem(
position = 15,
keyName = "clanchatMenuIcons",
name = "Show clan chat ranks",
description = "Add clan chat rank to right click menu and next to player names"
)
default boolean showClanChatRanks()
{
return true;
}
}

View File

@@ -34,6 +34,7 @@ import javax.inject.Singleton;
import net.runelite.api.FriendsChatRank;
import net.runelite.api.Player;
import net.runelite.api.Point;
import net.runelite.api.clan.ClanTitle;
import net.runelite.client.game.ChatIconManager;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
@@ -108,40 +109,49 @@ public class PlayerIndicatorsOverlay extends Overlay
return;
}
if (actor.isFriendsChatMember() && config.showFriendsChatRanks())
BufferedImage rankImage = null;
if (actor.isFriendsChatMember() && config.highlightFriendsChat() && config.showFriendsChatRanks())
{
final FriendsChatRank rank = playerIndicatorsService.getFriendsChatRank(actor);
if (rank != FriendsChatRank.UNRANKED)
{
final BufferedImage rankImage = chatIconManager.getRankImage(rank);
if (rankImage != null)
{
final int imageWidth = rankImage.getWidth();
final int imageTextMargin;
final int imageNegativeMargin;
if (drawPlayerNamesConfig == PlayerNameLocation.MODEL_RIGHT)
{
imageTextMargin = imageWidth;
imageNegativeMargin = 0;
}
else
{
imageTextMargin = imageWidth / 2;
imageNegativeMargin = imageWidth / 2;
}
final int textHeight = graphics.getFontMetrics().getHeight() - graphics.getFontMetrics().getMaxDescent();
final Point imageLocation = new Point(textLocation.getX() - imageNegativeMargin - 1, textLocation.getY() - textHeight / 2 - rankImage.getHeight() / 2);
OverlayUtil.renderImageLocation(graphics, imageLocation, rankImage);
// move text
textLocation = new Point(textLocation.getX() + imageTextMargin, textLocation.getY());
}
rankImage = chatIconManager.getRankImage(rank);
}
}
else if (actor.isClanMember() && config.highlightClanMembers() && config.showClanChatRanks())
{
ClanTitle clanTitle = playerIndicatorsService.getClanTitle(actor);
if (clanTitle != null)
{
rankImage = chatIconManager.getRankImage(clanTitle);
}
}
if (rankImage != null)
{
final int imageWidth = rankImage.getWidth();
final int imageTextMargin;
final int imageNegativeMargin;
if (drawPlayerNamesConfig == PlayerNameLocation.MODEL_RIGHT)
{
imageTextMargin = imageWidth;
imageNegativeMargin = 0;
}
else
{
imageTextMargin = imageWidth / 2;
imageNegativeMargin = imageWidth / 2;
}
final int textHeight = graphics.getFontMetrics().getHeight() - graphics.getFontMetrics().getMaxDescent();
final Point imageLocation = new Point(textLocation.getX() - imageNegativeMargin - 1, textLocation.getY() - textHeight / 2 - rankImage.getHeight() / 2);
OverlayUtil.renderImageLocation(graphics, imageLocation, rankImage);
// move text
textLocation = new Point(textLocation.getX() + imageTextMargin, textLocation.getY());
}
OverlayUtil.renderTextLocation(graphics, textLocation, name, color);
}

View File

@@ -46,6 +46,7 @@ import static net.runelite.api.MenuAction.SPELL_CAST_ON_PLAYER;
import static net.runelite.api.MenuAction.WALK;
import net.runelite.api.MenuEntry;
import net.runelite.api.Player;
import net.runelite.api.clan.ClanTitle;
import net.runelite.api.events.ClientTick;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
@@ -189,11 +190,11 @@ public class PlayerIndicatorsPlugin extends Plugin
int image = -1;
Color color = null;
if (config.highlightFriends() && player.isFriend())
if (player.isFriend() && config.highlightFriends())
{
color = config.getFriendColor();
}
else if (config.drawFriendsChatMemberNames() && player.isFriendsChatMember())
else if (player.isFriendsChatMember() && config.highlightFriendsChat())
{
color = config.getFriendsChatMemberColor();
@@ -206,12 +207,24 @@ public class PlayerIndicatorsPlugin extends Plugin
}
}
}
else if (config.highlightTeamMembers()
&& player.getTeam() > 0 && client.getLocalPlayer().getTeam() == player.getTeam())
else if (player.getTeam() > 0 && client.getLocalPlayer().getTeam() == player.getTeam() && config.highlightTeamMembers())
{
color = config.getTeamMemberColor();
}
else if (config.highlightOthers() && !player.isFriendsChatMember())
else if (player.isClanMember() && config.highlightClanMembers())
{
color = config.getClanMemberColor();
if (config.showClanChatRanks())
{
ClanTitle clanTitle = playerIndicatorsService.getClanTitle(player);
if (clanTitle != null)
{
image = chatIconManager.getIconNumber(clanTitle);
}
}
}
else if (!player.isFriendsChatMember() && !player.isClanMember() && config.highlightOthers())
{
color = config.getOthersColor();
}

View File

@@ -33,6 +33,11 @@ import net.runelite.api.FriendsChatManager;
import net.runelite.api.FriendsChatMember;
import net.runelite.api.FriendsChatRank;
import net.runelite.api.Player;
import net.runelite.api.clan.ClanChannel;
import net.runelite.api.clan.ClanChannelMember;
import net.runelite.api.clan.ClanRank;
import net.runelite.api.clan.ClanSettings;
import net.runelite.api.clan.ClanTitle;
@Singleton
public class PlayerIndicatorsService
@@ -49,8 +54,9 @@ public class PlayerIndicatorsService
public void forEachPlayer(final BiConsumer<Player, Color> consumer)
{
if (!config.highlightOwnPlayer() && !config.drawFriendsChatMemberNames()
&& !config.highlightFriends() && !config.highlightOthers())
if (!config.highlightOwnPlayer() && !config.highlightFriendsChat()
&& !config.highlightFriends() && !config.highlightOthers()
&& !config.highlightClanMembers())
{
return;
}
@@ -65,6 +71,7 @@ public class PlayerIndicatorsService
}
boolean isFriendsChatMember = player.isFriendsChatMember();
boolean isClanMember = player.isClanMember();
if (player == localPlayer)
{
@@ -77,7 +84,7 @@ public class PlayerIndicatorsService
{
consumer.accept(player, config.getFriendColor());
}
else if (config.drawFriendsChatMemberNames() && isFriendsChatMember)
else if (config.highlightFriendsChat() && isFriendsChatMember)
{
consumer.accept(player, config.getFriendsChatMemberColor());
}
@@ -85,13 +92,36 @@ public class PlayerIndicatorsService
{
consumer.accept(player, config.getTeamMemberColor());
}
else if (config.highlightOthers() && !isFriendsChatMember)
else if (config.highlightClanMembers() && isClanMember)
{
consumer.accept(player, config.getClanMemberColor());
}
else if (config.highlightOthers() && !isFriendsChatMember && !isClanMember)
{
consumer.accept(player, config.getOthersColor());
}
}
}
ClanTitle getClanTitle(Player player)
{
ClanChannel clanChannel = client.getClanChannel();
ClanSettings clanSettings = client.getClanSettings();
if (clanChannel == null || clanSettings == null)
{
return null;
}
ClanChannelMember member = clanChannel.findMember(player.getName());
if (member == null)
{
return null;
}
ClanRank rank = member.getRank();
return clanSettings.titleForRank(rank);
}
FriendsChatRank getFriendsChatRank(Player player)
{
final FriendsChatManager friendsChatManager = client.getFriendsChatManager();