protected BufferedImage initBackgroundImage(IImageLoader loader,Point topLeft) {
BufferedImage bg = super.initBackgroundImage(loader,topLeft);
Graphics2D g2d = bg.createGraphics();
g2d.setColor(Color.BLACK);
try {
GlyphVector gv = opPainter.createGlyphVector(g2d, "Personal", 24); // TODO externalize
double titleHeight = gv.getVisualBounds().getHeight();
int length = (int) Math.rint(gv.getVisualBounds().getWidth());
int x = ((bg.getWidth()-getInset().left-getInset().right)-length)/2;
int y = getInset().top+10+(int)Math.rint(titleHeight*2/3);
g2d.drawGlyphVector(gv, x, y);
// Dynamic row
y += titleHeight;
y += (int)Math.rint(titleHeight*2/3);
BufferedImage waxSeal = loader.getImage("waxseal");
int yLineDiff = waxSeal.getHeight();
int leftBorderX = topLeft.x+getInset().left;
int firstColumn = leftBorderX+20; // right aligned
int xPortrait = leftBorderX+200;
int yPortrait = y+yLineDiff*10;
// Initialize the position relative to the frame
positions = new DialogPositions( yLineDiff, xPortrait,yPortrait);
leftBorderX = getInset().left; // Use local coordinates
firstColumn = leftBorderX+20; // right aligned
// table header
IPlayer player = city.getPlayer();
IPersonalData data = player.getPersonalData();
y += positions.lineHeight; // more space to the title
// Name
y = drawRow(g2d, y, firstColumn, "Name");
StringBuilder sb = new StringBuilder();
sb.append(data.getName()).append(" ").append(data.getLastName());
ESocialRank rank = player.getRank();
sb.append(" (").append(player.getCareerLevel()).append(" ").append(rank).append(")"); // TODO externalize
y = drawRow(g2d, y, firstColumn, sb.toString());
y += positions.lineHeight;
// Birth
DateObject now = new DateObject(Date.getInstance(0).getCurrentDate()); // TODO ugly
y = drawRow(g2d, y, firstColumn, "Born");
sb = new StringBuilder();
ICity birthPlace = data.getBirthPlace();
sb.append("on ").append(data.getBirthDate().toDisplayString()).append(" in ").append(birthPlace.getName()).append(", ");
sb.append("Age ").append(data.getAge(now));
y = drawRow(g2d, y, firstColumn, sb.toString());
y += positions.lineHeight;
y = drawRow(g2d, y, firstColumn, "Hometown");
y = drawRow(g2d, y, firstColumn, player.getHometown().getName());
y += positions.lineHeight;
sb = new StringBuilder();
sb.append("Social status in this town: ").append(city.getCity().getSocialRank());
y = drawRow(g2d, y, firstColumn, sb.toString());
IReputation rep = city.getCity().getReputation(player);
int repDiff = rep.getReputationDifference();
sb = new StringBuilder();
if (repDiff<0){
// reputation has sunk
if (repDiff<=-10 && repDiff>-25){
sb.append("Your reputation has sunken.");
} else if (repDiff>-10){
sb.append("Your reputation has sunken slightly");
} else {
sb.append("Your reputation has dropped");
}
} else if (repDiff>0){
// reputation has risen
if (repDiff>=10 && repDiff<25){
sb.append("Your reputation has risen");
} else if (repDiff<10){
sb.append("Your reputation has risen slightly");
} else {
sb.append("Your reputation has risen massivly");
}
} else {
sb.append("Your reputation in this city is unchanged");
}
y = drawRow(g2d, y, firstColumn, sb.toString());
if (rank!=ESocialRank.ALDERMAN && rank!=ESocialRank.MAYOR){
// draw string what is needed
ESocialRank nextRank = rank.getNextRank();
boolean needFortune = false;
if (player.getCompany().getCompanyValue()<nextRank.getCompanyValue()){
needFortune=true;
}
boolean needReputation=false;
if (city.getCity().getReputation(player).getPopularity()<nextRank.getSocialReputation()){
needReputation=true;
}
sb = new StringBuilder();
if (needFortune && needReputation){
sb.append("You need more fortune and respect in ").append(city.getCity().getName()).append(" to");
y = drawRow(g2d, y, firstColumn, sb.toString());
sb = new StringBuilder();
sb.append("advanve to the next social rank");
y = drawRow(g2d, y, firstColumn, sb.toString());
} else if (needFortune){
sb.append("You need more fortune in ").append(city.getCity().getName()).append(" to");
y = drawRow(g2d, y, firstColumn, sb.toString());
sb = new StringBuilder();
sb.append("advanve to the next social rank");
y = drawRow(g2d, y, firstColumn, sb.toString());
} else if (needReputation){
sb.append("You need more respect in ").append(city.getCity().getName()).append(" to");
y = drawRow(g2d, y, firstColumn, sb.toString());
sb = new StringBuilder();
sb.append("advanve to the next social rank");
y = drawRow(g2d, y, firstColumn, sb.toString());
} else {
y += positions.lineHeight;
y += positions.lineHeight;
}
} else {
y += positions.lineHeight;
y += positions.lineHeight;
}
// Draw underworld string
ICareer careerLevel = player.getCareerLevel();
String s;
if (careerLevel instanceof IMilitantCareer){
if (((EMilitantCareer)careerLevel)!=EMilitantCareer.BOISTEROUS &&
((EMilitantCareer)careerLevel)!=EMilitantCareer.BOLD ){
s = "The underworld fears you";
} else {
s = "The underworld avoids you";
}
} else {
s = "The underworld avoids you";
}
y = drawRow(g2d, y, firstColumn, s);
y += positions.lineHeight;
if (player.getSpouseData()!=null){
ISpouseData spouse = player.getSpouseData();
// Name
if (spouse.isMale()){
s = "Name of husband"; // TODO externalize
} else {
s = "Name of wife";
}
y = drawRow(g2d, y, firstColumn, s);
sb = new StringBuilder();
sb.append(spouse.getName()).append(" ").append(spouse.getLastName());
sb.append(", Age ").append(spouse.getAge(now));
y = drawRow(g2d, y, firstColumn, sb.toString());
y += positions.lineHeight;
// Birth
y = drawRow(g2d, y, firstColumn, "Born");
sb = new StringBuilder();
sb.append("on ").append(data.getBirthDate().toDisplayString()).append(" in ").append(birthPlace.getName());
y = drawRow(g2d, y, firstColumn, sb.toString());
y += positions.lineHeight;
y = drawRow(g2d, y, firstColumn, "Children");
y = drawRow(g2d, y, firstColumn, String.valueOf(spouse.getNumberOfChildren()));
y += positions.lineHeight;
sb = new StringBuilder();
if (city.getCity()==birthPlace){
// TODO consider the spouses popularity and relations
if (spouse.isMale()){
sb.append("Your husband is unknown to the citizens of ").append(city.getCity().getName());
} else {
sb.append("Your wife is unknown to the citizens of ").append(city.getCity().getName());
}
y = drawRow(g2d, y, firstColumn, sb.toString());
sb = new StringBuilder();
y = drawRow(g2d, y, firstColumn, sb.toString());
sb.append("and has no relations with the counsilmen.");
} else if (city.getCity()==player.getCompany().getHomeTown()){
// TODO consider the spouses popularity and relations
if (spouse.isMale()){
sb.append("Your husband is unknown to the citizens of ").append(city.getCity().getName());
} else {
sb.append("Your wife is unknown to the citizens of ").append(city.getCity().getName());
}
y = drawRow(g2d, y, firstColumn, sb.toString());
sb = new StringBuilder();
y = drawRow(g2d, y, firstColumn, sb.toString());
sb.append("and has no relations with the counsilmen.");
} else {
if (spouse.isMale()){
sb.append("Your husband is unknown to the citizens of ").append(city.getCity().getName());
} else {
sb.append("Your wife is unknown to the citizens of ").append(city.getCity().getName());
}
y = drawRow(g2d, y, firstColumn, sb.toString());
sb = new StringBuilder();
y = drawRow(g2d, y, firstColumn, sb.toString());
sb.append("and has no relations with the counsilmen.");
}
if (spouse.getPortrait()!=null){
g2d.drawImage(spouse.getPortrait(), positions.xPortrait, positions.yPortrait, null);
}
}
// Footer buttons
y = bg.getHeight()-getInset().bottom-positions.lineHeight;
x = getInset().left+30;
int footerWidth = bg.getWidth()-getInset().left-getInset().right-2*30;
x += 3*footerWidth/4;
// close
g2d.drawImage(waxSeal, x,y-(int)(positions.lineHeight*0.8), null);
NamedPolygon polygon = new NamedPolygon("Close");
polygon.addPoint(topLeft.x+x, topLeft.y+y-(int)(positions.lineHeight*0.8));
polygon.addPoint(topLeft.x+x+waxSeal.getWidth(), topLeft.y+y-(int)(positions.lineHeight*0.8));
polygon.addPoint(topLeft.x+x+waxSeal.getWidth(), topLeft.y+y-(int)(positions.lineHeight*0.8)+waxSeal.getHeight());
polygon.addPoint(topLeft.x+x, topLeft.y+y-(int)(positions.lineHeight*0.8)+waxSeal.getHeight());
footerPolygons.add(polygon, new CloseAction(this));
g2d.setColor(new Color(0xEA,0xC1,0x17)); // Gold
gv = opPainter.createGlyphVector(g2d, "X", 18);
int xPadding = imageUtils.computeCenterAlignX(x, waxSeal.getWidth(), (int)gv.getVisualBounds().getWidth());
g2d.drawGlyphVector(gv, xPadding, y); // centeralign
} catch (FontFormatException e1) {
e1.printStackTrace();