From 4b16ec983456444ec57a18bc4d830912fcd0cf27 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 4 Nov 2024 18:07:08 -0500 Subject: [PATCH] status bars: cleanup --- .../plugins/statusbars/BarRenderer.java | 9 ++- .../plugins/statusbars/StatusBarsConfig.java | 10 ++- .../plugins/statusbars/StatusBarsOverlay.java | 65 +++++-------------- .../client/plugins/statusbars/Viewport.java | 15 ++--- .../plugins/statusbars/config/BarMode.java | 35 ---------- 5 files changed, 39 insertions(+), 95 deletions(-) delete mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/statusbars/config/BarMode.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/BarRenderer.java b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/BarRenderer.java index 96cfbc4cf49..4b8d3232bb9 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/BarRenderer.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/BarRenderer.java @@ -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()) @@ -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) @@ -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) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsConfig.java index eacbb8cd376..0ae67de9f2e 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsConfig.java @@ -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 @@ -66,6 +65,15 @@ default boolean enableRestorationBars() return true; } + enum BarMode + { + DISABLED, + HITPOINTS, + PRAYER, + RUN_ENERGY, + SPECIAL_ATTACK, + } + @ConfigItem( keyName = "leftBarMode", name = "Left Bar", diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsOverlay.java index 391c8817920..6328337aea9 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsOverlay.java @@ -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; @@ -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; @@ -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 barRenderers = new EnumMap<>(BarMode.class); + private final Map barRenderers = new EnumMap<>(StatusBarsConfig.BarMode.class); @Inject private StatusBarsOverlay(Client client, StatusBarsPlugin plugin, StatusBarsConfig config, SkillIconManager skillIconManager, ItemStatChangesService itemstatservice, SpriteManager spriteManager) @@ -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()), @@ -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()), @@ -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"), @@ -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) )); } @@ -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()); @@ -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() diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/Viewport.java b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/Viewport.java index 7352f7c6389..1ad19b72950 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/Viewport.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/Viewport.java @@ -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; } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/config/BarMode.java b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/config/BarMode.java deleted file mode 100644 index 53ee959127c..00000000000 --- a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/config/BarMode.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2019, Jos - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package net.runelite.client.plugins.statusbars.config; - -public enum BarMode -{ - DISABLED, - HITPOINTS, - PRAYER, - RUN_ENERGY, - SPECIAL_ATTACK, - ; -}