screenmarkers: cleanup widget marker overlay bounds logic
This additionally adds a null check to the getChild() call
This commit is contained in:
@@ -35,6 +35,7 @@ import net.runelite.api.MenuEntry;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.api.widgets.WidgetItem;
|
||||
import net.runelite.api.widgets.WidgetType;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
import net.runelite.client.ui.overlay.OverlayLayer;
|
||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
@@ -63,58 +64,66 @@ class ScreenMarkerWidgetHighlightOverlay extends Overlay
|
||||
return null;
|
||||
}
|
||||
|
||||
if (client.isMenuOpen())
|
||||
{
|
||||
plugin.setSelectedWidgetBounds(null);
|
||||
return null;
|
||||
}
|
||||
|
||||
final MenuEntry[] menuEntries = client.getMenuEntries();
|
||||
|
||||
final int last = menuEntries.length - 1;
|
||||
if (last < 0)
|
||||
if (client.isMenuOpen() || menuEntries.length == 0)
|
||||
{
|
||||
plugin.setSelectedWidgetBounds(null);
|
||||
return null;
|
||||
}
|
||||
|
||||
final MenuEntry menuEntry = menuEntries[last];
|
||||
final MenuEntry menuEntry = menuEntries[menuEntries.length - 1];
|
||||
final int childIdx = menuEntry.getParam0();
|
||||
final int widgetId = menuEntry.getParam1();
|
||||
final int groupId = WidgetInfo.TO_GROUP(widgetId);
|
||||
final int childId = WidgetInfo.TO_CHILD(widgetId);
|
||||
final int componentId = WidgetInfo.TO_CHILD(widgetId);
|
||||
|
||||
final Widget widget = client.getWidget(groupId, childId);
|
||||
final Widget widget = client.getWidget(groupId, componentId);
|
||||
if (widget == null)
|
||||
{
|
||||
plugin.setSelectedWidgetBounds(null);
|
||||
return null;
|
||||
}
|
||||
|
||||
final int param0 = menuEntry.getParam0();
|
||||
if (param0 > -1)
|
||||
Rectangle bounds = null;
|
||||
if (childIdx > -1)
|
||||
{
|
||||
final WidgetItem widgetItem = widget.getWidgetItem(param0);
|
||||
if (widgetItem != null)
|
||||
if (widget.getType() == WidgetType.INVENTORY)
|
||||
{
|
||||
drawHighlight(widgetItem.getCanvasBounds(), graphics);
|
||||
final WidgetItem widgetItem = widget.getWidgetItem(childIdx);
|
||||
if (widgetItem != null)
|
||||
{
|
||||
bounds = widgetItem.getCanvasBounds();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
drawHighlight(widget.getChild(param0).getBounds(), graphics);
|
||||
final Widget child = widget.getChild(childIdx);
|
||||
if (child != null)
|
||||
{
|
||||
bounds = child.getBounds();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
drawHighlight(widget.getBounds(), graphics);
|
||||
bounds = widget.getBounds();
|
||||
}
|
||||
|
||||
if (bounds == null)
|
||||
{
|
||||
plugin.setSelectedWidgetBounds(null);
|
||||
return null;
|
||||
}
|
||||
|
||||
drawHighlight(graphics, bounds);
|
||||
plugin.setSelectedWidgetBounds(bounds);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void drawHighlight(Rectangle bounds, Graphics2D graphics)
|
||||
private static void drawHighlight(Graphics2D graphics, Rectangle bounds)
|
||||
{
|
||||
graphics.setColor(Color.GREEN);
|
||||
graphics.draw(bounds);
|
||||
plugin.setSelectedWidgetBounds(bounds);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user