Java Code Examples for net.runelite.api.widgets.Widget#getChild()

The following examples show how to use net.runelite.api.widgets.Widget#getChild() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ItemStatPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
private void resetGEInventory()
{
	final Widget invContainer = getInventoryContainer();

	if (invContainer == null)
	{
		return;
	}

	if (itemInformationTitle != null && invContainer.getChild(0) == itemInformationTitle)
	{
		invContainer.deleteAllChildren();
		itemInformationTitle = null;
	}

	final Widget geInv = client.getWidget(WidgetInfo.GRAND_EXCHANGE_INVENTORY_ITEMS_CONTAINER);
	if (geInv != null)
	{
		geInv.setHidden(false);
	}
}
 
Example 2
Source File: FriendsChatPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
private void colorIgnoredPlayers(Color ignoreColor)
{
	Widget chatList = client.getWidget(WidgetInfo.FRIENDS_CHAT_LIST);
	if (chatList == null || chatList.getChildren() == null)
	{
		return;
	}

	NameableContainer<Ignore> ignoreContainer = client.getIgnoreContainer();
	// Iterate every 3 widgets, since the order of widgets is name, world, icon
	for (int i = 0; i < chatList.getChildren().length; i += 3)
	{
		Widget listWidget = chatList.getChild(i);
		String memberName = listWidget.getText();
		if (memberName.isEmpty() || ignoreContainer.findByName(memberName) == null)
		{
			continue;
		}

		listWidget.setTextColor(ignoreColor.getRGB());
	}
}
 
Example 3
Source File: FriendsChatPlugin.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void colorIgnoredPlayers(Color ignoreColor)
{
	Widget chatList = client.getWidget(WidgetInfo.FRIENDS_CHAT_LIST);
	if (chatList == null || chatList.getChildren() == null)
	{
		return;
	}

	NameableContainer<Ignore> ignoreContainer = client.getIgnoreContainer();
	// Iterate every 3 widgets, since the order of widgets is name, world, icon
	for (int i = 0; i < chatList.getChildren().length; i += 3)
	{
		Widget listWidget = chatList.getChild(i);
		String memberName = listWidget.getText();
		if (memberName.isEmpty() || ignoreContainer.findByName(memberName) == null)
		{
			continue;
		}

		listWidget.setTextColor(ignoreColor.getRGB());
	}
}
 
Example 4
Source File: ItemStatPlugin.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void resetGEInventory()
{
	final Widget invContainer = getInventoryContainer();

	if (invContainer == null)
	{
		return;
	}

	if (itemInformationTitle != null && invContainer.getChild(0) == itemInformationTitle)
	{
		invContainer.deleteAllChildren();
		itemInformationTitle = null;
	}

	final Widget geInv = client.getWidget(WidgetInfo.GRAND_EXCHANGE_INVENTORY_ITEMS_CONTAINER);
	if (geInv != null)
	{
		geInv.setHidden(false);
	}
}
 
Example 5
Source File: WikiPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
private Widget getWidget(int wid, int index)
{
	Widget w = client.getWidget(WidgetInfo.TO_GROUP(wid), WidgetInfo.TO_CHILD(wid));
	if (index != -1)
	{
		w = w.getChild(index);
	}
	return w;
}
 
Example 6
Source File: BankTagsPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
private void onMenuEntryAdded(MenuEntryAdded event)
{
	if (event.getParam1() == WidgetInfo.BANK_ITEM_CONTAINER.getId()
		&& event.getOption().equals("Examine"))
	{
		Widget container = client.getWidget(WidgetInfo.BANK_ITEM_CONTAINER);
		Widget item = container.getChild(event.getParam0());
		int itemID = item.getItemId();
		String text = EDIT_TAGS_MENU_OPTION;
		int tagCount = tagManager.getTags(itemID, false).size() + tagManager.getTags(itemID, true).size();

		if (tagCount > 0)
		{
			text += " (" + tagCount + ")";
		}

		client.insertMenuItem(
			text,
			event.getTarget(),
			MenuOpcode.RUNELITE.getId(),
			event.getIdentifier(),
			event.getParam0(),
			event.getParam1(),
			false
		);
	}

	tabInterface.handleAdd(event);
}
 
