From d89a64505b2e749719b580fc105e268e064933c8 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 19 Jun 2022 14:09:42 -0400 Subject: [PATCH] boosts: right justify compact overlay text Also replace buff/debuff images with one that is sized 16x16 similar to the small skill icons, so that the text aligns properly too. --- .../client/plugins/boosts/BoostsPlugin.java | 13 +----- .../plugins/boosts/CompactBoostsOverlay.java | 37 ++++++++++++------ .../client/plugins/boosts/buffedsmall.png | Bin 0 -> 580 bytes .../client/plugins/boosts/debuffedsmall.png | Bin 0 -> 625 bytes 4 files changed, 28 insertions(+), 22 deletions(-) create mode 100644 runelite-client/src/main/resources/net/runelite/client/plugins/boosts/buffedsmall.png create mode 100644 runelite-client/src/main/resources/net/runelite/client/plugins/boosts/debuffedsmall.png diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/boosts/BoostsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/boosts/BoostsPlugin.java index 02f23a8776..cd47e26719 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/boosts/BoostsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/boosts/BoostsPlugin.java @@ -26,13 +26,11 @@ package net.runelite.client.plugins.boosts; import com.google.common.collect.ImmutableSet; import com.google.inject.Provides; -import java.awt.image.BufferedImage; import java.util.Arrays; import java.util.EnumSet; import java.util.Set; import javax.inject.Inject; import javax.inject.Singleton; -import lombok.AccessLevel; import lombok.Getter; import net.runelite.api.Client; import net.runelite.api.Constants; @@ -104,9 +102,6 @@ public class BoostsPlugin extends Plugin private final Set shownSkills = EnumSet.noneOf(Skill.class); - @Getter(AccessLevel.PACKAGE) - private BufferedImage buffed, debuffed; - private boolean isChangedDown = false; private boolean isChangedUp = false; private final int[] lastSkillLevels = new int[Skill.values().length - 1]; @@ -135,12 +130,9 @@ public class BoostsPlugin extends Plugin updateShownSkills(); Arrays.fill(lastSkillLevels, -1); - buffed = ImageUtil.loadImageResource(getClass(), "buffed.png"); - debuffed = ImageUtil.loadImageResource(getClass(), "debuffed.png"); - // Add infoboxes for everything at startup and then determine inside if it will be rendered - infoBoxManager.addInfoBox(new StatChangeIndicator(true, buffed, this, config)); - infoBoxManager.addInfoBox(new StatChangeIndicator(false, debuffed, this, config)); + infoBoxManager.addInfoBox(new StatChangeIndicator(true, ImageUtil.loadImageResource(getClass(), "buffed.png"), this, config)); + infoBoxManager.addInfoBox(new StatChangeIndicator(false, ImageUtil.loadImageResource(getClass(), "debuffed.png"), this, config)); for (final Skill skill : Skill.values()) { @@ -165,7 +157,6 @@ public class BoostsPlugin extends Plugin isChangedUp = false; isChangedDown = false; skillsToDisplay.clear(); - buffed = debuffed = null; } @Subscribe diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/boosts/CompactBoostsOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/boosts/CompactBoostsOverlay.java index 828feef03d..ee66149dda 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/boosts/CompactBoostsOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/boosts/CompactBoostsOverlay.java @@ -28,6 +28,7 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.FontMetrics; import java.awt.Graphics2D; +import java.awt.Point; import java.awt.image.BufferedImage; import java.util.Set; import javax.inject.Inject; @@ -37,9 +38,17 @@ import net.runelite.client.game.SkillIconManager; import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.OverlayPriority; +import net.runelite.client.ui.overlay.components.TextComponent; +import net.runelite.client.util.ImageUtil; class CompactBoostsOverlay extends Overlay { + private static final int H_PADDING = 2; + private static final int V_PADDING = 1; + private static final int TEXT_WIDTH = 22; + private static final BufferedImage BUFFED = ImageUtil.loadImageResource(CompactBoostsOverlay.class, "buffedsmall.png"); + private static final BufferedImage DEBUFFED = ImageUtil.loadImageResource(CompactBoostsOverlay.class, "debuffedsmall.png"); + private final Client client; private final BoostsConfig config; private final BoostsPlugin plugin; @@ -94,18 +103,18 @@ class CompactBoostsOverlay extends Overlay if (time != -1) { drawBoost(graphics, fontMetrics, fontHeight, - plugin.getBuffed(), + BUFFED, time < 10 ? Color.RED.brighter() : Color.WHITE, - String.format("%02d", plugin.getChangeTime(time))); + Integer.toString(plugin.getChangeTime(time))); } time = plugin.getChangeDownTicks(); if (time != -1) { drawBoost(graphics, fontMetrics, fontHeight, - plugin.getDebuffed(), + DEBUFFED, time < 10 ? Color.RED.brighter() : Color.WHITE, - String.format("%02d", plugin.getChangeTime(time))); + Integer.toString(plugin.getChangeTime(time))); } return new Dimension(maxX, curY); @@ -115,17 +124,23 @@ class CompactBoostsOverlay extends Overlay { graphics.drawImage(image, 0, curY, null); - // add a little bit of padding to get the text off the side of the image - final int x = image.getWidth() + 6; - graphics.setColor(color); - graphics.drawString(text, x, + final int stringWidth = fontMetrics.stringWidth(text); + final TextComponent textComponent = new TextComponent(); + textComponent.setColor(color); + textComponent.setText(text); + textComponent.setOutline(true); + textComponent.setPosition(new Point( + image.getWidth() + + H_PADDING // add a little bit of padding to get the text off the side of the image + + (TEXT_WIDTH - stringWidth), // right justify to TEXT_WIDTH // this really should be y + (image.getHeight() / 2) + (fontHeight / 2), but in practice // it is the same - curY + fontHeight); + curY + fontHeight)); + textComponent.render(graphics); curY += Math.max(image.getHeight(), fontHeight) - + 1; // padding to keep images from touching - maxX = Math.max(maxX, x + fontMetrics.stringWidth(text)); + + V_PADDING; // padding to keep images from touching + maxX = Math.max(maxX, image.getWidth() + H_PADDING + TEXT_WIDTH); } private String getBoostText(int boost, int base, int boosted) diff --git a/runelite-client/src/main/resources/net/runelite/client/plugins/boosts/buffedsmall.png b/runelite-client/src/main/resources/net/runelite/client/plugins/boosts/buffedsmall.png new file mode 100644 index 0000000000000000000000000000000000000000..f4757d0ca34a874a85c5545bf4768a0c98185983 GIT binary patch literal 580 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GXl47!?A1LR^7dAX89SP)A3bhnpLS z>_Q!ZBv2Gcx_i3=Wr2v9nHk8{7Z*1W7uOaOV`5_VR#XIv0Fji8p@5(SP>rUkmX4Wj z>9U&6Wj&T2R#TTuowa86{I&DLx}sI>)pflLBId*cjrDBxFZ&;-n;=4R!P}%WB5^r6 zA%%fa&C^peO^nSVA$9V!X%kb~H(NH$nC$Hr=NQPTbb$BBn^Rh=R%Hb+%57*^wQHAF zNW=90c!vOHl?9xF0z%g=g@v+mu2|K?T2ivL(T0Pe`$eWQXGcee(Fz-Mh!dH68#x z!e3C%&%(*V+HKs@($?1M?&9X=di=<-V@JIi81|f3t>VZ`-2wCkgQu&X%Q~loCIEjp Bo+|(V literal 0 HcmV?d00001 diff --git a/runelite-client/src/main/resources/net/runelite/client/plugins/boosts/debuffedsmall.png b/runelite-client/src/main/resources/net/runelite/client/plugins/boosts/debuffedsmall.png new file mode 100644 index 0000000000000000000000000000000000000000..6e02339e742b51b20f5365e83fba40f081dac984 GIT binary patch literal 625 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GXl47`*~~LR^7dAX89SP)A3bhnpM7 z0g`s1j&QcSw>wY)5HT||0|oWP#SO&8wZ+7kn3%m46@el^Bqd`gASeM;qiL$8W2RfW ztfq5WkEMsz)Fo4At(iT4?fkH=XjOZ4T`z-(Iq`ifCU~~`x6WzxZ1L0a&4pOO*uq1v7A1 zPvaD}d8o)Q{gh9{B;dx2*H=%viLP7c#}ngN3RJbn)5S4F;&O6A3In5>re!y*;Ncw|?H*7^