Search in sources :

Example 6 with Widget

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

the class CombatLevelPlugin method updateCombatLevel.

@Subscribe
public void updateCombatLevel(GameTick event) {
    if (client.getGameState() != GameState.LOGGED_IN) {
        return;
    }
    Widget combatLevelWidget = client.getWidget(WidgetInfo.COMBAT_LEVEL);
    if (combatLevelWidget == null) {
        return;
    }
    double combatLevelPrecise = Experience.getCombatLevelPrecise(client.getRealSkillLevel(Skill.ATTACK), client.getRealSkillLevel(Skill.STRENGTH), client.getRealSkillLevel(Skill.DEFENCE), client.getRealSkillLevel(Skill.HITPOINTS), client.getRealSkillLevel(Skill.MAGIC), client.getRealSkillLevel(Skill.RANGED), client.getRealSkillLevel(Skill.PRAYER));
    combatLevelWidget.setText("Combat Lvl: " + decimalFormat.format(combatLevelPrecise));
}
Also used : Widget(net.runelite.api.widgets.Widget) Subscribe(com.google.common.eventbus.Subscribe)

Example 7 with Widget

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

the class WidgetInspector method addWidget.

private DefaultMutableTreeNode addWidget(String type, Widget widget) {
    if (widget == null || widget.isHidden()) {
        return null;
    }
    DefaultMutableTreeNode node = new WidgetTreeNode(type, widget);
    Widget[] childComponents = widget.getDynamicChildren();
    if (childComponents != null) {
        for (Widget component : childComponents) {
            DefaultMutableTreeNode childNode = addWidget("D", component);
            if (childNode != null) {
                node.add(childNode);
            }
        }
    }
    childComponents = widget.getStaticChildren();
    if (childComponents != null) {
        for (Widget component : childComponents) {
            DefaultMutableTreeNode childNode = addWidget("S", component);
            if (childNode != null) {
                node.add(childNode);
            }
        }
    }
    childComponents = widget.getNestedChildren();
    if (childComponents != null) {
        for (Widget component : childComponents) {
            DefaultMutableTreeNode childNode = addWidget("N", component);
            if (childNode != null) {
                node.add(childNode);
            }
        }
    }
    Collection<WidgetItem> items = widget.getWidgetItems();
    if (items != null) {
        for (WidgetItem item : items) {
            if (item == null) {
                continue;
            }
            node.add(new WidgetItemNode(item));
        }
    }
    return node;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Widget(net.runelite.api.widgets.Widget) WidgetItem(net.runelite.api.widgets.WidgetItem)

Example 8 with Widget

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

the class ScreenshotPlugin method parseLevelUpWidget.

public String parseLevelUpWidget(WidgetInfo levelUpSkill, WidgetInfo levelUpLevel) {
    Widget skillChild = client.getWidget(levelUpSkill);
    Widget levelChild = client.getWidget(levelUpLevel);
    if (skillChild == null || levelChild == null) {
        return null;
    }
    // "Congratulations, you just advanced a Firemaking level."
    String skillText = skillChild.getText();
    // "Your Firemaking level is now 9."
    String levelText = levelChild.getText();
    String[] splitSkillName = skillText.split(" ");
    String skillName = splitSkillName[splitSkillName.length - 2];
    String skillLevel = levelText.substring(levelText.lastIndexOf(" ") + 1, levelText.length() - 1);
    return skillName + "(" + skillLevel + ")";
}
Also used : Widget(net.runelite.api.widgets.Widget)

Example 9 with Widget

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

the class ScreenshotPlugin method hideWidgets.

@Subscribe
public void hideWidgets(WidgetHiddenChanged event) {
    Widget widget = event.getWidget();
    if (widget.isHidden()) {
        return;
    }
    switch(TO_GROUP(widget.getId())) {
        case LEVEL_UP_GROUP_ID:
            if (!config.screenshotLevels()) {
                return;
            }
            break;
        case QUEST_COMPLETED_GROUP_ID:
        case CLUE_SCROLL_REWARD_GROUP_ID:
        case BARROWS_REWARD_GROUP_ID:
        case RAIDS_REWARD_GROUP_ID:
            if (!config.screenshotRewards()) {
                return;
            }
            break;
    }
    String fileName;
    switch(TO_GROUP(widget.getId())) {
        case LEVEL_UP_GROUP_ID:
            {
                fileName = parseLevelUpWidget(WidgetInfo.LEVEL_UP_SKILL, WidgetInfo.LEVEL_UP_LEVEL);
                break;
            }
        case DIALOG_SPRITE_GROUP_ID:
            {
                fileName = parseLevelUpWidget(WidgetInfo.DIALOG_SPRITE_SPRITE, WidgetInfo.DIALOG_SPRITE_TEXT);
                break;
            }
        case QUEST_COMPLETED_GROUP_ID:
            {
                Widget textChild = client.getWidget(WidgetInfo.QUEST_COMPLETED_NAME_TEXT);
                if (textChild == null) {
                    return;
                }
                // "You have completed The Corsair Curse!"
                String text = textChild.getText();
                fileName = text.substring(19, text.length() - 1);
                break;
            }
        case CLUE_SCROLL_REWARD_GROUP_ID:
            {
                if (clueType == null || clueNumber == null) {
                    return;
                }
                fileName = Character.toUpperCase(clueType.charAt(0)) + clueType.substring(1) + "(" + clueNumber + ")";
                clueType = null;
                clueNumber = null;
                break;
            }
        case BARROWS_REWARD_GROUP_ID:
            {
                if (barrowsNumber == null) {
                    return;
                }
                fileName = "Barrows(" + barrowsNumber + ")";
                barrowsNumber = null;
                break;
            }
        case RAIDS_REWARD_GROUP_ID:
            {
                if (raidsNumber == null) {
                    return;
                }
                fileName = "Raids(" + raidsNumber + ")";
                raidsNumber = null;
                break;
            }
        default:
            return;
    }
    if (fileName == null) {
        return;
    }
    takeScreenshot(fileName, config.displayDate());
}
Also used : Widget(net.runelite.api.widgets.Widget) Subscribe(com.google.common.eventbus.Subscribe)

Example 10 with Widget

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

the class SlayerPlugin method scheduledChecks.

@Schedule(period = 600, unit = ChronoUnit.MILLIS)
public void scheduledChecks() {
    Widget NPCDialog = client.getWidget(WidgetInfo.DIALOG_NPC_TEXT);
    if (NPCDialog != null) {
        // remove color and linebreaks
        String NPCText = Text.removeTags(NPCDialog.getText());
        // number, name
        Matcher mAssign = NPC_ASSIGN_MESSAGE.matcher(NPCText);
        // name, number
        Matcher mCurrent = NPC_CURRENT_MESSAGE.matcher(NPCText);
        boolean found1 = mAssign.find();
        boolean found2 = mCurrent.find();
        if (!found1 && !found2) {
            return;
        }
        String taskName = found1 ? mAssign.group(2) : mCurrent.group(1);
        int amount = Integer.parseInt(found1 ? mAssign.group(1) : mCurrent.group(2));
        setTask(taskName, amount);
    }
    Widget rewardsBarWidget = client.getWidget(WidgetInfo.SLAYER_REWARDS_TOPBAR);
    if (rewardsBarWidget != null) {
        for (Widget w : rewardsBarWidget.getDynamicChildren()) {
            Matcher mPoints = REWARD_POINTS.matcher(w.getText());
            if (mPoints.find()) {
                points = Integer.parseInt(mPoints.group(1));
                break;
            }
        }
    }
    if (infoTimer != null) {
        Duration timeSinceInfobox = Duration.between(infoTimer, Instant.now());
        Duration statTimeout = Duration.ofMinutes(config.statTimeout());
        if (timeSinceInfobox.compareTo(statTimeout) >= 0) {
            removeCounter();
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) Widget(net.runelite.api.widgets.Widget) Duration(java.time.Duration) Schedule(net.runelite.client.task.Schedule)

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