Add full item name clickboxes
- Expand the clickbox for highlighting/hiding item to it's entire name - Left click on name highlights item, right click hides item - Highlight background when in highlighting mode of the background item that is hovered - In order to help in cluttered environment, bring ground item that is hovered to front. These changes makes easy to see what item are you trying to highlight/hide in cluttered areas. Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -41,6 +41,7 @@ class GroundItem
|
||||
private int height;
|
||||
private int haPrice;
|
||||
private int gePrice;
|
||||
private int offset;
|
||||
private boolean tradeable;
|
||||
|
||||
@Value
|
||||
|
||||
@@ -24,13 +24,11 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.grounditems;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.Map;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.Point;
|
||||
import javax.swing.SwingUtilities;
|
||||
import net.runelite.client.input.KeyListener;
|
||||
import net.runelite.client.input.MouseListener;
|
||||
|
||||
@@ -38,9 +36,6 @@ public class GroundItemInputListener extends MouseListener implements KeyListene
|
||||
{
|
||||
private static final int HOTKEY = KeyEvent.VK_ALT;
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@Inject
|
||||
private GroundItemsPlugin plugin;
|
||||
|
||||
@@ -65,39 +60,51 @@ public class GroundItemInputListener extends MouseListener implements KeyListene
|
||||
if (e.getKeyCode() == HOTKEY)
|
||||
{
|
||||
plugin.setHotKeyPressed(false);
|
||||
plugin.getHighlightBoxes().clear();
|
||||
plugin.getHiddenBoxes().clear();
|
||||
plugin.setTextBoxBounds(null);
|
||||
plugin.setHiddenBoxBounds(null);
|
||||
plugin.setHighlightBoxBounds(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MouseEvent mousePressed(MouseEvent e)
|
||||
{
|
||||
final Point mousePos = e.getPoint();
|
||||
|
||||
if (plugin.isHotKeyPressed())
|
||||
{
|
||||
// Check if left click
|
||||
if (e.getButton() == MouseEvent.BUTTON1)
|
||||
if (SwingUtilities.isLeftMouseButton(e))
|
||||
{
|
||||
Point mousePos = client.getMouseCanvasPosition();
|
||||
|
||||
for (Map.Entry<Rectangle, String> entry : plugin.getHiddenBoxes().entrySet())
|
||||
// Process both click boxes for hidden and highlighted items
|
||||
if (plugin.getHiddenBoxBounds() != null && plugin.getHiddenBoxBounds().getKey().contains(mousePos))
|
||||
{
|
||||
if (entry.getKey().contains(mousePos.getX(), mousePos.getY()))
|
||||
{
|
||||
plugin.updateList(entry.getValue(), true);
|
||||
e.consume();
|
||||
return e;
|
||||
}
|
||||
plugin.updateList(plugin.getHiddenBoxBounds().getValue().getName(), true);
|
||||
e.consume();
|
||||
return e;
|
||||
}
|
||||
|
||||
for (Map.Entry<Rectangle, String> entry : plugin.getHighlightBoxes().entrySet())
|
||||
if (plugin.getHighlightBoxBounds() != null && plugin.getHighlightBoxBounds().getKey().contains(mousePos))
|
||||
{
|
||||
if (entry.getKey().contains(mousePos.getX(), mousePos.getY()))
|
||||
{
|
||||
plugin.updateList(entry.getValue(), false);
|
||||
e.consume();
|
||||
return e;
|
||||
}
|
||||
plugin.updateList(plugin.getHighlightBoxBounds().getValue().getName(), false);
|
||||
e.consume();
|
||||
return e;
|
||||
}
|
||||
|
||||
// There is one name click box for left click and one for right click
|
||||
if (plugin.getTextBoxBounds() != null && plugin.getTextBoxBounds().getKey().contains(mousePos))
|
||||
{
|
||||
plugin.updateList(plugin.getTextBoxBounds().getValue().getName(), false);
|
||||
e.consume();
|
||||
return e;
|
||||
}
|
||||
}
|
||||
else if (SwingUtilities.isRightMouseButton(e))
|
||||
{
|
||||
if (plugin.getTextBoxBounds() != null && plugin.getTextBoxBounds().getKey().contains(mousePos))
|
||||
{
|
||||
plugin.updateList(plugin.getTextBoxBounds().getValue().getName(), true);
|
||||
e.consume();
|
||||
return e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,10 @@ import java.awt.Dimension;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
@@ -45,6 +48,7 @@ import net.runelite.client.plugins.grounditems.config.PriceDisplayMode;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
import net.runelite.client.ui.overlay.OverlayLayer;
|
||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
import net.runelite.client.ui.overlay.components.BackgroundComponent;
|
||||
import net.runelite.client.ui.overlay.components.TextComponent;
|
||||
import net.runelite.client.util.StackFormatter;
|
||||
import net.runelite.http.api.item.ItemPrice;
|
||||
@@ -67,6 +71,7 @@ public class GroundItemsOverlay extends Overlay
|
||||
private final GroundItemsPlugin plugin;
|
||||
private final GroundItemsConfig config;
|
||||
private final StringBuilder itemStringBuilder = new StringBuilder();
|
||||
private final BackgroundComponent backgroundComponent = new BackgroundComponent();
|
||||
private final TextComponent textComponent = new TextComponent();
|
||||
private final Map<WorldPoint, Integer> offsetMap = new HashMap<>();
|
||||
private final ItemManager itemManager;
|
||||
@@ -102,8 +107,61 @@ public class GroundItemsOverlay extends Overlay
|
||||
|
||||
offsetMap.clear();
|
||||
final LocalPoint localLocation = player.getLocalLocation();
|
||||
final Point mousePos = client.getMouseCanvasPosition();
|
||||
final List<GroundItem> groundItemList = new ArrayList<>(plugin.getCollectedGroundItems().values());
|
||||
GroundItem topGroundItem = null;
|
||||
|
||||
for (GroundItem item : plugin.getCollectedGroundItems().values())
|
||||
if (plugin.isHotKeyPressed())
|
||||
{
|
||||
final java.awt.Point awtMousePos = new java.awt.Point(mousePos.getX(), mousePos.getY());
|
||||
GroundItem groundItem = null;
|
||||
|
||||
for (GroundItem item : groundItemList)
|
||||
{
|
||||
item.setOffset(offsetMap.compute(item.getLocation(), (k, v) -> v != null ? v + 1 : 0));
|
||||
|
||||
if (groundItem != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (plugin.getTextBoxBounds() != null
|
||||
&& item.equals(plugin.getTextBoxBounds().getValue())
|
||||
&& plugin.getTextBoxBounds().getKey().contains(awtMousePos))
|
||||
{
|
||||
groundItem = item;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (plugin.getHiddenBoxBounds() != null
|
||||
&& item.equals(plugin.getHiddenBoxBounds().getValue())
|
||||
&& plugin.getHiddenBoxBounds().getKey().contains(awtMousePos))
|
||||
{
|
||||
groundItem = item;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (plugin.getHighlightBoxBounds() != null
|
||||
&& item.equals(plugin.getHighlightBoxBounds().getValue())
|
||||
&& plugin.getHighlightBoxBounds().getKey().contains(awtMousePos))
|
||||
{
|
||||
groundItem = item;
|
||||
}
|
||||
}
|
||||
|
||||
if (groundItem != null)
|
||||
{
|
||||
groundItemList.remove(groundItem);
|
||||
groundItemList.add(groundItem);
|
||||
topGroundItem = groundItem;
|
||||
}
|
||||
}
|
||||
|
||||
plugin.setTextBoxBounds(null);
|
||||
plugin.setHiddenBoxBounds(null);
|
||||
plugin.setHighlightBoxBounds(null);
|
||||
|
||||
for (GroundItem item : groundItemList)
|
||||
{
|
||||
final LocalPoint groundPoint = LocalPoint.fromWorld(client, item.getLocation());
|
||||
|
||||
@@ -215,48 +273,73 @@ public class GroundItemsOverlay extends Overlay
|
||||
continue;
|
||||
}
|
||||
|
||||
final int offset = offsetMap.compute(item.getLocation(), (k, v) -> v != null ? v + 1 : 0);
|
||||
final int offset = plugin.isHotKeyPressed()
|
||||
? item.getOffset()
|
||||
: 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();
|
||||
|
||||
// Hidden box
|
||||
final Rectangle itemHiddenBox = new Rectangle(
|
||||
textX + stringWidth,
|
||||
textY - (RECTANGLE_SIZE + stringHeight) / 2,
|
||||
RECTANGLE_SIZE,
|
||||
RECTANGLE_SIZE);
|
||||
// Item bounds
|
||||
int x = textX - 2;
|
||||
int y = textY - stringHeight - 2;
|
||||
int width = stringWidth + 4;
|
||||
int height = stringHeight + 4;
|
||||
final Rectangle itemBounds = new Rectangle(x, y, width, height);
|
||||
|
||||
plugin.getHiddenBoxes().put(itemHiddenBox, item.getName());
|
||||
// Hidden box
|
||||
x += width + 2;
|
||||
y = textY - (RECTANGLE_SIZE + stringHeight) / 2;
|
||||
width = height = RECTANGLE_SIZE - 2;
|
||||
final Rectangle itemHiddenBox = new Rectangle(x, y, width, height);
|
||||
|
||||
// Highlight box
|
||||
final Rectangle itemHighlightBox = new Rectangle(
|
||||
textX + stringWidth + RECTANGLE_SIZE + 2,
|
||||
textY - (RECTANGLE_SIZE + stringHeight) / 2,
|
||||
RECTANGLE_SIZE,
|
||||
RECTANGLE_SIZE);
|
||||
x += width + 2;
|
||||
final Rectangle itemHighlightBox = new Rectangle(x, y, width, height);
|
||||
|
||||
plugin.getHighlightBoxes().put(itemHighlightBox, item.getName());
|
||||
|
||||
final Point mousePos = client.getMouseCanvasPosition();
|
||||
boolean mouseInBox = itemBounds.contains(mousePos.getX(), mousePos.getY());
|
||||
boolean mouseInHiddenBox = itemHiddenBox.contains(mousePos.getX(), mousePos.getY());
|
||||
boolean mouseInHighlightBox = itemHighlightBox.contains(mousePos.getX(), mousePos.getY());
|
||||
|
||||
if (mouseInBox)
|
||||
{
|
||||
plugin.setTextBoxBounds(new SimpleEntry<>(itemBounds, item));
|
||||
}
|
||||
else if (mouseInHiddenBox)
|
||||
{
|
||||
plugin.setHiddenBoxBounds(new SimpleEntry<>(itemHiddenBox, item));
|
||||
|
||||
}
|
||||
else if (mouseInHighlightBox)
|
||||
{
|
||||
plugin.setHighlightBoxBounds(new SimpleEntry<>(itemHighlightBox, item));
|
||||
}
|
||||
|
||||
boolean topItem = topGroundItem == item;
|
||||
|
||||
// Draw background if hovering
|
||||
if (topItem && (mouseInBox || mouseInHiddenBox || mouseInHighlightBox))
|
||||
{
|
||||
backgroundComponent.setRectangle(itemBounds);
|
||||
backgroundComponent.render(graphics);
|
||||
}
|
||||
|
||||
// Draw hidden box
|
||||
drawRectangle(graphics, itemHiddenBox, mouseInHiddenBox ? Color.RED : color, hidden, true);
|
||||
drawRectangle(graphics, itemHiddenBox, topItem && mouseInHiddenBox ? Color.RED : color, hidden, true);
|
||||
|
||||
// Draw highlight box
|
||||
drawRectangle(graphics, itemHighlightBox, mouseInHighlightBox ? Color.GREEN : color, highlighted, false);
|
||||
drawRectangle(graphics, itemHighlightBox, topItem && mouseInHighlightBox ? Color.GREEN : color, highlighted, false);
|
||||
}
|
||||
|
||||
textComponent.setText(itemString);
|
||||
textComponent.setColor(color);
|
||||
textComponent.setPosition(new java.awt.Point(textX, textY));
|
||||
textComponent.render(graphics);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -316,9 +399,9 @@ public class GroundItemsOverlay extends Overlay
|
||||
graphics.drawLine
|
||||
(
|
||||
rect.x + 2,
|
||||
rect.y + (RECTANGLE_SIZE / 2),
|
||||
rect.x + RECTANGLE_SIZE - 2,
|
||||
rect.y + (RECTANGLE_SIZE / 2)
|
||||
rect.y + (rect.height / 2),
|
||||
rect.x + rect.width - 2,
|
||||
rect.y + (rect.height / 2)
|
||||
);
|
||||
|
||||
if (!hiddenBox)
|
||||
@@ -326,10 +409,10 @@ public class GroundItemsOverlay extends Overlay
|
||||
// Plus symbol
|
||||
graphics.drawLine
|
||||
(
|
||||
rect.x + (RECTANGLE_SIZE / 2),
|
||||
rect.x + (rect.width / 2),
|
||||
rect.y + 2,
|
||||
rect.x + (RECTANGLE_SIZE / 2),
|
||||
rect.y + RECTANGLE_SIZE - 2
|
||||
rect.x + (rect.width / 2),
|
||||
rect.y + rect.height - 2
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
@@ -107,10 +106,16 @@ public class GroundItemsPlugin extends Plugin
|
||||
private static final int COINS = ItemID.COINS_995;
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private final Map<Rectangle, String> hiddenBoxes = new ConcurrentHashMap<>();
|
||||
@Setter(AccessLevel.PACKAGE)
|
||||
private Map.Entry<Rectangle, GroundItem> textBoxBounds;
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private final Map<Rectangle, String> highlightBoxes = new ConcurrentHashMap<>();
|
||||
@Setter(AccessLevel.PACKAGE)
|
||||
private Map.Entry<Rectangle, GroundItem> hiddenBoxBounds;
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
@Setter(AccessLevel.PACKAGE)
|
||||
private Map.Entry<Rectangle, GroundItem> highlightBoxBounds;
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
@Setter(AccessLevel.PACKAGE)
|
||||
|
||||
Reference in New Issue
Block a user