Add special attack minimap orb
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* 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.specorb;
|
||||
|
||||
import net.runelite.client.config.Config;
|
||||
import net.runelite.client.config.ConfigGroup;
|
||||
import net.runelite.client.config.ConfigItem;
|
||||
|
||||
@ConfigGroup(
|
||||
keyName = "specorb",
|
||||
name = "Special Attack Orb",
|
||||
description = "Configuration for the Special Attack Orbplugin"
|
||||
)
|
||||
public interface SpecOrbConfig extends Config
|
||||
{
|
||||
@ConfigItem(
|
||||
keyName = "enabled",
|
||||
name = "Enabled",
|
||||
description = "Configures whether or not Special Attack Orb plugin is displayed"
|
||||
)
|
||||
default boolean enabled()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* 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.specorb;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.api.Point;
|
||||
import net.runelite.api.Varbits;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.client.events.GameTick;
|
||||
import net.runelite.client.events.VarbitChanged;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
import net.runelite.client.ui.overlay.OverlayUtil;
|
||||
|
||||
public class SpecOrbOverlay extends Overlay
|
||||
{
|
||||
private static final int RECHARGE_TIME_TICKS = 51;
|
||||
|
||||
private static final int ORB_X_OFFSET = 60;
|
||||
private static final int ORB_Y_OFFSET = 123;
|
||||
private static final Color SPECIAL_ORB_BACKGROUND_COLOR = new Color(51, 102, 255);
|
||||
private static final Color SPECIAL_ORB_RECHARGE_COLOR = new Color(153, 204, 255, 50);
|
||||
|
||||
private final Client client;
|
||||
private final SpecOrbConfig config;
|
||||
private final SpecOrbPlugin plugin;
|
||||
private int lastSpecialPercent = 0;
|
||||
private int tickCounter = 0;
|
||||
|
||||
@Inject
|
||||
public SpecOrbOverlay(@Nullable Client client, SpecOrbConfig config, SpecOrbPlugin plugin)
|
||||
{
|
||||
super(OverlayPosition.DYNAMIC);
|
||||
this.client = client;
|
||||
this.config = config;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension render(Graphics2D graphics)
|
||||
{
|
||||
if (client.getGameState() != GameState.LOGGED_IN || !config.enabled())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Widget xpOrb = client.getWidget(WidgetInfo.MINIMAP_XP_ORB);
|
||||
if (xpOrb == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
graphics.setColor(SPECIAL_ORB_BACKGROUND_COLOR);
|
||||
|
||||
boolean specialAttackEnabled = client.getSetting(Varbits.SPECIAL_ATTACK_ENABLED) == 1;
|
||||
|
||||
// draw relative to the xp orb
|
||||
Point xpOrbPoint = xpOrb.getCanvasLocation();
|
||||
Point specOrbPoint = new Point(xpOrbPoint.getX() + ORB_X_OFFSET, xpOrbPoint.getY() + ORB_Y_OFFSET);
|
||||
|
||||
double specialPercent = client.getSetting(Varbits.SPECIAL_ATTACK_PERCENT) / 1000.0;
|
||||
double specialRechargePercent = tickCounter / (double) RECHARGE_TIME_TICKS;
|
||||
|
||||
OverlayUtil.drawMinimapOrb(graphics, specOrbPoint, specialPercent,
|
||||
SPECIAL_ORB_RECHARGE_COLOR, specialRechargePercent,
|
||||
plugin.getMinimapOrbBackground(), plugin.getSpecialAttackIcon(),
|
||||
(int) (specialPercent * 100), specialAttackEnabled);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void onVarbitChanged(VarbitChanged event)
|
||||
{
|
||||
int specialPercent = client.getSetting(Varbits.SPECIAL_ATTACK_PERCENT);
|
||||
if (lastSpecialPercent != specialPercent)
|
||||
{
|
||||
int diff = specialPercent - lastSpecialPercent;
|
||||
lastSpecialPercent = specialPercent;
|
||||
onSpecialChange(diff);
|
||||
}
|
||||
}
|
||||
|
||||
private void onSpecialChange(int diff)
|
||||
{
|
||||
// If we went from 500-600 for example
|
||||
if (diff > 0)
|
||||
{
|
||||
// Reset the tick counter as we just recharged
|
||||
tickCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void onTick(GameTick event)
|
||||
{
|
||||
// 1000 = 100%, 500 = 50%, 0 = 0%
|
||||
int specialPercent = client.getSetting(Varbits.SPECIAL_ATTACK_PERCENT);
|
||||
// The recharge doesn't tick when at 100%
|
||||
if (specialPercent == 1000)
|
||||
{
|
||||
tickCounter = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
tickCounter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* 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.specorb;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.google.inject.Binder;
|
||||
import com.google.inject.Provides;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.events.GameTick;
|
||||
import net.runelite.client.events.VarbitChanged;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.inject.Inject;
|
||||
import java.awt.Image;
|
||||
|
||||
@PluginDescriptor(
|
||||
name = "Special Attack Orb plugin"
|
||||
)
|
||||
public class SpecOrbPlugin extends Plugin
|
||||
{
|
||||
private Image minimapOrbBackground;
|
||||
private Image specialAttackIcon;
|
||||
|
||||
@Inject
|
||||
SpecOrbOverlay overlay;
|
||||
|
||||
@Override
|
||||
public void configure(Binder binder)
|
||||
{
|
||||
binder.bind(SpecOrbOverlay.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
SpecOrbConfig getConfig(ConfigManager configManager)
|
||||
{
|
||||
return configManager.getConfig(SpecOrbConfig.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Overlay getOverlay()
|
||||
{
|
||||
return overlay;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
minimapOrbBackground = ImageIO.read(getClass().getResourceAsStream("minimap_orb_background.png"));
|
||||
specialAttackIcon = ImageIO.read(getClass().getResourceAsStream("special_orb_icon.png"));
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onVarbitChanged(VarbitChanged event)
|
||||
{
|
||||
overlay.onVarbitChanged(event);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onTick(GameTick event)
|
||||
{
|
||||
overlay.onTick(event);
|
||||
}
|
||||
|
||||
public Image getMinimapOrbBackground()
|
||||
{
|
||||
return minimapOrbBackground;
|
||||
}
|
||||
|
||||
public Image getSpecialAttackIcon()
|
||||
{
|
||||
return specialAttackIcon;
|
||||
}
|
||||
}
|
||||
@@ -26,14 +26,20 @@ package net.runelite.client.ui.overlay;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.Paint;
|
||||
import java.awt.Polygon;
|
||||
import java.awt.RadialGradientPaint;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import net.runelite.api.Actor;
|
||||
import net.runelite.api.Point;
|
||||
import net.runelite.api.SpritePixels;
|
||||
import net.runelite.api.TileObject;
|
||||
import net.runelite.client.ui.FontManager;
|
||||
|
||||
|
||||
/**
|
||||
@@ -41,6 +47,7 @@ import net.runelite.api.TileObject;
|
||||
*/
|
||||
public class OverlayUtil
|
||||
{
|
||||
|
||||
public static void renderPolygon(Graphics2D graphics, Polygon poly, Color color)
|
||||
{
|
||||
graphics.setColor(color);
|
||||
@@ -50,6 +57,143 @@ public class OverlayUtil
|
||||
graphics.fillPolygon(poly);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a minimap orb like the prayer/HP/run orbs. The background color can be set by graphics.setColor() before calling this
|
||||
*
|
||||
* @param graphics graphics to draw to
|
||||
* @param pos top left position of the orb
|
||||
* @param percentFilled how far filled the orb should be
|
||||
* @param rechargeColor color of the recharge meter of this orb. This can be used to track things like hp regen or special regen.
|
||||
* @param rechargePercentFilled how far through the recharge this stat is
|
||||
* @param minimapOrbBackground background image of the minimap orb
|
||||
* @param overlayImage
|
||||
* @param amount number to display on the orb
|
||||
* @param enabled
|
||||
*/
|
||||
public static void drawMinimapOrb(Graphics2D graphics, Point pos, double percentFilled, Color rechargeColor, double rechargePercentFilled, Image minimapOrbBackground, Image overlayImage, int amount, boolean enabled)
|
||||
{
|
||||
Color startColor = graphics.getColor();
|
||||
|
||||
Point orbPos = new Point(pos.getX() + 26, pos.getY() + 2);
|
||||
|
||||
graphics.setColor(new Color(20, 20, 20));
|
||||
// draw black background for the orb when it's partially missing
|
||||
drawOrbPercent(graphics, orbPos, 1, 28, false, false);
|
||||
graphics.setColor(startColor);
|
||||
|
||||
// draw orb with shading
|
||||
drawOrbPercent(graphics, orbPos, percentFilled, 28, true, enabled);
|
||||
|
||||
graphics.setColor(rechargeColor);
|
||||
// draw recharge
|
||||
drawOrbPercent(graphics, orbPos, rechargePercentFilled, 28, false, false);
|
||||
graphics.setColor(startColor);
|
||||
|
||||
// draw background
|
||||
graphics.drawImage(minimapOrbBackground, pos.getX(), pos.getY(), null);
|
||||
// draw overlay
|
||||
graphics.drawImage(overlayImage, pos.getX() + 32, pos.getY() + 9, null);
|
||||
|
||||
drawOrbAmount(graphics, pos, amount);//draw number on orb
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the amount text on minimap orbs. For example HP number on the HP minimap orb
|
||||
*
|
||||
* @param graphics graphics to draw on
|
||||
* @param pos start position
|
||||
* @param amount number amount
|
||||
*/
|
||||
private static void drawOrbAmount(Graphics2D graphics, Point pos, int amount)
|
||||
{
|
||||
Color startColor = graphics.getColor();
|
||||
|
||||
Font font = FontManager.getRunescapeSmallFont();
|
||||
graphics.setFont(font);
|
||||
|
||||
FontMetrics fm = graphics.getFontMetrics();
|
||||
|
||||
String numberString = Integer.toString(amount);
|
||||
Point numberPos = new Point(pos.getX() + 22 - fm.stringWidth(numberString), pos.getY() + 26);
|
||||
graphics.setColor(Color.black);
|
||||
graphics.drawString(numberString, numberPos.getX() + 1, numberPos.getY() + 1);//black shadow on text
|
||||
graphics.setColor(Color.green);
|
||||
graphics.drawString(numberString, numberPos.getX(), numberPos.getY());
|
||||
|
||||
graphics.setColor(startColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a orb similar to the health/prayer orbs already in the client.
|
||||
* This has a slight shadow effect similar to the clients orbs if shadow = true
|
||||
*
|
||||
* @param graphics graphics to draw to
|
||||
* @param pos Top left position of the orb
|
||||
* @param percent 0.0-1.0 percent of how filled the orb is
|
||||
* @param diameter diameter of the orb
|
||||
* @param shadow draw shadow
|
||||
*/
|
||||
private static void drawOrbPercent(Graphics2D graphics, Point pos, double percent, int diameter, boolean shadow, boolean enabled)
|
||||
{
|
||||
BufferedImage bufferedImage = new BufferedImage(diameter, diameter, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D bufferedImageGraphics = bufferedImage.createGraphics();
|
||||
float[] dist = {0.2f, 1f};
|
||||
|
||||
Color setColor = graphics.getColor();
|
||||
|
||||
int r = setColor.getRed();
|
||||
int g = setColor.getGreen();
|
||||
int b = setColor.getBlue();
|
||||
int a = setColor.getAlpha();
|
||||
|
||||
Paint startPaint = bufferedImageGraphics.getPaint();
|
||||
|
||||
if (shadow)
|
||||
{
|
||||
float darkenMultiplier = 0.4f;
|
||||
Point2D center = new Point2D.Float(diameter / 2.7f, diameter / 2.7f);
|
||||
|
||||
if (enabled)
|
||||
{
|
||||
// Darken and move center to make it look like the orb is pressed down
|
||||
darkenMultiplier = 0.20f;
|
||||
center = new Point2D.Float((diameter / 1.8f), (diameter / 1.8f));
|
||||
dist = new float[]{0.7f, 1f};
|
||||
}
|
||||
|
||||
// Darken the base color to create a shadow effect on the edges of the orb
|
||||
r *= darkenMultiplier;
|
||||
g *= darkenMultiplier;
|
||||
b *= darkenMultiplier;
|
||||
|
||||
Color[] colors = {setColor, new Color(r, g, b, a)};
|
||||
|
||||
// Divided by 2.7f for a gradient in the top left of the orb
|
||||
RadialGradientPaint p = new RadialGradientPaint(center,
|
||||
diameter / 2.0f, dist, colors);
|
||||
|
||||
bufferedImageGraphics.setPaint(p);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
bufferedImageGraphics.setColor(setColor);
|
||||
}
|
||||
|
||||
bufferedImageGraphics.fillArc(0, 0, diameter, diameter, 0, 360);
|
||||
if (percent < 1)
|
||||
{
|
||||
// Clear the top part of the orb. if we input 90% we need to clear the top 10%
|
||||
bufferedImageGraphics.setBackground(new Color(255, 255, 255, 0));
|
||||
bufferedImageGraphics.clearRect(0, 0, diameter, (int) ((diameter) * (1 - percent)));
|
||||
}
|
||||
|
||||
graphics.drawImage(bufferedImage, pos.getX(), pos.getY(), null);
|
||||
|
||||
bufferedImageGraphics.setPaint(startPaint);
|
||||
}
|
||||
|
||||
public static void renderMinimapLocation(Graphics2D graphics, Point mini, Color color)
|
||||
{
|
||||
graphics.setColor(color);
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 860 B |
Reference in New Issue
Block a user