Example 7
Source File: BankGridOverlay.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
private static Widget findDraggedWidgetIndex(Client client, Widget widget, int size)
{
	for (int i = 0; i < size; i++)
	{
		if (client.getDraggedWidget() == widget.getChild(i))
		{
			return widget.getChild(i);
		}
	}

	return null;
}
 
Example 8
Source File: WikiPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Widget getWidget(int wid, int index)
{
	Widget w = client.getWidget(WidgetInfo.TO_GROUP(wid), WidgetInfo.TO_CHILD(wid));
	if (index != -1)
	{
		w = w.getChild(index);
	}
	return w;
}
 
Example 9
Source File: BankTagsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded event)
{
	MenuEntry[] entries = client.getMenuEntries();

	if (event.getActionParam1() == WidgetInfo.BANK_ITEM_CONTAINER.getId()
		&& event.getOption().equals("Examine"))
	{
		Widget container = client.getWidget(WidgetInfo.BANK_ITEM_CONTAINER);
		Widget item = container.getChild(event.getActionParam0());
		int itemID = item.getItemId();
		String text = EDIT_TAGS_MENU_OPTION;
		int tagCount = tagManager.getTags(itemID, false).size() + tagManager.getTags(itemID, true).size();

		if (tagCount > 0)
		{
			text += " (" + tagCount + ")";
		}

		MenuEntry editTags = new MenuEntry();
		editTags.setParam0(event.getActionParam0());
		editTags.setParam1(event.getActionParam1());
		editTags.setTarget(event.getTarget());
		editTags.setOption(text);
		editTags.setType(MenuAction.RUNELITE.getId());
		editTags.setIdentifier(event.getIdentifier());
		entries = Arrays.copyOf(entries, entries.length + 1);
		entries[entries.length - 1] = editTags;
		client.setMenuEntries(entries);
	}

	tabInterface.handleAdd(event);
}
 
Example 10
Source File: ScreenMarkerWidgetHighlightOverlay.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Dimension render(Graphics2D graphics)
{
	if (!plugin.isCreatingScreenMarker() || plugin.isDrawingScreenMarker())
	{
		return null;
	}

	final MenuEntry[] menuEntries = client.getMenuEntries();

	if (client.isMenuOpen() || menuEntries.length == 0)
	{
		plugin.setSelectedWidgetBounds(null);
		return null;
	}

	final MenuEntry menuEntry = menuEntries[menuEntries.length - 1];
	final int childIdx = menuEntry.getParam0();
	final int widgetId = menuEntry.getParam1();
	final int groupId = WidgetInfo.TO_GROUP(widgetId);
	final int componentId = WidgetInfo.TO_CHILD(widgetId);

	final Widget widget = client.getWidget(groupId, componentId);
	if (widget == null)
	{
		plugin.setSelectedWidgetBounds(null);
		return null;
	}

	Rectangle bounds = null;
	if (childIdx > -1)
	{
		if (widget.getType() == WidgetType.INVENTORY)
		{
			final WidgetItem widgetItem = widget.getWidgetItem(childIdx);
			if (widgetItem != null)
			{
				bounds = widgetItem.getCanvasBounds();
			}
		}
		else
		{
			final Widget child = widget.getChild(childIdx);
			if (child != null)
			{
				bounds = child.getBounds();
			}
		}
	}
	else
	{
		bounds = widget.getBounds();
	}

	if (bounds == null)
	{
		plugin.setSelectedWidgetBounds(null);
		return null;
	}

	drawHighlight(graphics, bounds);
	plugin.setSelectedWidgetBounds(bounds);

	return null;
}
 
