From 0fd85d65e5e09c46162fff864d7a0f5b3b68ad87 Mon Sep 17 00:00:00 2001 From: Tyler Hardy Date: Thu, 9 Nov 2017 21:04:03 -0500 Subject: [PATCH 1/3] runelite-client: add tooltip system --- .../client/ui/overlay/OverlayRenderer.java | 13 +- .../client/ui/overlay/tooltips/Tooltip.java | 47 +++++ .../ui/overlay/tooltips/TooltipPriority.java | 32 ++++ .../ui/overlay/tooltips/TooltipRenderer.java | 176 ++++++++++++++++++ 4 files changed, 266 insertions(+), 2 deletions(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/ui/overlay/tooltips/Tooltip.java create mode 100644 runelite-client/src/main/java/net/runelite/client/ui/overlay/tooltips/TooltipPriority.java create mode 100644 runelite-client/src/main/java/net/runelite/client/ui/overlay/tooltips/TooltipRenderer.java diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayRenderer.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayRenderer.java index f5bdbce3a0..b9de6813be 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayRenderer.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayRenderer.java @@ -28,17 +28,18 @@ import java.awt.image.BufferedImage; import net.runelite.client.RuneLite; import net.runelite.client.plugins.Plugin; import net.runelite.client.ui.overlay.infobox.InfoBoxOverlay; +import net.runelite.client.ui.overlay.tooltips.TooltipRenderer; public class OverlayRenderer { - private final InfoBoxOverlay infoBoxOverlay = new InfoBoxOverlay(); + private final TooltipRenderer tooltipRenderer = new TooltipRenderer(); + private final InfoBoxOverlay infoBoxOverlay = new InfoBoxOverlay(tooltipRenderer); public void render(BufferedImage clientBuffer) { TopDownRendererLeft tdl = new TopDownRendererLeft(); TopDownRendererRight tdr = new TopDownRendererRight(); DynamicRenderer dr = new DynamicRenderer(); - for (Plugin plugin : RuneLite.getRunelite().getPluginManager().getPlugins()) { for (Overlay overlay : plugin.getOverlays()) @@ -63,5 +64,13 @@ public class OverlayRenderer tdl.render(clientBuffer); tdr.render(clientBuffer); dr.render(clientBuffer); + + // tooltips are always rendered on top of other overlays + tooltipRenderer.render(clientBuffer); + } + + public TooltipRenderer getTooltipRenderer() + { + return tooltipRenderer; } } diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/tooltips/Tooltip.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/tooltips/Tooltip.java new file mode 100644 index 0000000000..459a700db4 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/tooltips/Tooltip.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2017, Tyler + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.ui.overlay.tooltips; + +public class Tooltip +{ + private final TooltipPriority priority; // if multiple overlays exist in the same position, who wins + private final String tooltipText; + + public Tooltip(TooltipPriority priority, String tooltipText) + { + this.priority = priority; + this.tooltipText = tooltipText; + } + + public TooltipPriority getPriority() + { + return priority; + } + + public String getText() + { + return tooltipText; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/tooltips/TooltipPriority.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/tooltips/TooltipPriority.java new file mode 100644 index 0000000000..f63e4ceac0 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/tooltips/TooltipPriority.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2017, Tyler + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.ui.overlay.tooltips; + +public enum TooltipPriority +{ + LOW, + MED, + HIGH; +} diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/tooltips/TooltipRenderer.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/tooltips/TooltipRenderer.java new file mode 100644 index 0000000000..157a62bc60 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/tooltips/TooltipRenderer.java @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2017, Tyler + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.ui.overlay.tooltips; + +import java.awt.Color; +import java.awt.FontMetrics; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import net.runelite.api.Client; +import net.runelite.api.Point; +import net.runelite.client.RuneLite; +import net.runelite.client.config.RuneliteConfig; +import net.runelite.client.ui.overlay.Renderer; + +public class TooltipRenderer implements Renderer +{ + private static final Pattern COLOR_SPLIT = Pattern.compile("<\\/?col=?([^>]+)?>"); + private static final Pattern BR = Pattern.compile("
"); + + private static final int BORDER_SIZE = 2; + private static final int JSWING_BORDER_RIGHT = 5; + private static final Color BACKGROUND_COLOR = new Color(Color.gray.getRed(), Color.gray.getGreen(), Color.gray.getBlue(), 150); + private static final Color BORDER_COLOR = Color.black; + private static final Color FONT_COLOR = Color.white; + + private final Client client = RuneLite.getClient(); + private final RuneliteConfig config = RuneLite.getRunelite().getConfig(); + + private Tooltip tooltip; + + @Override + public void render(BufferedImage clientBuffer) + { + Point mousePos = client.getMouseCanvasPosition(); + Graphics2D graphics = clientBuffer.createGraphics(); + Renderer.setAntiAliasing(graphics); + drawTooltip(graphics, mousePos.getX(), mousePos.getY()); + graphics.dispose(); + + this.tooltip = null; + } + + public void add(Tooltip tooltip) + { + if (this.tooltip != null && tooltip.getPriority().compareTo(this.tooltip.getPriority()) < 0) + { + return; + } + + this.tooltip = tooltip; + } + + private void drawTooltip(Graphics2D graphics, int x, int y) + { + if (tooltip == null || tooltip.getText() == null || tooltip.getText().isEmpty()) + { + return; + } + + FontMetrics metrics = graphics.getFontMetrics(); + String tooltipText = tooltip.getText(); + int tooltipWidth = 0; + int tooltipHeight = 0; + int textHeight = metrics.getHeight(); + int textDescent = metrics.getDescent(); + + // Tooltip size + String[] lines = BR.split(tooltipText); + for (String line : lines) + { + String lineClean = COLOR_SPLIT.matcher(line).replaceAll(""); + int textWidth = metrics.stringWidth(lineClean); + if (textWidth > tooltipWidth) + { + tooltipWidth = textWidth; + } + + tooltipHeight += textHeight; + } + + // Position tooltip + if (config.tooltipLeft()) + { + x = x - tooltipWidth; + if (x < 0) + { + x = 0; + } + } + else + { + int clientWidth = client.getCanvas().getWidth(); + if (x + tooltipWidth + JSWING_BORDER_RIGHT > clientWidth) + { + x = clientWidth - tooltipWidth - JSWING_BORDER_RIGHT; + } + } + + y = y - tooltipHeight; + if (y < 0) + { + y = 0; + } + + // Render tooltip - background + graphics.setColor(BACKGROUND_COLOR); + graphics.fillRect(x, y, tooltipWidth + BORDER_SIZE * 2, tooltipHeight); + graphics.setColor(BORDER_COLOR); + graphics.drawRect(x, y, tooltipWidth + BORDER_SIZE * 2, tooltipHeight); + graphics.setColor(FONT_COLOR); + + // Render tooltip - text - line by line + int lineX; + Color nextColor = Color.WHITE; + for (int i = 0; i < lines.length; i++) + { + lineX = x; + String line = lines[i]; + Matcher m = COLOR_SPLIT.matcher(line); + + int begin = 0; + while (m.find()) + { + // Draw text prior to color tag + String preText = line.substring(begin, m.start()); + graphics.setColor(Color.BLACK); + graphics.drawString(preText, lineX + BORDER_SIZE + 1, y + (i + 1) * textHeight - textDescent + 1); // shadow + graphics.setColor(nextColor); + graphics.drawString(preText, lineX + BORDER_SIZE, y + (i + 1) * textHeight - textDescent); // text + + // Set color for next text part + if (m.group(1) == null) + { + // no color tag + nextColor = Color.WHITE; + } + else + { + // color tag + nextColor = Color.decode("#" + m.group(1)); + } + begin = m.end(); + lineX += metrics.stringWidth(preText); + } + // Draw trailing text (after last tag) + graphics.setColor(Color.BLACK); + graphics.drawString(line.substring(begin, line.length()), lineX + BORDER_SIZE + 1, y + (i + 1) * textHeight - textDescent + 1); + graphics.setColor(nextColor); + graphics.drawString(line.substring(begin, line.length()), lineX + BORDER_SIZE, y + (i + 1) * textHeight - textDescent); + } + } +} From 89f0b59945e7d373621259e0f97c515929d758d5 Mon Sep 17 00:00:00 2001 From: Tyler Hardy Date: Thu, 9 Nov 2017 21:04:40 -0500 Subject: [PATCH 2/3] runelite-client: add runelite config with tooltip config --- .../java/net/runelite/client/RuneLite.java | 13 +++++- .../client/config/RuneliteConfig.java | 43 +++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/config/RuneliteConfig.java diff --git a/runelite-client/src/main/java/net/runelite/client/RuneLite.java b/runelite-client/src/main/java/net/runelite/client/RuneLite.java index d5cc92b3f4..1150027870 100644 --- a/runelite-client/src/main/java/net/runelite/client/RuneLite.java +++ b/runelite-client/src/main/java/net/runelite/client/RuneLite.java @@ -55,6 +55,7 @@ import net.runelite.api.Client; import net.runelite.api.Query; import net.runelite.client.account.AccountSession; import net.runelite.client.config.ConfigManager; +import net.runelite.client.config.RuneliteConfig; import net.runelite.client.events.SessionClose; import net.runelite.client.events.SessionOpen; import net.runelite.client.game.ItemManager; @@ -86,6 +87,7 @@ public class RuneLite private final RuneliteProperties properties = new RuneliteProperties(); private ClientUI gui; + private RuneliteConfig config; private PluginManager pluginManager; private final MenuManager menuManager = new MenuManager(this); private OverlayRenderer renderer; @@ -152,8 +154,12 @@ public class RuneLite configManager.load(); + config = configManager.getConfig(RuneliteConfig.class); + eventBus.register(menuManager); + renderer = new OverlayRenderer(); + // Load the plugins, but does not start them yet. // This will initialize configuration pluginManager = new PluginManager(this); @@ -166,8 +172,6 @@ public class RuneLite // Start plugins pluginManager.start(); - renderer = new OverlayRenderer(); - loadSession(); } @@ -425,6 +429,11 @@ public class RuneLite return configManager; } + public RuneliteConfig getConfig() + { + return config; + } + public ItemManager getItemManager() { return itemManager; diff --git a/runelite-client/src/main/java/net/runelite/client/config/RuneliteConfig.java b/runelite-client/src/main/java/net/runelite/client/config/RuneliteConfig.java new file mode 100644 index 0000000000..df75212c40 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/config/RuneliteConfig.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017, Tyler + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.config; + +@ConfigGroup( + keyName = "runelite", + name = "Runelite", + description = "Configuration for Runelite client options" +) +public interface RuneliteConfig +{ + @ConfigItem( + keyName = "tooltipLeft", + name = "Tooltip left of mouse?", + description = "Places the tooltip on the left side of the mouse" + ) + default boolean tooltipLeft() + { + return false; + } +} From 1fdbdf08f86b6ea26793375302846a52790eb5d0 Mon Sep 17 00:00:00 2001 From: Tyler Hardy Date: Thu, 9 Nov 2017 21:05:18 -0500 Subject: [PATCH 3/3] runelite-client: Use tooltip system for plugins and infoboxes --- .../mousehighlight/MouseHighlightOverlay.java | 108 ++---------------- .../plugins/runepouch/RuneImageCache.java | 5 + .../plugins/runepouch/RunepouchOverlay.java | 24 +++- .../client/plugins/slayer/Slayer.java | 3 +- .../ui/overlay/infobox/InfoBoxOverlay.java | 34 ++---- 5 files changed, 48 insertions(+), 126 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/mousehighlight/MouseHighlightOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/mousehighlight/MouseHighlightOverlay.java index aaa220c0ca..43bd0abc4e 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/mousehighlight/MouseHighlightOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/mousehighlight/MouseHighlightOverlay.java @@ -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 // Player1 - private final Pattern p = Pattern.compile("]+)>([^<]*)"); 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 parts = new ArrayList<>(); - List 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("]+)>", ""); - - 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; } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/runepouch/RuneImageCache.java b/runelite-client/src/main/java/net/runelite/client/plugins/runepouch/RuneImageCache.java index d36a66af4f..6097ed2873 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/runepouch/RuneImageCache.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/runepouch/RuneImageCache.java @@ -96,4 +96,9 @@ public class RuneImageCache return null; } } + + public String getName(int runeId) + { + return RUNE_NAMES[runeId]; + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/runepouch/RunepouchOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/runepouch/RunepouchOverlay.java index f335ef7abf..52493d2363 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/runepouch/RunepouchOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/runepouch/RunepouchOverlay.java @@ -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(" ") + .append(runeImageCache.getName(runeId)) + .append("
"); + 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; } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/slayer/Slayer.java b/runelite-client/src/main/java/net/runelite/client/plugins/slayer/Slayer.java index fbbfbc6c81..9a6e0043cf 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/slayer/Slayer.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/slayer/Slayer.java @@ -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("%s
Pts: %s
Streak: %s", + capsString(taskName), points, streak)); infoBoxManager.addInfoBox(counter); } diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/infobox/InfoBoxOverlay.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/infobox/InfoBoxOverlay.java index 0457a61813..cd1e5e9ec0 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/infobox/InfoBoxOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/infobox/InfoBoxOverlay.java @@ -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;