Search in sources :

Example 1 with Widget

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

the class BankTitle method reset.

void reset() {
    Widget widgetBankTitleBar = client.getWidget(WidgetInfo.BANK_TITLE_BAR);
    if (widgetBankTitleBar == null || widgetBankTitleBar.isHidden()) {
        return;
    }
    widgetBankTitleBar.setText(bankTitle);
}
Also used : Widget(net.runelite.api.widgets.Widget)

Example 2 with Widget

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

the class BankCalculation method calculate.

/**
 * Calculate the bank based on the cache, price can be 0 if bank not active, or cache not set
 */
void calculate() {
    Widget widgetBankTitleBar = client.getWidget(WidgetInfo.BANK_TITLE_BAR);
    // Don't update on a search because rs seems to constantly update the title
    if (widgetBankTitleBar == null || widgetBankTitleBar.isHidden() || widgetBankTitleBar.getText().contains("Showing")) {
        return;
    }
    WidgetItem[] widgetItems = new BankItemQuery().result(client);
    if (widgetItems.length == 0 || !isBankDifferent(widgetItems)) {
        return;
    }
    log.debug("Calculating new bank value...");
    gePrice = haPrice = 0;
    finished = false;
    List<ItemComposition> itemCompositions = new ArrayList<>();
    Map<Integer, WidgetItem> itemMap = new HashMap<>();
    List<Integer> itemIds = new ArrayList<>();
    // Generate our lists (and do some quick price additions)
    for (WidgetItem widgetItem : widgetItems) {
        if (widgetItem.getId() <= 0 || widgetItem.getQuantity() == 0) {
            continue;
        }
        if (widgetItem.getId() == COINS_995) {
            gePrice += widgetItem.getQuantity();
            haPrice += widgetItem.getQuantity();
            continue;
        }
        if (widgetItem.getId() == PLATINUM_TOKEN) {
            gePrice += widgetItem.getQuantity() * 1000;
            haPrice += widgetItem.getQuantity() * 1000;
            continue;
        }
        ItemComposition itemComposition = itemManager.getItemComposition(widgetItem.getId());
        itemCompositions.add(itemComposition);
        itemMap.put(widgetItem.getId(), widgetItem);
        if (config.showGE()) {
            itemIds.add(widgetItem.getId());
        }
    }
    // Now do the calculations
    if (config.showGE() && !itemIds.isEmpty()) {
        CompletableFuture<ItemPrice[]> future = itemManager.getItemPriceBatch(itemIds);
        future.whenComplete((ItemPrice[] itemPrices, Throwable ex) -> {
            if (ex != null) {
                log.debug("Error looking up item prices", ex);
                return;
            }
            if (itemPrices == null) {
                log.debug("Error looking up item prices");
                return;
            }
            log.debug("Price lookup is complete. {} prices.", itemPrices.length);
            try {
                for (ItemPrice itemPrice : itemPrices) {
                    if (itemPrice.getItem() == null) {
                        // cached no price
                        continue;
                    }
                    gePrice += itemPrice.getPrice() * itemMap.get(itemPrice.getItem().getId()).getQuantity();
                }
            } catch (Exception ex2) {
                log.warn("error calculating price", ex2);
            } finally {
                finished = true;
            }
        });
    } else {
        finished = true;
    }
    if (config.showHA()) {
        for (ItemComposition itemComposition : itemCompositions) {
            int price = itemComposition.getPrice();
            if (price > 0) {
                haPrice += Math.round(price * HIGH_ALCHEMY_CONSTANT) * itemMap.get(itemComposition.getId()).getQuantity();
            }
        }
    }
}
Also used : BankItemQuery(net.runelite.api.queries.BankItemQuery) HashMap(java.util.HashMap) Widget(net.runelite.api.widgets.Widget) ArrayList(java.util.ArrayList) ItemPrice(net.runelite.http.api.item.ItemPrice) WidgetItem(net.runelite.api.widgets.WidgetItem) ItemComposition(net.runelite.api.ItemComposition)

Example 3 with Widget

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

the class BarbarianAssaultOverlay method render.

@Override
public Dimension render(Graphics2D graphics) {
    if (client.getGameState() != GameState.LOGGED_IN || currentRound == null) {
        return null;
    }
    Role role = currentRound.getRoundRole();
    if (role == null) {
        return null;
    }
    Widget roleText = client.getWidget(role.getRoleText());
    Widget roleSprite = client.getWidget(role.getRoleSprite());
    if (config.showTimer() && roleText != null && roleSprite != null) {
        roleText.setText(String.format("00:%02d", currentRound.getTimeToChange()));
        Rectangle spriteBounds = roleSprite.getBounds();
        roleSprite.setHidden(true);
        graphics.drawImage(plugin.getClockImage(), spriteBounds.x, spriteBounds.y, null);
    }
    return null;
}
Also used : Widget(net.runelite.api.widgets.Widget) Rectangle(java.awt.Rectangle)

Example 4 with Widget

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

the class DevToolsOverlay method renderWidgets.

public void renderWidgets(Graphics2D graphics) {
    Widget widget = plugin.currentWidget;
    int itemIndex = plugin.itemIndex;
    if (widget == null || widget.isHidden()) {
        return;
    }
    Rectangle childBounds = widget.getBounds();
    graphics.setColor(CYAN);
    graphics.draw(childBounds);
    if (itemIndex == -1) {
        return;
    }
    if (widget.getItemId() != ITEM_EMPTY && widget.getItemId() != ITEM_FILLED) {
        Rectangle componentBounds = widget.getBounds();
        graphics.setColor(ORANGE);
        graphics.draw(componentBounds);
        renderWidgetText(graphics, componentBounds, widget.getItemId(), YELLOW);
    }
    WidgetItem widgetItem = widget.getWidgetItem(itemIndex);
    if (widgetItem == null || widgetItem.getId() == ITEM_EMPTY || widgetItem.getId() == ITEM_FILLED) {
        return;
    }
    Rectangle itemBounds = widgetItem.getCanvasBounds();
    graphics.setColor(ORANGE);
    graphics.draw(itemBounds);
    renderWidgetText(graphics, itemBounds, widgetItem.getId(), YELLOW);
}
Also used : Widget(net.runelite.api.widgets.Widget) Rectangle(java.awt.Rectangle) WidgetItem(net.runelite.api.widgets.WidgetItem) LocalPoint(net.runelite.api.coords.LocalPoint)

Example 5 with Widget

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

the class BlastFurnaceCofferOverlay method render.

@Override
public Dimension render(Graphics2D graphics) {
    if (plugin.getConveyorBelt() == null) {
        return null;
    }
    Widget sack = client.getWidget(WidgetInfo.BLAST_FURNACE_COFFER);
    panelComponent.getLines().clear();
    if (sack != null) {
        sack.setHidden(true);
        panelComponent.getLines().add(new PanelComponent.Line("Coffer:", StackFormatter.quantityToStackSize(client.getSetting(BLAST_FURNACE_COFFER)) + " gp"));
    }
    return panelComponent.render(graphics);
}
Also used : Widget(net.runelite.api.widgets.Widget) PanelComponent(net.runelite.client.ui.overlay.components.PanelComponent)

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