Example 11
Source File: ChatHistoryPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@Subscribe
public void onMenuOpened(MenuOpened event)
{
	if (event.getMenuEntries().length < 2 || !config.copyToClipboard())
	{
		return;
	}

	// Use second entry as first one can be walk here with transparent chatbox
	final MenuEntry entry = event.getMenuEntries()[event.getMenuEntries().length - 2];

	if (entry.getOpcode() != MenuOpcode.CC_OP_LOW_PRIORITY.getId() && entry.getOpcode() != MenuOpcode.RUNELITE.getId())
	{
		return;
	}

	final int groupId = TO_GROUP(entry.getParam1());
	final int childId = TO_CHILD(entry.getParam1());

	if (groupId != WidgetInfo.CHATBOX.getGroupId())
	{
		return;
	}

	final Widget widget = client.getWidget(groupId, childId);
	final Widget parent = widget.getParent();

	if (WidgetInfo.CHATBOX_MESSAGE_LINES.getId() != parent.getId())
	{
		return;
	}

	// Get child id of first chat message static child so we can substract this offset to link to dynamic child
	// later
	final int first = WidgetInfo.CHATBOX_FIRST_MESSAGE.getChildId();

	// Convert current message static widget id to dynamic widget id of message node with message contents
	// When message is right clicked, we are actually right clicking static widget that contains only sender.
	// The actual message contents are stored in dynamic widgets that follow same order as static widgets.
	// Every first dynamic widget is message sender and every second one is message contents.
	final int dynamicChildId = (childId - first) * 2 + 1;

	// Extract and store message contents when menu is opened because dynamic children can change while right click
	// menu is open and dynamicChildId will be outdated
	final Widget messageContents = parent.getChild(dynamicChildId);
	if (messageContents == null)
	{
		return;
	}

	currentMessage = messageContents.getText();

	final MenuEntry menuEntry = new MenuEntry();
	menuEntry.setOption(COPY_TO_CLIPBOARD);
	menuEntry.setTarget(entry.getTarget());
	menuEntry.setOpcode(MenuOpcode.RUNELITE.getId());
	menuEntry.setParam0(entry.getParam0());
	menuEntry.setParam1(entry.getParam1());
	menuEntry.setIdentifier(entry.getIdentifier());
	client.setMenuEntries(ArrayUtils.insert(1, client.getMenuEntries(), menuEntry));
}
 
Example 12
Source File: BankPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Subscribe
public void onScriptCallbackEvent(ScriptCallbackEvent event)
{
	int[] intStack = client.getIntStack();
	String[] stringStack = client.getStringStack();
	int intStackSize = client.getIntStackSize();
	int stringStackSize = client.getStringStackSize();

	switch (event.getEventName())
	{
		case "setBankTitle":
			final ContainerPrices prices = calculate(getBankTabItems());
			if (prices == null)
			{
				return;
			}

			final String strCurrentTab = createValueText(prices);

			stringStack[stringStackSize - 1] += strCurrentTab;
			break;
		case "bankSearchFilter":
			int itemId = intStack[intStackSize - 1];
			String search = stringStack[stringStackSize - 1];

			if (valueSearch(itemId, search))
			{
				// return true
				intStack[intStackSize - 2] = 1;
			}

			break;
		case "bankpinButtonSetup":
		{
			if (!config.bankPinKeyboard())
			{
				return;
			}

			final int compId = intStack[intStackSize - 2];
			final int buttonId = intStack[intStackSize - 1];
			Widget button = client.getWidget(TO_GROUP(compId), TO_CHILD(compId));
			Widget buttonRect = button.getChild(0);

			final Object[] onOpListener = buttonRect.getOnOpListener();
			buttonRect.setOnKeyListener((JavaScriptCallback) e ->
			{
				int typedChar = e.getTypedKeyChar() - '0';
				if (typedChar != buttonId)
				{
					return;
				}

				log.debug("Bank pin keypress");

				final String input = client.getVar(VarClientStr.CHATBOX_TYPED_TEXT);
				clientThread.invokeLater(() ->
				{
					// reset chatbox input to avoid pin going to chatbox..
					client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, input);
					client.runScript(ScriptID.CHAT_PROMPT_INIT);

					client.runScript(onOpListener);
				});
			});
			break;
		}
	}
}
 
