Java Code Examples for net.runelite.api.events.MenuOptionClicked#getWidgetId()

The following examples show how to use net.runelite.api.events.MenuOptionClicked#getWidgetId() . 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: MenuManager.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onMenuOptionClicked(MenuOptionClicked event)
{
	if (event.getMenuAction() != MenuAction.RUNELITE
		&& event.getMenuAction() != MenuAction.RUNELITE_PLAYER)
	{
		return; // not a managed widget option or custom player option
	}

	int widgetId = event.getWidgetId();
	Collection<WidgetMenuOption> options = managedMenuOptions.get(widgetId);

	for (WidgetMenuOption curMenuOption : options)
	{
		if (curMenuOption.getMenuTarget().equals(event.getMenuTarget())
			&& curMenuOption.getMenuOption().equals(event.getMenuOption()))
		{
			WidgetMenuOptionClicked customMenu = new WidgetMenuOptionClicked();
			customMenu.setMenuOption(event.getMenuOption());
			customMenu.setMenuTarget(event.getMenuTarget());
			customMenu.setWidget(curMenuOption.getWidget());
			eventBus.post(customMenu);
			return; // don't continue because it's not a player option
		}
	}

	// removes bounty hunter emblem tag and tier from player name, e.g:
	// "username<img=20>5<col=40ff00>  (level-42)" -> "username<col=40ff00>  (level-42)"
	String target = BOUNTY_EMBLEM_TAG_AND_TIER_REGEXP.matcher(event.getMenuTarget()).replaceAll("");

	// removes tags and level from player names for example:
	// <col=ffffff>username<col=40ff00>  (level-42) or <col=ffffff><img=2>username</col>
	String username = Text.removeTags(target).split("[(]")[0].trim();

	PlayerMenuOptionClicked playerMenuOptionClicked = new PlayerMenuOptionClicked();
	playerMenuOptionClicked.setMenuOption(event.getMenuOption());
	playerMenuOptionClicked.setMenuTarget(username);

	eventBus.post(playerMenuOptionClicked);
}
 
Example 2
Source File: ObjectIndicatorsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onMenuOptionClicked(MenuOptionClicked event)
{
	if (event.getMenuAction() != MenuAction.RUNELITE
		|| !(event.getMenuOption().equals(MARK) || event.getMenuOption().equals(UNMARK)))
	{
		return;
	}

	Scene scene = client.getScene();
	Tile[][][] tiles = scene.getTiles();
	final int x = event.getActionParam();
	final int y = event.getWidgetId();
	final int z = client.getPlane();
	final Tile tile = tiles[z][x][y];

	TileObject object = findTileObject(tile, event.getId());
	if (object == null)
	{
		return;
	}

	// object.getId() is always the base object id, getObjectComposition transforms it to
	// the correct object we see
	ObjectComposition objectDefinition = getObjectComposition(object.getId());
	String name = objectDefinition.getName();
	// Name is probably never "null" - however prevent adding it if it is, as it will
	// become ambiguous as objects with no name are assigned name "null"
	if (Strings.isNullOrEmpty(name) || name.equals("null"))
	{
		return;
	}

	markObject(objectDefinition, name, object);
}
 
Example 3
Source File: ExaminePlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Subscribe
public void onMenuOptionClicked(MenuOptionClicked event)
{
	if (!Text.removeTags(event.getMenuOption()).equals("Examine"))
	{
		return;
	}

	ExamineType type;
	int id, quantity = -1;
	switch (event.getMenuAction())
	{
		case EXAMINE_ITEM:
		{
			type = ExamineType.ITEM;
			id = event.getId();

			int widgetId = event.getWidgetId();
			int widgetGroup = TO_GROUP(widgetId);
			int widgetChild = TO_CHILD(widgetId);
			Widget widget = client.getWidget(widgetGroup, widgetChild);
			WidgetItem widgetItem = widget.getWidgetItem(event.getActionParam());
			quantity = widgetItem != null && widgetItem.getId() >= 0 ? widgetItem.getQuantity() : 1;
			break;
		}
		case EXAMINE_ITEM_GROUND:
			type = ExamineType.ITEM;
			id = event.getId();
			break;
		case CC_OP_LOW_PRIORITY:
		{
			type = ExamineType.ITEM_BANK_EQ;
			int[] qi = findItemFromWidget(event.getWidgetId(), event.getActionParam());
			if (qi == null)
			{
				log.debug("Examine for item with unknown widget: {}", event);
				return;
			}
			quantity = qi[0];
			id = qi[1];
			break;
		}
		case EXAMINE_OBJECT:
			type = ExamineType.OBJECT;
			id = event.getId();
			break;
		case EXAMINE_NPC:
			type = ExamineType.NPC;
			id = event.getId();
			break;
		default:
			return;
	}

	PendingExamine pendingExamine = new PendingExamine();
	pendingExamine.setType(type);
	pendingExamine.setId(id);
	pendingExamine.setQuantity(quantity);
	pendingExamine.setCreated(Instant.now());
	pending.push(pendingExamine);
}
 
