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.
This commit is contained in:
Adam
2021-11-21 17:58:43 -05:00
parent 73b81701f8
commit c56c26ff48
4 changed files with 39 additions and 22 deletions

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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());
}
}
}

View File

@@ -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);
}
}