net.runelite.api.VarClientStr Java Examples

The following examples show how to use net.runelite.api.VarClientStr. 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: AutoPrayFlickPlugin.java    From ExternalPlugins with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void keyReleased(KeyEvent e)
{
	if (config.useMouse())
	{
		return;
	}
	if (config.holdMode())
	{
		toggleFlick = false;
		held = false;
		firstFlick = false;
	}
	if (config.clearChat() && config.hotkey2().matches(e))
	{
		String chat = client.getVar(VarClientStr.CHATBOX_TYPED_TEXT);
		if (chat.endsWith(String.valueOf(e.getKeyChar())))
		{
			chat = chat.substring(0, chat.length() - 1);
			client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, chat);
		}
	}
}
 
Example #2
Source File: ChatHistoryPlugin.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private String findPreviousFriend()
{
	final String currentTarget = client.getVar(VarClientStr.PRIVATE_MESSAGE_TARGET);
	if (currentTarget == null || friends.isEmpty())
	{
		return null;
	}

	for (Iterator<String> it = friends.descendingIterator(); it.hasNext(); )
	{
		String friend = it.next();
		if (friend.equals(currentTarget))
		{
			return it.hasNext() ? it.next() : friends.getLast();
		}
	}

	return friends.getLast();
}
 
Example #3
Source File: KeyRemappingPlugin.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
protected void startUp() throws Exception
{
	typing = false;
	keyManager.registerKeyListener(inputListener);

	clientThread.invoke(() ->
	{
		if (client.getGameState() == GameState.LOGGED_IN)
		{
			lockChat();
			// Clear any typed text
			client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, "");
		}
	});
}
 
Example #4
Source File: BankTagsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Subscribe
public void onGrandExchangeSearched(GrandExchangeSearched event)
{
	final String input = client.getVar(VarClientStr.INPUT_TEXT);
	if (!input.startsWith(TAG_SEARCH))
	{
		return;
	}

	event.consume();

	final String tag = input.substring(TAG_SEARCH.length()).trim();
	final Set<Integer> ids = tagManager.getItemsForTag(tag)
		.stream()
		.mapToInt(Math::abs)
		.mapToObj(ItemVariationMapping::getVariations)
		.flatMap(Collection::stream)
		.distinct()
		.filter(i -> itemManager.getItemComposition(i).isTradeable())
		.limit(MAX_RESULT_COUNT)
		.collect(Collectors.toCollection(TreeSet::new));

	client.setGeSearchResultIndex(0);
	client.setGeSearchResultCount(ids.size());
	client.setGeSearchResultIds(Shorts.toArray(ids));
}
 
Example #5
Source File: BankPlugin.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Subscribe
public void onScriptPostFired(ScriptPostFired event)
{
	if (event.getScriptId() != ScriptID.BANKMAIN_SEARCH_REFRESH)
	{
		return;
	}

	// vanilla only lays out the bank every 40 client ticks, so if the search input has changed,
	// and the bank wasn't laid out this tick, lay it out early
	final String inputText = client.getVar(VarClientStr.INPUT_TEXT);
	if (searchString != inputText && client.getGameCycle() % 40 != 0)
	{
		clientThread.invokeLater(bankSearch::layoutBank);
		searchString = inputText;
	}
}
 
Example #6
Source File: CommandManager.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void runCommand()
{
	String typedText = client.getVar(VarClientStr.CHATBOX_TYPED_TEXT).substring(2); // strip ::

	log.debug("Command: {}", typedText);

	String[] split = typedText.split(" ");

	// Fixes ArrayIndexOutOfBounds when typing ":: "
	if (split.length == 0)
	{
		return;
	}

	String command = split[0];
	String[] args = Arrays.copyOfRange(split, 1, split.length);

	CommandExecuted commandExecuted = new CommandExecuted(command, args);
	eventBus.post(commandExecuted);
}
 
Example #7
Source File: ChatHistoryPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
private String findPreviousFriend()
{
	final String currentTarget = client.getVar(VarClientStr.PRIVATE_MESSAGE_TARGET);
	if (currentTarget == null || friends.isEmpty())
	{
		return null;
	}

	for (Iterator<String> it = friends.descendingIterator(); it.hasNext(); )
	{
		String friend = it.next();
		if (friend.equals(currentTarget))
		{
			return it.hasNext() ? it.next() : friends.getLast();
		}
	}

	return friends.getLast();
}
 
Example #8
Source File: KeyRemappingPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void startUp()
{
	typing = false;
	keyManager.registerKeyListener(inputListener);

	clientThread.invoke(() ->
	{
		if (client.getGameState() == GameState.LOGGED_IN)
		{
			lockChat();
			// Clear any typed text
			client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, "");
		}
	});
}
 
