net.runelite.api.widgets.Widget Java Examples

The following examples show how to use net.runelite.api.widgets.Widget. 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: ScreenshotPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Receives a Widget containing the level-up dialog,
 * and parses it into a shortened string for filename usage.
 *
 * @param levelUpWidget Widget containing the level-up text,
 *                      with the format "Your Skill (level is/are) now 99."
 * @return Shortened string in the format "Skill(99)"
 */
String parseLevelUpWidget(Widget levelUpWidget)
{
	if (levelUpWidget == null)
	{
		return null;
	}

	Matcher m = LEVEL_UP_PATTERN.matcher(levelUpWidget.getText());
	if (!m.matches())
	{
		return null;
	}

	String skillName = m.group(1);
	String skillLevel = m.group(2);
	return skillName + "(" + skillLevel + ")";
}
 
Example #2
Source File: ScreenshotPluginTest.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testHunterLevel2()
{
	Widget levelChild = mock(Widget.class);
	when(client.getWidget(eq(DIALOG_SPRITE_TEXT))).thenReturn(levelChild);

	when(levelChild.getText()).thenReturn("<col=000080>Congratulations, you've just advanced a Hunter level.<col=000000><br><br>Your Hunter level is now 2.");

	assertEquals("Hunter(2)", screenshotPlugin.parseLevelUpWidget(client.getWidget(DIALOG_SPRITE_TEXT)));

	WidgetLoaded event = new WidgetLoaded();
	event.setGroupId(DIALOG_SPRITE_GROUP_ID);
	screenshotPlugin.onWidgetLoaded(event);

	GameTick tick = GameTick.INSTANCE;
	screenshotPlugin.onGameTick(tick);

	verify(drawManager).requestNextFrameListener(any(Consumer.class));
}
 
Example #3
Source File: WidgetField.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
void setValue(Widget widget, Object inValue)
{
	Object value = null;
	if ("null".equals(inValue))
	{
		value = null;
	}
	if (type.isAssignableFrom(inValue.getClass()))
	{
		value = inValue;
	}
	else if (type == Boolean.class)
	{
		value = Boolean.valueOf((String) inValue);
	}
	else if (type == Integer.class)
	{
		value = Integer.valueOf((String) inValue);
	}
	else
	{
		log.warn("Type {} is not supported for editing", type);
	}
	setter.accept(widget, (T) value);
}
 
Example #4
Source File: WidgetInspector.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void removePickerWidget()
{
	if (picker == null)
	{
		return;
	}

	Widget parent = picker.getParent();
	if (parent == null)
	{
		return;
	}

	Widget[] children = parent.getChildren();
	if (children == null || children.length <= picker.getIndex() || children[picker.getIndex()] != picker)
	{
		return;
	}

	children[picker.getIndex()] = null;
}
 
Example #5
Source File: KeyRemappingPlugin.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Subscribe
public void onScriptCallbackEvent(ScriptCallbackEvent scriptCallbackEvent)
{
	switch (scriptCallbackEvent.getEventName())
	{
		case SCRIPT_EVENT_SET_CHATBOX_INPUT:
			Widget chatboxInput = client.getWidget(WidgetInfo.CHATBOX_INPUT);
			if (chatboxInput != null)
			{
				if (chatboxFocused() && !typing)
				{
					setChatboxWidgetInput(chatboxInput, PRESS_ENTER_TO_CHAT);
				}
			}
			break;
		case SCRIPT_EVENT_BLOCK_CHAT_INPUT:
			if (!typing)
			{
				int[] intStack = client.getIntStack();
				int intStackSize = client.getIntStackSize();
				intStack[intStackSize - 1] = 1;
			}
			break;
	}
}
 
Example #6
Source File: ExaminePluginTest.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testLargeStacks()
{
	when(client.getWidget(anyInt(), anyInt())).thenReturn(mock(Widget.class));
	when(itemManager.getItemComposition(anyInt())).thenReturn(mock(ItemComposition.class));

	MenuOptionClicked menuOptionClicked = new MenuOptionClicked();
	menuOptionClicked.setMenuOption("Examine");
	menuOptionClicked.setMenuAction(MenuAction.EXAMINE_ITEM);
	menuOptionClicked.setId(ItemID.ABYSSAL_WHIP);
	examinePlugin.onMenuOptionClicked(menuOptionClicked);

	ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.ITEM_EXAMINE, "", "100000 x Abyssal whip", "", 0);
	examinePlugin.onChatMessage(chatMessage);

	verify(examineClient, never()).submitItem(anyInt(), anyString());
}
 
