Add support for component tooltips
Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -34,10 +34,9 @@ import java.awt.Rectangle;
|
||||
import java.util.regex.Pattern;
|
||||
import lombok.Setter;
|
||||
import net.runelite.api.IndexedSprite;
|
||||
import net.runelite.client.ui.overlay.RenderableEntity;
|
||||
|
||||
@Setter
|
||||
public class TooltipComponent implements RenderableEntity
|
||||
public class TooltipComponent implements LayoutableRenderableEntity
|
||||
{
|
||||
private static final Pattern BR = Pattern.compile("</br>");
|
||||
private static final int OFFSET = 4;
|
||||
@@ -225,4 +224,22 @@ public class TooltipComponent implements RenderableEntity
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle getBounds()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPreferredLocation(Point position)
|
||||
{
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPreferredSize(Dimension dimension)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,12 +24,22 @@
|
||||
*/
|
||||
package net.runelite.client.ui.overlay.tooltip;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import net.runelite.client.ui.overlay.components.LayoutableRenderableEntity;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Tooltip
|
||||
{
|
||||
private final String text;
|
||||
private String text;
|
||||
private LayoutableRenderableEntity component;
|
||||
|
||||
public Tooltip(final String text)
|
||||
{
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public Tooltip(final LayoutableRenderableEntity component)
|
||||
{
|
||||
this.component = component;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ 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.OverlayPriority;
|
||||
import net.runelite.client.ui.overlay.components.LayoutableRenderableEntity;
|
||||
import net.runelite.client.ui.overlay.components.TooltipComponent;
|
||||
|
||||
@Singleton
|
||||
@@ -97,12 +98,22 @@ public class TooltipOverlay extends Overlay
|
||||
|
||||
for (Tooltip tooltip : tooltips)
|
||||
{
|
||||
final TooltipComponent tooltipComponent = new TooltipComponent();
|
||||
tooltipComponent.setModIcons(client.getModIcons());
|
||||
tooltipComponent.setText(tooltip.getText());
|
||||
tooltipComponent.setPosition(new Point(tooltipX, tooltipY + newBounds.height));
|
||||
final LayoutableRenderableEntity entity;
|
||||
|
||||
final Dimension dimension = tooltipComponent.render(graphics);
|
||||
if (tooltip.getComponent() != null)
|
||||
{
|
||||
entity = tooltip.getComponent();
|
||||
}
|
||||
else
|
||||
{
|
||||
final TooltipComponent tooltipComponent = new TooltipComponent();
|
||||
tooltipComponent.setModIcons(client.getModIcons());
|
||||
tooltipComponent.setText(tooltip.getText());
|
||||
entity = tooltipComponent;
|
||||
}
|
||||
|
||||
entity.setPreferredLocation(new Point(tooltipX, tooltipY + newBounds.height));
|
||||
final Dimension dimension = entity.render(graphics);
|
||||
|
||||
// Create incremental tooltip newBounds
|
||||
newBounds.height += dimension.height + PADDING;
|
||||
|
||||
Reference in New Issue
Block a user