Example #9
Source File: BankTagsPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
public void onGrandExchangeSearched(GrandExchangeSearched event)
{
	final String input = client.getVar(VarClientStr.INPUT_TEXT);
	if (!input.startsWith(TAG_SEARCH))
	{
		return;
	}

	event.consume();

	final String tag = input.substring(TAG_SEARCH.length()).trim();
	final Set<Integer> ids = tagManager.getItemsForTag(tag)
		.stream()
		.mapToInt(Math::abs)
		.mapToObj(ItemVariationMapping::getVariations)
		.flatMap(Collection::stream)
		.distinct()
		.filter(i -> itemManager.getItemDefinition(i).isTradeable())
		.limit(MAX_RESULT_COUNT)
		.collect(Collectors.toCollection(TreeSet::new));

	client.setGeSearchResultIndex(0);
	client.setGeSearchResultCount(ids.size());
	client.setGeSearchResultIds(Shorts.toArray(ids));
}
 
Example #10
Source File: BankPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
public void onScriptPostFired(ScriptPostFired event)
{
	if (event.getScriptId() != ScriptID.BANKMAIN_SEARCH_REFRESH)
	{
		return;
	}

	// vanilla only lays out the bank every 40 client ticks, so if the search input has changed,
	// and the bank wasn't laid out this tick, lay it out early
	final String inputText = client.getVar(VarClientStr.INPUT_TEXT);
	if (searchString != inputText && client.getGameCycle() % 40 != 0)
	{
		clientThread.invokeLater(bankSearch::layoutBank);
		searchString = inputText;
	}
}
 
Example #11
Source File: ChatKeyboardListener.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
private void applyText(int inputType, String replacement)
{
	if (inputType == InputType.NONE.getType())
	{
		client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, replacement);
		client.runScript(ScriptID.CHAT_PROMPT_INIT);
	}
	else if (inputType == InputType.PRIVATE_MESSAGE.getType())
	{
		client.setVar(VarClientStr.INPUT_TEXT, replacement);
		client.runScript(ScriptID.CHAT_TEXT_INPUT_REBUILD, "");
	}
}
 
Example #12
Source File: ChatHistoryPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void keyPressed(KeyEvent e)
{
	if (e.getKeyCode() != CYCLE_HOTKEY || !config.pmTargetCycling())
	{
		return;
	}

	if (client.getVar(VarClientInt.INPUT_TYPE) != InputType.PRIVATE_MESSAGE.getType())
	{
		return;
	}

	clientThread.invoke(() ->
	{
		final String target = findPreviousFriend();
		if (target == null)
		{
			return;
		}

		final String currentMessage = client.getVar(VarClientStr.INPUT_TEXT);

		client.runScript(ScriptID.OPEN_PRIVATE_MESSAGE_INTERFACE, target);

		client.setVar(VarClientStr.INPUT_TEXT, currentMessage);
		client.runScript(ScriptID.CHAT_TEXT_INPUT_REBUILD, "");
	});
}
 
Example #13
Source File: FriendsChatPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onVarClientStrChanged(VarClientStrChanged strChanged)
{
	if (strChanged.getIndex() == VarClientStr.RECENT_FRIENDS_CHAT.getIndex() && config.recentChats())
	{
		updateRecentChat(client.getVar(VarClientStr.RECENT_FRIENDS_CHAT));
	}
}
 
Example #14
Source File: KeyRemappingPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
void unlockChat()
{
	Widget chatboxInput = client.getWidget(WidgetInfo.CHATBOX_INPUT);
	if (chatboxInput != null)
	{
		if (client.getGameState() == GameState.LOGGED_IN)
		{
			final boolean isChatboxTransparent = client.isResized() && client.getVar(Varbits.TRANSPARENT_CHATBOX) == 1;
			final Color textColor = isChatboxTransparent ? JagexColors.CHAT_TYPED_TEXT_TRANSPARENT_BACKGROUND : JagexColors.CHAT_TYPED_TEXT_OPAQUE_BACKGROUND;
			setChatboxWidgetInput(chatboxInput, ColorUtil.wrapWithColorTag(client.getVar(VarClientStr.CHATBOX_TYPED_TEXT) + "*", textColor));
		}
	}
}
 
Example #15
Source File: ChatKeyboardListener.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void applyText(int inputType, String replacement)
{
	if (inputType == InputType.NONE.getType())
	{
		client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, replacement);
		client.runScript(ScriptID.CHAT_PROMPT_INIT);
	}
	else if (inputType == InputType.PRIVATE_MESSAGE.getType())
	{
		client.setVar(VarClientStr.INPUT_TEXT, replacement);
		client.runScript(ScriptID.CHAT_TEXT_INPUT_REBUILD, "");
	}
}
 