Example 13
Source File: ScreenMarkerWidgetHighlightOverlay.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public Dimension render(Graphics2D graphics)
{
	if (!plugin.isCreatingScreenMarker() || plugin.isDrawingScreenMarker())
	{
		return null;
	}

	final MenuEntry[] menuEntries = client.getMenuEntries();
	if (client.isMenuOpen() || menuEntries.length == 0)
	{
		plugin.setSelectedWidgetBounds(null);
		return null;
	}

	final MenuEntry menuEntry = menuEntries[menuEntries.length - 1];
	final int childIdx = menuEntry.getParam0();
	final int widgetId = menuEntry.getParam1();
	final int groupId = WidgetInfo.TO_GROUP(widgetId);
	final int componentId = WidgetInfo.TO_CHILD(widgetId);

	final Widget widget = client.getWidget(groupId, componentId);
	if (widget == null)
	{
		plugin.setSelectedWidgetBounds(null);
		return null;
	}

	Rectangle bounds = null;
	if (childIdx > -1)
	{
		if (widget.getType() == WidgetType.INVENTORY)
		{
			final WidgetItem widgetItem = widget.getWidgetItem(childIdx);
			if (widgetItem != null)
			{
				bounds = widgetItem.getCanvasBounds();
			}
		}
		else
		{
			final Widget child = widget.getChild(childIdx);
			if (child != null)
			{
				bounds = child.getBounds();
			}
		}
	}
	else
	{
		bounds = widget.getBounds();
	}

	if (bounds == null)
	{
		plugin.setSelectedWidgetBounds(null);
		return null;
	}

	drawHighlight(graphics, bounds);
	plugin.setSelectedWidgetBounds(bounds);

	return null;
}
 
Example 14
Source File: ChatHistoryPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Subscribe
public void onMenuOpened(MenuOpened event)
{
	if (event.getMenuEntries().length < 2 || !config.copyToClipboard())
	{
		return;
	}

	// Use second entry as first one can be walk here with transparent chatbox
	final MenuEntry entry = event.getMenuEntries()[event.getMenuEntries().length - 2];

	if (entry.getType() != MenuAction.CC_OP_LOW_PRIORITY.getId() && entry.getType() != MenuAction.RUNELITE.getId())
	{
		return;
	}

	final int groupId = TO_GROUP(entry.getParam1());
	final int childId = TO_CHILD(entry.getParam1());

	if (groupId != WidgetInfo.CHATBOX.getGroupId())
	{
		return;
	}

	final Widget widget = client.getWidget(groupId, childId);
	final Widget parent = widget.getParent();

	if (WidgetInfo.CHATBOX_MESSAGE_LINES.getId() != parent.getId())
	{
		return;
	}

	// Get child id of first chat message static child so we can substract this offset to link to dynamic child
	// later
	final int first = WidgetInfo.CHATBOX_FIRST_MESSAGE.getChildId();

	// Convert current message static widget id to dynamic widget id of message node with message contents
	// When message is right clicked, we are actually right clicking static widget that contains only sender.
	// The actual message contents are stored in dynamic widgets that follow same order as static widgets.
	// Every first dynamic widget is message sender and every second one is message contents.
	final int dynamicChildId = (childId - first) * 2 + 1;

	// Extract and store message contents when menu is opened because dynamic children can change while right click
	// menu is open and dynamicChildId will be outdated
	final Widget messageContents = parent.getChild(dynamicChildId);
	if (messageContents == null)
	{
		return;
	}

	currentMessage = messageContents.getText();

	final MenuEntry menuEntry = new MenuEntry();
	menuEntry.setOption(COPY_TO_CLIPBOARD);
	menuEntry.setTarget(entry.getTarget());
	menuEntry.setType(MenuAction.RUNELITE.getId());
	menuEntry.setParam0(entry.getParam0());
	menuEntry.setParam1(entry.getParam1());
	menuEntry.setIdentifier(entry.getIdentifier());
	client.setMenuEntries(ArrayUtils.insert(1, client.getMenuEntries(), menuEntry));
}