Example 4
Source File: TabInterface.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void handleClick(MenuOptionClicked event)
{
	if (isHidden())
	{
		return;
	}

	if (chatboxPanelManager.getCurrentInput() != null
		&& event.getMenuAction() != MenuAction.CANCEL
		&& !event.getMenuOption().equals(SCROLL_UP)
		&& !event.getMenuOption().equals(SCROLL_DOWN))
	{
		chatboxPanelManager.close();
	}

	if ((event.getWidgetId() == WidgetInfo.BANK_ITEM_CONTAINER.getId()
			|| event.getWidgetId() == WidgetInfo.BANK_INVENTORY_ITEMS_CONTAINER.getId())
		&& event.getMenuAction() == MenuAction.CC_OP_LOW_PRIORITY
		&& (event.getMenuOption().equalsIgnoreCase("withdraw-x")
			|| event.getMenuOption().equalsIgnoreCase("deposit-x")))
	{
		waitSearchTick = true;
		rememberedSearch = client.getVar(VarClientStr.INPUT_TEXT);
		bankSearch.search(InputType.NONE, rememberedSearch, true);
	}

	if (activeTab != null
		&& event.getMenuOption().equals("Search")
		&& client.getWidget(WidgetInfo.BANK_SEARCH_BUTTON_BACKGROUND).getSpriteId() != SpriteID.EQUIPMENT_SLOT_SELECTED)
	{
		activateTab(null);
		// This ensures that when clicking Search when tab is selected, the search input is opened rather
		// than client trying to close it first
		client.setVar(VarClientStr.INPUT_TEXT, "");
		client.setVar(VarClientInt.INPUT_TYPE, 0);
	}
	else if (activeTab != null
		&& event.getMenuOption().startsWith("View tab"))
	{
		activateTab(null);
	}
	else if (activeTab != null
		&& event.getWidgetId() == WidgetInfo.BANK_ITEM_CONTAINER.getId()
		&& event.getMenuAction() == MenuAction.RUNELITE
		&& event.getMenuOption().startsWith(REMOVE_TAG))
	{
		// Add "remove" menu entry to all items in bank while tab is selected
		event.consume();
		final ItemComposition item = getItem(event.getActionParam());
		final int itemId = item.getId();
		tagManager.removeTag(itemId, activeTab.getTag());
		bankSearch.search(InputType.SEARCH, TAG_SEARCH + activeTab.getTag(), true);
	}
	else if (event.getMenuAction() == MenuAction.RUNELITE
		&& ((event.getWidgetId() == WidgetInfo.BANK_DEPOSIT_INVENTORY.getId() && event.getMenuOption().equals(TAG_INVENTORY))
		|| (event.getWidgetId() == WidgetInfo.BANK_DEPOSIT_EQUIPMENT.getId() && event.getMenuOption().equals(TAG_GEAR))))
	{
		handleDeposit(event, event.getWidgetId() == WidgetInfo.BANK_DEPOSIT_INVENTORY.getId());
	}
	else if (activeTab != null && ((event.getWidgetId() == WidgetInfo.BANK_EQUIPMENT_BUTTON.getId() && event.getMenuOption().equals(SHOW_WORN))
		|| (event.getWidgetId() == WidgetInfo.BANK_SETTINGS_BUTTON.getId() && event.getMenuOption().equals(SHOW_SETTINGS))
		|| (event.getWidgetId() == WidgetInfo.BANK_TUTORIAL_BUTTON.getId() && event.getMenuOption().equals(SHOW_TUTORIAL))))
	{
		saveTab();
		rememberedSearch = TAG_SEARCH + activeTab.getTag();
	}
	else if (!Strings.isNullOrEmpty(rememberedSearch) && ((event.getWidgetId() == WidgetInfo.BANK_EQUIPMENT_BUTTON.getId() && event.getMenuOption().equals(HIDE_WORN))
			|| (event.getWidgetId() == WidgetInfo.BANK_SETTINGS_BUTTON.getId() && event.getMenuOption().equals(HIDE_SETTINGS))))
	{
		bankSearch.reset(true);
		bankSearch.search(InputType.NONE, rememberedSearch, true);
		rememberedSearch = "";
	}
}
 
