Java Code Examples for net.runelite.api.widgets.WidgetInfo#TO_GROUP

The following examples show how to use net.runelite.api.widgets.WidgetInfo#TO_GROUP . 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: FriendTaggingPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
private void onMenuEntryAdded(MenuEntryAdded event)
{
	final int groupId = WidgetInfo.TO_GROUP(event.getParam1());

	if (groupId == WidgetInfo.FRIENDS_LIST.getGroupId() && event.getOption().equals("Message"))
	{
		// Friends have color tags
		String friendName = Text.removeTags(event.getTarget());

		// Build "Add Note" or "Edit Note" menu entry
		client.insertMenuItem(
			friendName == null || getTag(friendName) == null ? ADD_TAG : DELETE_TAG,
			event.getTarget(),
			MenuOpcode.RUNELITE.getId(),
			0,
			event.getParam0(),
			event.getParam1(),
			false
		);
		// Add menu entry
		// jk it is already added
	}
}
 
Example 2
Source File: GrandExchangePlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
private void onMenuEntryAdded(MenuEntryAdded menuEntry)
{
	// At the moment, if the user disables quick lookup, the input listener gets disabled. Thus, isHotKeyPressed()
	// should always return false when quick lookup is disabled.
	// Replace the default option with "Search ..." when holding alt
	if (client.getGameState() != GameState.LOGGED_IN || !hotKeyPressed)
	{
		return;
	}

	final int widgetId = menuEntry.getParam1();
	final int groupId = WidgetInfo.TO_GROUP(widgetId);

	switch (groupId)
	{
		case WidgetID.BANK_GROUP_ID:
			// Don't show for view tabs and such
			if (WidgetInfo.TO_CHILD(widgetId) != WidgetInfo.BANK_ITEM_CONTAINER.getChildId())
			{
				break;
			}
		case WidgetID.INVENTORY_GROUP_ID:
		case WidgetID.BANK_INVENTORY_GROUP_ID:
		case WidgetID.GRAND_EXCHANGE_INVENTORY_GROUP_ID:
		case WidgetID.SHOP_INVENTORY_GROUP_ID:
			menuEntry.setOption(SEARCH_GRAND_EXCHANGE);
			menuEntry.setOpcode(MenuOpcode.RUNELITE.getId());
			menuEntry.setModified();
	}
}
 
Example 3
Source File: TimersPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
private void onWidgetHiddenChanged(WidgetHiddenChanged event)
{
	Widget widget = event.getWidget();
	if (WorldType.isPvpWorld(client.getWorldType())
		&& WidgetInfo.TO_GROUP(widget.getId()) == WidgetID.PVP_GROUP_ID)
	{
		widgetHiddenChangedOnPvpWorld = true;
	}
}
 
Example 4
Source File: FriendTaggingPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
private void onMenuOptionClicked(MenuOptionClicked event)
{
	if (WidgetInfo.TO_GROUP(event.getParam1()) == WidgetInfo.FRIENDS_LIST.getGroupId())
	{
		if (Strings.isNullOrEmpty(event.getTarget()))
		{
			return;
		}

		final String sanitizedTarget = Text.removeTags(event.getTarget());

		if (event.getOption().equals(ADD_TAG))
		{
			event.consume();
			final ChatboxTextInput build = chatboxPanelManager.openTextInput("Enter the tag").value("")
				.onDone((content) ->
				{
					if (content == null)
					{
						return;
					}
					content = Text.removeTags(content).trim();
					setTag(sanitizedTarget, content);
				}).build();
		}
		if (event.getOption().equals(DELETE_TAG))
		{
			event.consume();
			client.getLogger().info(sanitizedTarget);
			taggedFriends.forEach((k, v) -> client.getLogger().info(k + ": ", v));
			deleteTag(sanitizedTarget);
		}
	}

}
 
