Java Code Examples for net.runelite.api.widgets.WidgetItem#getId()
The following examples show how to use
net.runelite.api.widgets.WidgetItem#getId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AlchemyRoom.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void over(Graphics2D graphics) { if (!inside() || !config.alchemy() || best == null) { return; } Widget inventory = client.getWidget(WidgetInfo.INVENTORY); if (inventory.isHidden()) { return; } for (WidgetItem item : inventory.getWidgetItems()) { if (item.getId() != best.getId()) { continue; } drawItem(graphics, item, Color.GREEN); } }
Example 2
Source File: AlchemyRoom.java From plugins with GNU General Public License v3.0 | 6 votes |
@Override public void over(Graphics2D graphics) { if (!inside() || !config.alchemy() || best == null) { return; } Widget inventory = client.getWidget(WidgetInfo.INVENTORY); if (inventory.isHidden()) { return; } for (WidgetItem item : inventory.getWidgetItems()) { if (item.getId() != best.getId()) { continue; } drawItem(graphics, item); } }
Example 3
Source File: OneClickPlugin.java From ExternalPlugins with GNU General Public License v3.0 | 6 votes |
public Pair<Integer, Integer> findItem(int id) { final Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY); final List<WidgetItem> itemList = (List<WidgetItem>) inventoryWidget.getWidgetItems(); for (int i = itemList.size() - 1; i >= 0; i--) { final WidgetItem item = itemList.get(i); if (item.getId() == id) { return Pair.of(item.getId(), item.getIndex()); } } return Pair.of(-1, -1); }
Example 4
Source File: AboveWidgetsOverlay.java From plugins with GNU General Public License v3.0 | 6 votes |
private void renderInventoryHighlights(Graphics2D graphics, int itemID, Color color) { Widget inventory = client.getWidget(WidgetInfo.INVENTORY); if (inventory == null || inventory.isHidden() || itemID == -1) { return; } Color highlight = new Color(color.getRed(), color.getGreen(), color.getBlue(), 150); BufferedImage image = ImageUtil.fillImage(client.createItemSprite(itemID, 300, 2, 0, 0, true, 710).toBufferedImage(), highlight); for (WidgetItem item : inventory.getWidgetItems()) { if (item.getId() == itemID) { OverlayUtil.renderImageLocation(graphics, item.getCanvasLocation(), image); //The item's text quantity is rendered after the sprite's image is rendered so that the text appears on top if (item.getQuantity() > 1) { OverlayUtil.renderTextLocation(graphics, new Point(item.getCanvasLocation().getX() + OFFSET_X_TEXT_QUANTITY, item.getCanvasLocation().getY() + OFFSET_Y_TEXT_QUANTITY), String.valueOf(item.getQuantity()), Color.YELLOW); } } } }
Example 5
Source File: CustomSwapper.java From ExternalPlugins with GNU General Public License v3.0 | 5 votes |
private Rectangle invBounds(int id) { final Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY); for (WidgetItem item : inventoryWidget.getWidgetItems()) { if (item.getId() == id) { return item.getCanvasBounds(); } } return null; }
Example 6
Source File: InventoryGridOverlay.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
private void drawItem(Graphics2D graphics, Rectangle bounds, WidgetItem item) { if (item.getId() == -1) { return; } final BufferedImage draggedItemImage = itemManager.getImage(item.getId(), item.getQuantity(), false); final int x = (int) bounds.getX(); final int y = (int) bounds.getY(); graphics.setComposite(AlphaComposite.SrcOver.derive(0.3f)); graphics.drawImage(draggedItemImage, x, y, null); graphics.setComposite(AlphaComposite.SrcOver); }
Example 7
Source File: WidgetInspectorOverlay.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
private void renderWiw(Graphics2D g, Object wiw, Color color) { g.setColor(color); if (wiw instanceof WidgetItem) { WidgetItem wi = (WidgetItem) wiw; Rectangle bounds = wi.getCanvasBounds(); g.draw(bounds); String text = wi.getId() + ""; FontMetrics fm = g.getFontMetrics(); Rectangle2D textBounds = fm.getStringBounds(text, g); int textX = (int) (bounds.getX() + (bounds.getWidth() / 2) - (textBounds.getWidth() / 2)); int textY = (int) (bounds.getY() + (bounds.getHeight() / 2) + (textBounds.getHeight() / 2)); g.setColor(Color.BLACK); g.drawString(text, textX + 1, textY + 1); g.setColor(Color.ORANGE); g.drawString(text, textX, textY); } else { Widget w = (Widget) wiw; g.draw(w.getBounds()); } }
Example 8
Source File: DevToolsOverlay.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
private void renderInventory(Graphics2D graphics) { Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY); if (inventoryWidget == null || inventoryWidget.isHidden()) { return; } for (WidgetItem item : inventoryWidget.getWidgetItems()) { Rectangle slotBounds = item.getCanvasBounds(); String idText = "" + item.getId(); FontMetrics fm = graphics.getFontMetrics(); Rectangle2D textBounds = fm.getStringBounds(idText, graphics); int textX = (int) (slotBounds.getX() + (slotBounds.getWidth() / 2) - (textBounds.getWidth() / 2)); int textY = (int) (slotBounds.getY() + (slotBounds.getHeight() / 2) + (textBounds.getHeight() / 2)); graphics.setColor(new Color(255, 255, 255, 65)); graphics.fill(slotBounds); graphics.setColor(Color.BLACK); graphics.drawString(idText, textX + 1, textY + 1); graphics.setColor(YELLOW); graphics.drawString(idText, textX, textY); } }
Example 9
Source File: Hooks.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void drawItem(int itemId, WidgetItem widgetItem) { // Empty bank item if (widgetItem.getId() != NullItemID.NULL_6512) { overlayManager.getItemWidgets().add(widgetItem); } }
Example 10
Source File: CustomSwapper.java From ExternalPlugins with GNU General Public License v3.0 | 5 votes |
private List<Rectangle> listOfBounds(int id) { final Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY); final List<Rectangle> bounds = new ArrayList<>(); for (WidgetItem item : inventoryWidget.getWidgetItems()) { if (item.getId() == id) { bounds.add(item.getCanvasBounds()); } } return bounds; }
Example 11
Source File: InventoryGridOverlay.java From plugins with GNU General Public License v3.0 | 5 votes |
private void drawItem(Graphics2D graphics, Rectangle bounds, WidgetItem item) { if (item.getId() == -1) { return; } final BufferedImage draggedItemImage = itemManager.getImage(item.getId(), item.getQuantity(), false); final int x = (int) bounds.getX(); final int y = (int) bounds.getY(); graphics.setComposite(AlphaComposite.SrcOver.derive(0.3f)); graphics.drawImage(draggedItemImage, x, y, null); graphics.setComposite(AlphaComposite.SrcOver); }
Example 12
Source File: ZalcanoUtil.java From plugins with GNU General Public License v3.0 | 5 votes |
int countItemInInventory(int itemID) { int i = 0; Widget widget = client.getWidget(WidgetInfo.INVENTORY); for (WidgetItem widgetItem : widget.getWidgetItems()) { if (widgetItem.getId() == itemID) { i++; } } return i; }
Example 13
Source File: WidgetInspectorOverlay.java From plugins with GNU General Public License v3.0 | 5 votes |
private void renderWiw(Graphics2D g, Object wiw, Color color) { g.setColor(color); if (wiw instanceof WidgetItem) { WidgetItem wi = (WidgetItem) wiw; Rectangle bounds = wi.getCanvasBounds(); g.draw(bounds); String text = wi.getId() + ""; FontMetrics fm = g.getFontMetrics(); Rectangle2D textBounds = fm.getStringBounds(text, g); int textX = (int) (bounds.getX() + (bounds.getWidth() / 2) - (textBounds.getWidth() / 2)); int textY = (int) (bounds.getY() + (bounds.getHeight() / 2) + (textBounds.getHeight() / 2)); g.setColor(Color.BLACK); g.drawString(text, textX + 1, textY + 1); g.setColor(Color.ORANGE); g.drawString(text, textX, textY); } else { Widget w = (Widget) wiw; g.draw(w.getBounds()); } }
Example 14
Source File: DevToolsOverlay.java From plugins with GNU General Public License v3.0 | 5 votes |
private void renderInventory(Graphics2D graphics) { Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY); if (inventoryWidget == null || inventoryWidget.isHidden()) { return; } for (WidgetItem item : inventoryWidget.getWidgetItems()) { Rectangle slotBounds = item.getCanvasBounds(); String idText = "" + item.getId(); FontMetrics fm = graphics.getFontMetrics(); Rectangle2D textBounds = fm.getStringBounds(idText, graphics); int textX = (int) (slotBounds.getX() + (slotBounds.getWidth() / 2) - (textBounds.getWidth() / 2)); int textY = (int) (slotBounds.getY() + (slotBounds.getHeight() / 2) + (textBounds.getHeight() / 2)); graphics.setColor(new Color(255, 255, 255, 65)); graphics.fill(slotBounds); graphics.setColor(Color.BLACK); graphics.drawString(idText, textX + 1, textY + 1); graphics.setColor(YELLOW); graphics.drawString(idText, textX, textY); } }
Example 15
Source File: InventoryGridOverlay.java From plugins with GNU General Public License v3.0 | 4 votes |
@Override public Dimension render(Graphics2D graphics) { final Widget if1DraggingWidget = client.getIf1DraggedWidget(); final Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY); if (if1DraggingWidget == null || if1DraggingWidget != inventoryWidget || client.getItemPressedDuration() < config.dragDelay() / Constants.CLIENT_TICK_LENGTH) { initialMousePoint = null; hoverActive = false; 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 Rectangle initialBounds = draggedItem.getCanvasBounds(false); if (initialMousePoint == null) { initialMousePoint = mousePoint; } if (draggedItem.getId() == -1 || !hoverActive && initialMousePoint.distance(mousePoint) < DISTANCE_TO_ACTIVATE_HOVER) { return null; } hoverActive = true; for (int i = 0; i < INVENTORY_SIZE; ++i) { WidgetItem targetWidgetItem = inventoryWidget.getWidgetItem(i); final Rectangle bounds = targetWidgetItem.getCanvasBounds(false); boolean inBounds = bounds.contains(mousePoint); if (config.showItem() && inBounds) { drawItem(graphics, bounds, draggedItem); drawItem(graphics, initialBounds, targetWidgetItem); } if (config.showHighlight() && inBounds) { graphics.setColor(config.highlightColor()); graphics.fill(bounds); } else if (config.showInventoryGrid()) { graphics.setColor(config.gridColor()); graphics.fill(bounds); } } return null; }
Example 16
Source File: ExaminePlugin.java From plugins with GNU General Public License v3.0 | 4 votes |
@Subscribe void onMenuOptionClicked(MenuOptionClicked event) { if (!event.getOption().equals("Examine")) { return; } ExamineType type; int id, quantity = -1; switch (event.getMenuOpcode()) { case EXAMINE_ITEM: { type = ExamineType.ITEM; id = event.getIdentifier(); int widgetId = event.getParam1(); int widgetGroup = TO_GROUP(widgetId); int widgetChild = TO_CHILD(widgetId); Widget widget = client.getWidget(widgetGroup, widgetChild); WidgetItem widgetItem = widget.getWidgetItem(event.getParam0()); quantity = widgetItem != null && widgetItem.getId() >= 0 ? widgetItem.getQuantity() : 1; break; } case EXAMINE_ITEM_GROUND: type = ExamineType.ITEM; id = event.getIdentifier(); break; case CC_OP_LOW_PRIORITY: { type = ExamineType.ITEM_BANK_EQ; int[] qi = findItemFromWidget(event.getParam1(), event.getParam0()); if (qi == null) { log.debug("Examine for item with unknown widget: {}", event); return; } quantity = qi[0]; id = qi[1]; break; } case EXAMINE_OBJECT: type = ExamineType.OBJECT; id = event.getIdentifier(); break; case EXAMINE_NPC: type = ExamineType.NPC; id = event.getIdentifier(); break; default: return; } PendingExamine pendingExamine = new PendingExamine(); pendingExamine.setType(type); pendingExamine.setId(id); pendingExamine.setQuantity(quantity); pendingExamine.setCreated(Instant.now()); pending.push(pendingExamine); }
Example 17
Source File: ExaminePlugin.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
@Subscribe public void onMenuOptionClicked(MenuOptionClicked event) { if (!Text.removeTags(event.getMenuOption()).equals("Examine")) { return; } ExamineType type; int id, quantity = -1; switch (event.getMenuAction()) { case EXAMINE_ITEM: { type = ExamineType.ITEM; id = event.getId(); int widgetId = event.getWidgetId(); int widgetGroup = TO_GROUP(widgetId); int widgetChild = TO_CHILD(widgetId); Widget widget = client.getWidget(widgetGroup, widgetChild); WidgetItem widgetItem = widget.getWidgetItem(event.getActionParam()); quantity = widgetItem != null && widgetItem.getId() >= 0 ? widgetItem.getQuantity() : 1; break; } case EXAMINE_ITEM_GROUND: type = ExamineType.ITEM; id = event.getId(); break; case CC_OP_LOW_PRIORITY: { type = ExamineType.ITEM_BANK_EQ; int[] qi = findItemFromWidget(event.getWidgetId(), event.getActionParam()); if (qi == null) { log.debug("Examine for item with unknown widget: {}", event); return; } quantity = qi[0]; id = qi[1]; break; } case EXAMINE_OBJECT: type = ExamineType.OBJECT; id = event.getId(); break; case EXAMINE_NPC: type = ExamineType.NPC; id = event.getId(); break; default: return; } PendingExamine pendingExamine = new PendingExamine(); pendingExamine.setType(type); pendingExamine.setId(id); pendingExamine.setQuantity(quantity); pendingExamine.setCreated(Instant.now()); pending.push(pendingExamine); }
Example 18
Source File: InventoryGridOverlay.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
@Override public Dimension render(Graphics2D graphics) { final Widget if1DraggingWidget = client.getIf1DraggedWidget(); final Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY); if (if1DraggingWidget == null || if1DraggingWidget != inventoryWidget) { initialMousePoint = null; hoverActive = false; 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 Rectangle initialBounds = draggedItem.getCanvasBounds(false); if (initialMousePoint == null) { initialMousePoint = mousePoint; } if (draggedItem.getId() == -1 || client.getItemPressedDuration() < config.dragDelay() / Constants.CLIENT_TICK_LENGTH || !hoverActive && initialMousePoint.distance(mousePoint) < DISTANCE_TO_ACTIVATE_HOVER) { return null; } hoverActive = true; for (int i = 0; i < INVENTORY_SIZE; ++i) { WidgetItem targetWidgetItem = inventoryWidget.getWidgetItem(i); final Rectangle bounds = targetWidgetItem.getCanvasBounds(false); boolean inBounds = bounds.contains(mousePoint); if (config.showItem() && inBounds) { drawItem(graphics, bounds, draggedItem); drawItem(graphics, initialBounds, targetWidgetItem); } if (config.showHighlight() && inBounds) { graphics.setColor(HIGHLIGHT); graphics.fill(bounds); } else if (config.showGrid()) { graphics.setColor(GRID); graphics.fill(bounds); } } return null; }