Example #7
Source File: KeyRemappingPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
private void setChatboxWidgetInput(Widget widget, String input)
{
	if (config.hideDisplayName())
	{
		widget.setText(input);
		return;
	}

	String text = widget.getText();
	int idx = text.indexOf(':');
	if (idx != -1)
	{
		String newText = text.substring(0, idx) + ": " + input;
		widget.setText(newText);
	}
}
 
Example #8
Source File: ItemStatPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
private void resetGEInventory()
{
	final Widget invContainer = getInventoryContainer();

	if (invContainer == null)
	{
		return;
	}

	if (itemInformationTitle != null && invContainer.getChild(0) == itemInformationTitle)
	{
		invContainer.deleteAllChildren();
		itemInformationTitle = null;
	}

	final Widget geInv = client.getWidget(WidgetInfo.GRAND_EXCHANGE_INVENTORY_ITEMS_CONTAINER);
	if (geInv != null)
	{
		geInv.setHidden(false);
	}
}
 
Example #9
Source File: ScreenshotPluginTest.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testFiremakingLevel9()
{
	Widget levelChild = mock(Widget.class);
	when(client.getWidget(eq(LEVEL_UP_LEVEL))).thenReturn(levelChild);

	when(levelChild.getText()).thenReturn("Your Firemaking level is now 9.");

	assertEquals("Firemaking(9)", screenshotPlugin.parseLevelUpWidget(client.getWidget(LEVEL_UP_LEVEL)));

	WidgetLoaded event = new WidgetLoaded();
	event.setGroupId(LEVEL_UP_GROUP_ID);
	screenshotPlugin.onWidgetLoaded(event);

	GameTick tick = GameTick.INSTANCE;
	screenshotPlugin.onGameTick(tick);

	verify(drawManager).requestNextFrameListener(any(Consumer.class));
}
 
Example #10
Source File: OneClickPlugin.java    From ExternalPlugins with GNU General Public License v3.0 6 votes vote down vote up
public Pair<Integer, Integer> findItem(int id)
{
	final Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY);
	final List<WidgetItem> itemList = (List<WidgetItem>) inventoryWidget.getWidgetItems();

	for (int i = itemList.size() - 1; i >= 0; i--)
	{
		final WidgetItem item = itemList.get(i);
		if (item.getId() == id)
		{
			return Pair.of(item.getId(), item.getIndex());
		}
	}

	return Pair.of(-1, -1);
}
 
Example #11
Source File: BlastMineOreCountOverlay.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public Dimension render(Graphics2D graphics)
{
	final Widget blastMineWidget = client.getWidget(WidgetInfo.BLAST_MINE);

	if (blastMineWidget == null)
	{
		return null;
	}
	
	if (config.showOreOverlay())
	{
		blastMineWidget.setHidden(true);
		panelComponent.getChildren().add(new ImageComponent(getImage(ItemID.COAL, client.getVar(Varbits.BLAST_MINE_COAL))));
		panelComponent.getChildren().add(new ImageComponent(getImage(ItemID.GOLD_ORE, client.getVar(Varbits.BLAST_MINE_GOLD))));
		panelComponent.getChildren().add(new ImageComponent(getImage(ItemID.MITHRIL_ORE, client.getVar(Varbits.BLAST_MINE_MITHRIL))));
		panelComponent.getChildren().add(new ImageComponent(getImage(ItemID.ADAMANTITE_ORE, client.getVar(Varbits.BLAST_MINE_ADAMANTITE))));
		panelComponent.getChildren().add(new ImageComponent(getImage(ItemID.RUNITE_ORE, client.getVar(Varbits.BLAST_MINE_RUNITE))));
	}
	else
	{
		blastMineWidget.setHidden(false);
	}

	return super.render(graphics);
}
 
Example #12
Source File: BarrowsPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void shutDown()
{
	overlayManager.remove(barrowsOverlay);
	overlayManager.remove(brotherOverlay);
	walls.clear();
	ladders.clear();
	puzzleAnswer = null;
	wasInCrypt = false;
	stopPrayerDrainTimer();

	// Restore widgets
	final Widget potential = client.getWidget(WidgetInfo.BARROWS_POTENTIAL);
	if (potential != null)
	{
		potential.setHidden(false);
	}

	final Widget barrowsBrothers = client.getWidget(WidgetInfo.BARROWS_BROTHERS);
	if (barrowsBrothers != null)
	{
		barrowsBrothers.setHidden(false);
	}
}
 
