Search in sources :

Example 11 with ItemComposition

use of net.runelite.api.ItemComposition in project runelite by runelite.

the class GrandExchangePlugin method onGrandExchangeOfferChanged.

@Subscribe
public void onGrandExchangeOfferChanged(GrandExchangeOfferChanged offerEvent) {
    GrandExchangeOffer offer = offerEvent.getOffer();
    ItemComposition offerItem = itemManager.getItemComposition(offer.getItemId());
    boolean shouldStack = offerItem.isStackable() || offer.getTotalQuantity() > 1;
    BufferedImage itemImage = itemManager.getImage(offer.getItemId(), offer.getTotalQuantity(), shouldStack);
    SwingUtilities.invokeLater(() -> panel.updateOffer(offerItem, itemImage, offerEvent.getOffer(), offerEvent.getSlot()));
}
Also used : GrandExchangeOffer(net.runelite.api.GrandExchangeOffer) ItemComposition(net.runelite.api.ItemComposition) BufferedImage(java.awt.image.BufferedImage) Subscribe(com.google.common.eventbus.Subscribe)

Example 12 with ItemComposition

use of net.runelite.api.ItemComposition in project runelite by runelite.

the class GrandExchangeSearchPanel method priceLookup.

private void priceLookup(boolean exactMatch) {
    String lookup = searchBox.getText();
    if (Strings.isNullOrEmpty(lookup)) {
        return;
    }
    // Input is not empty, add searching label
    searchItemsPanel.removeAll();
    showSearchString("Searching...");
    SearchResult result;
    try {
        result = itemManager.searchForItem(lookup);
    } catch (ExecutionException ex) {
        log.warn("Unable to search for item {}", lookup, ex);
        showSearchString("Error performing search");
        return;
    }
    if (result != null && !result.getItems().isEmpty()) {
        itemClient = new ItemClient();
        for (Item item : result.getItems()) {
            int itemId = item.getId();
            ItemComposition itemComp = client.getItemDefinition(itemId);
            if (itemComp == null) {
                continue;
            }
            ItemPrice itemPrice = null;
            try {
                itemPrice = itemManager.getItemPrice(itemId);
            } catch (IOException ex) {
                log.warn("Unable to fetch item price for {}", itemId, ex);
            }
            BufferedImage itemImage = null;
            try {
                itemImage = itemClient.getIcon(itemId);
            } catch (IOException ex) {
                log.warn("Unable to fetch item icon for {}", itemId, ex);
            }
            if (itemImage == null) {
                log.warn("Unable to fetch item icon for {}", itemId);
            }
            ITEMS_LIST.add(new GrandExchangeItems(itemImage, item.getName(), itemId, itemPrice != null ? itemPrice.getPrice() : 0, itemComp.getPrice() * 0.6));
            // If using hotkey to lookup item, stop after finding match.
            if (exactMatch && item.getName().equalsIgnoreCase(lookup)) {
                break;
            }
        }
    }
    SwingUtilities.invokeLater(() -> {
        for (GrandExchangeItems item : ITEMS_LIST) {
            GrandExchangeItemPanel panel = new GrandExchangeItemPanel(item.getIcon(), item.getName(), item.getItemId(), item.getGePrice(), item.getHaPrice());
            searchItemsPanel.add(panel);
        }
        ITEMS_LIST.clear();
        // Remove searching label after search is complete
        showSearchString(null);
    });
}
Also used : Item(net.runelite.http.api.item.Item) ItemClient(net.runelite.http.api.item.ItemClient) ItemPrice(net.runelite.http.api.item.ItemPrice) ItemComposition(net.runelite.api.ItemComposition) SearchResult(net.runelite.http.api.item.SearchResult) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) BufferedImage(java.awt.image.BufferedImage)

Example 13 with ItemComposition

use of net.runelite.api.ItemComposition in project runelite by runelite.

the class ExaminePlugin method findExamineItem.

private void findExamineItem(PendingExamine pendingExamine) {
    int quantity = 1;
    int itemId = -1;
    // Get widget
    int widgetId = pendingExamine.getWidgetId();
    int widgetGroup = TO_GROUP(widgetId);
    int widgetChild = TO_CHILD(widgetId);
    Widget widget = client.getWidget(widgetGroup, widgetChild);
    if (widget == null) {
        return;
    }
    if (pendingExamine.getType() == ExamineType.ITEM) {
        WidgetItem widgetItem = widget.getWidgetItem(pendingExamine.getActionParam());
        quantity = widgetItem != null ? widgetItem.getQuantity() : 1;
        itemId = pendingExamine.getId();
    } else if (pendingExamine.getType() == ExamineType.ITEM_BANK_EQ) {
        if (WidgetInfo.EQUIPMENT.getGroupId() == widgetGroup) {
            Widget widgetItem = widget.getChild(1);
            if (widgetItem != null) {
                quantity = widgetItem.getItemQuantity();
                itemId = widgetItem.getItemId();
            }
        } else if (WidgetInfo.BANK_INVENTORY_ITEMS_CONTAINER.getGroupId() == widgetGroup || WidgetInfo.RUNE_POUCH_ITEM_CONTAINER.getGroupId() == widgetGroup) {
            Widget widgetItem = widget.getChild(pendingExamine.getActionParam());
            if (widgetItem != null) {
                quantity = widgetItem.getItemQuantity();
                itemId = widgetItem.getItemId();
            }
        } else if (WidgetInfo.BANK_ITEM_CONTAINER.getGroupId() == widgetGroup) {
            Widget[] children = widget.getDynamicChildren();
            if (pendingExamine.getActionParam() < children.length) {
                Widget widgetItem = children[pendingExamine.getActionParam()];
                quantity = widgetItem.getItemQuantity();
                itemId = widgetItem.getItemId();
            }
        }
    }
    if (itemId == -1) {
        return;
    }
    final int itemQuantity = quantity;
    final ItemComposition itemComposition = itemManager.getItemComposition(itemId);
    if (itemComposition != null) {
        executor.submit(() -> getItemPrice(itemComposition, itemQuantity));
    }
}
Also used : Widget(net.runelite.api.widgets.Widget) ItemComposition(net.runelite.api.ItemComposition) WidgetItem(net.runelite.api.widgets.WidgetItem)

Aggregations

ItemComposition (net.runelite.api.ItemComposition)13 ItemPrice (net.runelite.http.api.item.ItemPrice)6 WidgetItem (net.runelite.api.widgets.WidgetItem)4 Subscribe (com.google.common.eventbus.Subscribe)3 BufferedImage (java.awt.image.BufferedImage)3 LocalPoint (net.runelite.api.coords.LocalPoint)3 Widget (net.runelite.api.widgets.Widget)3 IOException (java.io.IOException)2 ExecutionException (java.util.concurrent.ExecutionException)2 PostItemComposition (net.runelite.api.events.PostItemComposition)2 Item (net.runelite.http.api.item.Item)2 SearchResult (net.runelite.http.api.item.SearchResult)2 Color (java.awt.Color)1 Font (java.awt.Font)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 MouseEvent (java.awt.event.MouseEvent)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Nullable (javax.annotation.Nullable)1