From c56c26ff48839d297973e59f4babc9b5b91f2ad2 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 21 Nov 2021 17:58:43 -0500 Subject: [PATCH] barrows: fix vanilla overlay flashing with unlocked fps The flashing is caused by the vanilla overlays being hidden by the detached overlay after being drawn, and so the remaining frames before the next tick would have them hidden. Just always hide the overlay in BeforeRender so that they are never drawn when the plugin is on. Also add a quick check if the barrows region is loaded before trying to draw the barrows brothers minimap overlay. --- .../barrows/BarrowsBrotherSlainOverlay.java | 12 ++------ .../plugins/barrows/BarrowsBrothers.java | 6 ++-- .../plugins/barrows/BarrowsOverlay.java | 15 +++++----- .../client/plugins/barrows/BarrowsPlugin.java | 28 +++++++++++++++++++ 4 files changed, 39 insertions(+), 22 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/barrows/BarrowsBrotherSlainOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/barrows/BarrowsBrotherSlainOverlay.java index a1fd31954e..42aabfcef3 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/barrows/BarrowsBrotherSlainOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/barrows/BarrowsBrotherSlainOverlay.java @@ -42,7 +42,7 @@ import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.OverlayPriority; import net.runelite.client.ui.overlay.components.LineComponent; -public class BarrowsBrotherSlainOverlay extends OverlayPanel +class BarrowsBrotherSlainOverlay extends OverlayPanel { private static final DecimalFormat REWARD_POTENTIAL_FORMATTER = new DecimalFormat("##0.00%"); @@ -61,21 +61,13 @@ public class BarrowsBrotherSlainOverlay extends OverlayPanel @Override public Dimension render(Graphics2D graphics) { + // Only render the brothers slain overlay if the vanilla interface is loaded final Widget barrowsBrothers = client.getWidget(WidgetInfo.BARROWS_BROTHERS); if (barrowsBrothers == null) { return null; } - // Hide original brother and potential overlays - barrowsBrothers.setHidden(true); - - final Widget potential = client.getWidget(WidgetInfo.BARROWS_POTENTIAL); - if (potential != null) - { - potential.setHidden(true); - } - for (BarrowsBrothers brother : BarrowsBrothers.values()) { final boolean brotherSlain = client.getVar(brother.getKilledVarbit()) > 0; diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/barrows/BarrowsBrothers.java b/runelite-client/src/main/java/net/runelite/client/plugins/barrows/BarrowsBrothers.java index 6b2f3edab4..ed180fe59e 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/barrows/BarrowsBrothers.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/barrows/BarrowsBrothers.java @@ -30,7 +30,8 @@ import net.runelite.api.Varbits; import net.runelite.api.coords.WorldPoint; @RequiredArgsConstructor -public enum BarrowsBrothers +@Getter +enum BarrowsBrothers { AHRIM("Ahrim", new WorldPoint(3566, 3289, 0), Varbits.BARROWS_KILLED_AHRIM), DHAROK("Dharok", new WorldPoint(3575, 3298, 0), Varbits.BARROWS_KILLED_DHAROK), @@ -39,10 +40,7 @@ public enum BarrowsBrothers TORAG("Torag", new WorldPoint(3553, 3283, 0), Varbits.BARROWS_KILLED_TORAG), VERAC("Verac", new WorldPoint(3557, 3298, 0), Varbits.BARROWS_KILLED_VERAC); - @Getter private final String name; - @Getter private final WorldPoint location; - @Getter private final Varbits killedVarbit; } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/barrows/BarrowsOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/barrows/BarrowsOverlay.java index 686cecbf2a..b3d4d1c801 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/barrows/BarrowsOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/barrows/BarrowsOverlay.java @@ -31,6 +31,7 @@ import java.awt.Rectangle; import javax.inject.Inject; import net.runelite.api.Client; import net.runelite.api.Perspective; +import net.runelite.api.Point; import net.runelite.api.coords.LocalPoint; import net.runelite.api.widgets.Widget; import net.runelite.client.ui.overlay.Overlay; @@ -56,13 +57,12 @@ class BarrowsOverlay extends Overlay @Override public Dimension render(Graphics2D graphics) { - Widget puzzleAnswer = plugin.getPuzzleAnswer(); - - if (config.showBrotherLoc()) + if (plugin.isBarrowsLoaded() && config.showBrotherLoc()) { renderBarrowsBrothers(graphics); } + Widget puzzleAnswer = plugin.getPuzzleAnswer(); if (puzzleAnswer != null && config.showPuzzleAnswer() && !puzzleAnswer.isHidden()) { Rectangle answerRect = puzzleAnswer.getBounds(); @@ -78,20 +78,19 @@ class BarrowsOverlay extends Overlay for (BarrowsBrothers brother : BarrowsBrothers.values()) { LocalPoint localLocation = LocalPoint.fromWorld(client, brother.getLocation()); - if (localLocation == null) { continue; } String brotherLetter = Character.toString(brother.getName().charAt(0)); - net.runelite.api.Point minimapText = Perspective.getCanvasTextMiniMapLocation(client, graphics, + Point miniMapLocation = Perspective.getCanvasTextMiniMapLocation(client, graphics, localLocation, brotherLetter); - if (minimapText != null) + if (miniMapLocation != null) { graphics.setColor(Color.black); - graphics.drawString(brotherLetter, minimapText.getX() + 1, minimapText.getY() + 1); + graphics.drawString(brotherLetter, miniMapLocation.getX() + 1, miniMapLocation.getY() + 1); if (client.getVar(brother.getKilledVarbit()) > 0) { @@ -102,7 +101,7 @@ class BarrowsOverlay extends Overlay graphics.setColor(config.brotherLocColor()); } - graphics.drawString(brotherLetter, minimapText.getX(), minimapText.getY()); + graphics.drawString(brotherLetter, miniMapLocation.getX(), miniMapLocation.getY()); } } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/barrows/BarrowsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/barrows/BarrowsPlugin.java index 0cb6174d6e..4f2bc0b18d 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/barrows/BarrowsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/barrows/BarrowsPlugin.java @@ -37,6 +37,7 @@ import net.runelite.api.Item; import net.runelite.api.ItemContainer; import net.runelite.api.Player; import net.runelite.api.SpriteID; +import net.runelite.api.events.BeforeRender; import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.WidgetClosed; import net.runelite.api.events.WidgetLoaded; @@ -59,6 +60,7 @@ import net.runelite.client.ui.overlay.infobox.InfoBoxManager; import net.runelite.client.ui.overlay.infobox.InfoBoxPriority; import net.runelite.client.ui.overlay.infobox.LoopTimer; import net.runelite.client.util.QuantityFormatter; +import org.apache.commons.lang3.ArrayUtils; @PluginDescriptor( name = "Barrows Brothers", @@ -75,6 +77,7 @@ public class BarrowsPlugin extends Plugin private static final long PRAYER_DRAIN_INTERVAL_MS = 18200; private static final int CRYPT_REGION_ID = 14231; + private static final int BARROWS_REGION_ID = 14131; private LoopTimer barrowsPrayerDrainTimer; @@ -214,6 +217,26 @@ public class BarrowsPlugin extends Plugin } } + @Subscribe + public void onBeforeRender(BeforeRender beforeRender) + { + // The barrows brothers and potential overlays have timers to unhide them each tick. Set them + // hidden here instead of in the overlay, because if the overlay renders on the ABOVE_WIDGETS + // layer due to being moved outside of the snap corner, it will be running after the overlays + // had already been rendered. + final Widget barrowsBrothers = client.getWidget(WidgetInfo.BARROWS_BROTHERS); + if (barrowsBrothers != null) + { + barrowsBrothers.setHidden(true); + } + + final Widget potential = client.getWidget(WidgetInfo.BARROWS_POTENTIAL); + if (potential != null) + { + potential.setHidden(true); + } + } + @Subscribe public void onWidgetClosed(WidgetClosed widgetClosed) { @@ -256,4 +279,9 @@ public class BarrowsPlugin extends Plugin Player localPlayer = client.getLocalPlayer(); return localPlayer != null && localPlayer.getWorldLocation().getRegionID() == CRYPT_REGION_ID; } + + boolean isBarrowsLoaded() + { + return ArrayUtils.contains(client.getMapRegions(), BARROWS_REGION_ID); + } }