Example #16
Source File: VarInspector.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onVarClientStrChanged(VarClientStrChanged e)
{
	int idx = e.getIndex();
	String neew = (String) client.getVarcMap().getOrDefault(idx, "");
	String old = (String) varcs.getOrDefault(idx, "");
	varcs.put(idx, neew);

	if (!Objects.equals(old, neew))
	{
		String name = String.format("%d", idx);
		for (VarClientStr varc : VarClientStr.values())
		{
			if (varc.getIndex() == idx)
			{
				name = String.format("%s(%d)", varc.name(), idx);
				break;
			}
		}
		if (old != null)
		{
			old = "\"" + old + "\"";
		}
		else
		{
			old = "null";
		}
		if (neew != null)
		{
			neew = "\"" + neew + "\"";
		}
		else
		{
			neew = "null";
		}
		addVarLog(VarType.VARCSTR, name, old, neew);
	}
}
 
Example #17
Source File: KeyRemappingPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
void unlockChat()
{
	Widget chatboxInput = client.getWidget(WidgetInfo.CHATBOX_INPUT);
	if (chatboxInput != null && client.getGameState() == GameState.LOGGED_IN)
	{
		final boolean isChatboxTransparent = client.isResized() && client.getVar(Varbits.TRANSPARENT_CHATBOX) == 1;
		final Color textColor = isChatboxTransparent ? JagexColors.CHAT_TYPED_TEXT_TRANSPARENT_BACKGROUND : JagexColors.CHAT_TYPED_TEXT_OPAQUE_BACKGROUND;
		setChatboxWidgetInput(chatboxInput, ColorUtil.wrapWithColorTag(client.getVar(VarClientStr.CHATBOX_TYPED_TEXT) + "*", textColor));
	}
}
 
Example #18
Source File: ChatHistoryPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void keyPressed(KeyEvent e)
{
	if (e.getKeyCode() != CYCLE_HOTKEY || !config.pmTargetCycling())
	{
		return;
	}

	if (client.getVar(VarClientInt.INPUT_TYPE) != InputType.PRIVATE_MESSAGE.getType())
	{
		return;
	}

	clientThread.invoke(() ->
	{
		final String target = findPreviousFriend();
		if (target == null)
		{
			return;
		}

		final String currentMessage = client.getVar(VarClientStr.INPUT_TEXT);

		client.runScript(ScriptID.OPEN_PRIVATE_MESSAGE_INTERFACE, target);

		client.setVar(VarClientStr.INPUT_TEXT, currentMessage);
		client.runScript(ScriptID.CHAT_TEXT_INPUT_REBUILD, "");
	});
}
 
Example #19
Source File: FriendsChatPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
private void onGameTick(GameTick gameTick)
{
	if (client.getGameState() != GameState.LOGGED_IN)
	{
		return;
	}

	client.setVar(VarClientStr.RECENT_FRIENDS_CHAT, config.friendschatName());

	Widget chatTitleWidget = client.getWidget(WidgetInfo.FRIENDS_CHAT_TITLE);
	if (chatTitleWidget != null)
	{
		Widget chatList = client.getWidget(WidgetInfo.FRIENDS_CHAT_LIST);
		Widget owner = client.getWidget(WidgetInfo.FRIENDS_CHAT_OWNER);
		FriendsChatManager friendsChatManager = client.getFriendsChatManager();
		if (friendsChatManager != null && friendsChatManager.getCount() > 0)
		{
			chatTitleWidget.setText(TITLE + " (" + friendsChatManager.getCount() + "/100)");
		}
		else if (config.recentChats() && chatList.getChildren() == null && !Strings.isNullOrEmpty(owner.getText()))
		{
			chatTitleWidget.setText(RECENT_TITLE);

			loadFriendsChats();
		}
	}

	if (!config.showJoinLeave())
	{
		return;
	}

	timeoutMessages();

	addActivityMessages();
}
 
Example #20
Source File: FriendsChatPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
private void onVarClientStrChanged(VarClientStrChanged strChanged)
{
	if (strChanged.getIndex() == VarClientStr.RECENT_FRIENDS_CHAT.getIndex() && config.recentChats())
	{
		updateRecentChat(client.getVar(VarClientStr.RECENT_FRIENDS_CHAT));
	}
}
 
