Merge pull request #8845 from Hydrox6/hd-prayer-bar

prayer: Add HD Prayer Bar
This commit is contained in:
Adam
2019-07-02 13:11:18 -04:00
committed by GitHub
3 changed files with 40 additions and 2 deletions

View File

@@ -28,6 +28,7 @@ package net.runelite.client.plugins.prayer;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.inject.Inject;
import javax.inject.Singleton;
import net.runelite.api.Client;
@@ -35,11 +36,13 @@ import net.runelite.api.Perspective;
import net.runelite.api.Player;
import net.runelite.api.Point;
import net.runelite.api.Skill;
import net.runelite.api.SpriteID;
import net.runelite.api.coords.LocalPoint;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayPriority;
import net.runelite.client.util.ImageUtil;
@Singleton
class PrayerBarOverlay extends Overlay
@@ -48,6 +51,9 @@ class PrayerBarOverlay extends Overlay
private static final Color BAR_BG_COLOR = Color.black;
private static final Color FLICK_HELP_COLOR = Color.white;
private static final Dimension PRAYER_BAR_SIZE = new Dimension(30, 5);
private static final int HD_PRAYER_BAR_PADDING = 1;
private static final BufferedImage HD_FRONT_BAR = ImageUtil.getResourceStreamFromClass(PrayerPlugin.class, "front.png");
private static final BufferedImage HD_BACK_BAR = ImageUtil.getResourceStreamFromClass(PrayerPlugin.class, "back.png");
private final Client client;
private final PrayerConfig config;
@@ -79,12 +85,44 @@ class PrayerBarOverlay extends Overlay
final LocalPoint localLocation = client.getLocalPlayer().getLocalLocation();
final Point canvasPoint = Perspective.localToCanvas(client, localLocation, client.getPlane(), height);
final float ratio = (float) client.getBoostedSkillLevel(Skill.PRAYER) / client.getRealSkillLevel(Skill.PRAYER);
// Draw HD bar
if (client.getSpriteOverrides().containsKey(SpriteID.HEALTHBAR_DEFAULT_FRONT_30PX))
{
final int barWidth = HD_FRONT_BAR.getWidth();
final int barHeight = HD_FRONT_BAR.getHeight();
final int barX = canvasPoint.getX() - barWidth / 2;
final int barY = canvasPoint.getY();
// Include padding so the bar doesn't show empty at very low prayer values
final int progressFill = (int) Math.ceil(Math.max(HD_PRAYER_BAR_PADDING * 2, Math.min((barWidth * ratio), barWidth)));
graphics.drawImage(HD_BACK_BAR, barX, barY, barWidth, barHeight, null);
// Use a sub-image to create the same effect the HD Health Bar has
graphics.drawImage(HD_FRONT_BAR.getSubimage(0, 0, progressFill, barHeight), barX, barY, progressFill, barHeight, null);
if ((plugin.isPrayersActive() || config.prayerFlickAlwaysOn())
&& (config.prayerFlickLocation().equals(PrayerFlickLocation.PRAYER_BAR)
|| config.prayerFlickLocation().equals(PrayerFlickLocation.BOTH)))
{
final double t = plugin.getTickProgress();
final int halfBarWidth = (barWidth / 2) - HD_PRAYER_BAR_PADDING;
final int xOffset = (int) (-Math.cos(t) * halfBarWidth) + ((barWidth / 2) - halfBarWidth);
graphics.setColor(FLICK_HELP_COLOR);
graphics.fillRect(barX + xOffset + HD_PRAYER_BAR_PADDING, barY + HD_PRAYER_BAR_PADDING, 1, barHeight - HD_PRAYER_BAR_PADDING * 2);
}
return new Dimension(barWidth, barHeight);
}
// Draw bar
final int barX = canvasPoint.getX() - 15;
final int barY = canvasPoint.getY();
final int barWidth = PRAYER_BAR_SIZE.width;
final int barHeight = PRAYER_BAR_SIZE.height;
final float ratio = (float) client.getBoostedSkillLevel(Skill.PRAYER) / client.getRealSkillLevel(Skill.PRAYER);
// Restricted by the width to prevent the bar from being too long while you are boosted above your real prayer level.
final int progressFill = (int) Math.ceil(Math.min((barWidth * ratio), barWidth));
@@ -100,7 +138,7 @@ class PrayerBarOverlay extends Overlay
{
double t = plugin.getTickProgress();
int xOffset = (int) (-Math.cos(t) * barWidth / 2) + barWidth / 2;
final int xOffset = (int) (-Math.cos(t) * barWidth / 2) + barWidth / 2;
graphics.setColor(FLICK_HELP_COLOR);
graphics.fillRect(barX + xOffset, barY, 1, barHeight);

Binary file not shown.

After

Width:  |  Height:  |  Size: 358 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 437 B