Skip to content

Commit

Permalink
boosts: right justify compact overlay text
Browse files Browse the repository at this point in the history
Also replace buff/debuff images with one that is sized 16x16 similar to
the small skill icons, so that the text aligns properly too.
  • Loading branch information
Adam- committed Jun 19, 2022
1 parent ec79cca commit d89a645
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@

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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -135,12 +130,9 @@ protected void startUp() throws Exception
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())
{
Expand All @@ -165,7 +157,6 @@ protected void shutDown() throws Exception
isChangedUp = false;
isChangedDown = false;
skillsToDisplay.clear();
buffed = debuffed = null;
}

@Subscribe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand All @@ -37,9 +38,17 @@
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;
Expand Down Expand Up @@ -94,18 +103,18 @@ public Dimension render(Graphics2D graphics)
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);
Expand All @@ -115,17 +124,23 @@ private void drawBoost(Graphics2D graphics, FontMetrics fontMetrics, int fontHei
{
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)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d89a645

Please sign in to comment.