Search in sources :

Example 16 with WidgetItem

use of net.runelite.api.widgets.WidgetItem in project runelite by runelite.

the class RSWidgetMixin method getWidgetItems.

@Inject
@Override
public Collection<WidgetItem> getWidgetItems() {
    int[] itemIds = getItemIds();
    if (itemIds == null) {
        return null;
    }
    List<WidgetItem> items = new ArrayList<WidgetItem>(itemIds.length);
    for (int i = 0; i < itemIds.length; ++i) {
        WidgetItem item = getWidgetItem(i);
        if (item != null) {
            items.add(item);
        }
    }
    return items;
}
Also used : ArrayList(java.util.ArrayList) WidgetItem(net.runelite.api.widgets.WidgetItem) Point(net.runelite.api.Point) Inject(net.runelite.api.mixins.Inject)

Example 17 with WidgetItem

use of net.runelite.api.widgets.WidgetItem in project runelite by runelite.

the class InventoryWidgetItemQuery method getInventoryItems.

private Collection<WidgetItem> getInventoryItems(Client client) {
    Collection<WidgetItem> widgetItems = new ArrayList<>();
    for (WidgetInfo widgetInfo : INVENTORY_WIDGET_INFOS) {
        Widget inventory = client.getWidget(widgetInfo);
        if (inventory == null || inventory.isHidden()) {
            continue;
        }
        if (widgetInfo == WidgetInfo.INVENTORY) {
            widgetItems.addAll(inventory.getWidgetItems());
            break;
        } else {
            Widget[] children = inventory.getDynamicChildren();
            for (int i = 0; i < children.length; i++) {
                // set bounds to same size as default inventory
                Rectangle bounds = children[i].getBounds();
                bounds.setBounds(bounds.x - 1, bounds.y - 1, 32, 32);
                widgetItems.add(new WidgetItem(children[i].getItemId(), children[i].getItemQuantity(), i, bounds));
            }
            break;
        }
    }
    return widgetItems;
}
Also used : ArrayList(java.util.ArrayList) Widget(net.runelite.api.widgets.Widget) Rectangle(java.awt.Rectangle) WidgetItem(net.runelite.api.widgets.WidgetItem) WidgetInfo(net.runelite.api.widgets.WidgetInfo)

Example 18 with WidgetItem

use of net.runelite.api.widgets.WidgetItem in project runelite by runelite.

the class BankItemQuery method getBankItems.

private Collection<WidgetItem> getBankItems(Client client) {
    Collection<WidgetItem> widgetItems = new ArrayList<>();
    Widget bank = client.getWidget(WidgetInfo.BANK_ITEM_CONTAINER);
    if (bank != null && !bank.isHidden()) {
        Widget[] children = bank.getDynamicChildren();
        for (int i = 0; i < children.length; i++) {
            if (children[i].getItemId() == ITEM_EMPTY || children[i].isHidden()) {
                continue;
            }
            // set bounds to same size as default inventory
            Rectangle bounds = children[i].getBounds();
            bounds.setBounds(bounds.x - 1, bounds.y - 1, 32, 32);
            // Index is set to 0 because the widget's index does not correlate to the order in the bank
            widgetItems.add(new WidgetItem(children[i].getItemId(), children[i].getItemQuantity(), 0, bounds));
        }
    }
    return widgetItems;
}
Also used : ArrayList(java.util.ArrayList) Widget(net.runelite.api.widgets.Widget) Rectangle(java.awt.Rectangle) WidgetItem(net.runelite.api.widgets.WidgetItem)

Example 19 with WidgetItem

use of net.runelite.api.widgets.WidgetItem in project runelite by runelite.

the class EquipmentItemQuery method getEquippedItems.