Example 5
Source File: FriendNotesPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
private void onMenuEntryAdded(MenuEntryAdded event)
{
	final int groupId = WidgetInfo.TO_GROUP(event.getParam1());

	// Look for "Message" on friends list
	if (groupId == WidgetInfo.FRIENDS_LIST.getGroupId() && event.getOption().equals("Message"))
	{
		// Friends have color tags
		setHoveredFriend(Text.toJagexName(Text.removeTags(event.getTarget())));

		// Build "Add Note" or "Edit Note" menu entry
		// Add menu entry
		client.insertMenuItem(
			hoveredFriend == null || hoveredFriend.getNote() == null ? ADD_NOTE : EDIT_NOTE,
			event.getTarget(),
			MenuOpcode.RUNELITE.getId(),
			0,
			event.getParam0(),
			event.getParam1(),
			false
		);
	}
	else if (hoveredFriend != null)
	{
		hoveredFriend = null;
	}
}
 
Example 6
Source File: FriendNotesPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
private void onMenuOptionClicked(MenuOptionClicked event)
{
	if (WidgetInfo.TO_GROUP(event.getParam1()) == WidgetInfo.FRIENDS_LIST.getGroupId())
	{
		if (Strings.isNullOrEmpty(event.getTarget()))
		{
			return;
		}

		// Handle clicks on "Add Note" or "Edit Note"
		if (event.getOption().equals(ADD_NOTE) || event.getOption().equals(EDIT_NOTE))
		{
			event.consume();

			//Friends have color tags
			final String sanitizedTarget = Text.toJagexName(Text.removeTags(event.getTarget()));
			final String note = getFriendNote(sanitizedTarget);

			// Open the new chatbox input dialog
			chatboxPanelManager.openTextInput(String.format(NOTE_PROMPT_FORMAT, sanitizedTarget, CHARACTER_LIMIT))
				.value(Strings.nullToEmpty(note))
				.onDone((content) ->
				{
					if (content == null)
					{
						return;
					}

					content = Text.removeTags(content).trim();
					log.debug("Set note for '{}': '{}'", sanitizedTarget, content);
					setFriendNote(sanitizedTarget, content);
				}).build();
		}
	}

}
 
Example 7
Source File: WidgetInspector.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
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.getOpcode() != MenuOpcode.ITEM_USE_ON_WIDGET.getId()
			&& entry.getOpcode() != MenuOpcode.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 8
Source File: HiscorePlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded event)
{
	if (!config.menuOption())
	{
		return;
	}

	int groupId = WidgetInfo.TO_GROUP(event.getActionParam1());
	String option = event.getOption();

	if (groupId == WidgetInfo.FRIENDS_LIST.getGroupId() || groupId == WidgetInfo.FRIENDS_CHAT.getGroupId() ||
			groupId == WidgetInfo.CHATBOX.getGroupId() && !KICK_OPTION.equals(option) || //prevent from adding for Kick option (interferes with the raiding party one)
			groupId == WidgetInfo.RAIDING_PARTY.getGroupId() || groupId == WidgetInfo.PRIVATE_CHAT_MESSAGE.getGroupId() ||
			groupId == WidgetInfo.IGNORE_LIST.getGroupId())
	{
		if (!AFTER_OPTIONS.contains(option) || (option.equals("Delete") && groupId != WidgetInfo.IGNORE_LIST.getGroupId()))
		{
			return;
		}

		final MenuEntry lookup = new MenuEntry();
		lookup.setOption(LOOKUP);
		lookup.setTarget(event.getTarget());
		lookup.setType(MenuAction.RUNELITE.getId());
		lookup.setParam0(event.getActionParam0());
		lookup.setParam1(event.getActionParam1());
		lookup.setIdentifier(event.getIdentifier());

		insertMenuEntry(lookup, client.getMenuEntries());
	}
}
 
