use of net.runelite.api.Point in project runelite by runelite.
the class GroundItemsOverlay method render.
@Override
public Dimension render(Graphics2D graphics) {
final FontMetrics fm = graphics.getFontMetrics();
final Player player = client.getLocalPlayer();
if (player == null || client.getViewportWidget() == null) {
return null;
}
plugin.checkItems();
offsetMap.clear();
final LocalPoint localLocation = player.getLocalLocation();
for (GroundItem item : plugin.getCollectedGroundItems().values()) {
final LocalPoint groundPoint = LocalPoint.fromWorld(client, item.getLocation());
if (groundPoint == null || localLocation.distanceTo(groundPoint) > MAX_DISTANCE) {
continue;
}
final boolean highlighted = plugin.isHighlighted(item.getName());
if (!plugin.isHotKeyPressed() && !highlighted && ((item.getGePrice() > 0 && item.getGePrice() < config.getHideUnderGeValue()) || item.getHaPrice() < config.getHideUnderHAValue())) {
continue;
}
final boolean hidden = plugin.isHidden(item.getName());
final Color color = getCostColor(item.getGePrice() > 0 ? item.getGePrice() : item.getHaPrice(), highlighted, hidden);
itemStringBuilder.append(item.getName());
if (item.getQuantity() > 1) {
if (item.getQuantity() >= MAX_QUANTITY) {
itemStringBuilder.append(" (Lots!)");
} else {
itemStringBuilder.append(" (").append(item.getQuantity()).append(")");
}
}
if (config.showGEPrice() && item.getGePrice() > 0) {
itemStringBuilder.append(" (EX: ").append(StackFormatter.quantityToStackSize(item.getGePrice())).append(" gp)");
}
if (config.showHAValue() && item.getHaPrice() > 0) {
itemStringBuilder.append(" (HA: ").append(StackFormatter.quantityToStackSize(item.getHaPrice())).append(" gp)");
}
final String itemString = itemStringBuilder.toString();
itemStringBuilder.setLength(0);
final Point textPoint = Perspective.getCanvasTextLocation(client, graphics, groundPoint, itemString, OFFSET_Z);
if (textPoint == null) {
continue;
}
final int offset = offsetMap.compute(item.getLocation(), (k, v) -> v != null ? v + 1 : 0);
final int textX = textPoint.getX();
final int textY = textPoint.getY() - (STRING_GAP * offset);
textComponent.setText(itemString);
textComponent.setColor(color);
textComponent.setPosition(new java.awt.Point(textX, textY));
textComponent.render(graphics);
if (plugin.isHotKeyPressed()) {
final int stringWidth = fm.stringWidth(itemString);
final int stringHeight = fm.getHeight();
final int descent = fm.getDescent();
// Hidden box
final Rectangle itemHiddenBox = new Rectangle(textX + stringWidth, textY - (stringHeight / 2) - descent, RECTANGLE_SIZE, stringHeight / 2);
plugin.getHiddenBoxes().put(itemHiddenBox, item.getName());
// Highlight box
final Rectangle itemHighlightBox = new Rectangle(textX + stringWidth + RECTANGLE_SIZE + 2, textY - (stringHeight / 2) - descent, RECTANGLE_SIZE, stringHeight / 2);
plugin.getHighlightBoxes().put(itemHighlightBox, item.getName());
final Point mousePos = client.getMouseCanvasPosition();
boolean mouseInHiddenBox = itemHiddenBox.contains(mousePos.getX(), mousePos.getY());
boolean mouseInHighlightBox = itemHighlightBox.contains(mousePos.getX(), mousePos.getY());
// Draw hidden box
drawRectangle(graphics, itemHiddenBox, mouseInHiddenBox ? Color.RED : color, hidden, true);
// Draw highlight box
drawRectangle(graphics, itemHighlightBox, mouseInHighlightBox ? Color.GREEN : color, highlighted, false);
}
}
return null;
}
use of net.runelite.api.Point in project runelite by runelite.
the class CannonSpotOverlay method renderCannonSpot.
private void renderCannonSpot(Graphics2D graphics, Client client, LocalPoint point, BufferedImage image, Color color) {
// Render tile
Polygon poly = Perspective.getCanvasTilePoly(client, point);
if (poly != null) {
OverlayUtil.renderPolygon(graphics, poly, color);
}
// Render icon
Point imageLoc = Perspective.getCanvasImageLocation(client, graphics, point, image, 0);
if (imageLoc != null) {
OverlayUtil.renderImageLocation(graphics, imageLoc, image);
}
}
use of net.runelite.api.Point in project runelite by runelite.
the class GrandExchangePlugin method startUp.
@Override
protected void startUp() throws IOException {
panel = injector.getInstance(GrandExchangePanel.class);
BufferedImage icon;
synchronized (ImageIO.class) {
icon = ImageIO.read(getClass().getResourceAsStream("ge_icon.png"));
}
button = NavigationButton.builder().name("GE Offers").icon(icon).panel(panel).build();
pluginToolbar.addNavigation(button);
itemClick = new MouseListener() {
@Override
public MouseEvent mouseClicked(MouseEvent e) {
// Check if left click + alt
if (e.getButton() == MouseEvent.BUTTON1 && e.isAltDown()) {
Point mousePosition = client.getMouseCanvasPosition();
Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY);
if (inventoryWidget != null && !inventoryWidget.isHidden()) {
for (WidgetItem item : inventoryWidget.getWidgetItems()) {
if (item.getCanvasBounds().contains(mousePosition.getX(), mousePosition.getY())) {
ItemComposition itemComp = client.getItemDefinition(item.getId());
if (itemComp != null) {
e.consume();
SwingUtilities.invokeLater(() -> {
panel.showSearch();
if (!button.isSelected()) {
button.getOnSelect().run();
}
panel.getSearchPanel().priceLookup(itemComp.getName());
});
}
break;
}
}
}
}
return super.mouseClicked(e);
}
};
if (config.quickLookup()) {
mouseManager.registerMouseListener(itemClick);
}
}
Aggregations