widgetitem: associate Widget with WidgetItem

This commit is contained in:
Adam
2019-04-19 14:27:49 -04:00
parent a45ab3c887
commit 8bfc0f2b21
3 changed files with 16 additions and 36 deletions

View File

@@ -26,6 +26,7 @@ package net.runelite.api.widgets;
import java.awt.Rectangle; import java.awt.Rectangle;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString; import lombok.ToString;
import net.runelite.api.Point; import net.runelite.api.Point;
@@ -34,55 +35,34 @@ import net.runelite.api.Point;
*/ */
@AllArgsConstructor @AllArgsConstructor
@ToString @ToString
@Getter
public class WidgetItem public class WidgetItem
{ {
private final int id;
private final int quantity;
private final int index;
private final Rectangle canvasBounds;
/** /**
* Gets the ID of the item represented. * The ID of the item represented.
* *
* @return the items ID
* @see net.runelite.api.ItemID * @see net.runelite.api.ItemID
*/ */
public int getId() private final int id;
{
return id;
}
/** /**
* Gets the quantity of the represented item. * The quantity of the represented item.
*
* @return the items quantity
*/ */
public int getQuantity() private final int quantity;
{
return quantity;
}
/** /**
* Gets the index position of this WidgetItem inside its parents * The index position of this WidgetItem inside its parents
* WidgetItem array. * WidgetItem array.
* *
* @return the index in the parent widget
* @see Widget#getWidgetItems() * @see Widget#getWidgetItems()
*/ */
public int getIndex() private final int index;
{
return index;
}
/** /**
* Gets the area where the widget is drawn on the canvas. * The area where the widget is drawn on the canvas.
*
* @return the occupied area of the widget
*/ */
public Rectangle getCanvasBounds() private final Rectangle canvasBounds;
{ /**
return canvasBounds; * The widget which contains this item.
} */
private final Widget widget;
/** /**
* Gets the upper-left coordinate of where the widget is being drawn * Gets the upper-left coordinate of where the widget is being drawn

View File

@@ -1355,7 +1355,7 @@ public abstract class RSClientMixin implements RSClient
{ {
if (renderX >= minX && renderX <= maxX && renderY >= minY && renderY <= maxY) if (renderX >= minX && renderX <= maxX && renderY >= minY && renderY <= maxY)
{ {
WidgetItem widgetItem = new WidgetItem(widget.getItemId(), widget.getItemQuantity(), -1, widget.getBounds()); WidgetItem widgetItem = new WidgetItem(widget.getItemId(), widget.getItemQuantity(), -1, widget.getBounds(), widget);
callbacks.drawItem(widget.getItemId(), widgetItem); callbacks.drawItem(widget.getItemId(), widgetItem);
} }
} }

View File

@@ -300,7 +300,7 @@ public abstract class RSWidgetMixin implements RSWidget
int itemY = widgetCanvasLocation.getY() + ((ITEM_SLOT_SIZE + yPitch) * row); int itemY = widgetCanvasLocation.getY() + ((ITEM_SLOT_SIZE + yPitch) * row);
Rectangle bounds = new Rectangle(itemX - 1, itemY - 1, ITEM_SLOT_SIZE, ITEM_SLOT_SIZE); Rectangle bounds = new Rectangle(itemX - 1, itemY - 1, ITEM_SLOT_SIZE, ITEM_SLOT_SIZE);
return new WidgetItem(itemId - 1, itemQuantity, index, bounds); return new WidgetItem(itemId - 1, itemQuantity, index, bounds, this);
} }
@Inject @Inject