inventory-grid: show grid when viewing bank

Co-authored-by: while-loop <cvballa3g0@gmail.com>
This commit is contained in:
Adam
2020-08-02 11:48:34 -04:00
committed by Adam
parent df21c1f6f9
commit 9fef3ad47d

View File

@@ -72,20 +72,30 @@ class InventoryGridOverlay extends Overlay
@Override
public Dimension render(Graphics2D graphics)
{
final Widget if1DraggingWidget = client.getIf1DraggedWidget();
final Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY);
if (if1DraggingWidget == null || if1DraggingWidget != inventoryWidget)
final Widget draggingWidget = getDraggedWidget();
if (draggingWidget == null)
{
initialMousePoint = null;
hoverActive = false;
// not dragging
return null;
}
// grid is only supported on bank inventory and inventory
Widget inventoryWidget = draggingWidget.isIf3() ?
client.getWidget(WidgetInfo.BANK_INVENTORY_ITEMS_CONTAINER) :
client.getWidget(WidgetInfo.INVENTORY);
// with if3 the dragged widget is a child of the inventory, with if1 it is an item of the inventory (and the same widget)
if (inventoryWidget == null || (draggingWidget.isIf3() ? draggingWidget.getParent() != inventoryWidget : draggingWidget != inventoryWidget))
{
return null;
}
final net.runelite.api.Point mouse = client.getMouseCanvasPosition();
final Point mousePoint = new Point(mouse.getX(), mouse.getY());
final int if1DraggedItemIndex = client.getIf1DraggedItemIndex();
final WidgetItem draggedItem = inventoryWidget.getWidgetItem(if1DraggedItemIndex);
final int draggedItemIndex = draggingWidget.isIf3() ? draggingWidget.getIndex() : client.getIf1DraggedItemIndex();
final WidgetItem draggedItem = getWidgetItem(inventoryWidget, draggedItemIndex);
final Rectangle initialBounds = draggedItem.getCanvasBounds(false);
if (initialMousePoint == null)
@@ -104,8 +114,7 @@ class InventoryGridOverlay extends Overlay
for (int i = 0; i < INVENTORY_SIZE; ++i)
{
WidgetItem targetWidgetItem = inventoryWidget.getWidgetItem(i);
final WidgetItem targetWidgetItem = getWidgetItem(inventoryWidget, i);
final Rectangle bounds = targetWidgetItem.getCanvasBounds(false);
boolean inBounds = bounds.contains(mousePoint);
@@ -130,6 +139,29 @@ class InventoryGridOverlay extends Overlay
return null;
}
private Widget getDraggedWidget()
{
Widget widget = client.getIf1DraggedWidget(); // if1 drag
if (widget != null)
{
return widget;
}
return client.getDraggedWidget(); // if3 drag
}
private static WidgetItem getWidgetItem(Widget parentWidget, int idx)
{
if (parentWidget.isIf3())
{
Widget wi = parentWidget.getChild(idx);
return new WidgetItem(wi.getItemId(), wi.getItemQuantity(), -1, wi.getBounds(), parentWidget, wi.getBounds());
}
else
{
return parentWidget.getWidgetItem(idx);
}
}
private void drawItem(Graphics2D graphics, Rectangle bounds, WidgetItem item)
{
if (item.getId() == -1)