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

The following examples show how to use net.runelite.api.widgets.Widget#getItemId() . 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: CustomSwapper.java    From ExternalPlugins with GNU General Public License v3.0 6 votes vote down vote up
private Rectangle equipBounds(int id)
{
	final Widget equipmentWidget = client.getWidget(WidgetInfo.EQUIPMENT);

	if (equipmentWidget.getStaticChildren() == null)
	{
		return null;
	}

	for (Widget widgets : equipmentWidget.getStaticChildren())
	{
		for (Widget items : widgets.getDynamicChildren())
		{
			if (items.getItemId() == id)
			{
				return items.getBounds();
			}
		}
	}

	return null;
}
 
Example 2
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 3
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 4
Source File: WikiPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@Subscribe
private void onMenuOptionClicked(MenuOptionClicked ev)
{
	if (ev.getMenuOpcode() == MenuOpcode.RUNELITE)
	{
		checkQuestClicked(ev);
	}

	if (!wikiSelected)
	{
		return;
	}

	onDeselect();
	client.setSpellSelected(false);
	ev.consume();

	String type;
	int id;
	String name;
	WorldPoint location;

	switch (ev.getMenuOpcode())
	{
		case RUNELITE:
		case CANCEL:
			return;
		case ITEM_USE_ON_WIDGET:
		case SPELL_CAST_ON_GROUND_ITEM:
		{
			type = "item";
			id = itemManager.canonicalize(ev.getIdentifier());
			name = itemManager.getItemDefinition(id).getName();
			location = null;
			break;
		}
		case SPELL_CAST_ON_NPC:
		{
			type = "npc";
			NPC npc = client.getCachedNPCs()[ev.getIdentifier()];
			NPCDefinition nc = npc.getTransformedDefinition();
			id = nc.getId();
			name = nc.getName();
			location = npc.getWorldLocation();
			break;
		}
		case SPELL_CAST_ON_GAME_OBJECT:
		{
			type = "object";
			ObjectDefinition lc = client.getObjectDefinition(ev.getIdentifier());
			if (lc.getImpostorIds() != null)
			{
				lc = lc.getImpostor();
			}
			id = lc.getId();
			name = lc.getName();
			location = WorldPoint.fromScene(client, ev.getParam0(), ev.getParam1(), client.getPlane());
			break;
		}
		case SPELL_CAST_ON_WIDGET:
		{
			Widget w = getWidget(ev.getParam1(), ev.getParam0());

			if (w.getType() == WidgetType.GRAPHIC && w.getItemId() != -1)
			{
				type = "item";
				id = itemManager.canonicalize(w.getItemId());
				name = itemManager.getItemDefinition(id).getName();
				location = null;
				break;
			}
		}
			// fallthrough
		default:
			log.info("Unknown menu option: {} {} {}", ev, ev.getMenuOpcode(), ev.getMenuOpcode() == MenuOpcode.CANCEL);
			return;
	}

	name = Text.removeTags(name);
	HttpUrl.Builder urlBuilder = WIKI_BASE.newBuilder();
	urlBuilder.addPathSegments("w/Special:Lookup")
		.addQueryParameter("type", type)
		.addQueryParameter("id", "" + id)
		.addQueryParameter("name", name)
		.addQueryParameter(UTM_SOURCE_KEY, UTM_SOURCE_VALUE);

	if (location != null)
	{
		urlBuilder.addQueryParameter("x", "" + location.getX())
			.addQueryParameter("y", "" + location.getY())
			.addQueryParameter("plane", "" + location.getPlane());
	}

	HttpUrl url = urlBuilder.build();

	LinkBrowser.browse(url.toString());
}
 
