Merge remote-tracking branch 'runelite/master'
This commit is contained in:
@@ -35,6 +35,7 @@ import java.awt.Rectangle;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.runelite.api.util.Text;
|
||||
|
||||
@Setter
|
||||
@Builder
|
||||
@@ -73,6 +74,7 @@ public class LineComponent implements LayoutableRenderableEntity
|
||||
int y = baseY;
|
||||
final int leftFullWidth = getLineWidth(left, metrics);
|
||||
final int rightFullWidth = getLineWidth(right, metrics);
|
||||
final TextComponent textComponent = new TextComponent();
|
||||
|
||||
if (preferredSize.width < leftFullWidth + rightFullWidth)
|
||||
{
|
||||
@@ -92,30 +94,24 @@ public class LineComponent implements LayoutableRenderableEntity
|
||||
|
||||
for (int i = 0; i < lineCount; i++)
|
||||
{
|
||||
String leftText = "";
|
||||
String rightText = "";
|
||||
|
||||
if (i < leftSplitLines.length)
|
||||
{
|
||||
leftText = leftSplitLines[i];
|
||||
final String leftText = leftSplitLines[i];
|
||||
textComponent.setPosition(new Point(x, y));
|
||||
textComponent.setText(leftText);
|
||||
textComponent.setColor(leftColor);
|
||||
textComponent.render(graphics);
|
||||
}
|
||||
|
||||
if (i < rightSplitLines.length)
|
||||
{
|
||||
rightText = rightSplitLines[i];
|
||||
final String rightText = rightSplitLines[i];
|
||||
textComponent.setPosition(new Point(x + preferredSize.width - getLineWidth(rightText, metrics), y));
|
||||
textComponent.setText(rightText);
|
||||
textComponent.setColor(rightColor);
|
||||
textComponent.render(graphics);
|
||||
}
|
||||
|
||||
final TextComponent leftLineComponent = new TextComponent();
|
||||
leftLineComponent.setPosition(new Point(x, y));
|
||||
leftLineComponent.setText(leftText);
|
||||
leftLineComponent.setColor(leftColor);
|
||||
leftLineComponent.render(graphics);
|
||||
|
||||
final TextComponent rightLineComponent = new TextComponent();
|
||||
rightLineComponent.setPosition(new Point(x + leftSmallWidth + rightSmallWidth - getLineWidth(rightText, metrics), y));
|
||||
rightLineComponent.setText(rightText);
|
||||
rightLineComponent.setColor(rightColor);
|
||||
rightLineComponent.render(graphics);
|
||||
y += metrics.getHeight();
|
||||
}
|
||||
|
||||
@@ -125,17 +121,22 @@ public class LineComponent implements LayoutableRenderableEntity
|
||||
return dimension;
|
||||
}
|
||||
|
||||
final TextComponent leftLineComponent = new TextComponent();
|
||||
leftLineComponent.setPosition(new Point(x, y));
|
||||
leftLineComponent.setText(left);
|
||||
leftLineComponent.setColor(leftColor);
|
||||
leftLineComponent.render(graphics);
|
||||
if (!left.isEmpty())
|
||||
{
|
||||
textComponent.setPosition(new Point(x, y));
|
||||
textComponent.setText(left);
|
||||
textComponent.setColor(leftColor);
|
||||
textComponent.render(graphics);
|
||||
}
|
||||
|
||||
if (!right.isEmpty())
|
||||
{
|
||||
textComponent.setPosition(new Point(x + preferredSize.width - rightFullWidth, y));
|
||||
textComponent.setText(right);
|
||||
textComponent.setColor(rightColor);
|
||||
textComponent.render(graphics);
|
||||
}
|
||||
|
||||
final TextComponent rightLineComponent = new TextComponent();
|
||||
rightLineComponent.setPosition(new Point(x + preferredSize.width - getLineWidth(right, metrics), y));
|
||||
rightLineComponent.setText(right);
|
||||
rightLineComponent.setColor(rightColor);
|
||||
rightLineComponent.render(graphics);
|
||||
y += metrics.getHeight();
|
||||
|
||||
final Dimension dimension = new Dimension(preferredSize.width, y - baseY);
|
||||
@@ -146,7 +147,7 @@ public class LineComponent implements LayoutableRenderableEntity
|
||||
|
||||
private static int getLineWidth(final String line, final FontMetrics metrics)
|
||||
{
|
||||
return metrics.stringWidth(TextComponent.textWithoutColTags(line));
|
||||
return metrics.stringWidth(Text.removeTags(line));
|
||||
}
|
||||
|
||||
private static String[] lineBreakText(String text, int maxWidth, FontMetrics metrics)
|
||||
|
||||
@@ -167,8 +167,14 @@ public class PanelComponent implements LayoutableRenderableEntity
|
||||
}
|
||||
|
||||
// Remove last child gap
|
||||
totalWidth -= gap.x;
|
||||
totalHeight -= gap.y;
|
||||
if (orientation == ComponentOrientation.HORIZONTAL)
|
||||
{
|
||||
totalWidth -= gap.x;
|
||||
}
|
||||
else // VERTICAL
|
||||
{
|
||||
totalHeight -= gap.y;
|
||||
}
|
||||
|
||||
// Cache children bounds
|
||||
childDimensions.setSize(totalWidth, totalHeight);
|
||||
|
||||
@@ -35,6 +35,7 @@ import java.awt.Shape;
|
||||
import java.awt.font.GlyphVector;
|
||||
import java.util.regex.Pattern;
|
||||
import lombok.Setter;
|
||||
import net.runelite.api.util.Text;
|
||||
import net.runelite.client.ui.overlay.RenderableEntity;
|
||||
|
||||
@Setter
|
||||
@@ -42,32 +43,26 @@ public class TextComponent implements RenderableEntity
|
||||
{
|
||||
private static final String COL_TAG_REGEX = "(<col=([0-9a-fA-F]){2,6}>)";
|
||||
private static final Pattern COL_TAG_PATTERN_W_LOOKAHEAD = Pattern.compile("(?=" + COL_TAG_REGEX + ")");
|
||||
private static final Pattern COL_TAG_PATTERN = Pattern.compile(COL_TAG_REGEX);
|
||||
|
||||
private String text;
|
||||
private Point position = new Point();
|
||||
private Color color = Color.WHITE;
|
||||
private Color borderColor = Color.BLACK;
|
||||
|
||||
public static String textWithoutColTags(String text)
|
||||
{
|
||||
return COL_TAG_PATTERN.matcher(text).replaceAll("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension render(Graphics2D graphics)
|
||||
{
|
||||
final FontMetrics fontMetrics = graphics.getFontMetrics();
|
||||
|
||||
if (COL_TAG_PATTERN.matcher(text).find())
|
||||
if (COL_TAG_PATTERN_W_LOOKAHEAD.matcher(text).find())
|
||||
{
|
||||
final String[] parts = COL_TAG_PATTERN_W_LOOKAHEAD.split(text);
|
||||
int x = position.x;
|
||||
|
||||
for (String textSplitOnCol : parts)
|
||||
{
|
||||
final String textWithoutCol = textWithoutColTags(textSplitOnCol);
|
||||
final String colColor = textSplitOnCol.substring(textSplitOnCol.indexOf('=') + 1, textSplitOnCol.indexOf('>'));
|
||||
final String textWithoutCol = Text.removeTags(textSplitOnCol);
|
||||
final String colColor = textSplitOnCol.substring(textSplitOnCol.indexOf("=") + 1, textSplitOnCol.indexOf(">"));
|
||||
|
||||
renderText(graphics, x, position.y, textWithoutCol, Color.decode("#" + colColor), borderColor);
|
||||
|
||||
|
||||
@@ -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,21 @@ 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)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ import javax.annotation.Nullable;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import net.runelite.api.util.Text;
|
||||
import net.runelite.client.ui.overlay.components.ComponentConstants;
|
||||
import net.runelite.client.ui.overlay.components.LayoutableRenderableEntity;
|
||||
import net.runelite.client.ui.overlay.components.TextComponent;
|
||||
@@ -255,7 +256,7 @@ public class TableComponent implements LayoutableRenderableEntity
|
||||
|
||||
private static int getTextWidth(final FontMetrics metrics, final String cell)
|
||||
{
|
||||
return metrics.stringWidth(TextComponent.textWithoutColTags(cell));
|
||||
return metrics.stringWidth(Text.removeTags(cell));
|
||||
}
|
||||
|
||||
private static String[] lineBreakText(final String text, final int maxWidth, final FontMetrics metrics)
|
||||
|
||||
@@ -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