Java Code Examples for net.runelite.api.events.MenuEntryAdded#getActionParam0()

The following examples show how to use net.runelite.api.events.MenuEntryAdded#getActionParam0() . 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: ObjectIndicatorsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded event)
{
	if (event.getType() != MenuAction.EXAMINE_OBJECT.getId() || !client.isKeyPressed(KeyCode.KC_SHIFT))
	{
		return;
	}

	final Tile tile = client.getScene().getTiles()[client.getPlane()][event.getActionParam0()][event.getActionParam1()];
	final TileObject tileObject = findTileObject(tile, event.getIdentifier());

	if (tileObject == null)
	{
		return;
	}

	MenuEntry[] menuEntries = client.getMenuEntries();
	menuEntries = Arrays.copyOf(menuEntries, menuEntries.length + 1);
	MenuEntry menuEntry = menuEntries[menuEntries.length - 1] = new MenuEntry();
	menuEntry.setOption(objects.stream().anyMatch(o -> o.getTileObject() == tileObject) ? UNMARK : MARK);
	menuEntry.setTarget(event.getTarget());
	menuEntry.setParam0(event.getActionParam0());
	menuEntry.setParam1(event.getActionParam1());
	menuEntry.setIdentifier(event.getIdentifier());
	menuEntry.setType(MenuAction.RUNELITE.getId());
	client.setMenuEntries(menuEntries);
}
 
Example 2
Source File: GroundItemsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded event)
{
	if (config.itemHighlightMode() != OVERLAY)
	{
		final boolean telegrabEntry = event.getOption().equals("Cast") && event.getTarget().startsWith(TELEGRAB_TEXT) && event.getType() == CAST_ON_ITEM;
		if (!(event.getOption().equals("Take") && event.getType() == THIRD_OPTION) && !telegrabEntry)
		{
			return;
		}

		final int itemId = event.getIdentifier();
		final int sceneX = event.getActionParam0();
		final int sceneY = event.getActionParam1();

		MenuEntry[] menuEntries = client.getMenuEntries();
		MenuEntry lastEntry = menuEntries[menuEntries.length - 1];

		final WorldPoint worldPoint = WorldPoint.fromScene(client, sceneX, sceneY, client.getPlane());
		GroundItem.GroundItemKey groundItemKey = new GroundItem.GroundItemKey(itemId, worldPoint);
		GroundItem groundItem = collectedGroundItems.get(groundItemKey);
		int quantity = groundItem.getQuantity();

		final int gePrice = groundItem.getGePrice();
		final int haPrice = groundItem.getHaPrice();
		final Color hidden = getHidden(new NamedQuantity(groundItem.getName(), quantity), gePrice, haPrice, groundItem.isTradeable());
		final Color highlighted = getHighlighted(new NamedQuantity(groundItem.getName(), quantity), gePrice, haPrice);
		final Color color = getItemColor(highlighted, hidden);
		final boolean canBeRecolored = highlighted != null || (hidden != null && config.recolorMenuHiddenItems());

		if (color != null && canBeRecolored && !color.equals(config.defaultColor()))
		{
			final MenuHighlightMode mode = config.menuHighlightMode();

			if (mode == BOTH || mode == OPTION)
			{
				final String optionText = telegrabEntry ? "Cast" : "Take";
				lastEntry.setOption(ColorUtil.prependColorTag(optionText, color));
			}

			if (mode == BOTH || mode == NAME)
			{
				String target = lastEntry.getTarget();

				if (telegrabEntry)
				{
					target = target.substring(TELEGRAB_TEXT.length());
				}

				target = ColorUtil.prependColorTag(target.substring(target.indexOf('>') + 1), color);

				if (telegrabEntry)
				{
					target = TELEGRAB_TEXT + target;
				}

				lastEntry.setTarget(target);
			}
		}

		if (config.showMenuItemQuantities() && groundItem.isStackable() && quantity > 1)
		{
			lastEntry.setTarget(lastEntry.getTarget() + " (" + quantity + ")");
		}

		client.setMenuEntries(menuEntries);
	}
}