status bars: Add configurable width for modern resizable interface

This commit is contained in:
pwatts6060
2021-09-14 17:08:26 +04:00
committed by Jordan Atwood
parent 847c44c44c
commit 068ba565bc
3 changed files with 44 additions and 18 deletions

View File

@@ -41,8 +41,11 @@ class BarRenderer
private static final Color OVERHEAL_COLOR = new Color(216, 255, 139, 150); private static final Color OVERHEAL_COLOR = new Color(216, 255, 139, 150);
private static final int SKILL_ICON_HEIGHT = 35; private static final int SKILL_ICON_HEIGHT = 35;
private static final int COUNTER_ICON_HEIGHT = 18; private static final int COUNTER_ICON_HEIGHT = 18;
private static final int WIDTH = 20;
private static final int BORDER_SIZE = 1; private static final int BORDER_SIZE = 1;
private static final int MIN_ICON_AND_COUNTER_WIDTH = 16;
static final int DEFAULT_WIDTH = 20;
static final int MIN_WIDTH = 3;
static final int MAX_WIDTH = 40;
private final Supplier<Integer> maxValueSupplier; private final Supplier<Integer> maxValueSupplier;
private final Supplier<Integer> currentValueSupplier; private final Supplier<Integer> currentValueSupplier;
private final Supplier<Integer> healSupplier; private final Supplier<Integer> healSupplier;
@@ -67,42 +70,47 @@ class BarRenderer
* @param y The location on the client where it will draw the bar on the y axis starting on the bottom side. * @param y The location on the client where it will draw the bar on the y axis starting on the bottom side.
* @param height The height of the bar. * @param height The height of the bar.
*/ */
void renderBar(StatusBarsConfig config, Graphics2D graphics, int x, int y, int height) void renderBar(StatusBarsConfig config, Graphics2D graphics, int x, int y, int width, int height)
{ {
final int filledHeight = getBarHeight(maxValue, currentValue, height); final int filledHeight = getBarHeight(maxValue, currentValue, height);
final Color fill = colorSupplier.get(); final Color fill = colorSupplier.get();
refreshSkills(); refreshSkills();
graphics.setColor(BACKGROUND); graphics.setColor(BACKGROUND);
graphics.drawRect(x, y, WIDTH - BORDER_SIZE, height - BORDER_SIZE); graphics.drawRect(x, y, width - BORDER_SIZE, height - BORDER_SIZE);
graphics.fillRect(x, y, WIDTH, height); graphics.fillRect(x, y, width, height);
graphics.setColor(fill); graphics.setColor(fill);
graphics.fillRect(x + BORDER_SIZE, graphics.fillRect(x + BORDER_SIZE,
y + BORDER_SIZE + (height - filledHeight), y + BORDER_SIZE + (height - filledHeight),
WIDTH - BORDER_SIZE * 2, width - BORDER_SIZE * 2,
filledHeight - BORDER_SIZE * 2); filledHeight - BORDER_SIZE * 2);
if (config.enableRestorationBars()) if (config.enableRestorationBars())
{ {
renderRestore(graphics, x, y, height); renderRestore(graphics, x, y, width, height);
} }
if (config.enableSkillIcon() || config.enableCounter()) if (config.enableSkillIcon() || config.enableCounter())
{ {
renderIconsAndCounters(config, graphics, x, y); renderIconsAndCounters(config, graphics, x, y, width);
} }
} }
private void renderIconsAndCounters(StatusBarsConfig config, Graphics2D graphics, int x, int y) private void renderIconsAndCounters(StatusBarsConfig config, Graphics2D graphics, int x, int y, int width)
{ {
// Icons and counters overlap the bar at small widths, so they are not drawn when the bars are too small
if (width < MIN_ICON_AND_COUNTER_WIDTH)
{
return;
}
final boolean skillIconEnabled = config.enableSkillIcon(); final boolean skillIconEnabled = config.enableSkillIcon();
if (skillIconEnabled) if (skillIconEnabled)
{ {
final Image icon = iconSupplier.get(); final Image icon = iconSupplier.get();
final int xDraw = x + (WIDTH / 2) - (icon.getWidth(null) / 2); final int xDraw = x + (width / 2) - (icon.getWidth(null) / 2);
graphics.drawImage(icon, xDraw, y, null); graphics.drawImage(icon, xDraw, y, null);
} }
@@ -111,7 +119,7 @@ class BarRenderer
graphics.setFont(FontManager.getRunescapeSmallFont()); graphics.setFont(FontManager.getRunescapeSmallFont());
final String counterText = Integer.toString(currentValue); final String counterText = Integer.toString(currentValue);
final int widthOfCounter = graphics.getFontMetrics().stringWidth(counterText); final int widthOfCounter = graphics.getFontMetrics().stringWidth(counterText);
final int centerText = (WIDTH / 2) - (widthOfCounter / 2); final int centerText = (width / 2) - (widthOfCounter / 2);
final int yOffset = skillIconEnabled ? SKILL_ICON_HEIGHT : COUNTER_ICON_HEIGHT; final int yOffset = skillIconEnabled ? SKILL_ICON_HEIGHT : COUNTER_ICON_HEIGHT;
final TextComponent textComponent = new TextComponent(); final TextComponent textComponent = new TextComponent();
@@ -121,7 +129,7 @@ class BarRenderer
} }
} }
private void renderRestore(Graphics2D graphics, int x, int y, int height) private void renderRestore(Graphics2D graphics, int x, int y, int width, int height)
{ {
final Color color = healColorSupplier.get(); final Color color = healColorSupplier.get();
final int heal = healSupplier.get(); final int heal = healSupplier.get();
@@ -150,7 +158,7 @@ class BarRenderer
graphics.fillRect(x + BORDER_SIZE, graphics.fillRect(x + BORDER_SIZE,
fillY, fillY,
WIDTH - BORDER_SIZE * 2, width - BORDER_SIZE * 2,
fillHeight); fillHeight);
} }

