Class WidgetQuery
- java.lang.Object
-
- com.kraken.api.core.AbstractQuery<WidgetEntity,WidgetQuery,net.runelite.api.widgets.Widget>
-
- com.kraken.api.query.widget.WidgetQuery
-
public class WidgetQuery extends AbstractQuery<WidgetEntity,WidgetQuery,net.runelite.api.widgets.Widget>
-
-
Field Summary
-
Fields inherited from class com.kraken.api.core.AbstractQuery
ctx
-
-
Constructor Summary
Constructors Constructor Description WidgetQuery(Context ctx)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description WidgetEntityget(int packedId)Retrieves the firstWidgetEntitymatching the specified packed ID.WidgetEntityget(int groupId, int childId)Retrieves aWidgetEntitybased on the specified group ID and child ID.WidgetEntityget(net.runelite.api.widgets.WidgetInfo widgetInfo)Retrieves the firstWidgetEntitythat matches the specifiedWidgetInfo.WidgetQueryinGroup(int groupId)Filters for widgets belonging to a specific Interface Group.protected java.util.function.Supplier<java.util.stream.Stream<WidgetEntity>>source()WidgetQueryvisible()Filters for widgets which are currently visible on the canvas.WidgetQuerywithAction(java.lang.String action)Filters for widgets with a specific action.WidgetQuerywithChildId(int childId)Filters for a specific child component ID within a group.WidgetQuerywithGroupChild(int group, int child)Filters for a widget with a specific group ID and child ID.WidgetQuerywithId(int packedId)Filters for a widget with the exact packed ID.WidgetQuerywithIndex(int index)Filters by the widget's index in its parent's array.WidgetQuerywithListener()Finds widgets that have a specific listener (e.g., "Continue" buttons).WidgetQuerywithSprite(int spriteId)Finds widgets by their Sprite ID (images).WidgetQuerywithText(java.lang.String text)Filters for widgets containing the specified text in name, text, or actions.WidgetQuerywithText(java.lang.String text, boolean exact)Filters for widgets containing the specified text in name, text, or actions.
-
-
-
Constructor Detail
-
WidgetQuery
public WidgetQuery(Context ctx)
-
-
Method Detail
-
source
protected java.util.function.Supplier<java.util.stream.Stream<WidgetEntity>> source()
- Specified by:
sourcein classAbstractQuery<WidgetEntity,WidgetQuery,net.runelite.api.widgets.Widget>
-
withId
public WidgetQuery withId(int packedId)
Filters for a widget with the exact packed ID. Useful if you know the full ID (e.g., WidgetInfo.INVENTORY.getId()).- Overrides:
withIdin classAbstractQuery<WidgetEntity,WidgetQuery,net.runelite.api.widgets.Widget>- Parameters:
packedId- The packed widget id to search for. Packed ID's encapsulate both the group and child id into a single integer value.- Returns:
- WidgetQuery
-
get
public WidgetEntity get(int packedId)
Retrieves the firstWidgetEntitymatching the specified packed ID.This method filters widgets by their packed ID, which is a composite of the group ID and child ID. It is useful when the exact packed ID of a widget is known.
- Parameters:
packedId- The packed ID of the widget to retrieve. This ID encapsulates both the group and child ID into a single integer value.- Returns:
- The
WidgetEntitycorresponding to the specified packed ID, ornullif no matching widget is found.
-
get
public WidgetEntity get(net.runelite.api.widgets.WidgetInfo widgetInfo)
Retrieves the firstWidgetEntitythat matches the specifiedWidgetInfo.This method filters widgets based on the packed ID retrieved from the
WidgetInfoinstance.- Parameters:
widgetInfo- TheWidgetInfoinstance containing the packed ID to search for. The packed ID incorporates both the group and child ID.- Returns:
- The corresponding
WidgetEntity, ornullif no match is found.
-
get
public WidgetEntity get(int groupId, int childId)
Retrieves aWidgetEntitybased on the specified group ID and child ID.This method accesses a widget using its hierarchical identifiers:
- groupId: Represents the interface group to which the widget belongs.
- childId: Identifies the specific widget within the group.
The widget is created and returned as a
WidgetEntityinstance, allowing for further interaction or queries.- Parameters:
groupId- The group ID of the widget to retrieve. Represents the top-level container or interface.childId- The child ID of the widget to retrieve. Represents the specific item within the group.- Returns:
- A
WidgetEntityrepresenting the widget with the provided group ID and child ID, ornullif no matching widget is found.
-
withGroupChild
public WidgetQuery withGroupChild(int group, int child)
Filters for a widget with a specific group ID and child ID.This method evaluates the group and child ID of each widget by decomposing its packed ID. The packed ID is a combination where the group ID occupies the higher 16 bits, and the child ID occupies the lower 16 bits.
For example, in the packed id format:
packedId = (groupId << 16) | childId
The group ID and child ID are derived as follows:groupId = packedId >>> 16childId = packedId & 0xFFFF
Only the widgets that match the specified group and child ID will be included in the resulting query.
- Parameters:
group- The group identifier of the widget.child- The child identifier of the widget.- Returns:
- WidgetQuery A new query filtered for widgets with the specified group and child IDs.
-
inGroup
public WidgetQuery inGroup(int groupId)
Filters for widgets belonging to a specific Interface Group. Example: 149 is the Inventory group.- Parameters:
groupId- The group id of the widget to search for- Returns:
- WidgetQuery
-
withChildId
public WidgetQuery withChildId(int childId)
Filters for a specific child component ID within a group. Note: This checks the lower bits of the packed ID.- Parameters:
childId- The child widget id to search for- Returns:
- WidgetQuery
-
withIndex
public WidgetQuery withIndex(int index)
Filters by the widget's index in its parent's array. Crucial for dynamic lists (chatbox messages, bank slots) where every item has the same ID but a different index.- Parameters:
index- The index in the widgets parent array to search for- Returns:
- WidgetQuery
-
visible
public WidgetQuery visible()
Filters for widgets which are currently visible on the canvas.- Returns:
- WidgetQuery
-
withSprite
public WidgetQuery withSprite(int spriteId)
Finds widgets by their Sprite ID (images).- Parameters:
spriteId- The integer id of the sprite- Returns:
- WidgetQuery
-
withListener
public WidgetQuery withListener()
Finds widgets that have a specific listener (e.g., "Continue" buttons).- Returns:
- WidgetQuery
-
withAction
public WidgetQuery withAction(java.lang.String action)
Filters for widgets with a specific action.- Parameters:
action- The action string to filter widgets for- Returns:
- WidgetQuery
-
withText
public WidgetQuery withText(java.lang.String text)
Filters for widgets containing the specified text in name, text, or actions.- Parameters:
text- The text to search for- Returns:
- WidgetQuery
-
withText
public WidgetQuery withText(java.lang.String text, boolean exact)
Filters for widgets containing the specified text in name, text, or actions.- Parameters:
text- The text to search forexact- True if the text should match exactly otherwise a substring is used.- Returns:
- WidgetQuery
-
-