xp globes: add dynamic skill icon sizing

Co-authored-by: Yumleg <jamesz96.au@gmail.com>
Co-authored-by: Jordan Atwood <jordan.atwood423@gmail.com>
This commit is contained in:
Adam
2021-03-21 13:23:51 -04:00
committed by Adam
parent 63992dc27e
commit e7f50433a3
2 changed files with 47 additions and 5 deletions

View File

@@ -24,19 +24,28 @@
*/
package net.runelite.client.plugins.xpglobes;
import java.awt.image.BufferedImage;
import java.time.Instant;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import net.runelite.api.Skill;
@Getter
@Setter
@AllArgsConstructor
class XpGlobe
{
private Skill skill;
private int currentXp;
private int currentLevel;
private Instant time;
private int size;
private BufferedImage skillIcon;
XpGlobe(Skill skill, int currentXp, int currentLevel, Instant time)
{
this.skill = skill;
this.currentXp = currentXp;
this.currentLevel = currentLevel;
this.time = time;
}
}

View File

@@ -56,6 +56,7 @@ import net.runelite.client.ui.overlay.components.LineComponent;
import net.runelite.client.ui.overlay.components.PanelComponent;
import net.runelite.client.ui.overlay.tooltip.Tooltip;
import net.runelite.client.ui.overlay.tooltip.TooltipManager;
import net.runelite.client.util.ImageUtil;
public class XpGlobesOverlay extends Overlay
{
@@ -65,6 +66,7 @@ public class XpGlobesOverlay extends Overlay
private static final int TOOLTIP_RECT_SIZE_X = 150;
private static final Color DARK_OVERLAY_COLOR = new Color(0, 0, 0, 180);
static final String FLIP_ACTION = "Flip";
private static final double GLOBE_ICON_RATIO = 0.65;
private final Client client;
private final XpGlobesPlugin plugin;
@@ -235,7 +237,8 @@ public class XpGlobesOverlay extends Overlay
private void drawSkillImage(Graphics2D graphics, XpGlobe xpGlobe, int x, int y)
{
BufferedImage skillImage = iconManager.getSkillImage(xpGlobe.getSkill());
final int orbSize = config.xpOrbSize();
final BufferedImage skillImage = getScaledSkillIcon(xpGlobe, orbSize);
if (skillImage == null)
{
@@ -244,12 +247,42 @@ public class XpGlobesOverlay extends Overlay
graphics.drawImage(
skillImage,
x + (config.xpOrbSize() / 2) - (skillImage.getWidth() / 2),
y + (config.xpOrbSize() / 2) - (skillImage.getHeight() / 2),
x + (orbSize / 2) - (skillImage.getWidth() / 2),
y + (orbSize / 2) - (skillImage.getHeight() / 2),
null
);
}
private BufferedImage getScaledSkillIcon(XpGlobe xpGlobe, int orbSize)
{
// Cache the previous icon if the size hasn't changed
if (xpGlobe.getSkillIcon() != null && xpGlobe.getSize() == orbSize)
{
return xpGlobe.getSkillIcon();
}
BufferedImage icon = iconManager.getSkillImage(xpGlobe.getSkill());
if (icon == null)
{
return null;
}
final int size = orbSize - config.progressArcStrokeWidth();
final int width = (int) (size * GLOBE_ICON_RATIO);
final int height = (int) (size * GLOBE_ICON_RATIO);
if (width <= 0 || height <= 0)
{
return null;
}
icon = ImageUtil.resizeImage(icon, width, height);
xpGlobe.setSkillIcon(icon);
xpGlobe.setSize(orbSize);
return icon;
}
private void drawTooltip(XpGlobe mouseOverSkill, int goalXp)
{
// reset the timer on XpGlobe to prevent it from disappearing while hovered over it