58 lines
1.5 KiB
Java
58 lines
1.5 KiB
Java
package ee.futur.easygotr;
|
|
|
|
import lombok.Setter;
|
|
import net.runelite.api.widgets.Widget;
|
|
import net.runelite.client.ui.overlay.Overlay;
|
|
import net.runelite.client.ui.overlay.OverlayLayer;
|
|
import net.runelite.client.ui.overlay.OverlayPosition;
|
|
|
|
import javax.inject.Inject;
|
|
import java.awt.*;
|
|
|
|
/**
|
|
* Overlay that highlights UI widgets (inventory items) the player should interact with.
|
|
*/
|
|
public class EasyGOTRWidgetOverlay extends Overlay {
|
|
|
|
@Setter
|
|
private EasyGOTRActionHint hint;
|
|
|
|
@Inject
|
|
private EasyGOTRWidgetOverlay() {
|
|
setPosition(OverlayPosition.DYNAMIC);
|
|
setLayer(OverlayLayer.ABOVE_WIDGETS);
|
|
}
|
|
|
|
@Override
|
|
public Dimension render(Graphics2D graphics) {
|
|
EasyGOTRActionHint localHint = hint;
|
|
if (localHint == null) {
|
|
return null;
|
|
}
|
|
|
|
for (EasyGOTRHighlightTarget target : localHint.getHighlightsSafe()) {
|
|
target.getWidgetOptional().ifPresent(widget -> highlightWidget(graphics, widget, target.getColorOrDefault(Color.CYAN), target.getLabel()));
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
private void highlightWidget(Graphics2D graphics, Widget widget, Color color, String label) {
|
|
Rectangle bounds = widget.getBounds();
|
|
if (bounds == null) {
|
|
return;
|
|
}
|
|
|
|
graphics.setColor(color);
|
|
graphics.setStroke(new BasicStroke(2));
|
|
graphics.draw(bounds);
|
|
|
|
if (label != null && !label.isEmpty()) {
|
|
graphics.drawString(label, (int) bounds.getX(), (int) (bounds.getY() - 4));
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|