Search in sources :

Example 1 with MouseListener

use of net.runelite.client.input.MouseListener 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)

Aggregations

MouseEvent (java.awt.event.MouseEvent)1 BufferedImage (java.awt.image.BufferedImage)1 ImageIO (javax.imageio.ImageIO)1 ItemComposition (net.runelite.api.ItemComposition)1 Point (net.runelite.api.Point)1 Widget (net.runelite.api.widgets.Widget)1 WidgetItem (net.runelite.api.widgets.WidgetItem)1 MouseListener (net.runelite.client.input.MouseListener)1