Skip to content

Commit

Permalink
Hide ground items when interface is open (runelite#160)
Browse files Browse the repository at this point in the history
* Add viewport WidgetInfo

* Add side panels varbit

* Change ground items plugin to only display within viewport

* Change viewport ids to main interface viewport

* Hide ground items when viewport interfaces are open

* Change fixed viewport widget id
  • Loading branch information
devinfrench authored and Adam- committed Oct 7, 2017
1 parent 3e6be6d commit 0b3da3b
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 14 deletions.
7 changes: 6 additions & 1 deletion runelite-api/src/main/java/net/runelite/api/Varbits.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ public enum Varbits
* Venom - 1,000,000 (6dmg/hit) - 1,000,008 (20 dmg/hit)
*/
POISON(102, 0, 5),
VENOM(102, 6, 9);
VENOM(102, 6, 9),

/**
* Options
*/
SIDE_PANELS(4607, 1055, 8, 8);

/**
* varbit id
Expand Down
10 changes: 10 additions & 0 deletions runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class WidgetID
static final int MINIMAP_GROUP_ID = 160;
static final int LOGIN_CLICK_TO_PLAY_GROUP_ID = 378;
static final int CLUE_SCROLL_GROUP_ID = 203;
static final int FIXED_VIEWPORT_GROUP_ID = 548;
static final int RESIZABLE_VIEWPORT_OLD_SCHOOL_BOX_GROUP_ID = 161;
static final int RESIZABLE_VIEWPORT_BOTTOM_LINE_GROUP_ID = 164;

static class PestControl
{
Expand Down Expand Up @@ -92,4 +95,11 @@ static class Minimap
{
static final int XP_ORB = 1;
}

static class Viewport
{
static final int FIXED_VIEWPORT = 20;
static final int RESIZABLE_VIEWPORT_OLD_SCHOOL_BOX = 12;
static final int RESIZABLE_VIEWPORT_BOTTOM_LINE = 12;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ public enum WidgetInfo

MINIMAP_XP_ORB(WidgetID.MINIMAP_GROUP_ID, WidgetID.Minimap.XP_ORB),

LOGIN_CLICK_TO_PLAY_SCREEN(WidgetID.LOGIN_CLICK_TO_PLAY_GROUP_ID, 0);
LOGIN_CLICK_TO_PLAY_SCREEN(WidgetID.LOGIN_CLICK_TO_PLAY_GROUP_ID, 0),

FIXED_VIEWPORT(WidgetID.FIXED_VIEWPORT_GROUP_ID, WidgetID.Viewport.FIXED_VIEWPORT),
RESIZABLE_VIEWPORT_OLD_SCHOOL_BOX(WidgetID.RESIZABLE_VIEWPORT_OLD_SCHOOL_BOX_GROUP_ID, WidgetID.Viewport.RESIZABLE_VIEWPORT_OLD_SCHOOL_BOX),
RESIZABLE_VIEWPORT_BOTTOM_LINE(WidgetID.RESIZABLE_VIEWPORT_BOTTOM_LINE_GROUP_ID, WidgetID.Viewport.RESIZABLE_VIEWPORT_BOTTOM_LINE);


private final int groupId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
Expand All @@ -48,6 +49,8 @@
import net.runelite.api.Point;
import net.runelite.api.Region;
import net.runelite.api.Tile;
import net.runelite.api.Varbits;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.game.ItemManager;
import net.runelite.client.RuneLite;
Expand Down Expand Up @@ -121,11 +124,41 @@ public Dimension render(Graphics2D graphics)
return null;
}

//Widget bank = client.getWidget(WidgetInfo.BANK_ITEM_CONTAINER);
//if (bank != null && !bank.isHidden())
//{
// return null;
//}
WidgetInfo viewportInfo = WidgetInfo.FIXED_VIEWPORT;
if (client.isResized())
{
if (client.getSetting(Varbits.SIDE_PANELS) == 1)
{
viewportInfo = WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE;
}
else
{
viewportInfo = WidgetInfo.RESIZABLE_VIEWPORT_OLD_SCHOOL_BOX;
}
}
Widget viewport = client.getWidget(viewportInfo);

if (viewport != null)
{
Widget[] subViewports = viewport.getStaticChildren();
if (subViewports.length > 0)
{
for (Widget w : subViewports)
{
if (w.getNestedChildren().length > 0)
{
return null;
}
}
}
else
{
if (viewport.getNestedChildren().length > 0)
{
return null;
}
}
}

// gets the hidden/highlighted items from the text box in the config
String configItems = config.getHiddenItems();
Expand Down Expand Up @@ -199,6 +232,13 @@ public Dimension render(Graphics2D graphics)

for (int i = 0; i < itemIds.size(); ++i)
{
Point point = itemLayer.getCanvasLocation();
// if the item is offscreen, don't bother drawing it
if (point == null || !pointInWidget(point, viewport))
{
continue;
}

int itemId = itemIds.get(i);
int quantity = items.get(itemId);
ItemComposition item = itemCache.getUnchecked(itemId);
Expand Down Expand Up @@ -270,13 +310,6 @@ else if (cost >= LOW_VALUE) // 20,000 gp
String itemString = itemStringBuilder.toString();
itemStringBuilder.setLength(0);

Point point = itemLayer.getCanvasLocation();
// if the item is offscreen, don't bother drawing it
if (point == null)
{
continue;
}

int screenX = point.getX() + 2 - (fm.stringWidth(itemString) / 2);

// Drawing the shadow for the text, 1px on both x and y
Expand All @@ -291,4 +324,14 @@ else if (cost >= LOW_VALUE) // 20,000 gp

return null;
}

private boolean pointInWidget(Point point, Widget widget)
{
if (widget != null)
{
Rectangle bounds = widget.getBounds();
return bounds != null && bounds.contains(new java.awt.Point(point.getX(), point.getY()));
}
return false;
}
}

0 comments on commit 0b3da3b

Please sign in to comment.