Add support for making XP globes moveable

Add support for integration of XP globes with DETACHED overlay system,
e.g making them moveable.

Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
Tomas Slusny
2018-07-23 11:02:51 +02:00
parent 25ab36d56e
commit 30292b8f52

View File

@@ -28,6 +28,7 @@ import java.awt.BasicStroke;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints; import java.awt.RenderingHints;
import java.awt.Stroke; import java.awt.Stroke;
import java.awt.geom.Arc2D; import java.awt.geom.Arc2D;
@@ -35,7 +36,6 @@ import java.awt.geom.Ellipse2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.time.Instant; import java.time.Instant;
import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client; import net.runelite.api.Client;
@@ -54,84 +54,109 @@ import net.runelite.client.ui.overlay.components.ProgressBarComponent;
@Slf4j @Slf4j
public class XpGlobesOverlay extends Overlay public class XpGlobesOverlay extends Overlay
{ {
private static final int MINIMUM_STEP = 10;
private static final int PROGRESS_RADIUS_START = 90;
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 final Client client; private final Client client;
private final XpGlobesPlugin plugin; private final XpGlobesPlugin plugin;
private final XpGlobesConfig config; private final XpGlobesConfig config;
private final XpTrackerService xpTrackerService; private final XpTrackerService xpTrackerService;
private final PanelComponent xpTooltip = new PanelComponent(); private final PanelComponent xpTooltip = new PanelComponent();
private final SkillIconManager iconManager;
@Inject @Inject
private SkillIconManager iconManager; private XpGlobesOverlay(
Client client,
private static final int MINIMUM_STEP = 10; XpGlobesPlugin plugin,
XpGlobesConfig config,
private static final int PROGRESS_RADIUS_START = 90; XpTrackerService xpTrackerService,
private static final int PROGRESS_RADIUS_REMAINDER = 0; SkillIconManager iconManager)
private static final int DEFAULT_START_Y = 10;
private static final int TOOLTIP_RECT_SIZE_X = 150;
@Inject
public XpGlobesOverlay(Client client, XpGlobesPlugin plugin, XpGlobesConfig config, XpTrackerService xpTrackerService)
{ {
setPosition(OverlayPosition.DYNAMIC); this.iconManager = iconManager;
setPriority(OverlayPriority.HIGH);
this.client = client; this.client = client;
this.plugin = plugin; this.plugin = plugin;
this.config = config; this.config = config;
this.xpTrackerService = xpTrackerService; this.xpTrackerService = xpTrackerService;
setPosition(OverlayPosition.DETACHED);
setPriority(OverlayPriority.HIGH);
}
@Override
public Rectangle getBounds()
{
//if this is null there is no reason to draw e.g. switching between resizable and fixed
final Widget viewportWidget = client.getViewportWidget();
if (viewportWidget == null)
{
return new Rectangle();
}
final int queueSize = plugin.getXpGlobesSize();
if (queueSize == 0)
{
return new Rectangle();
}
// Get width of markers
final int markersLength = (queueSize * (config.xpOrbSize())) + ((MINIMUM_STEP) * (queueSize - 1));
final int startDrawX;
final int startDrawY;
if (getPreferredLocation() == null)
{
//check the width of the client if we can draw properly
final int clientWidth;
switch (config.centerOrbs())
{
case MIDDLE_CANVAS:
clientWidth = client.getViewportWidth();
break;
case MIDDLE_VIEWPORT:
clientWidth = viewportWidget.getWidth();
break;
case DYNAMIC:
clientWidth = (viewportWidget.getWidth() + client.getViewportWidth()) / 2;
break;
default:
clientWidth = client.getViewportWidth();
break;
}
startDrawX = clientWidth / 2 - markersLength / 2;
startDrawY = DEFAULT_START_Y;
}
else
{
startDrawX = getPreferredLocation().x;
startDrawY = getPreferredLocation().y;
}
return new Rectangle(startDrawX, startDrawY, markersLength, config.xpOrbSize());
} }
@Override @Override
public Dimension render(Graphics2D graphics) public Dimension render(Graphics2D graphics)
{ {
//if this is null there is no reason to draw e.g. switching between resizable and fixed final Rectangle bounds = getBounds();
Widget viewportWidget = client.getViewportWidget(); if (bounds.isEmpty())
if (viewportWidget == null)
{ {
return null; return null;
} }
//check the width of the client if we can draw properly int curDrawX = 0;
int clientWidth; for (final XpGlobe xpGlobe : plugin.getXpGlobes())
switch (config.centerOrbs())
{ {
case MIDDLE_CANVAS: renderProgressCircle(graphics, xpGlobe, curDrawX, 0, bounds);
clientWidth = client.getViewportWidth(); curDrawX += MINIMUM_STEP + config.xpOrbSize();
break;
case MIDDLE_VIEWPORT:
clientWidth = viewportWidget.getWidth();
break;
case DYNAMIC:
clientWidth = (viewportWidget.getWidth() + client.getViewportWidth()) / 2;
break;
default:
clientWidth = client.getViewportWidth();
break;
}
if (clientWidth <= 0)
{
return null;
}
int queueSize = plugin.getXpGlobesSize();
if (queueSize > 0)
{
List<XpGlobe> xpChangedQueue = plugin.getXpGlobes();
int markersLength = (queueSize * (config.xpOrbSize())) + ((MINIMUM_STEP) * (queueSize - 1));
int startDrawX = (clientWidth - markersLength) / 2;
for (XpGlobe xpGlobe : xpChangedQueue)
{
renderProgressCircle(graphics, xpGlobe, startDrawX, DEFAULT_START_Y);
startDrawX += MINIMUM_STEP + config.xpOrbSize();
}
} }
return null; return bounds.getSize();
} }
private void renderProgressCircle(Graphics2D graphics, XpGlobe skillToDraw, int x, int y)
private void renderProgressCircle(Graphics2D graphics, XpGlobe skillToDraw, int x, int y, Rectangle bounds)
{ {
double radiusCurrentXp = skillToDraw.getSkillProgressRadius(); double radiusCurrentXp = skillToDraw.getSkillProgressRadius();
double radiusToGoalXp = 360; //draw a circle double radiusToGoalXp = 360; //draw a circle
@@ -163,7 +188,7 @@ public class XpGlobesOverlay extends Overlay
if (config.enableTooltips()) if (config.enableTooltips())
{ {
drawTooltipIfMouseover(graphics, skillToDraw, backgroundCircle); drawTooltipIfMouseover(graphics, skillToDraw, backgroundCircle, bounds);
} }
} }
@@ -206,11 +231,11 @@ public class XpGlobesOverlay extends Overlay
); );
} }
private void drawTooltipIfMouseover(Graphics2D graphics, XpGlobe mouseOverSkill, Ellipse2D drawnGlobe) private void drawTooltipIfMouseover(Graphics2D graphics, XpGlobe mouseOverSkill, Ellipse2D drawnGlobe, Rectangle bounds)
{ {
Point mouse = client.getMouseCanvasPosition(); Point mouse = client.getMouseCanvasPosition();
int mouseX = mouse.getX(); int mouseX = mouse.getX() - bounds.x;
int mouseY = mouse.getY(); int mouseY = mouse.getY() - bounds.y;
if (!drawnGlobe.contains(mouseX, mouseY)) if (!drawnGlobe.contains(mouseX, mouseY))
{ {