Example 5
Source File: TabInterface.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
public void handleDrag(boolean isDragging, boolean shiftDown)
{
	if (isHidden())
	{
		return;
	}

	Widget draggedOn = client.getDraggedOnWidget();
	Widget draggedWidget = client.getDraggedWidget();

	// round-about way to prevent drag reordering when in a tag tab, now that it looks like a normal tab
	// returning early from drag release and nulling out the drag release listener have no effect,
	// probably a better way to do this though
	if (draggedWidget.getId() == WidgetInfo.BANK_ITEM_CONTAINER.getId() && isActive()
		&& config.removeSeparators())
	{
		client.setDraggedOnWidget(null);
	}

	if (!isDragging || draggedOn == null)
	{
		return;
	}

	// is dragging widget and mouse button released
	if (client.getMouseCurrentButton() == 0)
	{
		if (!isTabMenuActive() && draggedWidget.getItemId() > 0 && draggedWidget.getId() != parent.getId())
		{
			// Tag an item dragged on a tag tab
			if (draggedOn.getId() == parent.getId())
			{
				tagManager.addTag(draggedWidget.getItemId(), draggedOn.getName(), shiftDown);
				updateTabIfActive(Lists.newArrayList(Text.standardize(draggedOn.getName())));
			}
		}
		else if ((isTabMenuActive() && draggedWidget.getId() == draggedOn.getId() && draggedOn.getId() != parent.getId())
			|| (parent.getId() == draggedOn.getId() && parent.getId() == draggedWidget.getId()))
		{
			moveTagTab(draggedWidget, draggedOn);
		}
	}
	else if (draggedWidget.getItemId() > 0)
	{
		MenuEntry[] entries = client.getMenuEntries();

		if (entries.length > 0)
		{
			MenuEntry entry = entries[entries.length - 1];

			if (draggedWidget.getItemId() > 0 && entry.getOption().equals(VIEW_TAB) && draggedOn.getId() != draggedWidget.getId())
			{
				entry.setOption(TAG_SEARCH + Text.removeTags(entry.getTarget()) + (shiftDown ? VAR_TAG_SUFFIX : ""));
				entry.setTarget(draggedWidget.getName());
				client.setMenuEntries(entries);
			}

			if (entry.getOption().equals(SCROLL_UP))
			{
				scrollTick(-1);
			}
			else if (entry.getOption().equals(SCROLL_DOWN))
			{
				scrollTick(1);
			}
		}
	}
}
 
Example 6
Source File: TabInterface.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void handleDrag(boolean isDragging, boolean shiftDown)
{
	if (isHidden())
	{
		return;
	}

	Widget draggedOn = client.getDraggedOnWidget();
	Widget draggedWidget = client.getDraggedWidget();

	if (!isDragging || draggedOn == null)
	{
		return;
	}

	// is dragging widget and mouse button released
	if (client.getMouseCurrentButton() == 0)
	{
		if (!isTabMenuActive() && draggedWidget.getItemId() > 0 && draggedWidget.getId() != parent.getId())
		{
			// Tag an item dragged on a tag tab
			if (draggedOn.getId() == parent.getId())
			{
				tagManager.addTag(draggedWidget.getItemId(), draggedOn.getName(), shiftDown);
				updateTabIfActive(Lists.newArrayList(Text.standardize(draggedOn.getName())));
			}
		}
		else if ((isTabMenuActive() && draggedWidget.getId() == draggedOn.getId() && draggedOn.getId() != parent.getId())
			|| (parent.getId() == draggedOn.getId() && parent.getId() == draggedWidget.getId()))
		{
			// Reorder tag tabs
			moveTagTab(draggedWidget, draggedOn);
		}
	}
	else if (draggedWidget.getItemId() > 0)
	{
		MenuEntry[] entries = client.getMenuEntries();

		if (entries.length > 0)
		{
			MenuEntry entry = entries[entries.length - 1];

			if (draggedWidget.getItemId() > 0 && entry.getOption().equals(VIEW_TAB) && draggedOn.getId() != draggedWidget.getId())
			{
				entry.setOption(TAG_SEARCH + Text.removeTags(entry.getTarget()) + (shiftDown ? VAR_TAG_SUFFIX : ""));
				entry.setTarget(draggedWidget.getName());
				client.setMenuEntries(entries);
			}

			if (entry.getOption().equals(SCROLL_UP))
			{
				scrollTick(-1);
			}
			else if (entry.getOption().equals(SCROLL_DOWN))
			{
				scrollTick(1);
			}
		}
	}
}