Java Code Examples for net.runelite.api.MenuEntry#getType()

The following examples show how to use net.runelite.api.MenuEntry#getType() . 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: MenuEntrySwapperPlugin.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void bankModeSwap(int entryTypeId, int entryIdentifier)
{
	MenuEntry[] menuEntries = client.getMenuEntries();

	for (int i = menuEntries.length - 1; i >= 0; --i)
	{
		MenuEntry entry = menuEntries[i];

		if (entry.getType() == entryTypeId && entry.getIdentifier() == entryIdentifier)
		{
			// Raise the priority of the op so it doesn't get sorted later
			entry.setType(MenuAction.CC_OP.getId());

			menuEntries[i] = menuEntries[menuEntries.length - 1];
			menuEntries[menuEntries.length - 1] = entry;

			client.setMenuEntries(menuEntries);
			break;
		}
	}
}
 
Example 2
Source File: WidgetInspector.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
private void onMenuEntryAdded(MenuEntryAdded event)
{
	if (!pickerSelected)
	{
		return;
	}

	MenuEntry[] menuEntries = client.getMenuEntries();

	for (int i = 0; i < menuEntries.length; i++)
	{
		MenuEntry entry = menuEntries[i];
		if (entry.getType() != MenuAction.ITEM_USE_ON_WIDGET.getId()
			&& entry.getType() != MenuAction.SPELL_CAST_ON_WIDGET.getId())
		{
			continue;
		}
		String name = WidgetInfo.TO_GROUP(entry.getParam1()) + "." + WidgetInfo.TO_CHILD(entry.getParam1());

		if (entry.getParam0() != -1)
		{
			name += " [" + entry.getParam0() + "]";
		}

		Color color = colorForWidget(i, menuEntries.length);

		entry.setTarget(ColorUtil.wrapWithColorTag(name, color));
	}

	client.setMenuEntries(menuEntries);
}
 
Example 3
Source File: PlayerIndicatorsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Subscribe
public void onClientTick(ClientTick clientTick)
{
	if (client.isMenuOpen())
	{
		return;
	}

	MenuEntry[] menuEntries = client.getMenuEntries();
	boolean modified = false;

	for (MenuEntry entry : menuEntries)
	{
		int type = entry.getType();

		if (type >= MENU_ACTION_DEPRIORITIZE_OFFSET)
		{
			type -= MENU_ACTION_DEPRIORITIZE_OFFSET;
		}

		if (type == WALK.getId()
			|| type == SPELL_CAST_ON_PLAYER.getId()
			|| type == ITEM_USE_ON_PLAYER.getId()
			|| type == PLAYER_FIRST_OPTION.getId()
			|| type == PLAYER_SECOND_OPTION.getId()
			|| type == PLAYER_THIRD_OPTION.getId()
			|| type == PLAYER_FOURTH_OPTION.getId()
			|| type == PLAYER_FIFTH_OPTION.getId()
			|| type == PLAYER_SIXTH_OPTION.getId()
			|| type == PLAYER_SEVENTH_OPTION.getId()
			|| type == PLAYER_EIGTH_OPTION.getId()
			|| type == RUNELITE_PLAYER.getId())
		{
			Player[] players = client.getCachedPlayers();
			Player player = null;

			int identifier = entry.getIdentifier();

			// 'Walk here' identifiers are offset by 1 because the default
			// identifier for this option is 0, which is also a player index.
			if (type == WALK.getId())
			{
				identifier--;
			}

			if (identifier >= 0 && identifier < players.length)
			{
				player = players[identifier];
			}

			if (player == null)
			{
				continue;
			}

			Decorations decorations = getDecorations(player);

			if (decorations == null)
			{
				continue;
			}

			String oldTarget = entry.getTarget();
			String newTarget = decorateTarget(oldTarget, decorations);

			entry.setTarget(newTarget);
			modified = true;
		}
	}

	if (modified)
	{
		client.setMenuEntries(menuEntries);
	}
}
 
Example 4
Source File: MouseHighlightOverlay.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public Dimension render(Graphics2D graphics)
{
	if (client.isMenuOpen())
	{
		return null;
	}

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

	if (last < 0)
	{
		return null;
	}

	MenuEntry menuEntry = menuEntries[last];
	String target = menuEntry.getTarget();
	String option = menuEntry.getOption();
	int type = menuEntry.getType();

	if (type == MenuAction.RUNELITE_OVERLAY.getId() || type == MenuAction.CC_OP_LOW_PRIORITY.getId())
	{
		// These are always right click only
		return null;
	}

	if (Strings.isNullOrEmpty(option))
	{
		return null;
	}

	// Trivial options that don't need to be highlighted, add more as they appear.
	switch (option)
	{
		case "Walk here":
		case "Cancel":
		case "Continue":
			return null;
		case "Move":
			// Hide overlay on sliding puzzle boxes
			if (target.contains("Sliding piece"))
			{
				return null;
			}
	}

	final int widgetId = menuEntry.getParam1();
	final int groupId = WidgetInfo.TO_GROUP(widgetId);
	final int childId = WidgetInfo.TO_CHILD(widgetId);
	final Widget widget = client.getWidget(groupId, childId);

	if (!config.uiTooltip() && widget != null)
	{
		return null;
	}

	if (!config.chatboxTooltip() && groupId == WidgetInfo.CHATBOX.getGroupId())
	{
		return null;
	}

	if (config.disableSpellbooktooltip() && groupId == WidgetID.SPELLBOOK_GROUP_ID)
	{
		return null;
	}

	if (widget != null)
	{
		// If this varc is set, some CS is showing tooltip
		int tooltipTimeout = client.getVar(VarClientInt.TOOLTIP_TIMEOUT);
		if (tooltipTimeout > client.getGameCycle())
		{
			return null;
		}
	}

	// If this varc is set, a tooltip is already being displayed
	int tooltipDisplayed = client.getVar(VarClientInt.TOOLTIP_VISIBLE);
	if (tooltipDisplayed == 1)
	{
		return null;
	}

	tooltipManager.addFront(new Tooltip(option + (Strings.isNullOrEmpty(target) ? "" : " " + target)));
	return null;
}
 
Example 5
Source File: GroundItemsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Subscribe
public void onClientTick(ClientTick event)
{
	if (!config.collapseEntries())
	{
		return;
	}

	final MenuEntry[] menuEntries = client.getMenuEntries();
	final List<MenuEntryWithCount> newEntries = new ArrayList<>(menuEntries.length);

	outer:
	for (int i = menuEntries.length - 1; i >= 0; i--)
	{
		MenuEntry menuEntry = menuEntries[i];

		int menuType = menuEntry.getType();
		if (menuType == FIRST_OPTION || menuType == SECOND_OPTION || menuType == THIRD_OPTION
			|| menuType == FOURTH_OPTION || menuType == FIFTH_OPTION || menuType == EXAMINE_ITEM)
		{
			for (MenuEntryWithCount entryWCount : newEntries)
			{
				if (entryWCount.getEntry().equals(menuEntry))
				{
					entryWCount.increment();
					continue outer;
				}
			}
		}

		newEntries.add(new MenuEntryWithCount(menuEntry));
	}

	Collections.reverse(newEntries);

	client.setMenuEntries(newEntries.stream().map(e ->
	{
		final MenuEntry entry = e.getEntry();
		final int count = e.getCount();
		if (count > 1)
		{
			entry.setTarget(entry.getTarget() + " x " + count);
		}

		return entry;
	}).toArray(MenuEntry[]::new));
}
 
Example 6
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));
}