Add tooltips for InfoBoxes

This commit is contained in:
Tyler Hardy
2017-10-16 00:10:06 -05:00
committed by Adam
parent 2d5b2b78fd
commit 9fe360d614
2 changed files with 52 additions and 1 deletions

View File

@@ -31,6 +31,8 @@ public abstract class InfoBox
{
private final BufferedImage image;
private String tooltip;
public InfoBox(BufferedImage image)
{
this.image = image;
@@ -54,4 +56,14 @@ public abstract class InfoBox
{
return false;
}
public String getTooltip()
{
return tooltip;
}
public void setTooltip(String tooltip)
{
this.tooltip = tooltip;
}
}

View File

@@ -29,10 +29,12 @@ import java.awt.Color;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.util.List;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.Point;
import net.runelite.client.RuneLite;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
@@ -69,9 +71,14 @@ public class InfoBoxOverlay extends Overlay
FontMetrics metrics = graphics.getFontMetrics();
int width = infoBoxes.size() * BOXSIZE;
int width = infoBoxes.size() * (BOXSIZE + SEPARATOR);
Point mouse = client.getMouseCanvasPosition();
int mouseX = mouse.getX();
int mouseY = mouse.getY();
int x = 0;
Rectangle overlayBounds = this.getBounds();
for (InfoBox box : infoBoxes)
{
if (!box.render())
@@ -101,6 +108,38 @@ public class InfoBoxOverlay extends Overlay
graphics.setColor(color);
graphics.drawString(str, x + ((BOXSIZE - metrics.stringWidth(str)) / 2), BOXSIZE - SEPARATOR);
if (overlayBounds == null)
{
continue;
}
String tooltip = box.getTooltip();
if (tooltip == null || tooltip.isEmpty())
{
continue;
}
Rectangle bounds = new Rectangle((int) overlayBounds.getX() + x, (int) overlayBounds.getY(), BOXSIZE, BOXSIZE);
if (bounds.contains(mouse.getX(), mouse.getY()))
{
int tooltipWidth = metrics.stringWidth(tooltip);
int height = metrics.getHeight();
Color gray = new Color(Color.darkGray.getRed(), Color.darkGray.getGreen(), Color.darkGray.getBlue(), 190);
graphics.setColor(gray);
// Draws the background rect
graphics.fillRect(mouseX, mouseY - (height / 2), tooltipWidth + 6, height);
// Draws the outline of the rect
graphics.setColor(Color.BLACK);
graphics.drawRect(mouseX, mouseY - (height / 2), tooltipWidth + 6, height);
// Tooltip text
graphics.setColor(Color.WHITE);
graphics.drawString(tooltip, mouseX + 3, mouseY + 5);
}
x += BOXSIZE + SEPARATOR;
}