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.
This commit is contained in:
Adam
2022-06-19 14:09:42 -04:00
parent ec79cca130
commit d89a64505b
4 changed files with 28 additions and 22 deletions

View File

@@ -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<Skill> 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

View File

@@ -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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 625 B