Merge pull request #164 from devinfrench/jewelry

Change jewelry overlay font and position
This commit is contained in:
Adam
2017-10-11 11:30:47 -04:00
committed by GitHub
3 changed files with 27 additions and 13 deletions

View File

@@ -28,11 +28,16 @@ import net.runelite.client.RuneLite;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.Overlay;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
public class JewelryCount extends Plugin public class JewelryCount extends Plugin
{ {
private final JewelryCountConfig config = RuneLite.getRunelite().getConfigManager().getConfig(JewelryCountConfig.class); private final JewelryCountConfig config = RuneLite.getRunelite().getConfigManager().getConfig(JewelryCountConfig.class);
private final Overlay overlay = new JewelryCountOverlay(this); private final Overlay overlay = new JewelryCountOverlay(this);
private Font font;
@Override @Override
public Overlay getOverlay() public Overlay getOverlay()
{ {
@@ -42,7 +47,10 @@ public class JewelryCount extends Plugin
@Override @Override
protected void startUp() throws Exception protected void startUp() throws Exception
{ {
font = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/runescape_small.ttf"));
font = font.deriveFont(Font.PLAIN, 16);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(font);
} }
@Override @Override
@@ -55,4 +63,9 @@ public class JewelryCount extends Plugin
{ {
return config; return config;
} }
public Font getFont()
{
return font;
}
} }

View File

@@ -25,7 +25,6 @@
package net.runelite.client.plugins.jewelrycount; package net.runelite.client.plugins.jewelrycount;
import java.awt.*; import java.awt.*;
import java.awt.geom.Rectangle2D;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.GameState; import net.runelite.api.GameState;
@@ -39,11 +38,13 @@ import net.runelite.client.ui.overlay.OverlayPosition;
class JewelryCountOverlay extends Overlay class JewelryCountOverlay extends Overlay
{ {
private final JewelryCountConfig config; private final JewelryCountConfig config;
private final JewelryCount plugin;
JewelryCountOverlay(JewelryCount plugin) JewelryCountOverlay(JewelryCount plugin)
{ {
super(OverlayPosition.DYNAMIC); super(OverlayPosition.DYNAMIC);
this.config = plugin.getConfig(); this.config = plugin.getConfig();
this.plugin = plugin;
} }
@Override @Override
@@ -102,10 +103,6 @@ class JewelryCountOverlay extends Overlay
Rectangle widgetBounds = widget.getBounds(); Rectangle widgetBounds = widget.getBounds();
//to match inventory text
widgetBounds.x -= 5;
widgetBounds.y -= 1;
renderWidgetText(graphics, widgetBounds, charges.getCharges(), Color.white); renderWidgetText(graphics, widgetBounds, charges.getCharges(), Color.white);
} }
@@ -116,19 +113,23 @@ class JewelryCountOverlay extends Overlay
private void renderWidgetText(Graphics2D graphics, Rectangle bounds, int charges, Color color) private void renderWidgetText(Graphics2D graphics, Rectangle bounds, int charges, Color color)
{ {
String text = charges + ""; Font font = plugin.getFont();
FontMetrics fm = graphics.getFontMetrics(); if (font != null)
Rectangle2D textBounds = fm.getStringBounds(text, graphics); {
graphics.setFont(font);
}
int textX = (int) (bounds.getX() + bounds.getWidth() - textBounds.getWidth()); FontMetrics fm = graphics.getFontMetrics();
int textY = (int) (bounds.getY() + (textBounds.getHeight()));
int textX = (int) bounds.getX();
int textY = (int) bounds.getY() + fm.getHeight();
//text shadow //text shadow
graphics.setColor(Color.BLACK); graphics.setColor(Color.BLACK);
graphics.drawString(text, textX + 1, textY + 1); graphics.drawString(String.valueOf(charges), textX + 1, textY + 1);
graphics.setColor(color); graphics.setColor(color);
graphics.drawString(text, textX, textY); graphics.drawString(String.valueOf(charges), textX, textY);
} }
} }

Binary file not shown.