runelite-client: update pc plugin for widget changes, and cleanup

This commit is contained in:
Kyle Fricilone
2017-06-09 22:26:03 -04:00
committed by Adam
parent 892bf245d8
commit 9ce3852863
3 changed files with 66 additions and 69 deletions

View File

@@ -30,23 +30,27 @@ class WidgetID
static final int INVENTORY_GROUP_ID = 149; static final int INVENTORY_GROUP_ID = 149;
static final int PESTRCONTROL_GROUP_ID = 408; static final int PESTRCONTROL_GROUP_ID = 408;
static final int CLAN_CHAT_GROUP_ID = 7; static final int CLAN_CHAT_GROUP_ID = 7;
static final int MINIMAP_GROUP_ID = 160;
static class PestControl static class PestControl
{ {
static final int PURPLE_SHIELD = 18; static final int PURPLE_SHIELD = 21;
static final int BLUE_SHIELD = 20; static final int BLUE_SHIELD = 23;
static final int YELLOW_SHIELD = 22; static final int YELLOW_SHIELD = 25;
static final int RED_SHIELD = 24; static final int RED_SHIELD = 27;
static final int PURPLE_HEALTH = 14; static final int PURPLE_HEALTH = 17;
static final int BLUE_HEALTH = 15; static final int BLUE_HEALTH = 18;
static final int YELLOW_HEALTH = 16; static final int YELLOW_HEALTH = 19;
static final int RED_HEALTH = 17; static final int RED_HEALTH = 20;
static final int PURPLE_ICON = 10; static final int PURPLE_ICON = 13;
static final int BLUE_ICON = 11; static final int BLUE_ICON = 14;
static final int YELLOW_ICON = 12; static final int YELLOW_ICON = 15;
static final int RED_ICON = 13; static final int RED_ICON = 16;
static final int ACTIVITY_BAR = 6;
static final int ACTIVITY_PROGRESS = 8;
} }
static class ClanChat static class ClanChat
@@ -56,8 +60,13 @@ class WidgetID
static final int OWNER = 5; static final int OWNER = 5;
} }
public static class Bank static class Bank
{ {
static final int ITEM_CONTAINER = 12; static final int ITEM_CONTAINER = 12;
} }
static class Minimap
{
static final int XP_ORB = 1;
}
} }

View File

@@ -40,12 +40,17 @@ public enum WidgetInfo
PESTCONTROL_BLUE_ICON(WidgetID.PESTRCONTROL_GROUP_ID, WidgetID.PestControl.BLUE_ICON), PESTCONTROL_BLUE_ICON(WidgetID.PESTRCONTROL_GROUP_ID, WidgetID.PestControl.BLUE_ICON),
PESTCONTROL_YELLOW_ICON(WidgetID.PESTRCONTROL_GROUP_ID, WidgetID.PestControl.YELLOW_ICON), PESTCONTROL_YELLOW_ICON(WidgetID.PESTRCONTROL_GROUP_ID, WidgetID.PestControl.YELLOW_ICON),
PESTCONTROL_RED_ICON(WidgetID.PESTRCONTROL_GROUP_ID, WidgetID.PestControl.RED_ICON), PESTCONTROL_RED_ICON(WidgetID.PESTRCONTROL_GROUP_ID, WidgetID.PestControl.RED_ICON),
PESTCONTROL_ACTIVITY_BAR(WidgetID.PESTRCONTROL_GROUP_ID, WidgetID.PestControl.ACTIVITY_BAR),
PESTCONTROL_ACTIVITY_PROGRESS(WidgetID.PESTRCONTROL_GROUP_ID, WidgetID.PestControl.ACTIVITY_PROGRESS),
CLAN_CHAT_TITLE(WidgetID.CLAN_CHAT_GROUP_ID, WidgetID.ClanChat.TITLE), CLAN_CHAT_TITLE(WidgetID.CLAN_CHAT_GROUP_ID, WidgetID.ClanChat.TITLE),
CLAN_CHAT_NAME(WidgetID.CLAN_CHAT_GROUP_ID, WidgetID.ClanChat.NAME), CLAN_CHAT_NAME(WidgetID.CLAN_CHAT_GROUP_ID, WidgetID.ClanChat.NAME),
CLAN_CHAT_OWNER(WidgetID.CLAN_CHAT_GROUP_ID, WidgetID.ClanChat.OWNER), CLAN_CHAT_OWNER(WidgetID.CLAN_CHAT_GROUP_ID, WidgetID.ClanChat.OWNER),
BANK_ITEM_CONTAINER(WidgetID.BANK_GROUP_ID, WidgetID.Bank.ITEM_CONTAINER); BANK_ITEM_CONTAINER(WidgetID.BANK_GROUP_ID, WidgetID.Bank.ITEM_CONTAINER),
MINIMAP_XP_ORG(WidgetID.MINIMAP_GROUP_ID, WidgetID.Minimap.XP_ORB);
private final int groupId; private final int groupId;
private final int childId; private final int childId;

