Skip to content

Commit

Permalink
status bars: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam- committed Nov 4, 2024
1 parent 5282315 commit 4b16ec9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,11 @@ private void renderIconsAndCounters(StatusBarsConfig config, Graphics2D graphics
if (skillIconEnabled)
{
final Image icon = iconSupplier.get();
final int xDraw = x + (width / 2) - (icon.getWidth(null) / 2);
graphics.drawImage(icon, xDraw, y, null);
if (icon != null)
{
final int xDraw = x + (width / 2) - (icon.getWidth(null) / 2);
graphics.drawImage(icon, xDraw, y + 4, null);
}
}

if (config.enableCounter())
Expand All @@ -131,7 +134,6 @@ private void renderIconsAndCounters(StatusBarsConfig config, Graphics2D graphics

private void renderRestore(Graphics2D graphics, int x, int y, int width, int height)
{
final Color color = healColorSupplier.get();
final int heal = healSupplier.get();

if (heal <= 0)
Expand All @@ -142,6 +144,7 @@ private void renderRestore(Graphics2D graphics, int x, int y, int width, int hei
final int filledCurrentHeight = getBarHeight(maxValue, currentValue, height);
final int filledHealHeight = getBarHeight(maxValue, heal, height);
final int fillY, fillHeight;
final Color color = healColorSupplier.get();
graphics.setColor(color);

if (filledHealHeight + filledCurrentHeight > height)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import net.runelite.client.config.ConfigItem;
import net.runelite.client.config.Range;
import net.runelite.client.config.Units;
import net.runelite.client.plugins.statusbars.config.BarMode;

@ConfigGroup(StatusBarsConfig.GROUP)
public interface StatusBarsConfig extends Config
Expand Down Expand Up @@ -66,6 +65,15 @@ default boolean enableRestorationBars()
return true;
}

enum BarMode
{
DISABLED,
HITPOINTS,
PRAYER,
RUN_ENERGY,
SPECIAL_ATTACK,
}

@ConfigItem(
keyName = "leftBarMode",
name = "Left Bar",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import net.runelite.client.plugins.itemstats.Effect;
import net.runelite.client.plugins.itemstats.ItemStatChangesService;
import net.runelite.client.plugins.itemstats.StatChange;
import net.runelite.client.plugins.statusbars.config.BarMode;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
Expand All @@ -73,8 +72,6 @@ class StatusBarsOverlay extends Overlay
private static final Color PARASITE_COLOR = new Color(196, 62, 109, 181);
private static final int HEIGHT = 252;
private static final int RESIZED_BOTTOM_HEIGHT = 272;
private static final int IMAGE_SIZE = 17;
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;
Expand All @@ -84,16 +81,13 @@ class StatusBarsOverlay extends Overlay
private final StatusBarsPlugin plugin;
private final StatusBarsConfig config;
private final ItemStatChangesService itemStatService;
private final SkillIconManager skillIconManager;
private final SpriteManager spriteManager;

private final Image prayerIcon;
private final Image heartDisease;
private final Image heartPoison;
private final Image heartVenom;
private Image heartIcon;
private Image specialIcon;
private Image energyIcon;
private final Map<BarMode, BarRenderer> barRenderers = new EnumMap<>(BarMode.class);
private final Map<StatusBarsConfig.BarMode, BarRenderer> barRenderers = new EnumMap<>(StatusBarsConfig.BarMode.class);

@Inject
private StatusBarsOverlay(Client client, StatusBarsPlugin plugin, StatusBarsConfig config, SkillIconManager skillIconManager, ItemStatChangesService itemstatservice, SpriteManager spriteManager)
Expand All @@ -104,20 +98,19 @@ private StatusBarsOverlay(Client client, StatusBarsPlugin plugin, StatusBarsConf
this.plugin = plugin;
this.config = config;
this.itemStatService = itemstatservice;
this.skillIconManager = skillIconManager;
this.spriteManager = spriteManager;

prayerIcon = ImageUtil.resizeCanvas(ImageUtil.resizeImage(skillIconManager.getSkillImage(Skill.PRAYER, true), IMAGE_SIZE, IMAGE_SIZE), 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);
heartDisease = ImageUtil.loadImageResource(AlternateSprites.class, AlternateSprites.DISEASE_HEART);
heartPoison = ImageUtil.loadImageResource(AlternateSprites.class, AlternateSprites.POISON_HEART);
heartVenom = ImageUtil.loadImageResource(AlternateSprites.class, AlternateSprites.VENOM_HEART);

initRenderers();
}

private void initRenderers()
{
barRenderers.put(BarMode.DISABLED, null);
barRenderers.put(BarMode.HITPOINTS, new BarRenderer(
barRenderers.put(StatusBarsConfig.BarMode.HITPOINTS, new BarRenderer(
() -> inLms() ? Experience.MAX_REAL_LEVEL : client.getRealSkillLevel(Skill.HITPOINTS),
() -> client.getBoostedSkillLevel(Skill.HITPOINTS),
() -> getRestoreValue(Skill.HITPOINTS.getName()),
Expand Down Expand Up @@ -167,10 +160,10 @@ private void initRenderers()
return heartDisease;
}

return heartIcon;
return loadSprite(SpriteID.MINIMAP_ORB_HITPOINTS_ICON);
}
));
barRenderers.put(BarMode.PRAYER, new BarRenderer(
barRenderers.put(StatusBarsConfig.BarMode.PRAYER, new BarRenderer(
() -> inLms() ? Experience.MAX_REAL_LEVEL : client.getRealSkillLevel(Skill.PRAYER),
() -> client.getBoostedSkillLevel(Skill.PRAYER),
() -> getRestoreValue(Skill.PRAYER.getName()),
Expand All @@ -190,9 +183,9 @@ private void initRenderers()
return prayerColor;
},
() -> PRAYER_HEAL_COLOR,
() -> prayerIcon
() -> skillIconManager.getSkillImage(Skill.PRAYER, true)
));
barRenderers.put(BarMode.RUN_ENERGY, new BarRenderer(
barRenderers.put(StatusBarsConfig.BarMode.RUN_ENERGY, new BarRenderer(
() -> MAX_RUN_ENERGY_VALUE,
() -> client.getEnergy() / 100,
() -> getRestoreValue("Run Energy"),
Expand All @@ -208,15 +201,15 @@ private void initRenderers()
}
},
() -> ENERGY_HEAL_COLOR,
() -> energyIcon
() -> loadSprite(SpriteID.MINIMAP_ORB_WALK_ICON)
));
barRenderers.put(BarMode.SPECIAL_ATTACK, new BarRenderer(
barRenderers.put(StatusBarsConfig.BarMode.SPECIAL_ATTACK, new BarRenderer(
() -> MAX_SPECIAL_ATTACK_VALUE,
() -> client.getVarpValue(VarPlayer.SPECIAL_ATTACK_PERCENT) / 10,
() -> 0,
() -> SPECIAL_ATTACK_COLOR,
() -> SPECIAL_ATTACK_COLOR,
() -> specialIcon
() -> null,
() -> loadSprite(SpriteID.MINIMAP_ORB_SPECIAL_ICON)
));
}

Expand Down Expand Up @@ -272,8 +265,6 @@ public Dimension render(Graphics2D g)
offsetRightBarY = (location.getY() - offsetRight.getY());
}

buildIcons();

BarRenderer left = barRenderers.get(config.leftBarMode());
BarRenderer right = barRenderers.get(config.rightBarMode());

Expand Down Expand Up @@ -324,31 +315,9 @@ private int getRestoreValue(String skill)
return restoreValue;
}

private void buildIcons()
private BufferedImage loadSprite(int spriteId)
{
if (heartIcon == null)
{
heartIcon = loadAndResize(SpriteID.MINIMAP_ORB_HITPOINTS_ICON);
}
if (energyIcon == null)
{
energyIcon = loadAndResize(SpriteID.MINIMAP_ORB_WALK_ICON);
}
if (specialIcon == null)
{
specialIcon = loadAndResize(SpriteID.MINIMAP_ORB_SPECIAL_ICON);
}
}

private BufferedImage loadAndResize(int spriteId)
{
BufferedImage image = spriteManager.getSprite(spriteId, 0);
if (image == null)
{
return null;
}

return ImageUtil.resizeCanvas(image, ICON_DIMENSIONS.width, ICON_DIMENSIONS.height);
return spriteManager.getSprite(spriteId, 0);
}

private boolean inLms()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,16 @@
@AllArgsConstructor
enum Viewport
{
RESIZED_BOX(ComponentID.RESIZABLE_VIEWPORT_RESIZABLE_VIEWPORT_OLD_SCHOOL_BOX, ComponentID.RESIZABLE_VIEWPORT_INTERFACE_CONTAINER,
RESIZED_BOX(ComponentID.RESIZABLE_VIEWPORT_INTERFACE_CONTAINER,
new Point(20, -4), new Point(0, -4)),
RESIZED_BOTTOM(ComponentID.RESIZABLE_VIEWPORT_BOTTOM_LINE_RESIZABLE_VIEWPORT_BOTTOM_LINE, ComponentID.RESIZABLE_VIEWPORT_BOTTOM_LINE_INTERFACE_CONTAINER,
RESIZED_BOTTOM(ComponentID.RESIZABLE_VIEWPORT_BOTTOM_LINE_INTERFACE_CONTAINER,
new Point(61, -12), new Point(35, -12)),
FIXED(ComponentID.FIXED_VIEWPORT_FIXED_VIEWPORT, ComponentID.FIXED_VIEWPORT_INTERFACE_CONTAINER,
FIXED(ComponentID.FIXED_VIEWPORT_INTERFACE_CONTAINER,
new Point(20, -4), new Point(0, -4)),
FIXED_BANK(ComponentID.BANK_CONTAINER, ComponentID.BANK_INVENTORY_ITEM_CONTAINER,
FIXED_BANK(ComponentID.BANK_INVENTORY_ITEM_CONTAINER,
new Point(20, -4), new Point(0, -4));

private int container;
private int viewport;
private Point offsetLeft;
private Point offsetRight;
private final int viewport;
private final Point offsetLeft;
private final Point offsetRight;
}

This file was deleted.

0 comments on commit 4b16ec9

Please sign in to comment.