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. 
This commit is contained in:
committed by
Tomas Slusny
parent
7ce518f29b
commit
2a9d0e0924
@@ -27,6 +27,7 @@ package net.runelite.client.plugins.xpglobes;
|
|||||||
import java.awt.BasicStroke;
|
import java.awt.BasicStroke;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
import java.awt.FontMetrics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.RenderingHints;
|
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.SkillColor;
|
||||||
import net.runelite.client.ui.overlay.Overlay;
|
import net.runelite.client.ui.overlay.Overlay;
|
||||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
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.LineComponent;
|
||||||
import net.runelite.client.ui.overlay.components.PanelComponent;
|
import net.runelite.client.ui.overlay.components.PanelComponent;
|
||||||
import net.runelite.client.ui.overlay.components.ProgressBarComponent;
|
|
||||||
|
|
||||||
public class XpGlobesOverlay extends Overlay
|
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 PROGRESS_RADIUS_REMAINDER = 0;
|
||||||
private static final int DEFAULT_START_Y = 10;
|
private static final int DEFAULT_START_Y = 10;
|
||||||
private static final int TOOLTIP_RECT_SIZE_X = 150;
|
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 Client client;
|
||||||
private final XpGlobesPlugin plugin;
|
private final XpGlobesPlugin plugin;
|
||||||
@@ -108,7 +110,27 @@ public class XpGlobesOverlay extends Overlay
|
|||||||
|
|
||||||
Ellipse2D backgroundCircle = drawEllipse(graphics, x, y);
|
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);
|
graphics.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
|
||||||
|
|
||||||
drawProgressArc(
|
drawProgressArc(
|
||||||
@@ -126,15 +148,22 @@ public class XpGlobesOverlay extends Overlay
|
|||||||
PROGRESS_RADIUS_START, radiusCurrentXp,
|
PROGRESS_RADIUS_START, radiusCurrentXp,
|
||||||
config.progressArcStrokeWidth(),
|
config.progressArcStrokeWidth(),
|
||||||
config.enableCustomArcColor() ? config.progressArcColor() : SkillColor.find(skillToDraw.getSkill()).getColor());
|
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())
|
final FontMetrics metrics = graphics.getFontMetrics();
|
||||||
{
|
int drawX = x + (config.xpOrbSize() / 2) - (metrics.stringWidth(progress) / 2);
|
||||||
drawTooltipIfMouseover(graphics, skillToDraw, backgroundCircle, bounds);
|
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)
|
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
|
//draw tooltip under the globe of the mouse location
|
||||||
int x = (int) drawnGlobe.getX() - (TOOLTIP_RECT_SIZE_X / 2) + (config.xpOrbSize() / 2);
|
int x = (int) drawnGlobe.getX() - (TOOLTIP_RECT_SIZE_X / 2) + (config.xpOrbSize() / 2);
|
||||||
int y = (int) drawnGlobe.getY() + config.xpOrbSize() + 10;
|
int y = (int) drawnGlobe.getY() + config.xpOrbSize() + 10;
|
||||||
@@ -246,13 +266,6 @@ public class XpGlobesOverlay extends Overlay
|
|||||||
.right(xpHrString)
|
.right(xpHrString)
|
||||||
.build());
|
.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);
|
xpTooltip.render(graphics);
|
||||||
|
|||||||
Reference in New Issue
Block a user