Example 5
Source File: BankTagsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Subscribe
public void onMenuOptionClicked(MenuOptionClicked event)
{
	if (event.getWidgetId() == WidgetInfo.BANK_ITEM_CONTAINER.getId()
		&& event.getMenuAction() == MenuAction.RUNELITE
		&& event.getMenuOption().startsWith(EDIT_TAGS_MENU_OPTION))
	{
		event.consume();
		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();
		ItemComposition itemComposition = itemManager.getItemComposition(itemId);
		String name = itemComposition.getName();

		// Get both tags and vartags and append * to end of vartags name
		Collection<String> tags = tagManager.getTags(itemId, false);
		tagManager.getTags(itemId, true).stream()
			.map(i -> i + "*")
			.forEach(tags::add);

		boolean isSearchOpen = client.getVar(VarClientInt.INPUT_TYPE) == InputType.SEARCH.getType();
		String searchText = client.getVar(VarClientStr.INPUT_TEXT);
		String initialValue = Text.toCSV(tags);

		chatboxPanelManager.openTextInput(name + " tags:<br>(append " + VAR_TAG_SUFFIX + " for variation tag)")
			.addCharValidator(FILTERED_CHARS)
			.value(initialValue)
			.onDone((Consumer<String>) (newValue) ->
				clientThread.invoke(() ->
				{
					// Split inputted tags to vartags (ending with *) and regular tags
					final Collection<String> newTags = new ArrayList<>(Text.fromCSV(newValue.toLowerCase()));
					final Collection<String> newVarTags = new ArrayList<>(newTags).stream().filter(s -> s.endsWith(VAR_TAG_SUFFIX)).map(s ->
					{
						newTags.remove(s);
						return s.substring(0, s.length() - VAR_TAG_SUFFIX.length());
					}).collect(Collectors.toList());

					// And save them
					tagManager.setTagString(itemId, Text.toCSV(newTags), false);
					tagManager.setTagString(itemId, Text.toCSV(newVarTags), true);

					// Check both previous and current tags in case the tag got removed in new tags or in case
					// the tag got added in new tags
					tabInterface.updateTabIfActive(Text.fromCSV(initialValue.toLowerCase().replaceAll(Pattern.quote(VAR_TAG_SUFFIX), "")));
					tabInterface.updateTabIfActive(Text.fromCSV(newValue.toLowerCase().replaceAll(Pattern.quote(VAR_TAG_SUFFIX), "")));
				}))
			.build();

		if (isSearchOpen)
		{
			bankSearch.reset(false);
			bankSearch.search(InputType.SEARCH, searchText, false);
		}
	}
	else
	{
		tabInterface.handleClick(event);
	}
}
 
Example 6
Source File: PuzzleSolverPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Subscribe
public void onMenuOptionClicked(MenuOptionClicked menuOptionClicked)
{
	int widgetId = menuOptionClicked.getWidgetId();
	if (TO_GROUP(widgetId) != WidgetID.LIGHT_BOX_GROUP_ID)
	{
		return;
	}

	Combination combination;
	if (widgetId == LIGHT_BOX_BUTTON_A.getId())
	{
		combination = Combination.A;
	}
	else if (widgetId == LIGHT_BOX_BUTTON_B.getId())
	{
		combination = Combination.B;
	}
	else if (widgetId == LIGHT_BOX_BUTTON_C.getId())
	{
		combination = Combination.C;
	}
	else if (widgetId == LIGHT_BOX_BUTTON_D.getId())
	{
		combination = Combination.D;
	}
	else if (widgetId == LIGHT_BOX_BUTTON_E.getId())
	{
		combination = Combination.E;
	}
	else if (widgetId == LIGHT_BOX_BUTTON_F.getId())
	{
		combination = Combination.F;
	}
	else if (widgetId == LIGHT_BOX_BUTTON_G.getId())
	{
		combination = Combination.G;
	}
	else if (widgetId == LIGHT_BOX_BUTTON_H.getId())
	{
		combination = Combination.H;
	}
	else
	{
		return;
	}

	if (lastClick != null)
	{
		lastClickInvalid = true;
	}
	else
	{
		lastClick = combination;
	}
}
 
Example 7
Source File: MenuEntrySwapperPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Subscribe
public void onMenuOptionClicked(MenuOptionClicked event)
{
	if (event.getMenuAction() != MenuAction.RUNELITE || event.getWidgetId() != WidgetInfo.INVENTORY.getId())
	{
		return;
	}

	int itemId = event.getId();

	if (itemId == -1)
	{
		return;
	}

	String option = event.getMenuOption();
	String target = event.getMenuTarget();
	ItemComposition itemComposition = client.getItemDefinition(itemId);

	if (option.equals(RESET) && target.equals(MENU_TARGET))
	{
		unsetSwapConfig(itemId);
		return;
	}

	if (!itemComposition.getName().equals(Text.removeTags(target)))
	{
		return;
	}

	if (option.equals("Use")) //because "Use" is not in inventoryActions
	{
		setSwapConfig(itemId, -1);
	}
	else
	{
		String[] inventoryActions = itemComposition.getInventoryActions();

		for (int index = 0; index < inventoryActions.length; index++)
		{
			if (option.equals(inventoryActions[index]))
			{
				setSwapConfig(itemId, index);
				break;
			}
		}
	}
}