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.Dimension;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Polygon; import java.awt.Polygon;
import java.awt.image.BufferedImage;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import net.runelite.api.ClanMemberRank;
import net.runelite.api.Player; 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.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayPriority; import net.runelite.client.ui.overlay.OverlayPriority;
@@ -41,12 +45,15 @@ public class PlayerIndicatorsOverlay extends Overlay
{ {
private final PlayerIndicatorsService playerIndicatorsService; private final PlayerIndicatorsService playerIndicatorsService;
private final PlayerIndicatorsConfig config; private final PlayerIndicatorsConfig config;
private final ClanManager clanManager;
@Inject @Inject
private PlayerIndicatorsOverlay(PlayerIndicatorsConfig config, PlayerIndicatorsService playerIndicatorsService) private PlayerIndicatorsOverlay(PlayerIndicatorsConfig config, PlayerIndicatorsService playerIndicatorsService,
ClanManager clanManager)
{ {
this.config = config; this.config = config;
this.playerIndicatorsService = playerIndicatorsService; this.playerIndicatorsService = playerIndicatorsService;
this.clanManager = clanManager;
setPosition(OverlayPosition.DYNAMIC); setPosition(OverlayPosition.DYNAMIC);
setPriority(OverlayPriority.HIGH); setPriority(OverlayPriority.HIGH);
} }
@@ -69,12 +76,29 @@ public class PlayerIndicatorsOverlay extends Overlay
} }
} }
final String name = actor.getName().replace('\u00A0', ' '); String name = actor.getName().replace('\u00A0', ' ');
net.runelite.api.Point textLocation = actor int offset = actor.getLogicalHeight() + 40;
.getCanvasTextLocation(graphics, name, actor.getLogicalHeight() + 40); Point textLocation = actor.getCanvasTextLocation(graphics, name, offset);
if (textLocation != null) 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); OverlayUtil.renderTextLocation(graphics, textLocation, name, color);
} }
} }