status bars: Clean up rendering code

This commit is contained in:
Jordan Atwood
2021-09-16 15:03:00 -07:00
parent 3c009c8f54
commit 847c44c44c
2 changed files with 30 additions and 34 deletions

View File

@@ -39,15 +39,10 @@ class BarRenderer
{
private static final Color BACKGROUND = new Color(0, 0, 0, 150);
private static final Color OVERHEAL_COLOR = new Color(216, 255, 139, 150);
private static final int OVERHEAL_OFFSET = 2;
private static final int HEAL_OFFSET = 3;
private static final int ICON_AND_COUNTER_OFFSET_X = -4;
private static final int ICON_AND_COUNTER_OFFSET_Y = 25;
private static final int SKILL_ICON_HEIGHT = 35;
private static final int COUNTER_ICON_HEIGHT = 18;
private static final int OFFSET = 2;
private static final int WIDTH = 20;
private static final int PADDING = 1;
private static final int BORDER_SIZE = 1;
private final Supplier<Integer> maxValueSupplier;
private final Supplier<Integer> currentValueSupplier;
private final Supplier<Integer> healSupplier;
@@ -80,14 +75,14 @@ class BarRenderer
refreshSkills();
graphics.setColor(BACKGROUND);
graphics.drawRect(x, y, WIDTH - PADDING, height - PADDING);
graphics.drawRect(x, y, WIDTH - BORDER_SIZE, height - BORDER_SIZE);
graphics.fillRect(x, y, WIDTH, height);
graphics.setColor(fill);
graphics.fillRect(x + PADDING,
y + PADDING + (height - filledHeight),
WIDTH - PADDING * OFFSET,
filledHeight - PADDING * OFFSET);
graphics.fillRect(x + BORDER_SIZE,
y + BORDER_SIZE + (height - filledHeight),
WIDTH - BORDER_SIZE * 2,
filledHeight - BORDER_SIZE * 2);
if (config.enableRestorationBars())
{
@@ -107,7 +102,8 @@ class BarRenderer
if (skillIconEnabled)
{
final Image icon = iconSupplier.get();
graphics.drawImage(icon, x + ICON_AND_COUNTER_OFFSET_X + PADDING, y + ICON_AND_COUNTER_OFFSET_Y - icon.getWidth(null), null);
final int xDraw = x + (WIDTH / 2) - (icon.getWidth(null) / 2);
graphics.drawImage(icon, xDraw, y, null);
}
if (config.enableCounter())
@@ -115,12 +111,12 @@ class BarRenderer
graphics.setFont(FontManager.getRunescapeSmallFont());
final String counterText = Integer.toString(currentValue);
final int widthOfCounter = graphics.getFontMetrics().stringWidth(counterText);
final int centerText = (WIDTH - PADDING) / 2 - (widthOfCounter / 2);
final int centerText = (WIDTH / 2) - (widthOfCounter / 2);
final int yOffset = skillIconEnabled ? SKILL_ICON_HEIGHT : COUNTER_ICON_HEIGHT;
final TextComponent textComponent = new TextComponent();
textComponent.setText(counterText);
textComponent.setPosition(new Point(x + centerText + PADDING, y + yOffset));
textComponent.setPosition(new Point(x + centerText, y + yOffset));
textComponent.render(graphics);
}
}
@@ -136,26 +132,26 @@ class BarRenderer
}
final int filledCurrentHeight = getBarHeight(maxValue, currentValue, height);
int filledHeight = getBarHeight(maxValue, heal, height);
final int filledHealHeight = getBarHeight(maxValue, heal, height);
final int fillY, fillHeight;
graphics.setColor(color);
if (filledHeight + filledCurrentHeight > height)
if (filledHealHeight + filledCurrentHeight > height)
{
final int overHeal = filledHeight + filledCurrentHeight - height;
filledHeight = filledHeight - overHeal + OVERHEAL_OFFSET;
graphics.setColor(OVERHEAL_COLOR);
graphics.fillRect(x + PADDING,
y - filledCurrentHeight + (height - filledHeight) + HEAL_OFFSET,
WIDTH - PADDING * OVERHEAL_OFFSET,
filledHeight - PADDING * OVERHEAL_OFFSET);
fillY = y + BORDER_SIZE;
fillHeight = height - filledCurrentHeight - BORDER_SIZE;
}
else
{
graphics.fillRect(x + PADDING,
y - OVERHEAL_OFFSET - filledCurrentHeight + (height - filledHeight) + HEAL_OFFSET,
WIDTH - PADDING * OVERHEAL_OFFSET,
filledHeight + OVERHEAL_OFFSET - PADDING * OVERHEAL_OFFSET);
fillY = y + BORDER_SIZE + height - (filledCurrentHeight + filledHealHeight);
fillHeight = filledHealHeight;
}
graphics.fillRect(x + BORDER_SIZE,
fillY,
WIDTH - BORDER_SIZE * 2,
fillHeight);
}
private static int getBarHeight(int base, int current, int size)

