Search in sources :

Example 51 with Widget

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

the class ClueScrollPlugin method findClueScroll.

private ClueScroll findClueScroll() {
    Widget clueScrollText = client.getWidget(WidgetInfo.CLUE_SCROLL_TEXT);
    if (clueScrollText != null) {
        // Remove line breaks and also the rare occasion where there are double line breaks
        String text = clueScrollText.getText().replaceAll("-<br>", "-").replaceAll("<br>", " ").replaceAll("[ ]+", " ").toLowerCase();
        if (clue != null && clue instanceof TextClueScroll) {
            if (((TextClueScroll) clue).getText().equalsIgnoreCase(text)) {
                return clue;
            }
        }
        if (text.startsWith("this anagram reveals who to speak to next:")) {
            return AnagramClue.forText(text);
        } else if (text.startsWith("the cipher reveals who to speak to next:")) {
            return CipherClue.forText(text);
        } else if (text.contains("degrees") && text.contains("minutes")) {
            return coordinatesToWorldPoint(text);
        } else {
            CrypticClue crypticClue = CrypticClue.forText(text);
            if (crypticClue != null) {
                return crypticClue;
            }
            EmoteClue emoteClue = EmoteClue.forText(text);
            if (emoteClue != null) {
                return emoteClue;
            }
            return FairyRingClue.forText(text);
        }
    }
    Item[] result = queryRunner.runQuery(new InventoryItemQuery(InventoryID.INVENTORY));
    if (result == null) {
        return null;
    }
    for (Item item : result) {
        MapClue clue = MapClue.forItemId(item.getId());
        if (clue != null) {
            return clue;
        }
    }
    return null;
}
Also used : Item(net.runelite.api.Item) MapClue(net.runelite.client.plugins.cluescrolls.clues.MapClue) EmoteClue(net.runelite.client.plugins.cluescrolls.clues.EmoteClue) Widget(net.runelite.api.widgets.Widget) InventoryItemQuery(net.runelite.api.queries.InventoryItemQuery) TextClueScroll(net.runelite.client.plugins.cluescrolls.clues.TextClueScroll) CrypticClue(net.runelite.client.plugins.cluescrolls.clues.CrypticClue)

Example 52 with Widget

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

the class DevToolsOverlay method renderInventory.

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);
    }
}
Also used : FontMetrics(java.awt.FontMetrics) Color(java.awt.Color) Widget(net.runelite.api.widgets.Widget) Rectangle(java.awt.Rectangle) Rectangle2D(java.awt.geom.Rectangle2D) WidgetItem(net.runelite.api.widgets.WidgetItem) LocalPoint(net.runelite.api.coords.LocalPoint)

Example 53 with Widget

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

the class GrandExchangePlugin method startUp.

@Override
protected void startUp() throws IOException {
    panel = injector.getInstance(GrandExchangePanel.class);
    BufferedImage icon;
    synchronized (ImageIO.class) {
        icon = ImageIO.read(getClass().getResourceAsStream("ge_icon.png"));
    }
    button = NavigationButton.builder().name("GE Offers").icon(icon).panel(panel).build();
    pluginToolbar.addNavigation(button);
    itemClick = new MouseListener() {

        @Override
        public MouseEvent mouseClicked(MouseEvent e) {
            // Check if left click + alt
            if (e.getButton() == MouseEvent.BUTTON1 && e.isAltDown()) {
                Point mousePosition = client.getMouseCanvasPosition();
                Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY);
                if (inventoryWidget != null && !inventoryWidget.isHidden()) {
                    for (WidgetItem item : inventoryWidget.getWidgetItems()) {
                        if (item.getCanvasBounds().contains(mousePosition.getX(), mousePosition.getY())) {
                            ItemComposition itemComp = client.getItemDefinition(item.getId());
                            if (itemComp != null) {
                                e.consume();
                                SwingUtilities.invokeLater(() -> {
                                    panel.showSearch();
                                    if (!button.isSelected()) {
                                        button.getOnSelect().run();
                                    }
                                    panel.getSearchPanel().priceLookup(itemComp.getName());
                                });
                            }
                            break;
                        }
                    }
                }
            }
            return super.mouseClicked(e);
        }
    };
    if (config.quickLookup()) {
        mouseManager.registerMouseListener(itemClick);
    }
}
Also used : MouseListener(net.runelite.client.input.MouseListener) MouseEvent(java.awt.event.MouseEvent) Widget(net.runelite.api.widgets.Widget) ItemComposition(net.runelite.api.ItemComposition) WidgetItem(net.runelite.api.widgets.WidgetItem) Point(net.runelite.api.Point) BufferedImage(java.awt.image.BufferedImage) ImageIO(javax.imageio.ImageIO)

Example 54 with Widget

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

the class WidgetTreeNode method toString.

@Override
public String toString() {
    Widget widget = getWidget();
    int id = widget.getId();
    WidgetInfo info = WidgetInspector.getWidgetInfo(id);
    return type + " " + TO_GROUP(id) + "." + TO_CHILD(id) + ((info != null) ? " " + info.name() : "");
}
Also used : Widget(net.runelite.api.widgets.Widget) WidgetInfo(net.runelite.api.widgets.WidgetInfo)

Example 55 with Widget

use of net.runelite.api.widgets.Widget 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

Widget (net.runelite.api.widgets.Widget)56 Rectangle (java.awt.Rectangle)10 WidgetItem (net.runelite.api.widgets.WidgetItem)10 ArrayList (java.util.ArrayList)9 Subscribe (com.google.common.eventbus.Subscribe)7 Inject (net.runelite.api.mixins.Inject)6 RSWidget (net.runelite.rs.api.RSWidget)6 Point (net.runelite.api.Point)5 WidgetHiddenChanged (net.runelite.api.events.WidgetHiddenChanged)5 PanelComponent (net.runelite.client.ui.overlay.components.PanelComponent)5 Test (org.junit.Test)5 FontMetrics (java.awt.FontMetrics)4 Rectangle2D (java.awt.geom.Rectangle2D)4 Consumer (java.util.function.Consumer)4 LocalPoint (net.runelite.api.coords.LocalPoint)4 ItemComposition (net.runelite.api.ItemComposition)3 WidgetInfo (net.runelite.api.widgets.WidgetInfo)3 Color (java.awt.Color)2 BufferedImage (java.awt.image.BufferedImage)2 Matcher (java.util.regex.Matcher)2