Example 9
Source File: HiscorePlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
private void onMenuEntryAdded(MenuEntryAdded event)
{
	if (!config.menuOption())
	{
		return;
	}

	int groupId = WidgetInfo.TO_GROUP(event.getParam1());
	String option = event.getOption();

	if (groupId == WidgetInfo.FRIENDS_LIST.getGroupId() || groupId == WidgetInfo.FRIENDS_CHAT.getGroupId() ||
		groupId == WidgetInfo.CHATBOX.getGroupId() && !KICK_OPTION.equals(option) || //prevent from adding for Kick option (interferes with the raiding party one)
		groupId == WidgetInfo.RAIDING_PARTY.getGroupId() || groupId == WidgetInfo.PRIVATE_CHAT_MESSAGE.getGroupId() ||
		groupId == WidgetInfo.IGNORE_LIST.getGroupId())
	{
		if (!AFTER_OPTIONS.contains(option) || (option.equals("Delete") && groupId != WidgetInfo.IGNORE_LIST.getGroupId()))
		{
			return;
		}

		final MenuEntry lookup = new MenuEntry();
		lookup.setOption(LOOKUP);
		lookup.setTarget(event.getTarget());
		lookup.setOpcode(MenuOpcode.RUNELITE.getId());
		lookup.setParam0(event.getParam0());
		lookup.setParam1(event.getParam1());
		lookup.setIdentifier(event.getIdentifier());

		if (client != null)
		{
			insertMenuEntry(lookup, client.getMenuEntries());
		}
	}
}
 
Example 10
Source File: GrimyHerbComparableEntry.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
public boolean matches(MenuEntry entry)
{
	final int groupId = WidgetInfo.TO_GROUP(entry.getParam1());

	if (groupId != WidgetID.INVENTORY_GROUP_ID)
	{
		return false;
	}

	int cleanLevel;
	try
	{
		cleanLevel = lookup.getCleanLevel(entry.getIdentifier());
	}
	catch (HerbNotFoundException e)
	{
		return false;
	}

	if (this.mode == SwapGrimyHerbMode.USE)
	{
		return StringUtils.equalsIgnoreCase(entry.getOption(), "use");
	}

	String swapOption = "use";
	if (client.getBoostedSkillLevel(Skill.HERBLORE) >= cleanLevel)
	{
		swapOption = "clean";
	}

	return StringUtils.equalsIgnoreCase(entry.getOption(), swapOption);
}
 
Example 11
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 12
Source File: GrandExchangePlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded event)
{
	// At the moment, if the user disables quick lookup, the input listener gets disabled. Thus, isHotKeyPressed()
	// should always return false when quick lookup is disabled.
	// Replace the default option with "Search ..." when holding alt
	if (client.getGameState() != GameState.LOGGED_IN || !hotKeyPressed)
	{
		return;
	}

	final MenuEntry[] entries = client.getMenuEntries();
	final MenuEntry menuEntry = entries[entries.length - 1];
	final int widgetId = menuEntry.getParam1();
	final int groupId = WidgetInfo.TO_GROUP(widgetId);

	switch (groupId)
	{
		case WidgetID.BANK_GROUP_ID:
			// Don't show for view tabs and such
			if (WidgetInfo.TO_CHILD(widgetId) != WidgetInfo.BANK_ITEM_CONTAINER.getChildId())
			{
				break;
			}
		case WidgetID.INVENTORY_GROUP_ID:
		case WidgetID.BANK_INVENTORY_GROUP_ID:
		case WidgetID.GRAND_EXCHANGE_INVENTORY_GROUP_ID:
		case WidgetID.SHOP_INVENTORY_GROUP_ID:
			menuEntry.setOption(SEARCH_GRAND_EXCHANGE);
			menuEntry.setType(MenuAction.RUNELITE.getId());
			client.setMenuEntries(entries);
	}
}
 
Example 13
Source File: TimersPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onWidgetHiddenChanged(WidgetHiddenChanged event)
{
	Widget widget = event.getWidget();
	if (WorldType.isPvpWorld(client.getWorldType())
		&& WidgetInfo.TO_GROUP(widget.getId()) == WidgetID.PVP_GROUP_ID)
	{
		widgetHiddenChangedOnPvpWorld = true;
	}
}
 
