for (int r = -1; r < drawnRows + 1; r++) {
for (int c = -1; c < drawnColumns + 1; c++) {
// real row and column
int row = r + offset.row;
int column = c + offset.column;
MapPosition p = new MapPosition(row, column);
// compute left, upper corner (shift is every second, real row)
int x = c * tileSize.width + ((row % 2 != 0) ? tileSize.width / 2 : 0);
int y = r * tileSize.height;
// still on the map?
if (row >= 0 && row < scenario.getNumberRows() && column >= 0 && column < scenario.getNumberColumns()) {
fulldrawn.add(new ScreenPosition(x, y, p));
} else {
row = Math.max(0, row);
row = Math.min(scenario.getNumberRows() - 1, row);
column = Math.max(0, column);
column = Math.min(scenario.getNumberColumns() - 1, column);
outside.add(new ScreenPosition(x, y, new MapPosition(row, column)));
}
}
}
// draw all terrain tiles
for (ScreenPosition r : fulldrawn) {
List<Pair<TilesTransition, Boolean>> list = new ArrayList<>(6);
for (TilesTransition transition : TilesTransition.values()) {
list.add(new Pair<TilesTransition, Boolean>(transition, scenario.isSameTerrain(r.p, transition)));
}
scenario.getTerrainTileAt(r.p).paint(g2d, r.x, r.y, list);
// drawImageCentered(g2d, scenario.getTerrainTileAt(r.p), r.x + tileSize.width / 2, r.y + tileSize.height / 2);
}
// draw terrain tiles for outside areas
for (ScreenPosition r : outside) {
drawImageCentered(g2d, scenario.getTerrainTileAt(r.p).getOuter(), r.x + tileSize.width / 2, r.y + tileSize.height / 2);
}
// draw resources
for (ScreenPosition r : fulldrawn) {
if (scenario.isResourceVisibleAt(r.p)) {
List<Pair<TilesTransition, Boolean>> list = new ArrayList<>(6);
for (TilesTransition transition : TilesTransition.values()) {
list.add(new Pair<TilesTransition, Boolean>(transition, scenario.isSameResource(r.p, transition)));
}
scenario.getResourceOverlayAt(r.p).paint(g2d, r.x, r.y, list);
// drawImageCentered(g2d, scenario.getResourceOverlayAt(r.p), r.x + tileSize.width / 2, r.y + tileSize.height / 2);
}
}
// draw rivers
for (ScreenPosition r : fulldrawn) {
Image overlay = scenario.getRiverOverlayAt(r.p);
if (overlay != null) {
drawImageCentered(g2d, overlay, r.x + tileSize.width / 2, r.y + tileSize.height / 2);
}
}
// draw tile borders, first province borders
for (ScreenPosition r : fulldrawn) {
// draw tile border
g2d.setColor(Color.white);
TilesBorder border = scenario.getBorder(r.p, TilesTransition.East);
if (border == TilesBorder.Province) {
// right border
drawBorder(g2d, border, r.x + tileSize.width, r.y, r.x + tileSize.width, r.y + tileSize.height);
}
border = scenario.getBorder(r.p, TilesTransition.SouthEast);
if (border == TilesBorder.Province) {
// lower right side
drawBorder(g2d, border, r.x + tileSize.width / 2, r.y + tileSize.height, r.x + tileSize.width, r.y + tileSize.height);
}
border = scenario.getBorder(r.p, TilesTransition.SouthWest);
if (border == TilesBorder.Province) {
// lower right side
drawBorder(g2d, border, r.x, r.y + tileSize.height, r.x + tileSize.width / 2, r.y + tileSize.height);
}
}
// draw tile borders, then nation borders
for (ScreenPosition r : fulldrawn) {
// draw tile border
g2d.setColor(Color.white);
TilesBorder border = scenario.getBorder(r.p, TilesTransition.East);
if (border == TilesBorder.Nation) {
// right border
drawBorder(g2d, border, r.x + tileSize.width, r.y, r.x + tileSize.width, r.y + tileSize.height);
}
border = scenario.getBorder(r.p, TilesTransition.SouthEast);
if (border == TilesBorder.Nation) {
// lower right side
drawBorder(g2d, border, r.x + tileSize.width / 2, r.y + tileSize.height, r.x + tileSize.width, r.y + tileSize.height);
}
border = scenario.getBorder(r.p, TilesTransition.SouthWest);
if (border == TilesBorder.Nation) {
// lower right side
drawBorder(g2d, border, r.x, r.y + tileSize.height, r.x + tileSize.width / 2, r.y + tileSize.height);
}
}
// draw railroad
for (ScreenPosition r : fulldrawn) {
// TODO really have to draw after all other tiles are drawn, otherwise parts get overdrawn again
g2d.setColor(Color.black);
int xc = r.x + tileSize.width / 2;
int yc = r.y + tileSize.height / 2;
if (scenario.hasRailRoad(r.p, TilesTransition.East)) {
g2d.drawLine(xc, yc, xc + tileSize.width, yc);
}
if (scenario.hasRailRoad(r.p, TilesTransition.SouthEast)) {
g2d.drawLine(xc, yc, xc + tileSize.width / 2, yc + tileSize.height);
}
if (scenario.hasRailRoad(r.p, TilesTransition.SouthWest)) {
g2d.drawLine(xc, yc, xc - tileSize.width / 2, yc + tileSize.height);
}
}
// draw cities
for (ScreenPosition r : fulldrawn) {
// draw city
String name = scenario.getTownAt(r.p);
// name = "Test";
if (name != null) {
drawImageCentered(g2d, scenario.getTileGraphicsRepository().getMiscOverlay("city"), r.x + tileSize.width / 2, r.y + tileSize.height / 2);
drawProvinceTownName(g2d, name, r.x + tileSize.width / 2, r.y + tileSize.height - 10);
}
}
// draw units
for (MapItem unit : scenario.getAllUnits()) {
MapPosition p = unit.getPosition();
int r = p.row - offset.row;
int c = p.column - offset.column;
// compute left, upper corner (shift is every second, real row)
int x = c * tileSize.width + ((p.row % 2 != 0) ? tileSize.width / 2 : 0);