Example #13
Source File: AboveSceneOverlay.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
private void renderHealthBars(Graphics2D graphics)
{
	for (Map.Entry<WidgetInfo, Point> teammate : TEAMMATES.entrySet())
	{
		Widget widget = client.getWidget(teammate.getKey());
		if (widget == null)
		{
			continue;
		}

		// This will give us two elements, the first will be current health, and the second will be max health
		String[] teammateHealth = widget.getText().split(" / ");

		graphics.setColor(HEALTH_BAR_COLOR);
		graphics.fillRect((widget.getCanvasLocation().getX() - teammate.getValue().getX()),
			(widget.getCanvasLocation().getY() - teammate.getValue().getY()),
			getBarWidth(Integer.parseInt(teammateHealth[1]), Integer.parseInt(teammateHealth[0])),
			HEALTH_BAR_HEIGHT);
	}
}
 
Example #14
Source File: PestControlOverlay.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void renderProgressWidget(Graphics2D graphics)
{
	Widget bar = client.getWidget(WidgetInfo.PEST_CONTROL_ACTIVITY_BAR).getChild(0);
	Rectangle2D bounds = bar.getBounds().getBounds2D();

	Widget prgs = client.getWidget(WidgetInfo.PEST_CONTROL_ACTIVITY_PROGRESS).getChild(0);
	int perc = (int) ((prgs.getBounds().getWidth() / bounds.getWidth()) * 100);

	Color color = Color.GREEN;
	if (perc < 25)
	{
		color = Color.RED;
	}

	String text = String.valueOf(perc) + "%";

	FontMetrics fm = graphics.getFontMetrics();
	Rectangle2D textBounds = fm.getStringBounds(text, graphics);
	int x = (int) (bounds.getX() - textBounds.getWidth());
	int y = (int) (bounds.getY() + fm.getHeight() - 2);

	graphics.setColor(Color.BLACK);
	graphics.drawString(text, x + 1, y + 1);
	graphics.setColor(color);
	graphics.drawString(text, x, y);
}
 
Example #15
Source File: CombatLevelPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
private void onGameTick(GameTick event)
{
	if (client.getGameState() != GameState.LOGGED_IN)
	{
		return;
	}

	Widget combatLevelWidget = client.getWidget(WidgetInfo.COMBAT_LEVEL);
	if (combatLevelWidget == null || !config.showPreciseCombatLevel())
	{
		return;
	}

	double combatLevelPrecise = Experience.getCombatLevelPrecise(
		client.getRealSkillLevel(Skill.ATTACK),
		client.getRealSkillLevel(Skill.STRENGTH),
		client.getRealSkillLevel(Skill.DEFENCE),
		client.getRealSkillLevel(Skill.HITPOINTS),
		client.getRealSkillLevel(Skill.MAGIC),
		client.getRealSkillLevel(Skill.RANGED),
		client.getRealSkillLevel(Skill.PRAYER)
	);

	combatLevelWidget.setText("Combat Lvl: " + DECIMAL_FORMAT.format(combatLevelPrecise));
}
 
Example #16
Source File: Hooks.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * When the world map opens it loads about ~100mb of data into memory, which
 * represents about half of the total memory allocated by the client.
 * This gets cached and never released, which causes GC pressure which can affect
 * performance. This method reinitializes the world map cache, which allows the
 * data to be garbage collected, and causes the map data from disk each time
 * is it opened.
 */
private void checkWorldMap()
{
	Widget widget = client.getWidget(WORLD_MAP_VIEW);

	if (widget != null)
	{
		return;
	}

	RenderOverview renderOverview = client.getRenderOverview();

	if (renderOverview == null)
	{
		return;
	}

	WorldMapManager manager = renderOverview.getWorldMapManager();

	if (manager != null && manager.isLoaded())
	{
		log.debug("World map was closed, reinitializing");
		renderOverview.initializeWorldMap(renderOverview.getWorldMapData());
	}
}
 
Example #17
Source File: WidgetOverlay.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public Dimension render(Graphics2D graphics)
{
	final Widget widget = client.getWidget(widgetInfo);
	final Rectangle bounds = super.getBounds();
	final Rectangle parent = getParentBounds(widget);

	if (parent.isEmpty())
	{
		return null;
	}

	int x = bounds.x;
	int y = bounds.y;
	x = Math.max(parent.x, x);
	y = Math.max(parent.y, y);
	x = Math.min((int)parent.getMaxX() - bounds.width, x);
	y = Math.min((int)parent.getMaxY() - bounds.height, y);
	bounds.setLocation(x, y);
	widget.setOriginalX(0);
	widget.setOriginalY(0);
	widget.setRelativeX(bounds.x - parent.x);
	widget.setRelativeY(bounds.y - parent.y);
	return new Dimension(widget.getWidth(), widget.getHeight());
}
 