private Collection<WidgetItem> getEquippedItems(Client client) {
    Collection<WidgetItem> widgetItems = new ArrayList<>();
    Widget equipment = client.getWidget(WidgetInfo.EQUIPMENT);
    if (equipment != null && !equipment.isHidden()) {
        if (slots.isEmpty()) {
            slots.addAll(Arrays.asList(ALL_EQUIPMENT_WIDGET_INFOS));
        }
        for (WidgetInfo slot : slots) {
            Widget parentWidget = client.getWidget(slot);
            Widget itemWidget = parentWidget.getChild(1);
            // Check if background icon is hidden. if hidden, item is equipped.
            boolean equipped = parentWidget.getChild(2).isHidden();
            // set bounds to same size as default inventory
            Rectangle bounds = itemWidget.getBounds();
            bounds.setBounds(bounds.x - 1, bounds.y - 1, 32, 32);
            // Index is set to 0 because there is no set in stone order of equipment slots
            widgetItems.add(new WidgetItem(equipped ? itemWidget.getItemId() : -1, itemWidget.getItemQuantity(), 0, bounds));
        }
    }
    return widgetItems;
}
Also used : ArrayList(java.util.ArrayList) Widget(net.runelite.api.widgets.Widget) Rectangle(java.awt.Rectangle) WidgetItem(net.runelite.api.widgets.WidgetItem) WidgetInfo(net.runelite.api.widgets.WidgetInfo)

Example 20 with WidgetItem

use of net.runelite.api.widgets.WidgetItem in project runelite by runelite.

the class ShiftClickConfigurationOverlay method render.

@Override
public Dimension render(Graphics2D graphics) {
    if (!plugin.isConfiguringShiftClick() || client.isMenuOpen() || client.getWidget(WidgetInfo.INVENTORY).isHidden()) {
        return null;
    }
    Font font = FontManager.getRunescapeSmallFont();
    graphics.setFont(font);
    net.runelite.api.Point mouseCanvasPosition = client.getMouseCanvasPosition();
    Point mousePoint = new Point(mouseCanvasPosition.getX(), mouseCanvasPosition.getY());
    for (WidgetItem item : plugin.getInventoryItems()) {
        final Rectangle bounds = item.getCanvasBounds();
        if (!bounds.contains(mousePoint)) {
            continue;
        }
        ItemComposition itemComposition = client.getItemDefinition(item.getId());
        String[] actions = itemComposition.getInventoryActions();
        int index = itemComposition.getShiftClickActionIndex();
        if (index >= 0 && actions[index] == null) {
            continue;
        }
        String action = index == -1 ? "Use" : actions[index];
        int textWidth = graphics.getFontMetrics().stringWidth(action);
        int textLocationX = (int) (bounds.x + bounds.getWidth() / 2 - textWidth / 2);
        int textLocationY = bounds.y + 28;
        final TextComponent textComponent = new TextComponent();
        textComponent.setPosition(new Point(textLocationX, textLocationY));
        textComponent.setText(action);
        textComponent.render(graphics);
    }
    return null;
}
Also used : TextComponent(net.runelite.client.ui.overlay.components.TextComponent) Rectangle(java.awt.Rectangle) ItemComposition(net.runelite.api.ItemComposition) WidgetItem(net.runelite.api.widgets.WidgetItem) Point(java.awt.Point) Font(java.awt.Font) Point(java.awt.Point)

Aggregations

WidgetItem (net.runelite.api.widgets.WidgetItem)25 Rectangle (java.awt.Rectangle)13 Widget (net.runelite.api.widgets.Widget)10 Point (java.awt.Point)8 ArrayList (java.util.ArrayList)8 InventoryWidgetItemQuery (net.runelite.api.queries.InventoryWidgetItemQuery)7 Query (net.runelite.api.Query)6 TextComponent (net.runelite.client.ui.overlay.components.TextComponent)5 ItemComposition (net.runelite.api.ItemComposition)4 Point (net.runelite.api.Point)4 EquipmentItemQuery (net.runelite.api.queries.EquipmentItemQuery)3 Color (java.awt.Color)2 BufferedImage (java.awt.image.BufferedImage)2 HashMap (java.util.HashMap)2 Varbits (net.runelite.api.Varbits)2 LocalPoint (net.runelite.api.coords.LocalPoint)2 Inject (net.runelite.api.mixins.Inject)2 WidgetInfo (net.runelite.api.widgets.WidgetInfo)2 Tooltip (net.runelite.client.ui.overlay.tooltip.Tooltip)2 Font (java.awt.Font)1