runelite-client: Use tooltip system for plugins and infoboxes
This commit is contained in:
@@ -24,27 +24,25 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.mousehighlight;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
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;
|
||||
import net.runelite.client.ui.overlay.tooltips.Tooltip;
|
||||
import net.runelite.client.ui.overlay.tooltips.TooltipPriority;
|
||||
import net.runelite.client.ui.overlay.tooltips.TooltipRenderer;
|
||||
|
||||
class MouseHighlightOverlay extends Overlay
|
||||
{
|
||||
// Grabs the colour and name from a target string
|
||||
// <col=ffffff>Player1
|
||||
private final Pattern p = Pattern.compile("<col=([^>]+)>([^<]*)");
|
||||
private final MouseHighlightConfig config;
|
||||
private final Client client = RuneLite.getClient();
|
||||
private final RuneLite runelite = RuneLite.getRunelite();
|
||||
private final TooltipRenderer tooltipRenderer = runelite.getRenderer().getTooltipRenderer();
|
||||
|
||||
MouseHighlightOverlay(MouseHighlight plugin)
|
||||
{
|
||||
@@ -54,8 +52,6 @@ class MouseHighlightOverlay extends Overlay
|
||||
@Override
|
||||
public Dimension render(Graphics2D graphics)
|
||||
{
|
||||
Client client = RuneLite.getClient();
|
||||
|
||||
if (client.getGameState() != GameState.LOGGED_IN || !config.enabled())
|
||||
{
|
||||
return null;
|
||||
@@ -92,95 +88,9 @@ class MouseHighlightOverlay extends Overlay
|
||||
return null;
|
||||
}
|
||||
|
||||
Matcher m = p.matcher(target);
|
||||
|
||||
List<String> parts = new ArrayList<>();
|
||||
List<String> colours = new ArrayList<>();
|
||||
|
||||
while (m.find())
|
||||
{
|
||||
colours.add(m.group(1));
|
||||
parts.add(m.group(2));
|
||||
}
|
||||
|
||||
if (parts.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Remove colour text from option
|
||||
option = option.replaceAll("<col=([^>]+)>", "");
|
||||
|
||||
Point mouse = client.getMouseCanvasPosition();
|
||||
int x = mouse.getX();
|
||||
int y = mouse.getY();
|
||||
|
||||
FontMetrics fm = graphics.getFontMetrics();
|
||||
// Gets the widths of the various strings we will be displaying
|
||||
int option_width = fm.stringWidth(option + " ");
|
||||
int total_width = option_width;
|
||||
for (String part : parts)
|
||||
{
|
||||
total_width += fm.stringWidth(part);
|
||||
}
|
||||
int height = fm.getHeight();
|
||||
|
||||
if (config.display_left())
|
||||
{
|
||||
x -= total_width + 6; // Draw to the left of the mouse
|
||||
|
||||
// Don't draw off of the screen (left)
|
||||
if (x < 0)
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Don't draw off of the screen (right)
|
||||
int canvas_width = client.getCanvas().getWidth();
|
||||
if (x + total_width + 7 > canvas_width)
|
||||
{
|
||||
x = canvas_width - total_width - 7;
|
||||
}
|
||||
}
|
||||
|
||||
y -= height / 2; // Draw slightly above the mouse
|
||||
|
||||
// Don't draw off of the screen (top)
|
||||
if (y < height / 2)
|
||||
{
|
||||
y = height / 2;
|
||||
}
|
||||
|
||||
Color gray = new Color(Color.darkGray.getRed(), Color.darkGray.getGreen(), Color.darkGray.getBlue(), 190);
|
||||
graphics.setColor(gray);
|
||||
|
||||
// Draws the background rect
|
||||
graphics.fillRect(x, y - (height / 2), total_width + 6, height);
|
||||
|
||||
// Draws the outline of the rect
|
||||
graphics.setColor(config.borderColor());
|
||||
graphics.drawRect(x, y - (height / 2), total_width + 6, height);
|
||||
x += 3;
|
||||
y += 5;
|
||||
|
||||
graphics.setColor(Color.white);
|
||||
// Draws the option (Use, Walk here, Wield)
|
||||
graphics.drawString(option + " ", x, y);
|
||||
// Write text
|
||||
int parts_width = 0;
|
||||
for (int i = 0; i < parts.size(); i++)
|
||||
{
|
||||
// Sets the string colour to the colour the game uses.
|
||||
graphics.setColor(Color.decode("#" + colours.get(i)));
|
||||
// Draws the target (Player, item)
|
||||
graphics.drawString(parts.get(i), x + option_width + parts_width, y);
|
||||
|
||||
parts_width += fm.stringWidth(parts.get(i));
|
||||
}
|
||||
|
||||
graphics.setColor(Color.white);
|
||||
Tooltip tooltip = new Tooltip(TooltipPriority.LOW,
|
||||
option + " " + target);
|
||||
tooltipRenderer.add(tooltip);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -96,4 +96,9 @@ public class RuneImageCache
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getName(int runeId)
|
||||
{
|
||||
return RUNE_NAMES[runeId];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,9 @@ import net.runelite.client.ui.FontManager;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
import net.runelite.client.ui.overlay.OverlayUtil;
|
||||
import net.runelite.client.ui.overlay.tooltips.Tooltip;
|
||||
import net.runelite.client.ui.overlay.tooltips.TooltipPriority;
|
||||
import net.runelite.client.ui.overlay.tooltips.TooltipRenderer;
|
||||
|
||||
public class RunepouchOverlay extends Overlay
|
||||
{
|
||||
@@ -56,6 +59,7 @@ public class RunepouchOverlay extends Overlay
|
||||
|
||||
private final Client client = RuneLite.getClient();
|
||||
private final RuneLite runelite = RuneLite.getRunelite();
|
||||
private final TooltipRenderer toolripRenderer = new TooltipRenderer();
|
||||
private final RuneImageCache runeImageCache = new RuneImageCache();
|
||||
private final RunepouchConfig config;
|
||||
|
||||
@@ -93,10 +97,10 @@ public class RunepouchOverlay extends Overlay
|
||||
|
||||
graphics.setFont(FontManager.getRunescapeSmallFont());
|
||||
|
||||
StringBuilder tooltipBuilder = new StringBuilder();
|
||||
for (int i = 0; i < AMOUNT_VARBITS.length; i++)
|
||||
{
|
||||
Varbits amountVarbit = AMOUNT_VARBITS[i];
|
||||
Varbits runeVarbit = RUNE_VARBITS[i];
|
||||
|
||||
int amount = client.getSetting(amountVarbit);
|
||||
if (amount <= 0)
|
||||
@@ -104,6 +108,9 @@ public class RunepouchOverlay extends Overlay
|
||||
continue;
|
||||
}
|
||||
|
||||
Varbits runeVarbit = RUNE_VARBITS[i];
|
||||
int runeId = client.getSetting(runeVarbit);
|
||||
|
||||
graphics.setColor(Color.black);
|
||||
graphics.drawString("" + formatNumber(amount), location.getX() + (config.showIcons() ? 13 : 1),
|
||||
location.getY() + 14 + graphics.getFontMetrics().getHeight() * i);
|
||||
@@ -112,13 +119,17 @@ public class RunepouchOverlay extends Overlay
|
||||
graphics.drawString("" + formatNumber(amount), location.getX() + (config.showIcons() ? 12 : 0),
|
||||
location.getY() + 13 + graphics.getFontMetrics().getHeight() * i);
|
||||
|
||||
tooltipBuilder
|
||||
.append(amount)
|
||||
.append(" <col=ffff00>")
|
||||
.append(runeImageCache.getName(runeId))
|
||||
.append("</col></br>");
|
||||
|
||||
if (!config.showIcons())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int runeId = client.getSetting(runeVarbit);
|
||||
|
||||
BufferedImage runeImg = runeImageCache.getImage(runeId);
|
||||
if (runeImg != null)
|
||||
{
|
||||
@@ -127,6 +138,13 @@ public class RunepouchOverlay extends Overlay
|
||||
runeImg);
|
||||
}
|
||||
}
|
||||
|
||||
if (runePouch.getCanvasBounds().contains(client.getMouseCanvasPosition().getX(), client.getMouseCanvasPosition().getY()))
|
||||
{
|
||||
String tooltipText = tooltipBuilder.toString();
|
||||
Tooltip tooltip = new Tooltip(TooltipPriority.HIGH, tooltipText);
|
||||
toolripRenderer.add(tooltip);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -280,7 +280,8 @@ public class Slayer extends Plugin
|
||||
|
||||
BufferedImage taskImg = runelite.getItemManager().getImage(itemSpriteId);
|
||||
counter = new TaskCounter(taskImg, amount);
|
||||
counter.setTooltip(capsString(taskName));
|
||||
counter.setTooltip(String.format("<col=ff7700>%s</br><col=ffff00>Pts:</col> %s</br><col=ffff00>Streak:</col> %s",
|
||||
capsString(taskName), points, streak));
|
||||
|
||||
infoBoxManager.addInfoBox(counter);
|
||||
}
|
||||
|
||||
@@ -39,6 +39,9 @@ import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
import net.runelite.client.ui.overlay.OverlayPriority;
|
||||
import net.runelite.client.ui.overlay.tooltips.Tooltip;
|
||||
import net.runelite.client.ui.overlay.tooltips.TooltipPriority;
|
||||
import net.runelite.client.ui.overlay.tooltips.TooltipRenderer;
|
||||
|
||||
public class InfoBoxOverlay extends Overlay
|
||||
{
|
||||
@@ -48,10 +51,12 @@ public class InfoBoxOverlay extends Overlay
|
||||
|
||||
private final RuneLite runelite = RuneLite.getRunelite();
|
||||
private final Client client = RuneLite.getClient();
|
||||
private final TooltipRenderer tooltipRenderer;
|
||||
|
||||
public InfoBoxOverlay()
|
||||
public InfoBoxOverlay(TooltipRenderer tooltipRenderer)
|
||||
{
|
||||
super(OverlayPosition.TOP_LEFT, OverlayPriority.LOW);
|
||||
this.tooltipRenderer = tooltipRenderer;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -114,8 +119,8 @@ public class InfoBoxOverlay extends Overlay
|
||||
continue;
|
||||
}
|
||||
|
||||
String tooltip = box.getTooltip();
|
||||
if (tooltip == null || tooltip.isEmpty())
|
||||
String tooltipText = box.getTooltip();
|
||||
if (tooltipText == null || tooltipText.isEmpty())
|
||||
{
|
||||
x += BOXSIZE + SEPARATOR;
|
||||
continue;
|
||||
@@ -124,26 +129,9 @@ public class InfoBoxOverlay extends Overlay
|
||||
Rectangle infoboxBounds = new Rectangle((int) overlayBounds.getX() + x, (int) overlayBounds.getY(), BOXSIZE, BOXSIZE);
|
||||
if (infoboxBounds.contains(mouseX, mouseY))
|
||||
{
|
||||
int tooltipWidth = metrics.stringWidth(tooltip);
|
||||
int height = metrics.getHeight();
|
||||
|
||||
int tooltipY = mouseY - (int) infoboxBounds.getY();
|
||||
if (tooltipY - height < 0)
|
||||
tooltipY = height;
|
||||
|
||||
Color gray = new Color(Color.darkGray.getRed(), Color.darkGray.getGreen(), Color.darkGray.getBlue(), 190);
|
||||
graphics.setColor(gray);
|
||||
|
||||
// Draws the background rect
|
||||
graphics.fillRect(mouseX, tooltipY - height, tooltipWidth + 6, height);
|
||||
|
||||
// Draws the outline of the rect
|
||||
graphics.setColor(Color.yellow);
|
||||
graphics.drawRect(mouseX, tooltipY - height, tooltipWidth + 6, height);
|
||||
|
||||
// Tooltip text
|
||||
graphics.setColor(Color.WHITE);
|
||||
graphics.drawString(tooltip, mouseX + 3, tooltipY - height / 2 + 5);
|
||||
Tooltip tooltip = new Tooltip(TooltipPriority.HIGH,
|
||||
tooltipText);
|
||||
tooltipRenderer.add(tooltip);
|
||||
}
|
||||
|
||||
x += BOXSIZE + SEPARATOR;
|
||||
|
||||
Reference in New Issue
Block a user