Search in sources :

Example 41 with Widget

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

the class ScreenshotPluginTest method testAttack.

@Test
public void testAttack() {
    Widget widget = mock(Widget.class);
    when(widget.getId()).thenReturn(PACK(LEVEL_UP_GROUP_ID, 0));
    Widget skillChild = mock(Widget.class);
    when(client.getWidget(Matchers.eq(LEVEL_UP_SKILL))).thenReturn(skillChild);
    Widget levelChild = mock(Widget.class);
    when(client.getWidget(Matchers.eq(LEVEL_UP_LEVEL))).thenReturn(levelChild);
    when(skillChild.getText()).thenReturn("Congratulations, you just advanced an Attack level.");
    when(levelChild.getText()).thenReturn("Your Attack level is now 70.");
    assertEquals("Attack(70)", screenshotPlugin.parseLevelUpWidget(LEVEL_UP_SKILL, LEVEL_UP_LEVEL));
    WidgetHiddenChanged event = new WidgetHiddenChanged();
    event.setWidget(widget);
    screenshotPlugin.hideWidgets(event);
    verify(overlayRenderer).requestScreenshot(Matchers.any(Consumer.class));
}
Also used : Consumer(java.util.function.Consumer) Widget(net.runelite.api.widgets.Widget) WidgetHiddenChanged(net.runelite.api.events.WidgetHiddenChanged) Test(org.junit.Test)

Example 42 with Widget

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

the class BankTagsPlugin method onMenuOptionClicked.

@Subscribe
public void onMenuOptionClicked(MenuOptionClicked event) {
    if (event.getWidgetId() == WidgetInfo.BANK_ITEM_CONTAINER.getId() && event.getMenuAction() == MenuAction.EXAMINE_ITEM_BANK_EQ && event.getId() == EDIT_TAGS_MENU_INDEX) {
        int inventoryIndex = event.getActionParam();
        ItemContainer bankContainer = client.getItemContainer(InventoryID.BANK);
        if (bankContainer == null) {
            return;
        }
        Item[] items = bankContainer.getItems();
        if (inventoryIndex < 0 || inventoryIndex >= items.length) {
            return;
        }
        Item item = bankContainer.getItems()[inventoryIndex];
        if (item == null) {
            return;
        }
        int itemId = item.getId();
        String itemName = itemManager.getItemComposition(itemId).getName();
        String initialValue = getTags(itemId);
        chatboxInputManager.openInputWindow(itemName + " Tags", initialValue, (newTags) -> {
            if (newTags == null) {
                return;
            }
            setTags(itemId, newTags);
            Widget bankContainerWidget = client.getWidget(WidgetInfo.BANK_ITEM_CONTAINER);
            if (bankContainerWidget == null) {
                return;
            }
            Widget[] bankItemWidgets = bankContainerWidget.getDynamicChildren();
            if (bankItemWidgets == null || inventoryIndex >= bankItemWidgets.length) {
                return;
            }
            Widget bankItemWidget = bankItemWidgets[inventoryIndex];
            String[] actions = bankItemWidget.getActions();
            if (actions == null || EDIT_TAGS_MENU_INDEX - 1 >= actions.length) {
                return;
            }
            int tagCount = getTagCount(itemId);
            actions[EDIT_TAGS_MENU_INDEX - 1] = EDIT_TAGS_MENU_OPTION;
            if (tagCount > 0) {
                actions[EDIT_TAGS_MENU_INDEX - 1] += " (" + tagCount + ")";
            }
        });
    }
}
Also used : ItemContainer(net.runelite.api.ItemContainer) Item(net.runelite.api.Item) Widget(net.runelite.api.widgets.Widget) Subscribe(com.google.common.eventbus.Subscribe)

Example 43 with Widget

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

the class BankTitle method update.

void update(long gePrice, long haPrice) {
    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") || widgetBankTitleBar.getText().contains("(")) {
        return;
    }
    String strCurrentTab = "";
    if (config.showGE() && gePrice != 0) {
        strCurrentTab += " (EX: " + StackFormatter.quantityToStackSize(gePrice) + ")";
    }
    if (config.showHA() && haPrice != 0) {
        strCurrentTab += " (HA: " + StackFormatter.quantityToStackSize(haPrice) + ")";
    }
    log.debug("Setting bank title: {}", bankTitle + strCurrentTab);
    widgetBankTitleBar.setText(bankTitle + strCurrentTab);
}
Also used : Widget(net.runelite.api.widgets.Widget)

Example 44 with Widget

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

the class BankTitle method save.

void save() {
    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("(") || widgetBankTitleBar.getText().contains("Showing")) {
        return;
    }
    bankTitle = widgetBankTitleBar.getText();
}
Also used : Widget(net.runelite.api.widgets.Widget)

Example 45 with Widget

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

the class BankValuePlugin method onGameTick.

@Subscribe
public void onGameTick(GameTick event) {
    Widget widgetBankTitleBar = client.getWidget(WidgetInfo.BANK_TITLE_BAR);
    if (widgetBankTitleBar == null || widgetBankTitleBar.isHidden()) {
        return;
    }
    bankTitle.save();
    bankCalculation.calculate();
    if (bankCalculation.isFinished()) {
        bankTitle.update(bankCalculation.getGePrice(), bankCalculation.getHaPrice());
    }
}
Also used : Widget(net.runelite.api.widgets.Widget) Subscribe(com.google.common.eventbus.Subscribe)

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