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:
@@ -24,19 +24,28 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.xpglobes;
|
package net.runelite.client.plugins.xpglobes;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import net.runelite.api.Skill;
|
import net.runelite.api.Skill;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@AllArgsConstructor
|
|
||||||
class XpGlobe
|
class XpGlobe
|
||||||
{
|
{
|
||||||
private Skill skill;
|
private Skill skill;
|
||||||
private int currentXp;
|
private int currentXp;
|
||||||
private int currentLevel;
|
private int currentLevel;
|
||||||
private Instant time;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.components.PanelComponent;
|
||||||
import net.runelite.client.ui.overlay.tooltip.Tooltip;
|
import net.runelite.client.ui.overlay.tooltip.Tooltip;
|
||||||
import net.runelite.client.ui.overlay.tooltip.TooltipManager;
|
import net.runelite.client.ui.overlay.tooltip.TooltipManager;
|
||||||
|
import net.runelite.client.util.ImageUtil;
|
||||||
|
|
||||||
public class XpGlobesOverlay extends Overlay
|
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 int TOOLTIP_RECT_SIZE_X = 150;
|
||||||
private static final Color DARK_OVERLAY_COLOR = new Color(0, 0, 0, 180);
|
private static final Color DARK_OVERLAY_COLOR = new Color(0, 0, 0, 180);
|
||||||
static final String FLIP_ACTION = "Flip";
|
static final String FLIP_ACTION = "Flip";
|
||||||
|
private static final double GLOBE_ICON_RATIO = 0.65;
|
||||||
|
|
||||||
private final Client client;
|
private final Client client;
|
||||||
private final XpGlobesPlugin plugin;
|
private final XpGlobesPlugin plugin;
|
||||||
@@ -235,7 +237,8 @@ public class XpGlobesOverlay extends Overlay
|
|||||||
|
|
||||||
private void drawSkillImage(Graphics2D graphics, XpGlobe xpGlobe, int x, int y)
|
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)
|
if (skillImage == null)
|
||||||
{
|
{
|
||||||
@@ -244,12 +247,42 @@ public class XpGlobesOverlay extends Overlay
|
|||||||
|
|
||||||
graphics.drawImage(
|
graphics.drawImage(
|
||||||
skillImage,
|
skillImage,
|
||||||
x + (config.xpOrbSize() / 2) - (skillImage.getWidth() / 2),
|
x + (orbSize / 2) - (skillImage.getWidth() / 2),
|
||||||
y + (config.xpOrbSize() / 2) - (skillImage.getHeight() / 2),
|
y + (orbSize / 2) - (skillImage.getHeight() / 2),
|
||||||
null
|
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)
|
private void drawTooltip(XpGlobe mouseOverSkill, int goalXp)
|
||||||
{
|
{
|
||||||
// reset the timer on XpGlobe to prevent it from disappearing while hovered over it
|
// reset the timer on XpGlobe to prevent it from disappearing while hovered over it
|
||||||
|
|||||||
Reference in New Issue
Block a user