View File

@@ -25,19 +25,18 @@
*/ */
package net.runelite.client.plugins.pestcontrol; package net.runelite.client.plugins.pestcontrol;
import java.awt.BasicStroke;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Font; import java.awt.Font;
import java.awt.FontMetrics; import java.awt.FontMetrics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import net.runelite.api.Actor; import java.util.Arrays;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.GameState; import net.runelite.api.GameState;
import net.runelite.api.NPC; import net.runelite.api.NPC;
import net.runelite.api.Point; import net.runelite.api.Query;
import net.runelite.api.queries.NPCQuery;
import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo; import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.RuneLite; import net.runelite.client.RuneLite;
@@ -47,6 +46,7 @@ import static net.runelite.client.plugins.pestcontrol.Portal.RED;
import static net.runelite.client.plugins.pestcontrol.Portal.YELLOW; import static net.runelite.client.plugins.pestcontrol.Portal.YELLOW;
import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -106,26 +106,9 @@ public class PestControlOverlay extends Overlay
private void renderSpinners(Graphics2D graphics) private void renderSpinners(Graphics2D graphics)
{ {
NPC[] npcs = client.getNpcs(); Query query = new NPCQuery().nameEquals("Spinner");
if (npcs == null) NPC[] result = client.runQuery(query);
{ Arrays.stream(result).forEach(npc -> OverlayUtil.renderActorOverlay(graphics, npc, npc.getName(), Color.CYAN));
return;
}
for (NPC npc : npcs)
{
if (npc == null)
{
continue;
}
String name = npc.getName();
if (name.toLowerCase().contains("spinner"))
{
renderActorOverlay(graphics, npc, name, Color.CYAN);
}
}
} }
private void renderPortalWidgets(Graphics2D graphics) private void renderPortalWidgets(Graphics2D graphics)
@@ -197,58 +180,58 @@ public class PestControlOverlay extends Overlay
{ {
renderWidgetOverlay(graphics, portal, "NEXT", Color.ORANGE); renderWidgetOverlay(graphics, portal, "NEXT", Color.ORANGE);
} }
renderProgressWidget(graphics);
} }
private void renderActorOverlay(Graphics2D graphics, Actor actor, String text, Color color) private void renderProgressWidget(Graphics2D graphics)
{ {
Polygon poly = actor.getCanvasTilePoly(); Widget bar = client.getWidget(WidgetInfo.PESTCONTROL_ACTIVITY_BAR).getChild(0);
if (poly != null) Rectangle2D bounds = bar.getBounds().getBounds2D();
Widget prgs = client.getWidget(WidgetInfo.PESTCONTROL_ACTIVITY_PROGRESS).getChild(0);
int perc = (int) ((prgs.getBounds().getWidth() / bounds.getWidth()) * 100);
Color color = Color.GREEN;
if (perc < 25)
{ {
graphics.setColor(color); color = Color.RED;
graphics.setStroke(new BasicStroke(2));
graphics.drawPolygon(poly);
graphics.setColor(new Color(0, 0, 0, 50));
graphics.fillPolygon(poly);
} }
Point minimapLocation = actor.getMinimapLocation(); String text = String.valueOf(perc) + "%";
if (minimapLocation != null)
{
graphics.setColor(color);
graphics.fillOval(minimapLocation.getX(), minimapLocation.getY(), 5, 5);
graphics.setColor(Color.WHITE);
graphics.setStroke(new BasicStroke(1));
graphics.drawOval(minimapLocation.getX(), minimapLocation.getY(), 5, 5);
}
Point textLocation = actor.getCanvasTextLocation(graphics, text, actor.getModelHeight() + 40); FontMetrics fm = graphics.getFontMetrics();
if (textLocation != null) Rectangle2D textBounds = fm.getStringBounds(text, graphics);
{ int x = (int) (bounds.getX() - textBounds.getWidth());
int x = textLocation.getX(); int y = (int) (bounds.getY() + fm.getHeight() - 2);
int y = textLocation.getY();
graphics.setColor(Color.BLACK); graphics.setColor(Color.BLACK);
graphics.drawString(text, x + 1, y + 1); graphics.drawString(text, x + 1, y + 1);
graphics.setColor(color);
graphics.setColor(color); graphics.drawString(text, x, y);
graphics.drawString(text, x, y);
}
} }
private void renderWidgetOverlay(Graphics2D graphics, Portal portal, String text, Color color) private void renderWidgetOverlay(Graphics2D graphics, Portal portal, String text, Color color)
{ {
Widget shield = client.getWidget(portal.getShield()); Widget shield = client.getWidget(portal.getShield());
Widget icon = client.getWidget(portal.getIcon()); Widget icon = client.getWidget(portal.getIcon());
Widget hp = client.getWidget(portal.getHitpoints());
Widget bar = client.getWidget(WidgetInfo.PESTCONTROL_ACTIVITY_BAR).getChild(0);
Rectangle2D barBounds = bar.getBounds().getBounds2D();
// create one rectangle from two different widget bounds // create one rectangle from two different widget bounds
Rectangle2D bounds = union(shield.getBounds().getBounds2D(), icon.getBounds().getBounds2D()); Rectangle2D bounds = union(shield.getBounds().getBounds2D(), icon.getBounds().getBounds2D());
bounds = union(bounds, hp.getBounds().getBounds2D());
graphics.setColor(color); graphics.setColor(color);
graphics.draw(bounds); graphics.draw(new Rectangle2D.Double(bounds.getX(), bounds.getY() - 2, bounds.getWidth(), bounds.getHeight() - 3));
FontMetrics fm = graphics.getFontMetrics(); FontMetrics fm = graphics.getFontMetrics();
Rectangle2D textBounds = fm.getStringBounds(text, graphics); Rectangle2D textBounds = fm.getStringBounds(text, graphics);
int x = (int) (bounds.getX() + (bounds.getWidth() / 2) - (textBounds.getWidth() / 2)); int x = (int) (bounds.getX() + (bounds.getWidth() / 2) - (textBounds.getWidth() / 2));
int y = (int) (bounds.getY() + bounds.getHeight() + textBounds.getHeight()); int y = (int) (bounds.getY() + bounds.getHeight() + textBounds.getHeight() + barBounds.getHeight());
graphics.setColor(Color.BLACK); graphics.setColor(Color.BLACK);
graphics.drawString(text, x + 1, y + 1); graphics.drawString(text, x + 1, y + 1);
@@ -283,4 +266,4 @@ public class PestControlOverlay extends Overlay
{ {
return widget.getText().trim().equals("0"); return widget.getText().trim().equals("0");
} }
} }