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 height;
|
||||||
private int haPrice;
|
private int haPrice;
|
||||||
private int gePrice;
|
private int gePrice;
|
||||||
|
private int offset;
|
||||||
private boolean tradeable;
|
private boolean tradeable;
|
||||||
|
|
||||||
@Value
|
@Value
|
||||||
|
|||||||
@@ -24,13 +24,11 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.grounditems;
|
package net.runelite.client.plugins.grounditems;
|
||||||
|
|
||||||
import java.awt.Rectangle;
|
import java.awt.Point;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.util.Map;
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import net.runelite.api.Client;
|
import javax.swing.SwingUtilities;
|
||||||
import net.runelite.api.Point;
|
|
||||||
import net.runelite.client.input.KeyListener;
|
import net.runelite.client.input.KeyListener;
|
||||||
import net.runelite.client.input.MouseListener;
|
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;
|
private static final int HOTKEY = KeyEvent.VK_ALT;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private Client client;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private GroundItemsPlugin plugin;
|
private GroundItemsPlugin plugin;
|
||||||
|
|
||||||
@@ -65,39 +60,51 @@ public class GroundItemInputListener extends MouseListener implements KeyListene
|
|||||||
if (e.getKeyCode() == HOTKEY)
|
if (e.getKeyCode() == HOTKEY)
|
||||||
{
|
{
|
||||||
plugin.setHotKeyPressed(false);
|
plugin.setHotKeyPressed(false);
|
||||||
plugin.getHighlightBoxes().clear();
|
plugin.setTextBoxBounds(null);
|
||||||
plugin.getHiddenBoxes().clear();
|
plugin.setHiddenBoxBounds(null);
|
||||||
|
plugin.setHighlightBoxBounds(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MouseEvent mousePressed(MouseEvent e)
|
public MouseEvent mousePressed(MouseEvent e)
|
||||||
{
|
{
|
||||||
|
final Point mousePos = e.getPoint();
|
||||||
|
|
||||||
if (plugin.isHotKeyPressed())
|
if (plugin.isHotKeyPressed())
|
||||||
{
|
{
|
||||||
// Check if left click
|
if (SwingUtilities.isLeftMouseButton(e))
|
||||||
if (e.getButton() == MouseEvent.BUTTON1)
|
|
||||||
{
|
{
|
||||||
Point mousePos = client.getMouseCanvasPosition();
|
// Process both click boxes for hidden and highlighted items
|
||||||
|
if (plugin.getHiddenBoxBounds() != null && plugin.getHiddenBoxBounds().getKey().contains(mousePos))
|
||||||
for (Map.Entry<Rectangle, String> entry : plugin.getHiddenBoxes().entrySet())
|
|
||||||
{
|
{
|
||||||
if (entry.getKey().contains(mousePos.getX(), mousePos.getY()))
|
plugin.updateList(plugin.getHiddenBoxBounds().getValue().getName(), true);
|
||||||
{
|
e.consume();
|
||||||
plugin.updateList(entry.getValue(), true);
|
return e;
|
||||||
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(plugin.getHighlightBoxBounds().getValue().getName(), false);
|
||||||
{
|
e.consume();
|
||||||
plugin.updateList(entry.getValue(), false);
|
return e;
|
||||||
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.FontMetrics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
|
import java.util.AbstractMap.SimpleEntry;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import net.runelite.api.Client;
|
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.Overlay;
|
||||||
import net.runelite.client.ui.overlay.OverlayLayer;
|
import net.runelite.client.ui.overlay.OverlayLayer;
|
||||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
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.ui.overlay.components.TextComponent;
|
||||||
import net.runelite.client.util.StackFormatter;
|
import net.runelite.client.util.StackFormatter;
|
||||||
import net.runelite.http.api.item.ItemPrice;
|
import net.runelite.http.api.item.ItemPrice;
|
||||||
@@ -67,6 +71,7 @@ public class GroundItemsOverlay extends Overlay
|
|||||||
private final GroundItemsPlugin plugin;
|
private final GroundItemsPlugin plugin;
|
||||||
private final GroundItemsConfig config;
|
private final GroundItemsConfig config;
|
||||||
private final StringBuilder itemStringBuilder = new StringBuilder();
|
private final StringBuilder itemStringBuilder = new StringBuilder();
|
||||||
|
private final BackgroundComponent backgroundComponent = new BackgroundComponent();
|
||||||
private final TextComponent textComponent = new TextComponent();
|
private final TextComponent textComponent = new TextComponent();
|
||||||
private final Map<WorldPoint, Integer> offsetMap = new HashMap<>();
|
private final Map<WorldPoint, Integer> offsetMap = new HashMap<>();
|
||||||
private final ItemManager itemManager;
|
private final ItemManager itemManager;
|
||||||
@@ -102,8 +107,61 @@ public class GroundItemsOverlay extends Overlay
|
|||||||
|
|
||||||
offsetMap.clear();
|
offsetMap.clear();
|
||||||
final LocalPoint localLocation = player.getLocalLocation();
|
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());
|
final LocalPoint groundPoint = LocalPoint.fromWorld(client, item.getLocation());
|
||||||
|
|
||||||
@@ -215,48 +273,73 @@ public class GroundItemsOverlay extends Overlay
|
|||||||
continue;
|
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 textX = textPoint.getX();
|
||||||
final int textY = textPoint.getY() - (STRING_GAP * offset);
|
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())
|
if (plugin.isHotKeyPressed())
|
||||||
{
|
{
|
||||||
final int stringWidth = fm.stringWidth(itemString);
|
final int stringWidth = fm.stringWidth(itemString);
|
||||||
final int stringHeight = fm.getHeight();
|
final int stringHeight = fm.getHeight();
|
||||||
|
|
||||||
// Hidden box
|
// Item bounds
|
||||||
final Rectangle itemHiddenBox = new Rectangle(
|
int x = textX - 2;
|
||||||
textX + stringWidth,
|
int y = textY - stringHeight - 2;
|
||||||
textY - (RECTANGLE_SIZE + stringHeight) / 2,
|
int width = stringWidth + 4;
|
||||||
RECTANGLE_SIZE,
|
int height = stringHeight + 4;
|
||||||
RECTANGLE_SIZE);
|
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
|
// Highlight box
|
||||||
final Rectangle itemHighlightBox = new Rectangle(
|
x += width + 2;
|
||||||
textX + stringWidth + RECTANGLE_SIZE + 2,
|
final Rectangle itemHighlightBox = new Rectangle(x, y, width, height);
|
||||||
textY - (RECTANGLE_SIZE + stringHeight) / 2,
|
|
||||||
RECTANGLE_SIZE,
|
|
||||||
RECTANGLE_SIZE);
|
|
||||||
|
|
||||||
plugin.getHighlightBoxes().put(itemHighlightBox, item.getName());
|
boolean mouseInBox = itemBounds.contains(mousePos.getX(), mousePos.getY());
|
||||||
|
|
||||||
final Point mousePos = client.getMouseCanvasPosition();
|
|
||||||
boolean mouseInHiddenBox = itemHiddenBox.contains(mousePos.getX(), mousePos.getY());
|
boolean mouseInHiddenBox = itemHiddenBox.contains(mousePos.getX(), mousePos.getY());
|
||||||
boolean mouseInHighlightBox = itemHighlightBox.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
|
// 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
|
// 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;
|
return null;
|
||||||
@@ -316,9 +399,9 @@ public class GroundItemsOverlay extends Overlay
|
|||||||
graphics.drawLine
|
graphics.drawLine
|
||||||
(
|
(
|
||||||
rect.x + 2,
|
rect.x + 2,
|
||||||
rect.y + (RECTANGLE_SIZE / 2),
|
rect.y + (rect.height / 2),
|
||||||
rect.x + RECTANGLE_SIZE - 2,
|
rect.x + rect.width - 2,
|
||||||
rect.y + (RECTANGLE_SIZE / 2)
|
rect.y + (rect.height / 2)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!hiddenBox)
|
if (!hiddenBox)
|
||||||
@@ -326,10 +409,10 @@ public class GroundItemsOverlay extends Overlay
|
|||||||
// Plus symbol
|
// Plus symbol
|
||||||
graphics.drawLine
|
graphics.drawLine
|
||||||
(
|
(
|
||||||
rect.x + (RECTANGLE_SIZE / 2),
|
rect.x + (rect.width / 2),
|
||||||
rect.y + 2,
|
rect.y + 2,
|
||||||
rect.x + (RECTANGLE_SIZE / 2),
|
rect.x + (rect.width / 2),
|
||||||
rect.y + RECTANGLE_SIZE - 2
|
rect.y + rect.height - 2
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@@ -107,10 +106,16 @@ public class GroundItemsPlugin extends Plugin
|
|||||||
private static final int COINS = ItemID.COINS_995;
|
private static final int COINS = ItemID.COINS_995;
|
||||||
|
|
||||||
@Getter(AccessLevel.PACKAGE)
|
@Getter(AccessLevel.PACKAGE)
|
||||||
private final Map<Rectangle, String> hiddenBoxes = new ConcurrentHashMap<>();
|
@Setter(AccessLevel.PACKAGE)
|
||||||
|
private Map.Entry<Rectangle, GroundItem> textBoxBounds;
|
||||||
|
|
||||||
@Getter(AccessLevel.PACKAGE)
|
@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)
|
@Getter(AccessLevel.PACKAGE)
|
||||||
@Setter(AccessLevel.PACKAGE)
|
@Setter(AccessLevel.PACKAGE)
|
||||||
|
|||||||
Reference in New Issue
Block a user