View File

@@ -27,6 +27,7 @@ package net.runelite.client.plugins.statusbars;
import net.runelite.client.config.Config; import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup; import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem; import net.runelite.client.config.ConfigItem;
import net.runelite.client.config.Range;
import net.runelite.client.config.Units; import net.runelite.client.config.Units;
import net.runelite.client.plugins.statusbars.config.BarMode; import net.runelite.client.plugins.statusbars.config.BarMode;
@@ -95,4 +96,18 @@ public interface StatusBarsConfig extends Config
{ {
return 0; return 0;
} }
@Range(
min = BarRenderer.MIN_WIDTH,
max = BarRenderer.MAX_WIDTH
)
@ConfigItem(
keyName = "barWidth",
name = "Bar Width",
description = "The width of the status bars in the modern resizeable layout."
)
default int barWidth()
{
return BarRenderer.DEFAULT_WIDTH;
}
} }

View File

@@ -245,18 +245,21 @@ class StatusBarsOverlay extends Overlay
final Point offsetLeft = curViewport.getOffsetLeft(); final Point offsetLeft = curViewport.getOffsetLeft();
final Point offsetRight = curViewport.getOffsetRight(); final Point offsetRight = curViewport.getOffsetRight();
final Point location = curWidget.getCanvasLocation(); final Point location = curWidget.getCanvasLocation();
final int height, offsetLeftBarX, offsetLeftBarY, offsetRightBarX, offsetRightBarY; final int width, height, offsetLeftBarX, offsetLeftBarY, offsetRightBarX, offsetRightBarY;
if (curViewport == Viewport.RESIZED_BOTTOM) if (curViewport == Viewport.RESIZED_BOTTOM)
{ {
width = config.barWidth();
height = RESIZED_BOTTOM_HEIGHT; height = RESIZED_BOTTOM_HEIGHT;
offsetLeftBarX = (location.getX() + RESIZED_BOTTOM_OFFSET_X - offsetLeft.getX()); final int barWidthOffset = width - BarRenderer.DEFAULT_WIDTH;
offsetLeftBarX = (location.getX() + RESIZED_BOTTOM_OFFSET_X - offsetLeft.getX() - 2 * barWidthOffset);
offsetLeftBarY = (location.getY() - RESIZED_BOTTOM_OFFSET_Y - offsetLeft.getY()); offsetLeftBarY = (location.getY() - RESIZED_BOTTOM_OFFSET_Y - offsetLeft.getY());
offsetRightBarX = (location.getX() + RESIZED_BOTTOM_OFFSET_X - offsetRight.getX()); offsetRightBarX = (location.getX() + RESIZED_BOTTOM_OFFSET_X - offsetRight.getX() - barWidthOffset);
offsetRightBarY = (location.getY() - RESIZED_BOTTOM_OFFSET_Y - offsetRight.getY()); offsetRightBarY = (location.getY() - RESIZED_BOTTOM_OFFSET_Y - offsetRight.getY());
} }
else else
{ {
width = BarRenderer.DEFAULT_WIDTH;
height = HEIGHT; height = HEIGHT;
offsetLeftBarX = (location.getX() - offsetLeft.getX()); offsetLeftBarX = (location.getX() - offsetLeft.getX());
offsetLeftBarY = (location.getY() - offsetLeft.getY()); offsetLeftBarY = (location.getY() - offsetLeft.getY());
@@ -271,12 +274,12 @@ class StatusBarsOverlay extends Overlay
if (left != null) if (left != null)
{ {
left.renderBar(config, g, offsetLeftBarX, offsetLeftBarY, height); left.renderBar(config, g, offsetLeftBarX, offsetLeftBarY, width, height);
} }
if (right != null) if (right != null)
{ {
right.renderBar(config, g, offsetRightBarX, offsetRightBarY, height); right.renderBar(config, g, offsetRightBarX, offsetRightBarY, width, height);
} }
return null; return null;