Search in sources :

Example 11 with Widget

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

the class Hooks method checkWorldMap.

/**
 * When the world map opens it loads about ~100mb of data into memory, which
 * represents about half of the total memory allocated by the client.
 * This gets cached and never released, which causes GC pressure which can affect
 * performance. This method reinitailzies the world map cache, which allows the
 * data to be garbage collecged, and causes the map data from disk each time
 * is it opened.
 */
private static void checkWorldMap() {
    Widget widget = client.getWidget(WORLD_MAP, 0);
    if (widget != null) {
        return;
    }
    RenderOverview renderOverview = client.getRenderOverview();
    if (renderOverview == null) {
        return;
    }
    WorldMapManager manager = renderOverview.getWorldMapManager();
    if (manager != null && manager.isLoaded()) {
        log.debug("World map was closed, reinitializing");
        renderOverview.initializeWorldMap(renderOverview.getWorldMapData());
    }
}
Also used : RenderOverview(net.runelite.api.RenderOverview) WorldMapManager(net.runelite.api.WorldMapManager) Widget(net.runelite.api.widgets.Widget)

Example 12 with Widget

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

the class ShopItemQuery method getShopItems.

private Collection<WidgetItem> getShopItems(Client client) {
    Collection<WidgetItem> widgetItems = new ArrayList<>();
    Widget shop = client.getWidget(WidgetInfo.SHOP_ITEMS_CONTAINER);
    if (shop != null && !shop.isHidden()) {
        Widget[] children = shop.getDynamicChildren();
        for (int i = 1; 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 - 1, 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 13 with Widget

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

the class KourendLibraryPlugin method onTick.

@Subscribe
void onTick(GameTick tick) {
    if (lastBookcaseAnimatedOn != null) {
        Widget find = client.getWidget(WidgetInfo.DIALOG_SPRITE_SPRITE);
        if (find != null) {
            Book book = Book.byId(find.getItemId());
            if (book != null) {
                library.mark(lastBookcaseAnimatedOn, book);
                panel.update();
                lastBookcaseAnimatedOn = null;
            }
        }
    }
    Widget npcHead = client.getWidget(WidgetInfo.DIALOG_NPC_HEAD_MODEL);
    if (npcHead != null) {
        LibraryCustomer cust = LibraryCustomer.getById(npcHead.getModelId());
        if (cust != null) {
            Widget textw = client.getWidget(WidgetInfo.DIALOG_NPC_TEXT);
            String text = textw.getText();
            Matcher m = BOOK_EXTRACTOR.matcher(text);
            if (m.find()) {
                String bookName = TAG_MATCHER.matcher(m.group(1).replace("<br>", " ")).replaceAll("");
                Book book = Book.byName(bookName);
                if (book == null) {
                    log.warn("Book '{}' is not recognised", bookName);
                    return;
                }
                library.setCustomer(cust, book);
                panel.update();
            } else if (text.contains("You can have this other book") || text.contains("please accept a token of my thanks.") || text.contains("Thanks, I'll get on with reading it.")) {
                library.setCustomer(null, null);
                panel.update();
            }
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) Widget(net.runelite.api.widgets.Widget) Subscribe(com.google.common.eventbus.Subscribe)

Example 14 with Widget

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

the class RSClientMixin method getGroup.

@Inject
@Override
public Widget[] getGroup(int groupId) {
    RSWidget[][] widgets = getWidgets();
    if (widgets == null || groupId < 0 || groupId >= widgets.length || widgets[groupId] == null) {
        return null;
    }
    List<Widget> w = new ArrayList<Widget>();
    for (Widget widget : widgets[groupId]) {
        if (widget != null) {
            w.add(widget);
        }
    }
    return w.toArray(new Widget[w.size()]);
}
Also used : Widget(net.runelite.api.widgets.Widget) RSWidget(net.runelite.rs.api.RSWidget) ArrayList(java.util.ArrayList) Inject(net.runelite.api.mixins.Inject)

Example 15 with Widget

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

the class RSClientMixin method getWidgetRoots.

@Inject
@Override
public Widget[] getWidgetRoots() {
    int topGroup = getWidgetRoot();
    List<Widget> widgets = new ArrayList<Widget>();
    for (Widget widget : getWidgets()[topGroup]) {
        if (widget != null && widget.getParentId() == -1) {
            widgets.add(widget);
        }
    }
    return widgets.toArray(new Widget[widgets.size()]);
}
Also used : Widget(net.runelite.api.widgets.Widget) RSWidget(net.runelite.rs.api.RSWidget) ArrayList(java.util.ArrayList) LocalPoint(net.runelite.api.coords.LocalPoint) Point(net.runelite.api.Point) Inject(net.runelite.api.mixins.Inject)

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