Turns out im going to use fontmetrics and lots of math, since the current system makes whoever wrote the map in charge of getting the text to fit. Bad plan.
So here is the codes
import java.awt.*;
import java.util.Iterator;
import java.awt.image.BufferedImage;
public class AlertWindow {
public static final int PORTRAIT_X_OFFSET = 30;
public static final int PORTRAIT_Y_OFFSET = 22;
public static final int PORTRAIT_STRING_X_OFFSET = 74;
public static final int NORMAL_STRING_X_OFFSET = 30;
public static final int START_STRING_Y_OFFSET = 30;
public static final int STRING_OFFSET_BETWEEN_LINES = 8;
public static final int FONT_SIZE = 12;
private static String text;
private static BufferedImage portrait;
private static BufferedImage image;
public static boolean drawing;
static int x, y;
public static void setImage(BufferedImage i) {
image = i;
x = (RunnerApp.WIDTH/2) - (getWidth()/2);
y = (RunnerApp.HEIGHT/2) - (getHeight()/2);
}
public static BufferedImage getImage() {
return image;
}
public static void setPortrait(BufferedImage np) {
portrait = np;
}
public static BufferedImage getPortrait() {
return portrait;
}
public static String getText() {
return text;
}
public static void setText(String t) {
text = t;
}
public static int getHeight() {
if (image == null) {
return 0;
} else {
return image.getHeight();
}
}
public static int getWidth() {
if (image == null) {
return 0;
} else {
return image.getWidth();
}
}
public static void draw(Graphics g) {
if (!drawing) return;
//g.drawImage(image, x, y, null);
g.drawImage(portrait, x + PORTRAIT_X_OFFSET, y + PORTRAIT_Y_OFFSET, null);
Font font = new Font("Helvetica Neue", Font.PLAIN, FONT_SIZE);
g.setFont(font);
g.setColor(Color.WHITE);
FontMetrics metrics = g.getFontMetrics(font);
drawTheText(g, 1, metrics);
}
public static void drawTheText(Graphics g, int lineNum, FontMetrics metrics) {
int boxWidth = (RunnerApp.WIDTH/2) + (getWidth()/2);
int width = metrics.stringWidth(getText());
int height = metrics.getHeight();
if (NORMAL_STRING_X_OFFSET + width >= boxWidth) {
g.drawString(frontHalfString(getText()), x + NORMAL_STRING_X_OFFSET, y + START_STRING_Y_OFFSET + (STRING_OFFSET_BETWEEN_LINES * lineNum) + (height * lineNum));
setText(secondHalfString(getText()));
drawTheText(g, ++lineNum, metrics);
} else {
g.drawString(getText(), x + NORMAL_STRING_X_OFFSET, y + START_STRING_Y_OFFSET + (STRING_OFFSET_BETWEEN_LINES * lineNum) + (height * lineNum));
}
return;
}
public static String frontHalfString(String string) {
return (string.substring(0, string.length()/2));
}
public static String secondHalfString(String string) {
return string.substring(string.length()/2, string.length());
}
}
Maybe im just really tired since its 2 in the morning. But this just draws the last segment of the string. It draws the first two which are quickly covered up or something. I think the game world is being drawn over it repeatedly. I noted out that other thing to see if the text ws under it for some reason. Im going ot bed. Anything obvious?