Example #18
Source File: BankSearch.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
public void layoutBank()
{
	Widget bankContainer = client.getWidget(WidgetInfo.BANK_ITEM_CONTAINER);
	if (bankContainer == null || bankContainer.isHidden())
	{
		return;
	}

	Object[] scriptArgs = bankContainer.getOnInvTransmit();

	if (scriptArgs == null)
	{
		return;
	}

	client.runScript(scriptArgs);
}
 
Example #19
Source File: AlchemyRoom.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void over(Graphics2D graphics)
{
	if (!inside() || !config.alchemy() || best == null)
	{
		return;
	}

	Widget inventory = client.getWidget(WidgetInfo.INVENTORY);
	if (inventory.isHidden())
	{
		return;
	}

	for (WidgetItem item : inventory.getWidgetItems())
	{
		if (item.getId() != best.getId())
		{
			continue;
		}

		drawItem(graphics, item, Color.GREEN);
	}
}
 
Example #20
Source File: KeyRemappingPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
private void onScriptCallbackEvent(ScriptCallbackEvent scriptCallbackEvent)
{
	switch (scriptCallbackEvent.getEventName())
	{
		case SCRIPT_EVENT_SET_CHATBOX_INPUT:
			Widget chatboxInput = client.getWidget(WidgetInfo.CHATBOX_INPUT);
			if (chatboxInput != null && chatboxFocused() && !typing)
			{
				setChatboxWidgetInput(chatboxInput, PRESS_ENTER_TO_CHAT);
			}
			break;
		case SCRIPT_EVENT_BLOCK_CHAT_INPUT:
			if (!typing)
			{
				int[] intStack = client.getIntStack();
				int intStackSize = client.getIntStackSize();
				intStack[intStackSize - 1] = 1;
			}
			break;
	}
}
 
Example #21
Source File: InterfaceStylesPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void adjustWidgetDimensions()
{
	for (WidgetOffset widgetOffset : WidgetOffset.values())
	{
		if (widgetOffset.getSkin() != config.skin())
		{
			continue;
		}

		Widget widget = client.getWidget(widgetOffset.getWidgetInfo());

		if (widget != null)
		{
			if (widgetOffset.getOffsetX() != null)
			{
				widget.setRelativeX(widgetOffset.getOffsetX());
			}

			if (widgetOffset.getOffsetY() != null)
			{
				widget.setRelativeY(widgetOffset.getOffsetY());
			}

			if (widgetOffset.getWidth() != null)
			{
				widget.setWidth(widgetOffset.getWidth());
			}

			if (widgetOffset.getHeight() != null)
			{
				widget.setHeight(widgetOffset.getHeight());
			}
		}
	}
}
 
Example #22
Source File: MaxHitPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
private void setWidgetMaxHit(MaxHit maxhit)
{
	Widget equipYourCharacter = client.getWidget(WidgetInfo.EQUIP_YOUR_CHARACTER);
	String maxHitText = "Melee Max Hit: " + maxhit.getMaxMeleeHit();
	maxHitText += "<br>Range Max Hit: " + maxhit.getMaxRangeHit();
	maxHitText += "<br>Magic Max Hit: " + maxhit.getMaxMagicHit();


	equipYourCharacter.setText(maxHitText);
}
 
Example #23
Source File: NightmareZonePlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void shutDown()
{
	overlayManager.remove(overlay);
	overlay.removeAbsorptionCounter();

	Widget nmzWidget = client.getWidget(WidgetInfo.NIGHTMARE_ZONE);

	if (nmzWidget != null)
	{
		nmzWidget.setHidden(false);
	}

	resetPointsPerHour();
}
 
Example #24
Source File: ChatboxPerformancePlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void fixWhiteLines(boolean upperLine)
{
	int currOpacity = 256;
	int prevWidth = 0;
	Widget[] children = client.getWidget(WidgetInfo.CHATBOX_TRANSPARENT_LINES).getDynamicChildren();
	Widget prev = null;
	for (Widget w : children)
	{
		if (w.getType() != WidgetType.RECTANGLE)
		{
			continue;
		}

		if ((w.getRelativeY() == 0 && !upperLine) ||
			(w.getRelativeY() != 0 && upperLine))
		{
			continue;
		}

		if (prev != null)
		{
			int width = w.getWidth();
			prev.setWidthMode(WidgetSizeMode.ABSOLUTE);
			prev.setRelativeX(width);
			prev.setOriginalX(width);
			prev.setWidth(prevWidth - width);
			prev.setOriginalWidth(prev.getWidth());
			prev.setOpacity(currOpacity);
		}

		prevWidth = w.getWidth();

		currOpacity -= upperLine ? 3 : 4; // Rough numbers, can't get exactly the same as Jagex because of rounding
		prev = w;
	}
	if (prev != null)
	{
		prev.setOpacity(currOpacity);
	}
}
 