View File

@@ -73,7 +73,7 @@ class StatusBarsOverlay extends Overlay
private static final int HEIGHT = 252;
private static final int RESIZED_BOTTOM_HEIGHT = 272;
private static final int IMAGE_SIZE = 17;
private static final int ICON_DIMENSIONS = 26;
private static final Dimension ICON_DIMENSIONS = new Dimension(26, 25);
private static final int RESIZED_BOTTOM_OFFSET_Y = 12;
private static final int RESIZED_BOTTOM_OFFSET_X = 10;
private static final int MAX_SPECIAL_ATTACK_VALUE = 100;
@@ -105,7 +105,7 @@ class StatusBarsOverlay extends Overlay
this.itemStatService = itemstatservice;
this.spriteManager = spriteManager;
prayerIcon = ImageUtil.resizeCanvas(ImageUtil.resizeImage(skillIconManager.getSkillImage(Skill.PRAYER, true), IMAGE_SIZE, IMAGE_SIZE), ICON_DIMENSIONS, ICON_DIMENSIONS);
prayerIcon = ImageUtil.resizeCanvas(ImageUtil.resizeImage(skillIconManager.getSkillImage(Skill.PRAYER, true), IMAGE_SIZE, IMAGE_SIZE), ICON_DIMENSIONS.width, ICON_DIMENSIONS.height);
initRenderers();
}
@@ -317,11 +317,11 @@ class StatusBarsOverlay extends Overlay
return;
}
heartIcon = ImageUtil.resizeCanvas(Objects.requireNonNull(spriteManager.getSprite(SpriteID.MINIMAP_ORB_HITPOINTS_ICON, 0)), ICON_DIMENSIONS, ICON_DIMENSIONS);
heartDisease = ImageUtil.resizeCanvas(ImageUtil.loadImageResource(AlternateSprites.class, AlternateSprites.DISEASE_HEART), ICON_DIMENSIONS, ICON_DIMENSIONS);
heartPoison = ImageUtil.resizeCanvas(ImageUtil.loadImageResource(AlternateSprites.class, AlternateSprites.POISON_HEART), ICON_DIMENSIONS, ICON_DIMENSIONS);
heartVenom = ImageUtil.resizeCanvas(ImageUtil.loadImageResource(AlternateSprites.class, AlternateSprites.VENOM_HEART), ICON_DIMENSIONS, ICON_DIMENSIONS);
energyIcon = ImageUtil.resizeCanvas(Objects.requireNonNull(spriteManager.getSprite(SpriteID.MINIMAP_ORB_WALK_ICON, 0)), ICON_DIMENSIONS, ICON_DIMENSIONS);
specialIcon = ImageUtil.resizeCanvas(Objects.requireNonNull(spriteManager.getSprite(SpriteID.MINIMAP_ORB_SPECIAL_ICON, 0)), ICON_DIMENSIONS, ICON_DIMENSIONS);
heartIcon = ImageUtil.resizeCanvas(Objects.requireNonNull(spriteManager.getSprite(SpriteID.MINIMAP_ORB_HITPOINTS_ICON, 0)), ICON_DIMENSIONS.width, ICON_DIMENSIONS.height);
heartDisease = ImageUtil.resizeCanvas(ImageUtil.loadImageResource(AlternateSprites.class, AlternateSprites.DISEASE_HEART), ICON_DIMENSIONS.width, ICON_DIMENSIONS.height);
heartPoison = ImageUtil.resizeCanvas(ImageUtil.loadImageResource(AlternateSprites.class, AlternateSprites.POISON_HEART), ICON_DIMENSIONS.width, ICON_DIMENSIONS.height);
heartVenom = ImageUtil.resizeCanvas(ImageUtil.loadImageResource(AlternateSprites.class, AlternateSprites.VENOM_HEART), ICON_DIMENSIONS.width, ICON_DIMENSIONS.height);
energyIcon = ImageUtil.resizeCanvas(Objects.requireNonNull(spriteManager.getSprite(SpriteID.MINIMAP_ORB_WALK_ICON, 0)), ICON_DIMENSIONS.width, ICON_DIMENSIONS.height);
specialIcon = ImageUtil.resizeCanvas(Objects.requireNonNull(spriteManager.getSprite(SpriteID.MINIMAP_ORB_SPECIAL_ICON, 0)), ICON_DIMENSIONS.width, ICON_DIMENSIONS.height);
}
}