Merge pull request #3879 from deathbeam/add-prayer-bar

Add prayer bar to prayer plugin
This commit is contained in:
Adam
2018-07-09 15:28:34 -04:00
committed by GitHub
3 changed files with 181 additions and 6 deletions

View File

@@ -0,0 +1,132 @@
/*
* Copyright (c) 2018, Tomas Slusny <slusnucky@gmail.com>
* Copyright (c) 2018, Chdata
* 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 java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import javax.inject.Inject;
import javax.inject.Singleton;
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;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayPriority;
@Singleton
class PrayerBarOverlay extends Overlay
{
private static final Color BAR_FILL_COLOR = Color.cyan;
private static final Color BAR_BG_COLOR = Color.white;
private static final Dimension PRAYER_BAR_SIZE = new Dimension(30, 5);
private final Client client;
private final PrayerConfig config;
private boolean showingPrayerBar;
@Inject
private PrayerBarOverlay(final Client client, final PrayerConfig config)
{
this.client = client;
this.config = config;
setPosition(OverlayPosition.DYNAMIC);
setPriority(OverlayPriority.HIGH);
setLayer(OverlayLayer.ABOVE_SCENE);
}
@Override
public Dimension render(Graphics2D graphics)
{
if (!config.showPrayerBar() || !showingPrayerBar)
{
return null;
}
final int height = client.getLocalPlayer().getLogicalHeight() + 10;
final LocalPoint localLocation = client.getLocalPlayer().getLocalLocation();
final Point canvasPoint = Perspective.worldToCanvas(client, localLocation.getX(), localLocation.getY(), client.getPlane(), height);
// Draw bar
final int barX = canvasPoint.getX() + client.getViewportXOffset() - 15;
final int barY = canvasPoint.getY() + client.getViewportYOffset();
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));
graphics.setColor(BAR_BG_COLOR);
graphics.fillRect(barX, barY, barWidth, barHeight);
graphics.setColor(BAR_FILL_COLOR);
graphics.fillRect(barX, barY, progressFill, barHeight);
return new Dimension(barWidth, barHeight);
}
void onTick()
{
final boolean anyPrayerActive = checkIfAnyPrayerIsActive();
final Player localPlayer = client.getLocalPlayer();
showingPrayerBar = true;
if (localPlayer == null)
{
showingPrayerBar = false;
return;
}
if (config.hideIfNotPraying() && !anyPrayerActive)
{
showingPrayerBar = false;
return;
}
if (config.hideIfOutOfCombat() && localPlayer.getHealth() == -1)
{
showingPrayerBar = false;
}
}
private boolean checkIfAnyPrayerIsActive()
{
for (Prayer pray : Prayer.values())
{
if (client.isPrayerActive(pray))
{
return true;
}
}
return false;
}
}

View File

@@ -45,7 +45,7 @@ public interface PrayerConfig extends Config
@ConfigItem(
position = 1,
keyName = "prayerIndicator",
name = "Boost Indicator",
name = "Boost indicator",
description = "Enable infoboxes for prayers"
)
default boolean prayerIndicator()
@@ -56,7 +56,7 @@ public interface PrayerConfig extends Config
@ConfigItem(
position = 2,
keyName = "prayerIndicatorOverheads",
name = "Overhead Indicator",
name = "Overhead indicator",
description = "Also enable infoboxes for overheads"
)
default boolean prayerIndicatorOverheads()
@@ -67,7 +67,7 @@ public interface PrayerConfig extends Config
@ConfigItem(
position = 3,
keyName = "showPrayerDoseIndicator",
name = "Show Prayer Dose Indicator",
name = "Show prayer dose indicator",
description = "Enables the prayer dose indicator."
)
default boolean showPrayerDoseIndicator()
@@ -77,12 +77,45 @@ public interface PrayerConfig extends Config
@ConfigItem(
position = 4,
keyName = "Statistics",
name = "Show Prayer Stats",
keyName = "showPrayerTooltip",
name = "Show prayer orb tooltip",
description = "Displays time remaining and prayer bonus as a tooltip on the quick-prayer icon."
)
default boolean showPrayerStatistics()
{
return true;
}
}
@ConfigItem(
position = 5,
keyName = "showPrayerBar",
name = "Show prayer bar",
description = "Displays prayer bar under HP bar when praying."
)
default boolean showPrayerBar()
{
return false;
}
@ConfigItem(
keyName = "prayerBarHideIfNotPraying",
name = "Hide bar while prayer is inactive",
description = "Prayer bar will be hidden while prayers are inactivate.",
position = 6
)
default boolean hideIfNotPraying()
{
return true;
}
@ConfigItem(
keyName = "prayerBarHideIfNonCombat",
name = "Hide bar while out-of-combat",
description = "Prayer bar will be hidden while out-of-combat.",
position = 7
)
default boolean hideIfOutOfCombat()
{
return false;
}
}

View File

@@ -70,6 +70,9 @@ public class PrayerPlugin extends Plugin
@Inject
private PrayerDoseOverlay doseOverlay;
@Inject
private PrayerBarOverlay barOverlay;
@Inject
private PrayerConfig config;
@@ -84,6 +87,7 @@ public class PrayerPlugin extends Plugin
{
overlayManager.add(flickOverlay);
overlayManager.add(doseOverlay);
overlayManager.add(barOverlay);
}
@Override
@@ -91,6 +95,7 @@ public class PrayerPlugin extends Plugin
{
overlayManager.remove(flickOverlay);
overlayManager.remove(doseOverlay);
overlayManager.remove(barOverlay);
removeIndicators();
}
@@ -149,6 +154,11 @@ public class PrayerPlugin extends Plugin
doseOverlay.onTick();
}
if (config.showPrayerBar())
{
barOverlay.onTick();
}
if (!config.prayerIndicator())
{
return;