Example #25
Source File: CombatLevelPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void shutDownAttackLevelRange()
{
	if (WorldType.isPvpWorld(client.getWorldType()))
	{
		return;
	}

	final Widget wildernessLevelWidget = client.getWidget(WidgetInfo.PVP_WILDERNESS_LEVEL);
	if (wildernessLevelWidget != null)
	{
		String wildernessLevelText = wildernessLevelWidget.getText();
		if (wildernessLevelText.contains("<br>"))
		{
			wildernessLevelWidget.setText(wildernessLevelText.substring(0, wildernessLevelText.indexOf("<br>")));
		}
		wildernessLevelWidget.setOriginalY(originalWildernessLevelTextPosition);
		clientThread.invoke(wildernessLevelWidget::revalidate);
	}
	originalWildernessLevelTextPosition = -1;

	final Widget skullContainer = client.getWidget(WidgetInfo.PVP_SKULL_CONTAINER);
	if (skullContainer != null)
	{
		skullContainer.setOriginalY(originalSkullContainerPosition);
		clientThread.invoke(skullContainer::revalidate);
	}
	originalSkullContainerPosition = -1;
}
 
Example #26
Source File: QuestListPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void shutDown()
{
	currentFilterState = null;
	Widget header = client.getWidget(WidgetInfo.QUESTLIST_BOX);
	if (header != null)
	{
		header.deleteAllChildren();
	}
}
 
Example #27
Source File: ExtUtils.java    From ExternalPlugins with GNU General Public License v3.0 5 votes vote down vote up
public List<Widget> getEquippedItems(int[] itemIds)
{
	assert client.isClientThread();

	Widget equipmentWidget = client.getWidget(WidgetInfo.EQUIPMENT);

	List<Integer> equippedIds = new ArrayList<>();

	for (int i : itemIds)
	{
		equippedIds.add(i);
	}

	List<Widget> equipped = new ArrayList<>();

	if (equipmentWidget.getStaticChildren() != null)
	{
		for (Widget widgets : equipmentWidget.getStaticChildren())
		{
			for (Widget items : widgets.getDynamicChildren())
			{
				if (equippedIds.contains(items.getItemId()))
				{
					equipped.add(items);
				}
			}
		}
	}
	else
	{
		log.error("Children is Null!");
	}

	return equipped;
}
 
Example #28
Source File: MusicPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void updateFilter(String input)
{
	final Widget container = client.getWidget(WidgetInfo.MUSIC_WINDOW);
	final Widget musicList = client.getWidget(WidgetInfo.MUSIC_TRACK_LIST);

	if (container == null || musicList == null)
	{
		return;
	}

	String filter = input.toLowerCase();
	updateList(musicList, filter);
}
 
Example #29
Source File: WidgetField.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
WidgetField(String name, Function<Widget, T> getter, BiConsumer<Widget, T> setter, Class<T> type)
{
	this.name = name;
	this.getter = getter;
	this.setter = setter;
	this.type = type;
}
 
Example #30
Source File: WidgetInspectorOverlay.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void renderWiw(Graphics2D g, Object wiw, Color color)
{
	g.setColor(color);

	if (wiw instanceof WidgetItem)
	{
		WidgetItem wi = (WidgetItem) wiw;
		Rectangle bounds = wi.getCanvasBounds();
		g.draw(bounds);

		String text = wi.getId() + "";
		FontMetrics fm = g.getFontMetrics();
		Rectangle2D textBounds = fm.getStringBounds(text, g);

		int textX = (int) (bounds.getX() + (bounds.getWidth() / 2) - (textBounds.getWidth() / 2));
		int textY = (int) (bounds.getY() + (bounds.getHeight() / 2) + (textBounds.getHeight() / 2));

		g.setColor(Color.BLACK);
		g.drawString(text, textX + 1, textY + 1);
		g.setColor(Color.ORANGE);
		g.drawString(text, textX, textY);
	}
	else
	{
		Widget w = (Widget) wiw;
		g.draw(w.getBounds());
	}
}