Search in sources :

Example 1 with MapTileDrawable

use of games.strategy.triplea.ui.screen.drawable.MapTileDrawable in project triplea by triplea-game.

the class TileManager method drawForCreate.

private void drawForCreate(final Territory selected, final GameData data, final MapData mapData, final Rectangle bounds, final Graphics2D graphics, final boolean drawOutline) {
    final Set<IDrawable> drawablesSet = new HashSet<>();
    final List<Tile> intersectingTiles = getTiles(bounds);
    for (final Tile tile : intersectingTiles) {
        drawablesSet.addAll(tile.getDrawables());
    }
    // so unscale them
    if (uiContext.getScale() != 1) {
        final List<IDrawable> toAdd = new ArrayList<>();
        final Iterator<IDrawable> iter = drawablesSet.iterator();
        while (iter.hasNext()) {
            final IDrawable drawable = iter.next();
            if (drawable instanceof MapTileDrawable) {
                iter.remove();
                toAdd.add(((MapTileDrawable) drawable).getUnscaledCopy());
            }
        }
        drawablesSet.addAll(toAdd);
    }
    final List<IDrawable> orderedDrawables = new ArrayList<>(drawablesSet);
    orderedDrawables.sort(Comparator.comparingInt(IDrawable::getLevel));
    for (final IDrawable drawer : orderedDrawables) {
        if (drawer.getLevel() >= IDrawable.UNITS_LEVEL) {
            break;
        }
        if (drawer.getLevel() == IDrawable.TERRITORY_TEXT_LEVEL) {
            continue;
        }
        drawer.draw(bounds, data, graphics, mapData, null, null);
    }
    if (!drawOutline) {
        final Color c;
        if (selected.isWater()) {
            c = Color.RED;
        } else {
            c = new Color(0, 0, 0);
        }
        final TerritoryOverLayDrawable told = new TerritoryOverLayDrawable(c, selected.getName(), 100, Operation.FILL);
        told.draw(bounds, data, graphics, mapData, null, null);
    }
    graphics.setStroke(new BasicStroke(10));
    graphics.setColor(Color.RED);
    for (Polygon poly : mapData.getPolygons(selected)) {
        poly = new Polygon(poly.xpoints, poly.ypoints, poly.npoints);
        poly.translate(-bounds.x, -bounds.y);
        graphics.drawPolygon(poly);
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) ArrayList(java.util.ArrayList) MapTileDrawable(games.strategy.triplea.ui.screen.drawable.MapTileDrawable) Polygon(java.awt.Polygon) IDrawable(games.strategy.triplea.ui.screen.drawable.IDrawable) HashSet(java.util.HashSet)

Aggregations

IDrawable (games.strategy.triplea.ui.screen.drawable.IDrawable)1 MapTileDrawable (games.strategy.triplea.ui.screen.drawable.MapTileDrawable)1 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 Polygon (java.awt.Polygon)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1