Example #21
Source File: VarInspector.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
private void onVarClientStrChanged(VarClientStrChanged e)
{
	int idx = e.getIndex();
	String neew = (String) client.getVarcMap().getOrDefault(idx, "");
	String old = (String) varcs.getOrDefault(idx, "");
	varcs.put(idx, neew);

	if (!Objects.equals(old, neew))
	{
		String name = String.format("%d", idx);
		for (VarClientStr varc : VarClientStr.values())
		{
			if (varc.getIndex() == idx)
			{
				name = String.format("%s(%d)", varc.name(), idx);
				break;
			}
		}
		if (old != null)
		{
			old = "\"" + old + "\"";
		}
		else
		{
			old = "null";
		}
		if (neew != null)
		{
			neew = "\"" + neew + "\"";
		}
		else
		{
			neew = "null";
		}
		addVarLog(VarType.VARCSTR, name, old, neew);
	}
}
 
Example #22
Source File: TabInterface.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private boolean isTabMenuActive()
{
	return TAB_MENU.equals(client.getVar(VarClientStr.INPUT_TEXT));
}
 
Example #23
Source File: BankTagsPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@Subscribe
private void onMenuOptionClicked(MenuOptionClicked event)
{
	if (event.getParam1() == WidgetInfo.BANK_ITEM_CONTAINER.getId()
		&& event.getMenuOpcode() == MenuOpcode.RUNELITE
		&& event.getOption().startsWith(EDIT_TAGS_MENU_OPTION))
	{
		event.consume();
		int inventoryIndex = event.getParam0();
		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();
		ItemDefinition itemDefinition = itemManager.getItemDefinition(itemId);
		String name = itemDefinition.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 #24
Source File: ChatTranslationPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void keyPressed(KeyEvent event)
{
	if (client.getGameState() != GameState.LOADING && client.getGameState() != GameState.LOGGED_IN)
	{
		return;
	}

	final Widget chatboxParent = client.getWidget(WidgetInfo.CHATBOX_PARENT);

	if (chatboxParent == null || chatboxParent.getOnKeyListener() == null || event.getKeyCode() != 0xA)
	{
		return;
	}

	final String message = client.getVar(VarClientStr.CHATBOX_TYPED_TEXT);
	final String translated;

	try
	{
		translated = translator.translateOutgoing(message);
	}
	catch (IOException e)
	{
		return;
	}

	if (message.startsWith("/"))
	{
		client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, translated.startsWith("/") ? translated : "/" + translated);
		return;
	}

	event.consume();

	client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, translated);

	clientThread.invoke(() -> client.runScript(CHATBOX_INPUT, 0, translated));

	client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, "");
}
 
Example #25
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 #26
Source File: GrandExchangePlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
private void highlightSearchMatches()
{
	if (!wasFuzzySearch)
	{
		return;
	}
	String input = client.getVar(VarClientStr.INPUT_TEXT);

	String underlineTag = "<u=" + ColorUtil.colorToHexCode(FUZZY_HIGHLIGHT_COLOR) + ">";

	Widget results = client.getWidget(WidgetInfo.CHATBOX_GE_SEARCH_RESULTS);
	Widget[] children = results.getDynamicChildren();
	int resultCount = children.length / 3;

	for (int i = 0; i < resultCount; i++)
	{
		Widget itemNameWidget = children[i * 3 + 1];
		String itemName = itemNameWidget.getText();

		List<Integer> indices;
		String otherName = itemName.replace('-', ' ');
		if (!itemName.contains("-") || FUZZY.fuzzyScore(itemName, input) >= FUZZY.fuzzyScore(otherName, input))
		{
			indices = findFuzzyIndices(itemName, input);
		}
		else
		{
			indices = findFuzzyIndices(otherName, input);
		}
		Collections.reverse(indices);

		StringBuilder newItemName = new StringBuilder(itemName);
		for (int index : indices)
		{
			if (wasFuzzySearch && (itemName.charAt(index) == ' ' || itemName.charAt(index) == '-'))
			{
				continue;
			}
			newItemName.insert(index + 1, "</u>");
			newItemName.insert(index, underlineTag);
		}

		itemNameWidget.setText(newItemName.toString());
	}
}
 
