Skip to content

Commit

Permalink
Updated XpGlobes to use new Components
Browse files Browse the repository at this point in the history
  • Loading branch information
Noremac201 committed Jan 3, 2018
1 parent 5a65d67 commit aede614
Showing 1 changed file with 28 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.geom.Arc2D;
import java.awt.geom.Ellipse2D;
Expand All @@ -45,6 +44,8 @@
import net.runelite.api.Skill;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.components.PanelComponent;
import net.runelite.client.ui.overlay.components.ProgressBarComponent;

@Slf4j
public class XpGlobesOverlay extends Overlay
Expand All @@ -69,8 +70,6 @@ public class XpGlobesOverlay extends Overlay
private final BufferedImage[] imgCache = new BufferedImage[Skill.values().length - 1];

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
public XpGlobesOverlay(@Nullable Client client, XpGlobesPlugin plugin, XpGlobesConfig config)
Expand Down Expand Up @@ -107,7 +106,7 @@ public Dimension render(Graphics2D graphics, java.awt.Point point)

for (XpGlobe xpGlobe : xpChangedQueue)
{
renderProgressCircle(graphics, xpGlobe, startDrawX, DEFAULT_START_Y);
renderProgressCircle(graphics, point, xpGlobe, startDrawX, DEFAULT_START_Y);
startDrawX += MINIMUM_STEP_WIDTH;
}
plugin.removeExpiredXpGlobes();
Expand All @@ -116,7 +115,7 @@ public Dimension render(Graphics2D graphics, java.awt.Point point)
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 radiusToGoalXp = 360; //draw a circle
Expand All @@ -141,7 +140,7 @@ private void renderProgressCircle(Graphics2D graphics, XpGlobe skillToDraw, int

if (config.enableTooltips())
{
drawTooltipIfMouseover(graphics, skillToDraw, backgroundCircle);
drawTooltipIfMouseover(graphics, parent, skillToDraw, backgroundCircle);
}
}

Expand Down Expand Up @@ -207,7 +206,7 @@ private BufferedImage getSkillImage(XpGlobe xpGlobe)
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();
int mouseX = mouse.getX();
Expand All @@ -221,55 +220,29 @@ private void drawTooltipIfMouseover(Graphics2D graphics, XpGlobe mouseOverSkill,
//draw tooltip under the globe of the mouse location
int x = (int) drawnGlobe.getX() - (TOOLTIP_RECT_SIZE_X / 2) + (DEFAULT_CIRCLE_WIDTH / 2);
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 skillCurrentXp = Integer.toString(mouseOverSkill.getCurrentXp());
String skillXpToLvl = Integer.toString((mouseOverSkill.getGoalXp() - mouseOverSkill.getCurrentXp()));

FontMetrics fm = graphics.getFontMetrics();
int skillLevelX = x + padding + (TOOLTIP_TEXT_RECT_SIZE_X - fm.stringWidth(skillLevel));
int skillCurrentXpX = x + padding + (TOOLTIP_TEXT_RECT_SIZE_X - fm.stringWidth(skillCurrentXp));
int skillXpToLvlX = x + padding + (TOOLTIP_TEXT_RECT_SIZE_X - fm.stringWidth(skillXpToLvl));
int stringHeight = fm.getHeight();

//draw tooltip container
graphics.setPaint(DEFAULT_XPGLOBE_BACKGROUND_COLOR);
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
graphics.setPaint(Color.WHITE);
graphics.drawString(mouseOverSkill.getSkillName(), stringX, y + stringHeight);
graphics.drawString(skillLevel, skillLevelX, y + stringHeight);
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
double progress = mouseOverSkill.getSkillProgress(Experience.getXpForLevel(mouseOverSkill.getCurrentLevel()), mouseOverSkill.getCurrentXp(), mouseOverSkill.getGoalXp());
int barWidth = TOOLTIP_TEXT_RECT_SIZE_X;
int barHeight = 16;
int barX = x + padding;
int barY = y + (stringHeight * 3) + 10;

DecimalFormat df = new DecimalFormat("#.00");
String progressText = df.format(progress) + "%";
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);

DecimalFormat decimalFormat = new DecimalFormat("###,###,###");
String skillCurrentXp = decimalFormat.format(mouseOverSkill.getCurrentXp());
String skillXpToLvl = decimalFormat.format(mouseOverSkill.getGoalXp() - mouseOverSkill.getCurrentXp());

PanelComponent xpTooltip = new PanelComponent();
xpTooltip.setPosition(new java.awt.Point(x, y));

List<PanelComponent.Line> lines = xpTooltip.getLines();
lines.add(new PanelComponent.Line(skillName, Color.WHITE, skillLevel, Color.WHITE));
lines.add(new PanelComponent.Line("Current xp:", Color.ORANGE, skillCurrentXp, Color.WHITE));
lines.add(new PanelComponent.Line("Xp to level: ", Color.ORANGE, skillXpToLvl, Color.WHITE));

//Create progress bar for skill.
ProgressBarComponent progressBar = new ProgressBarComponent();
double progress = mouseOverSkill.getSkillProgress(Experience.getXpForLevel(mouseOverSkill.getCurrentLevel()),
mouseOverSkill.getCurrentXp(), mouseOverSkill.getGoalXp());
progressBar.setProgress(progress);

xpTooltip.setProgressBar(progressBar);
xpTooltip.render(graphics, parent);
}
}

0 comments on commit aede614

Please sign in to comment.