player indicator overlay: render clan rank next to names

This commit is contained in:
Adam
2018-04-01 13:10:31 -04:00
parent 74fd91d887
commit c0bec73e5c

View File

@@ -28,9 +28,13 @@ import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.image.BufferedImage;
import javax.inject.Inject;
import javax.inject.Singleton;
import net.runelite.api.ClanMemberRank;
import net.runelite.api.Player;
import net.runelite.api.Point;
import net.runelite.client.game.ClanManager;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayPriority;
@@ -41,12 +45,15 @@ public class PlayerIndicatorsOverlay extends Overlay
{
private final PlayerIndicatorsService playerIndicatorsService;
private final PlayerIndicatorsConfig config;
private final ClanManager clanManager;
@Inject
private PlayerIndicatorsOverlay(PlayerIndicatorsConfig config, PlayerIndicatorsService playerIndicatorsService)
private PlayerIndicatorsOverlay(PlayerIndicatorsConfig config, PlayerIndicatorsService playerIndicatorsService,
ClanManager clanManager)
{
this.config = config;
this.playerIndicatorsService = playerIndicatorsService;
this.clanManager = clanManager;
setPosition(OverlayPosition.DYNAMIC);
setPriority(OverlayPriority.HIGH);
}
@@ -69,12 +76,29 @@ public class PlayerIndicatorsOverlay extends Overlay
}
}
final String name = actor.getName().replace('\u00A0', ' ');
net.runelite.api.Point textLocation = actor
.getCanvasTextLocation(graphics, name, actor.getLogicalHeight() + 40);
String name = actor.getName().replace('\u00A0', ' ');
int offset = actor.getLogicalHeight() + 40;
Point textLocation = actor.getCanvasTextLocation(graphics, name, offset);
if (textLocation != null)
{
if (actor.isClanMember())
{
ClanMemberRank rank = clanManager.getRank(name);
if (rank != ClanMemberRank.UNRANKED)
{
BufferedImage clanchatImage = clanManager.getClanImage(rank);
if (clanchatImage != null)
{
int width = clanchatImage.getWidth();
Point imageLocation = new Point(textLocation.getX() - width / 2, textLocation.getY() - clanchatImage.getHeight());
OverlayUtil.renderImageLocation(graphics, imageLocation, clanchatImage);
// move text
textLocation = new Point(textLocation.getX() + width / 2, textLocation.getY());
}
}
}
OverlayUtil.renderTextLocation(graphics, textLocation, name, color);
}
}