Example #27
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 #28
Source File: TabInterface.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void update()
{
	if (isHidden())
	{
		parent = null;
		waitSearchTick = false;
		rememberedSearch = "";

		saveTab();
		return;
	}

	// Don't continue ticking if equipment menu or bank menu is open
	if (parent.isSelfHidden())
	{
		return;
	}

	if (activeTab != null && client.getVar(VarClientInt.INPUT_TYPE) == InputType.RUNELITE.getType())
	{
		// don't reset active tab if we are editing tags
		updateBounds();
		scrollTab(0);
		return;
	}

	String str = client.getVar(VarClientStr.INPUT_TEXT);

	if (Strings.isNullOrEmpty(str))
	{
		str = "";
	}

	Widget bankTitle = client.getWidget(WidgetInfo.BANK_TITLE_BAR);
	if (bankTitle != null && !bankTitle.isHidden() && !str.startsWith(TAG_SEARCH))
	{
		str = bankTitle.getText().replaceFirst("Showing items: ", "");

		if (str.startsWith("Tab "))
		{
			str = "";
		}
	}

	str = Text.standardize(str);

	if (str.startsWith(BankTagsPlugin.TAG_SEARCH))
	{
		activateTab(tabManager.find(str.substring(TAG_SEARCH.length())));
	}
	else
	{
		activateTab(null);
	}

	if (!waitSearchTick
		&& activeTab == null
		&& !Strings.isNullOrEmpty(rememberedSearch)
		&& client.getVar(VarClientInt.INPUT_TYPE) == InputType.NONE.getType())
	{
		bankSearch.reset(true);
		bankSearch.search(InputType.NONE, rememberedSearch, true);
		rememberedSearch = "";
	}
	else if (waitSearchTick)
	{
		waitSearchTick = false;
	}

	updateBounds();
	scrollTab(0);
}
 
Example #29
Source File: GrandExchangePlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void highlightSearchMatches()
{
	if (!wasFuzzySearch)
	{
		return;
	}
	String input = client.getVar(VarClientStr.INPUT_TEXT);

	String underlineTag = "<u=" + ColorUtil.colorToHexCode(FUZZY_HIGHLIGHT_COLOR) + ">";

	Widget results = client.getWidget(WidgetInfo.CHATBOX_GE_SEARCH_RESULTS);
	Widget[] children = results.getDynamicChildren();
	int resultCount = children.length / 3;

	for (int i = 0; i < resultCount; i++)
	{
		Widget itemNameWidget = children[i * 3 + 1];
		String itemName = itemNameWidget.getText();

		List<Integer> indices;
		String otherName = itemName.replace('-', ' ');
		if (!itemName.contains("-") || FUZZY.fuzzyScore(itemName, input) >= FUZZY.fuzzyScore(otherName, input))
		{
			indices = findFuzzyIndices(itemName, input);
		}
		else
		{
			indices = findFuzzyIndices(otherName, input);
		}
		Collections.reverse(indices);

		StringBuilder newItemName = new StringBuilder(itemName);
		for (int index : indices)
		{
			if (itemName.charAt(index) == ' ' || itemName.charAt(index) == '-')
			{
				continue;
			}

			newItemName.insert(index + 1, "</u>");
			newItemName.insert(index, underlineTag);
		}

		itemNameWidget.setText(newItemName.toString());
	}
}
 
Example #30
Source File: TabInterface.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
public void update()
{
	if (isHidden())
	{
		parent = null;
		waitSearchTick = false;
		rememberedSearch = "";

		saveTab();
		return;
	}

	// Don't continue ticking if equipment menu or bank menu is open
	if (parent.isSelfHidden())
	{
		return;
	}

	if (activeTab != null && client.getVar(VarClientInt.INPUT_TYPE) == InputType.RUNELITE.getType())
	{
		// don't reset active tab if we are editing tags
		updateBounds();
		scrollTab(0);
		return;
	}

	String str = client.getVar(VarClientStr.INPUT_TEXT);

	if (Strings.isNullOrEmpty(str))
	{
		str = "";
	}

	Widget bankTitle = client.getWidget(WidgetInfo.BANK_TITLE_BAR);
	if (bankTitle != null && !bankTitle.isHidden() && !str.startsWith(TAG_SEARCH))
	{
		str = bankTitle.getText().replaceFirst("Showing items: ", "");

		if (str.startsWith("Tab "))
		{
			str = "";
		}
	}

	str = Text.standardize(str);

	if (str.startsWith(BankTagsPlugin.TAG_SEARCH))
	{
		activateTab(tabManager.find(str.substring(TAG_SEARCH.length())));
	}
	else
	{
		activateTab(null);
	}

	if (!waitSearchTick
		&& activeTab == null
		&& !Strings.isNullOrEmpty(rememberedSearch)
		&& client.getVar(VarClientInt.INPUT_TYPE) == InputType.NONE.getType())
	{
		bankSearch.reset(true);
		bankSearch.search(InputType.NONE, rememberedSearch, true);
		rememberedSearch = "";
	}
	else if (waitSearchTick)
	{
		waitSearchTick = false;
	}

	updateBounds();
	scrollTab(0);
}