Example 14
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 15
Source File: ItemPricesOverlay.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;
	}

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

	if (last < 0)
	{
		return null;
	}

	final MenuEntry menuEntry = menuEntries[last];
	final MenuAction action = MenuAction.of(menuEntry.getType());
	final int widgetId = menuEntry.getParam1();
	final int groupId = WidgetInfo.TO_GROUP(widgetId);
	final boolean isAlching = menuEntry.getOption().equals("Cast") && menuEntry.getTarget().contains("High Level Alchemy");

	// Tooltip action type handling
	switch (action)
	{
		case ITEM_USE_ON_WIDGET:
			if (!config.showWhileAlching() || !isAlching)
			{
				break;
			}
		case CC_OP:
		case ITEM_USE:
		case ITEM_FIRST_OPTION:
		case ITEM_SECOND_OPTION:
		case ITEM_THIRD_OPTION:
		case ITEM_FOURTH_OPTION:
		case ITEM_FIFTH_OPTION:
			// Item tooltip values
			switch (groupId)
			{
				case WidgetID.EXPLORERS_RING_ALCH_GROUP_ID:
					if (!config.showWhileAlching())
					{
						return null;
					}
				case WidgetID.INVENTORY_GROUP_ID:
					if (config.hideInventory() && !(config.showWhileAlching() && isAlching))
					{
						return null;
					}
					// intentional fallthrough
				case WidgetID.BANK_GROUP_ID:
				case WidgetID.BANK_INVENTORY_GROUP_ID:
				case WidgetID.SEED_VAULT_GROUP_ID:
				case WidgetID.SEED_VAULT_INVENTORY_GROUP_ID:
					// Make tooltip
					final String text = makeValueTooltip(menuEntry);
					if (text != null)
					{
						tooltipManager.add(new Tooltip(ColorUtil.prependColorTag(text, new Color(238, 238, 238))));
					}
					break;
			}
			break;
	}
	return null;
}
 
Example 16
Source File: WorldHopperPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded event)
{
	if (!config.menuOption())
	{
		return;
	}

	int groupId = WidgetInfo.TO_GROUP(event.getActionParam1());
	String option = event.getOption();

	if (groupId == WidgetInfo.FRIENDS_LIST.getGroupId() || groupId == WidgetInfo.FRIENDS_CHAT.getGroupId())
	{
		boolean after;

		if (AFTER_OPTIONS.contains(option))
		{
			after = true;
		}
		else if (BEFORE_OPTIONS.contains(option))
		{
			after = false;
		}
		else
		{
			return;
		}

		// Don't add entry if user is offline
		ChatPlayer player = getChatPlayerFromName(event.getTarget());
		WorldResult worldResult = worldService.getWorlds();

		if (player == null || player.getWorld() == 0 || player.getWorld() == client.getWorld()
			|| worldResult == null)
		{
			return;
		}

		World currentWorld = worldResult.findWorld(client.getWorld());
		World targetWorld = worldResult.findWorld(player.getWorld());
		if (targetWorld == null || currentWorld == null
			|| (!currentWorld.getTypes().contains(WorldType.PVP) && targetWorld.getTypes().contains(WorldType.PVP)))
		{
			// Disable Hop-to a PVP world from a regular world
			return;
		}

		final MenuEntry hopTo = new MenuEntry();
		hopTo.setOption(HOP_TO);
		hopTo.setTarget(event.getTarget());
		hopTo.setType(MenuAction.RUNELITE.getId());
		hopTo.setParam0(event.getActionParam0());
		hopTo.setParam1(event.getActionParam1());

		insertMenuEntry(hopTo, client.getMenuEntries(), after);
	}
}
 
