From 2a9d0e09246d1cda1d501ef921926c20989492df Mon Sep 17 00:00:00 2001 From: Ruben Amendoeira Date: Mon, 8 Oct 2018 07:19:38 +0100 Subject: [PATCH] XP Globes - Move progress bar display from tooltip to globe (#5856) This change removes duplicate progress bar from XP globes tooltip and adds new hover effect on each globe that will display percentage to next level. ![](https://i.gyazo.com/f75959e82408b4ff1a64e13ccad62486.png) --- .../plugins/xpglobes/XpGlobesOverlay.java | 63 +++++++++++-------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/xpglobes/XpGlobesOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/xpglobes/XpGlobesOverlay.java index 004ec2b941..391643e592 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/xpglobes/XpGlobesOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/xpglobes/XpGlobesOverlay.java @@ -27,6 +27,7 @@ package net.runelite.client.plugins.xpglobes; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Dimension; +import java.awt.FontMetrics; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.RenderingHints; @@ -45,9 +46,9 @@ import net.runelite.client.plugins.xptracker.XpTrackerService; import net.runelite.client.ui.SkillColor; 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.components.LineComponent; import net.runelite.client.ui.overlay.components.PanelComponent; -import net.runelite.client.ui.overlay.components.ProgressBarComponent; public class XpGlobesOverlay extends Overlay { @@ -56,6 +57,7 @@ public class XpGlobesOverlay extends Overlay private static final int PROGRESS_RADIUS_REMAINDER = 0; private static final int DEFAULT_START_Y = 10; private static final int TOOLTIP_RECT_SIZE_X = 150; + private static final Color DARK_OVERLAY_COLOR = new Color(0, 0, 0, 180); private final Client client; private final XpGlobesPlugin plugin; @@ -108,7 +110,27 @@ public class XpGlobesOverlay extends Overlay Ellipse2D backgroundCircle = drawEllipse(graphics, x, y); - Object renderHint = graphics.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL); + drawSkillImage(graphics, skillToDraw, x, y); + + Point mouse = client.getMouseCanvasPosition(); + int mouseX = mouse.getX() - bounds.x; + int mouseY = mouse.getY() - bounds.y; + + // If mouse is hovering the globe + if (backgroundCircle.contains(mouseX, mouseY)) + { + // Fill a darker overlay circle + graphics.setColor(DARK_OVERLAY_COLOR); + graphics.fill(backgroundCircle); + + drawProgressLabel(graphics, skillToDraw, x, y); + + if (config.enableTooltips()) + { + drawTooltip(graphics, skillToDraw, backgroundCircle); + } + } + graphics.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); drawProgressArc( @@ -126,15 +148,22 @@ public class XpGlobesOverlay extends Overlay PROGRESS_RADIUS_START, radiusCurrentXp, config.progressArcStrokeWidth(), config.enableCustomArcColor() ? config.progressArcColor() : SkillColor.find(skillToDraw.getSkill()).getColor()); + } - graphics.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, renderHint); + private void drawProgressLabel(Graphics2D graphics, XpGlobe globe, int x, int y) + { + final int currentExp = globe.getCurrentXp(); + final int goalExp = globe.getGoalXp(); + final int expForLevel = Experience.getXpForLevel(globe.getCurrentLevel()); - drawSkillImage(graphics, skillToDraw, x, y); + // Convert to int just to limit the decimal cases + String progress = (int) (globe.getSkillProgress(expForLevel, currentExp, goalExp)) + "%"; - if (config.enableTooltips()) - { - drawTooltipIfMouseover(graphics, skillToDraw, backgroundCircle, bounds); - } + final FontMetrics metrics = graphics.getFontMetrics(); + int drawX = x + (config.xpOrbSize() / 2) - (metrics.stringWidth(progress) / 2); + int drawY = y + (config.xpOrbSize() / 2) + (metrics.getHeight() / 2); + + OverlayUtil.renderTextLocation(graphics, new Point(drawX, drawY), progress, Color.WHITE); } private void drawProgressArc(Graphics2D graphics, int x, int y, int w, int h, double radiusStart, double radiusEnd, int strokeWidth, Color color) @@ -176,17 +205,8 @@ public class XpGlobesOverlay extends Overlay ); } - private void drawTooltipIfMouseover(Graphics2D graphics, XpGlobe mouseOverSkill, Ellipse2D drawnGlobe, Rectangle bounds) + private void drawTooltip(Graphics2D graphics, XpGlobe mouseOverSkill, Ellipse2D drawnGlobe) { - Point mouse = client.getMouseCanvasPosition(); - int mouseX = mouse.getX() - bounds.x; - int mouseY = mouse.getY() - bounds.y; - - if (!drawnGlobe.contains(mouseX, mouseY)) - { - return; - } - //draw tooltip under the globe of the mouse location int x = (int) drawnGlobe.getX() - (TOOLTIP_RECT_SIZE_X / 2) + (config.xpOrbSize() / 2); int y = (int) drawnGlobe.getY() + config.xpOrbSize() + 10; @@ -246,13 +266,6 @@ public class XpGlobesOverlay extends Overlay .right(xpHrString) .build()); } - - //Create progress bar for skill. - ProgressBarComponent progressBar = new ProgressBarComponent(); - double progress = mouseOverSkill.getSkillProgress(Experience.getXpForLevel(mouseOverSkill.getCurrentLevel()), - mouseOverSkill.getCurrentXp(), mouseOverSkill.getGoalXp()); - progressBar.setValue(progress); - xpTooltip.getChildren().add(progressBar); } xpTooltip.render(graphics);