use of games.strategy.triplea.attachments.TerritoryAttachment in project triplea by triplea-game.
the class TerritoryNameDrawable method draw.
@Override
public void draw(final Rectangle bounds, final GameData data, final Graphics2D graphics, final MapData mapData, final AffineTransform unscaled, final AffineTransform scaled) {
final Territory territory = data.getMap().getTerritory(territoryName);
final TerritoryAttachment ta = TerritoryAttachment.get(territory);
final boolean drawFromTopLeft = mapData.drawNamesFromTopLeft();
final boolean showSeaNames = mapData.drawSeaZoneNames();
final boolean showComments = mapData.drawComments();
boolean drawComments = false;
String commentText = null;
if (territory.isWater()) {
// this is for special comments, like convoy zones, etc.
if (ta != null && showComments) {
if (ta.getConvoyRoute() && ta.getProduction() > 0 && ta.getOriginalOwner() != null) {
drawComments = true;
if (ta.getConvoyAttached().isEmpty()) {
commentText = MyFormatter.defaultNamedToTextList(TerritoryAttachment.getWhatTerritoriesThisIsUsedInConvoysFor(territory, data)) + " " + ta.getOriginalOwner().getName() + " Blockade Route";
} else {
commentText = MyFormatter.defaultNamedToTextList(ta.getConvoyAttached()) + " " + ta.getOriginalOwner().getName() + " Convoy Route";
}
} else if (ta.getConvoyRoute()) {
drawComments = true;
if (ta.getConvoyAttached().isEmpty()) {
commentText = MyFormatter.defaultNamedToTextList(TerritoryAttachment.getWhatTerritoriesThisIsUsedInConvoysFor(territory, data)) + " Blockade Route";
} else {
commentText = MyFormatter.defaultNamedToTextList(ta.getConvoyAttached()) + " Convoy Route";
}
} else if (ta.getProduction() > 0 && ta.getOriginalOwner() != null) {
drawComments = true;
final PlayerID originalOwner = ta.getOriginalOwner();
commentText = originalOwner.getName() + " Convoy Center";
}
}
if (!drawComments && !showSeaNames) {
return;
}
}
graphics.setFont(MapImage.getPropertyMapFont());
graphics.setColor(MapImage.getPropertyTerritoryNameAndPuAndCommentColor());
final FontMetrics fm = graphics.getFontMetrics();
// if we specify a placement point, use it otherwise try to center it
final int x;
final int y;
final Optional<Point> namePlace = mapData.getNamePlacementPoint(territory);
if (namePlace.isPresent()) {
x = namePlace.get().x;
y = namePlace.get().y;
} else {
final Rectangle territoryBounds = getBestTerritoryNameRect(mapData, territory, fm);
x = territoryBounds.x + (int) territoryBounds.getWidth() / 2 - fm.stringWidth(territory.getName()) / 2;
y = territoryBounds.y + (int) territoryBounds.getHeight() / 2 + fm.getAscent() / 2;
}
// draw comments above names
if (showComments && drawComments && commentText != null) {
final Optional<Point> place = mapData.getCommentMarkerLocation(territory);
if (place.isPresent()) {
draw(bounds, graphics, place.get().x, place.get().y, null, commentText, drawFromTopLeft);
} else {
draw(bounds, graphics, x, y - fm.getHeight(), null, commentText, drawFromTopLeft);
}
}
// draw territory names
if (mapData.drawTerritoryNames() && mapData.shouldDrawTerritoryName(territoryName)) {
if (!territory.isWater() || showSeaNames) {
final Image nameImage = mapData.getTerritoryNameImages().get(territory.getName());
draw(bounds, graphics, x, y, nameImage, territory.getName(), drawFromTopLeft);
}
}
// draw the PUs.
if (ta != null && ta.getProduction() > 0 && mapData.drawResources()) {
final Image img = uiContext.getPuImageFactory().getPuImage(ta.getProduction());
final String prod = Integer.valueOf(ta.getProduction()).toString();
final Optional<Point> place = mapData.getPuPlacementPoint(territory);
// if pu_place.txt is specified draw there
if (place.isPresent()) {
draw(bounds, graphics, place.get().x, place.get().y, img, prod, drawFromTopLeft);
} else {
// otherwise, draw under the territory name
draw(bounds, graphics, x + ((fm.stringWidth(territoryName)) >> 1) - ((fm.stringWidth(prod)) >> 1), y + fm.getLeading() + fm.getAscent(), img, prod, drawFromTopLeft);
}
}
}
Aggregations