Example 17
Source File: WorldHopperPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@Subscribe
private void onMenuEntryAdded(MenuEntryAdded event)
{
	if (!config.menuOption())
	{
		return;
	}

	int groupId = WidgetInfo.TO_GROUP(event.getParam1());
	String option = event.getOption();

	if (groupId == WidgetInfo.FRIENDS_LIST.getGroupId() || groupId == WidgetInfo.FRIENDS_CHAT.getGroupId())
	{
		boolean after;

		if (AFTER_OPTIONS.contains(option))
		{
			after = true;
		}
		else if (BEFORE_OPTIONS.contains(option))
		{
			after = false;
		}
		else
		{
			return;
		}

		// Don't add entry if user is offline
		ChatPlayer player = getChatPlayerFromName(event.getTarget());
		WorldResult worldResult = worldService.getWorlds();

		if (player == null || player.getWorld() == 0 || player.getWorld() == client.getWorld()
			|| worldResult == null)
		{
			return;
		}

		World currentWorld = worldResult.findWorld(client.getWorld());
		World targetWorld = worldResult.findWorld(player.getWorld());
		if ((targetWorld == null || currentWorld == null)
			|| (config.removePVPWorld() && !currentWorld.getTypes().contains(WorldType.PVP) && targetWorld.getTypes().contains(WorldType.PVP))
			|| (config.removeBHWorld() && !currentWorld.getTypes().contains(WorldType.BOUNTY) && targetWorld.getTypes().contains(WorldType.BOUNTY)))
		{
			// Disable Hop-to a PVP world & BH world from a regular world
			return;
		}


		final MenuEntry hopTo = new MenuEntry();
		hopTo.setOption(HOP_TO);
		hopTo.setTarget(event.getTarget());
		hopTo.setOpcode(MenuOpcode.RUNELITE.getId());
		hopTo.setParam0(event.getParam0());
		hopTo.setParam1(event.getParam1());

		insertMenuEntry(hopTo, client.getMenuEntries(), after);
	}
}
 
Example 18
Source File: ItemPricesOverlay.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Dimension render(Graphics2D graphics)
{
	if (client.isMenuOpen())
	{
		return null;
	}

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

	if (last < 0)
	{
		return null;
	}

	final MenuEntry menuEntry = menuEntries[last];
	final MenuOpcode action = MenuOpcode.of(menuEntry.getOpcode());
	final int widgetId = menuEntry.getParam1();
	final int groupId = WidgetInfo.TO_GROUP(widgetId);
	final boolean isAlching = menuEntry.getOption().equals("Cast") && menuEntry.getTarget().contains("High Level Alchemy");

	// Tooltip action type handling
	switch (action)
	{
		case ITEM_USE_ON_WIDGET:
			if (!config.showWhileAlching() || !isAlching)
			{
				break;
			}
		case CC_OP:
		case ITEM_USE:
		case ITEM_FIRST_OPTION:
		case ITEM_SECOND_OPTION:
		case ITEM_THIRD_OPTION:
		case ITEM_FOURTH_OPTION:
		case ITEM_FIFTH_OPTION:
			// Item tooltip values
			switch (groupId)
			{
				case WidgetID.EXPLORERS_RING_ALCH_GROUP_ID:
					if (!config.showWhileAlching())
					{
						return null;
					}
				case WidgetID.INVENTORY_GROUP_ID:
					if (config.hideInventory() && !(config.showWhileAlching() && isAlching))
					{
						return null;
					}
					// intentional fallthrough
				case WidgetID.BANK_GROUP_ID:
				case WidgetID.BANK_INVENTORY_GROUP_ID:
					// Make tooltip
					final String text = makeValueTooltip(menuEntry);
					if (text != null)
					{
						tooltipManager.add(new Tooltip(ColorUtil.prependColorTag(text, new Color(238, 238, 238))));
					}
					break;
			}
			break;
	}
	return null;
}
 
Example 19
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 20
Source File: MouseHighlightOverlay.java    From plugins with GNU General Public License v3.0 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.getOpcode();

	if (shouldNotRenderMenuAction(type))
	{
		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 (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 (widget == null && !config.mainTooltip())
	{
		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;
}