diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/prayer/PrayerBarOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/prayer/PrayerBarOverlay.java index de84db9c30..c67f91b828 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/prayer/PrayerBarOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/prayer/PrayerBarOverlay.java @@ -34,7 +34,6 @@ import net.runelite.api.Client; import net.runelite.api.Perspective; import net.runelite.api.Player; import net.runelite.api.Point; -import net.runelite.api.Prayer; import net.runelite.api.Skill; import net.runelite.api.coords.LocalPoint; import net.runelite.client.ui.overlay.Overlay; @@ -51,13 +50,16 @@ class PrayerBarOverlay extends Overlay private final Client client; private final PrayerConfig config; + private final PrayerPlugin plugin; + private boolean showingPrayerBar; @Inject - private PrayerBarOverlay(final Client client, final PrayerConfig config) + private PrayerBarOverlay(final Client client, final PrayerConfig config, final PrayerPlugin plugin) { this.client = client; this.config = config; + this.plugin = plugin; setPosition(OverlayPosition.DYNAMIC); setPriority(OverlayPriority.HIGH); @@ -90,12 +92,22 @@ class PrayerBarOverlay extends Overlay graphics.fillRect(barX, barY, barWidth, barHeight); graphics.setColor(BAR_FILL_COLOR); graphics.fillRect(barX, barY, progressFill, barHeight); + + if (plugin.isPrayersActive() && (config.prayerFlickLocation().equals(PrayerFlickLocation.PRAYER_BAR) || config.prayerFlickLocation().equals(PrayerFlickLocation.BOTH))) + { + double t = plugin.getTickProgress(); + + int xOffset = (int) (-Math.cos(t) * barWidth / 2) + barWidth / 2; + + graphics.setColor(Color.black); + graphics.fillRect(barX + xOffset, barY, 1, barHeight); + } + return new Dimension(barWidth, barHeight); } void onTick() { - final boolean anyPrayerActive = checkIfAnyPrayerIsActive(); final Player localPlayer = client.getLocalPlayer(); showingPrayerBar = true; @@ -105,7 +117,7 @@ class PrayerBarOverlay extends Overlay return; } - if (config.hideIfNotPraying() && !anyPrayerActive) + if (config.hideIfNotPraying() && !plugin.isPrayersActive()) { showingPrayerBar = false; return; @@ -116,17 +128,4 @@ class PrayerBarOverlay extends Overlay showingPrayerBar = false; } } - - private boolean checkIfAnyPrayerIsActive() - { - for (Prayer pray : Prayer.values()) - { - if (client.isPrayerActive(pray)) - { - return true; - } - } - - return false; - } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/prayer/PrayerConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/prayer/PrayerConfig.java index 934ba4d1c1..b439f27bd5 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/prayer/PrayerConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/prayer/PrayerConfig.java @@ -33,13 +33,13 @@ public interface PrayerConfig extends Config { @ConfigItem( position = 0, - keyName = "prayerflick", - name = "Prayer flick helper", - description = "Enable the prayer flick helper" + keyName = "prayerFlickLocation", + name = "Pray flick location", + description = "Choose where to display the prayer flick helper" ) - default boolean prayerFlickHelper() + default PrayerFlickLocation prayerFlickLocation() { - return true; + return PrayerFlickLocation.NONE; } @ConfigItem( diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/prayer/PrayerFlickLocation.java b/runelite-client/src/main/java/net/runelite/client/plugins/prayer/PrayerFlickLocation.java new file mode 100644 index 0000000000..a39825677e --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/prayer/PrayerFlickLocation.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2018, Forsco + * 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.prayer; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum PrayerFlickLocation +{ + NONE("Off"), + PRAYER_ORB("Prayer Orb"), + PRAYER_BAR("Prayer Bar"), + BOTH("Both"); + + private final String name; + + @Override + public String toString() + { + return name; + } +} \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/prayer/PrayerFlickOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/prayer/PrayerFlickOverlay.java index 929daa66c9..87524fc5ef 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/prayer/PrayerFlickOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/prayer/PrayerFlickOverlay.java @@ -28,11 +28,8 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; -import java.time.Duration; -import java.time.Instant; import javax.inject.Inject; import net.runelite.api.Client; -import net.runelite.api.Prayer; import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.WidgetInfo; import net.runelite.client.ui.overlay.Overlay; @@ -42,27 +39,26 @@ import net.runelite.client.ui.overlay.OverlayPosition; class PrayerFlickOverlay extends Overlay { private final Client client; - private boolean prayersActive = false; - private Instant startOfLastTick = Instant.now(); + private final PrayerConfig config; + private final PrayerPlugin plugin; @Inject - private PrayerFlickOverlay(Client client) + private PrayerFlickOverlay(Client client, PrayerConfig config, PrayerPlugin plugin) { setPosition(OverlayPosition.DYNAMIC); setLayer(OverlayLayer.ABOVE_WIDGETS); this.client = client; - } - - void onTick() - { - startOfLastTick = Instant.now(); //Reset the tick timer - prayersActive = isAnyPrayerActive(); //Check if prayers are active + this.config = config; + this.plugin = plugin; } @Override public Dimension render(Graphics2D graphics) { - if (!prayersActive) //If there are no prayers active we don't need to be flicking + // If there are no prayers active or flick location is set to the prayer bar we don't require the flick helper + if (!plugin.isPrayersActive() + || config.prayerFlickLocation().equals(PrayerFlickLocation.NONE) + || config.prayerFlickLocation().equals(PrayerFlickLocation.PRAYER_BAR)) { return null; } @@ -86,12 +82,7 @@ class PrayerFlickOverlay extends Overlay int orbInnerX = (int) (bounds.getX() + 24);//x pos of the inside of the prayer orb int orbInnerY = (int) (bounds.getY() - 1);//y pos of the inside of the prayer orb - long timeSinceLastTick = Duration.between(startOfLastTick, Instant.now()).toMillis(); - - float tickProgress = timeSinceLastTick / 600f; - tickProgress = Math.min(tickProgress, 1);//Cap to 1, so if a tick continues past the expected 600 we don't move the indicator off the orb - - double t = tickProgress * Math.PI;//t on interval [0,pi] + double t = plugin.getTickProgress(); int xOffset = (int) (-Math.cos(t) * orbInnerWidth / 2) + orbInnerWidth / 2; int indicatorHeight = (int) (Math.sin(t) * orbInnerHeight); @@ -103,17 +94,4 @@ class PrayerFlickOverlay extends Overlay return new Dimension((int) bounds.getWidth(), (int) bounds.getHeight()); } - - boolean isAnyPrayerActive() - { - for (Prayer pray : Prayer.values())//Check if any prayers are active - { - if (client.isPrayerActive(pray)) - { - return true; - } - } - - return false; - } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/prayer/PrayerPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/prayer/PrayerPlugin.java index 5f27df6128..a28e535906 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/prayer/PrayerPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/prayer/PrayerPlugin.java @@ -27,7 +27,11 @@ package net.runelite.client.plugins.prayer; import com.google.common.eventbus.Subscribe; import com.google.inject.Provides; +import java.time.Duration; +import java.time.Instant; import javax.inject.Inject; +import lombok.AccessLevel; +import lombok.Getter; import net.runelite.api.Client; import net.runelite.api.InventoryID; import net.runelite.api.Item; @@ -52,6 +56,11 @@ public class PrayerPlugin extends Plugin { private final PrayerCounter[] prayerCounter = new PrayerCounter[PrayerType.values().length]; + private Instant startOfLastTick = Instant.now(); + + @Getter(AccessLevel.PACKAGE) + private boolean prayersActive = false; + @Inject private Client client; @@ -144,9 +153,11 @@ public class PrayerPlugin extends Plugin @Subscribe public void onGameTick(GameTick tick) { - if (config.prayerFlickHelper()) + prayersActive = isAnyPrayerActive(); + + if (!config.prayerFlickLocation().equals(PrayerFlickLocation.NONE)) { - flickOverlay.onTick(); + startOfLastTick = Instant.now(); } if (config.showPrayerDoseIndicator()) @@ -233,6 +244,27 @@ public class PrayerPlugin extends Plugin return total; } + double getTickProgress() + { + long timeSinceLastTick = Duration.between(startOfLastTick, Instant.now()).toMillis(); + + float tickProgress = (timeSinceLastTick % 600) / 600f; + return tickProgress * Math.PI; + } + + private boolean isAnyPrayerActive() + { + for (Prayer pray : Prayer.values())//Check if any prayers are active + { + if (client.isPrayerActive(pray)) + { + return true; + } + } + + return false; + } + private void removeIndicators() { infoBoxManager.removeIf(entry -> entry instanceof PrayerCounter);