Hp bar work

This commit is contained in:
Adam
2016-04-23 14:50:17 -04:00
parent 755d013873
commit 6e8338455c
2 changed files with 68 additions and 1 deletions

View File

@@ -1,6 +1,9 @@
package net.runelite.client.plugins.opponentinfo;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import net.runelite.api.Actor;
import net.runelite.api.Client;
import net.runelite.api.Player;
@@ -9,6 +12,21 @@ import net.runelite.client.plugins.Plugin;
public class OpponentInfo extends Plugin
{
private static final int WIDTH = 140;
private static final int HEIGHT = 75;
private static final int TOP_BORDER = 2;
private static final int BOTTOM_BORDER = 2;
private static final int BAR_WIDTH = 124;
private static final int BAR_HEIGHT = 20;
private static final Color BACKGROUND = new Color(Color.gray.getRed(), Color.gray.getGreen(), Color.gray.getBlue(), 127);
private static final Color HP_GREEN = new Color(0, 146, 54, 230);
private static final Color HP_RED = new Color(102, 15, 16, 230);
private final BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
private Actor getOpponent()
{
Client client = RuneLite.getClient();
@@ -27,6 +45,53 @@ public class OpponentInfo extends Plugin
if (opponent == null)
return;
graphics.drawString(opponent.getName() + " " + opponent.getHealth() + "/" + opponent.getMaxHealth(), 42, 42);
int cur = opponent.getHealth();
int max = opponent.getMaxHealth();
Graphics g = image.getGraphics();
FontMetrics fm = g.getFontMetrics();
int height = TOP_BORDER
+ fm.getHeight(); // opponent name
if (max > 0)
height += 1 // between name and hp bar
+ BAR_HEIGHT; // bar
height += BOTTOM_BORDER;
g.setColor(BACKGROUND);
g.fillRect(0, 0, image.getWidth(), height);
String str = opponent.getName();
int x = (image.getWidth() - fm.stringWidth(str)) / 2;
g.setColor(Color.white);
g.drawString(str, x, fm.getHeight() + TOP_BORDER);
// hp bar
if (max > 0)
{
float percent = (float) cur / (float) max;
if (percent > 100f)
percent = 100f;
int barWidth = (int) (percent * (float) BAR_WIDTH);
int barY = TOP_BORDER + fm.getHeight() + 1;
g.setColor(HP_GREEN);
g.fillRect((WIDTH - BAR_WIDTH) / 2, barY, barWidth, BAR_HEIGHT);
g.setColor(HP_RED);
g.fillRect(((WIDTH - BAR_WIDTH) / 2) + barWidth, barY, BAR_WIDTH - barWidth, BAR_HEIGHT);
str = cur + " / " + max;
x = (image.getWidth() - fm.stringWidth(str)) / 2;
g.setColor(Color.white);
g.drawString(str, x, barY + fm.getHeight());
}
g.dispose();
graphics.drawImage(image, 10, 25, null);
}
}

View File

@@ -20,6 +20,8 @@ public class RSCanvasCallback
//clientGraphics.drawString("something, something 2", 42, 42);
new OpponentInfo().draw(clientGraphics);
clientGraphics.dispose();
superGraphics.drawImage(clientBuffer, 0, 0, null);
return gameBuffer.getGraphics();