Add flick helper to player bar (#3882)
Allows the player to toggle the prayer flick location between the Quick Prayer Orb, Prayer Bar or Both.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Forsco <https://github.com/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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user