Updated XpGlobes to use new Components

This commit is contained in:
noremac201
2018-01-03 15:42:54 -06:00
parent 4a2ba1c6fe
commit 13de888d6c

View File

@@ -27,7 +27,6 @@ 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.geom.Arc2D; import java.awt.geom.Arc2D;
import java.awt.geom.Ellipse2D; import java.awt.geom.Ellipse2D;
@@ -45,6 +44,8 @@ import net.runelite.api.Point;
import net.runelite.api.Skill; import net.runelite.api.Skill;
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.components.PanelComponent;
import net.runelite.client.ui.overlay.components.ProgressBarComponent;
@Slf4j @Slf4j
public class XpGlobesOverlay extends Overlay public class XpGlobesOverlay extends Overlay
@@ -69,8 +70,6 @@ public class XpGlobesOverlay extends Overlay
private final BufferedImage[] imgCache = new BufferedImage[Skill.values().length - 1]; private final BufferedImage[] imgCache = new BufferedImage[Skill.values().length - 1];
private static final int TOOLTIP_RECT_SIZE_X = 140; private static final int TOOLTIP_RECT_SIZE_X = 140;
private static final int TOOLTIP_TEXT_RECT_SIZE_X = TOOLTIP_RECT_SIZE_X - 10;
private static final int TOOLTIP_RECT_SIZE_Y = 80;
@Inject @Inject
public XpGlobesOverlay(@Nullable Client client, XpGlobesPlugin plugin, XpGlobesConfig config) public XpGlobesOverlay(@Nullable Client client, XpGlobesPlugin plugin, XpGlobesConfig config)
@@ -107,7 +106,7 @@ public class XpGlobesOverlay extends Overlay
for (XpGlobe xpGlobe : xpChangedQueue) for (XpGlobe xpGlobe : xpChangedQueue)
{ {
renderProgressCircle(graphics, xpGlobe, startDrawX, DEFAULT_START_Y); renderProgressCircle(graphics, point, xpGlobe, startDrawX, DEFAULT_START_Y);
startDrawX += MINIMUM_STEP_WIDTH; startDrawX += MINIMUM_STEP_WIDTH;
} }
plugin.removeExpiredXpGlobes(); plugin.removeExpiredXpGlobes();
@@ -116,7 +115,7 @@ public class XpGlobesOverlay extends Overlay
return null; return null;
} }
private void renderProgressCircle(Graphics2D graphics, XpGlobe skillToDraw, int x, int y) private void renderProgressCircle(Graphics2D graphics, java.awt.Point parent, XpGlobe skillToDraw, int x, int y)
{ {
double radiusCurrentXp = skillToDraw.getSkillProgressRadius(); double radiusCurrentXp = skillToDraw.getSkillProgressRadius();
double radiusToGoalXp = 360; //draw a circle double radiusToGoalXp = 360; //draw a circle
@@ -141,7 +140,7 @@ public class XpGlobesOverlay extends Overlay
if (config.enableTooltips()) if (config.enableTooltips())
{ {
drawTooltipIfMouseover(graphics, skillToDraw, backgroundCircle); drawTooltipIfMouseover(graphics, parent, skillToDraw, backgroundCircle);
} }
} }
@@ -207,7 +206,7 @@ public class XpGlobesOverlay extends Overlay
return skillImage; return skillImage;
} }
private void drawTooltipIfMouseover(Graphics2D graphics, XpGlobe mouseOverSkill, Ellipse2D drawnGlobe) private void drawTooltipIfMouseover(Graphics2D graphics, java.awt.Point parent, XpGlobe mouseOverSkill, Ellipse2D drawnGlobe)
{ {
Point mouse = client.getMouseCanvasPosition(); Point mouse = client.getMouseCanvasPosition();
int mouseX = mouse.getX(); int mouseX = mouse.getX();
@@ -221,55 +220,29 @@ public class XpGlobesOverlay extends Overlay
//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) + (DEFAULT_CIRCLE_WIDTH / 2); int x = (int) drawnGlobe.getX() - (TOOLTIP_RECT_SIZE_X / 2) + (DEFAULT_CIRCLE_WIDTH / 2);
int y = (int) drawnGlobe.getY() + DEFAULT_CIRCLE_HEIGHT + 10; int y = (int) drawnGlobe.getY() + DEFAULT_CIRCLE_HEIGHT + 10;
int padding = (TOOLTIP_RECT_SIZE_X - TOOLTIP_TEXT_RECT_SIZE_X) / 2;
int stringX = x + padding;
String skillName = mouseOverSkill.getSkillName();
String skillLevel = Integer.toString(mouseOverSkill.getCurrentLevel()); String skillLevel = Integer.toString(mouseOverSkill.getCurrentLevel());
String skillCurrentXp = Integer.toString(mouseOverSkill.getCurrentXp());
String skillXpToLvl = Integer.toString((mouseOverSkill.getGoalXp() - mouseOverSkill.getCurrentXp()));
FontMetrics fm = graphics.getFontMetrics(); DecimalFormat decimalFormat = new DecimalFormat("###,###,###");
int skillLevelX = x + padding + (TOOLTIP_TEXT_RECT_SIZE_X - fm.stringWidth(skillLevel)); String skillCurrentXp = decimalFormat.format(mouseOverSkill.getCurrentXp());
int skillCurrentXpX = x + padding + (TOOLTIP_TEXT_RECT_SIZE_X - fm.stringWidth(skillCurrentXp)); String skillXpToLvl = decimalFormat.format(mouseOverSkill.getGoalXp() - mouseOverSkill.getCurrentXp());
int skillXpToLvlX = x + padding + (TOOLTIP_TEXT_RECT_SIZE_X - fm.stringWidth(skillXpToLvl));
int stringHeight = fm.getHeight();
//draw tooltip container PanelComponent xpTooltip = new PanelComponent();
graphics.setPaint(DEFAULT_XPGLOBE_BACKGROUND_COLOR); xpTooltip.setPosition(new java.awt.Point(x, y));
graphics.fillRect(x, y, TOOLTIP_RECT_SIZE_X, TOOLTIP_RECT_SIZE_Y);
graphics.setPaint(DEFAULT_PROGRESS_REMAINDER_ARC_COLOR);
graphics.setStroke(new BasicStroke(2));
graphics.drawRect(x, y, TOOLTIP_RECT_SIZE_X, TOOLTIP_RECT_SIZE_Y);
//draw the text List<PanelComponent.Line> lines = xpTooltip.getLines();
graphics.setPaint(Color.WHITE); lines.add(new PanelComponent.Line(skillName, Color.WHITE, skillLevel, Color.WHITE));
graphics.drawString(mouseOverSkill.getSkillName(), stringX, y + stringHeight); lines.add(new PanelComponent.Line("Current xp:", Color.ORANGE, skillCurrentXp, Color.WHITE));
graphics.drawString(skillLevel, skillLevelX, y + stringHeight); lines.add(new PanelComponent.Line("Xp to level: ", Color.ORANGE, skillXpToLvl, Color.WHITE));
graphics.drawString("Current exp:", stringX, y + (stringHeight * 2));
graphics.drawString(skillCurrentXp, skillCurrentXpX, y + (stringHeight * 2));
graphics.drawString("Exp to level:", stringX, y + (stringHeight * 3));
graphics.drawString(skillXpToLvl, skillXpToLvlX, y + (stringHeight * 3));
//draw the progress bar //Create progress bar for skill.
double progress = mouseOverSkill.getSkillProgress(Experience.getXpForLevel(mouseOverSkill.getCurrentLevel()), mouseOverSkill.getCurrentXp(), mouseOverSkill.getGoalXp()); ProgressBarComponent progressBar = new ProgressBarComponent();
int barWidth = TOOLTIP_TEXT_RECT_SIZE_X; double progress = mouseOverSkill.getSkillProgress(Experience.getXpForLevel(mouseOverSkill.getCurrentLevel()),
int barHeight = 16; mouseOverSkill.getCurrentXp(), mouseOverSkill.getGoalXp());
int barX = x + padding; progressBar.setProgress(progress);
int barY = y + (stringHeight * 3) + 10;
DecimalFormat df = new DecimalFormat("#.00"); xpTooltip.setProgressBar(progressBar);
String progressText = df.format(progress) + "%"; xpTooltip.render(graphics, parent);
int progressTextLength = fm.stringWidth(progressText);
int progressTextX = barX + (barWidth / 2) - (progressTextLength / 2);
int progressTextY = barY + 12;
int progressFill = (int) ((barWidth / 100F) * progress);
graphics.setColor(Color.WHITE);
graphics.fillRect(barX, barY, barWidth, barHeight);
graphics.setColor(Color.GREEN);
graphics.fillRect(barX, barY, progressFill, barHeight);
graphics.setPaint(Color.BLACK);
graphics.drawString(progressText, progressTextX, progressTextY);
} }
} }