Search in sources :

Example 1 with IDrawable

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

the class TileManager method setTerritoryOverlayForBorder.

public void setTerritoryOverlayForBorder(final Territory territory, final Color color, final GameData data, final MapData mapData) {
    acquireLock();
    try {
        final IDrawable drawable = new TerritoryOverLayDrawable(color, territory.getName(), Operation.DRAW);
        territoryOverlays.put(territory.getName(), drawable);
    } finally {
        releaseLock();
    }
    updateTerritory(territory, data, mapData);
}
Also used : IDrawable(games.strategy.triplea.ui.screen.drawable.IDrawable)

Example 2 with IDrawable

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

the class Tile method draw.

private void draw(final Graphics2D g, final GameData data, final MapData mapData) {
    final AffineTransform unscaled = g.getTransform();
    final AffineTransform scaled;
    if (scale != 1) {
        scaled = new AffineTransform();
        scaled.scale(scale, scale);
        g.setTransform(scaled);
    } else {
        scaled = unscaled;
    }
    final Stopwatch stopWatch = new Stopwatch(logger, Level.FINEST, "Drawing Tile at" + bounds);
    // clear
    g.setColor(Color.BLACK);
    g.fill(new Rectangle(0, 0, TileManager.TILE_SIZE, TileManager.TILE_SIZE));
    contents.sort(Comparator.comparingInt(IDrawable::getLevel));
    for (final IDrawable drawable : contents) {
        drawable.draw(bounds, data, g, mapData, unscaled, scaled);
    }
    isDirty = false;
    // draw debug graphics
    if (DRAW_DEBUG) {
        g.setColor(Color.PINK);
        final Rectangle r = new Rectangle(1, 1, TileManager.TILE_SIZE - 2, TileManager.TILE_SIZE - 2);
        g.setStroke(new BasicStroke(1));
        g.draw(r);
        g.setFont(new Font("Ariel", Font.BOLD, 25));
        g.drawString(x + " " + y, 40, 40);
    }
    stopWatch.done();
}
Also used : BasicStroke(java.awt.BasicStroke) Stopwatch(games.strategy.triplea.util.Stopwatch) Rectangle(java.awt.Rectangle) AffineTransform(java.awt.geom.AffineTransform) IDrawable(games.strategy.triplea.ui.screen.drawable.IDrawable) Font(java.awt.Font)

Example 3 with IDrawable

use of games.strategy.triplea.ui.screen.drawable.IDrawable 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)

Example 4 with IDrawable

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

the class TileManager method setTerritoryOverlay.

public void setTerritoryOverlay(final Territory territory, final Color color, final int alpha, final GameData data, final MapData mapData) {
    acquireLock();
    try {
        final IDrawable drawable = new TerritoryOverLayDrawable(color, territory.getName(), alpha, Operation.DRAW);
        territoryOverlays.put(territory.getName(), drawable);
    } finally {
        releaseLock();
    }
    updateTerritory(territory, data, mapData);
}
Also used : IDrawable(games.strategy.triplea.ui.screen.drawable.IDrawable)

Example 5 with IDrawable

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

the class TileManager method drawTerritory.

private void drawTerritory(final Territory territory, final GameData data, final MapData mapData) {
    final Set<Tile> drawnOn = new HashSet<>();
    final Set<IDrawable> drawing = new HashSet<>();
    if (territoryOverlays.get(territory.getName()) != null) {
        drawing.add(territoryOverlays.get(territory.getName()));
    }
    if (uiContext.getShowTerritoryEffects()) {
        drawTerritoryEffects(territory, mapData, drawing);
    }
    if (uiContext.getShowUnits()) {
        drawUnits(territory, mapData, drawnOn, drawing, data);
    }
    drawing.add(new BattleDrawable(territory.getName()));
    final TerritoryAttachment ta = TerritoryAttachment.get(territory);
    if (!territory.isWater()) {
        drawing.add(new LandTerritoryDrawable(territory.getName()));
    } else {
        if (ta != null) {
            // Kamikaze Zones
            if (ta.getKamikazeZone()) {
                drawing.add(new KamikazeZoneDrawable(territory, uiContext));
            }
            // Blockades
            if (ta.getBlockadeZone()) {
                drawing.add(new BlockadeZoneDrawable(territory));
            }
            // Convoy Routes
            if (ta.getConvoyRoute()) {
                drawing.add(new ConvoyZoneDrawable(territory.getOwner(), territory, uiContext));
            }
            // Convoy Centers
            if (ta.getProduction() > 0) {
                drawing.add(new ConvoyZoneDrawable(territory.getOwner(), territory, uiContext));
            }
        }
        drawing.add(new SeaZoneOutlineDrawable(territory.getName()));
    }
    final OptionalExtraBorderLevel optionalBorderLevel = uiContext.getDrawTerritoryBordersAgain();
    if (optionalBorderLevel != OptionalExtraBorderLevel.LOW) {
        drawing.add(new OptionalExtraTerritoryBordersDrawable(territory.getName(), optionalBorderLevel));
    }
    drawing.add(new TerritoryNameDrawable(territory.getName(), uiContext));
    if (ta != null && ta.isCapital() && mapData.drawCapitolMarkers()) {
        final PlayerID capitalOf = data.getPlayerList().getPlayerId(ta.getCapital());
        drawing.add(new CapitolMarkerDrawable(capitalOf, territory, uiContext));
    }
    if (ta != null && (ta.getVictoryCity() != 0)) {
        drawing.add(new VcDrawable(territory));
    }
    // add to the relevant tiles
    for (Tile tile : getTiles(mapData.getBoundingRect(territory.getName()))) {
        drawnOn.add(tile);
        tile.addDrawables(drawing);
    }
    territoryDrawables.put(territory.getName(), drawing);
    territoryTiles.put(territory.getName(), drawnOn);
}
Also used : BlockadeZoneDrawable(games.strategy.triplea.ui.screen.drawable.BlockadeZoneDrawable) PlayerID(games.strategy.engine.data.PlayerID) TerritoryAttachment(games.strategy.triplea.attachments.TerritoryAttachment) ConvoyZoneDrawable(games.strategy.triplea.ui.screen.drawable.ConvoyZoneDrawable) OptionalExtraBorderLevel(games.strategy.triplea.ui.screen.drawable.IDrawable.OptionalExtraBorderLevel) CapitolMarkerDrawable(games.strategy.triplea.ui.screen.drawable.CapitolMarkerDrawable) SeaZoneOutlineDrawable(games.strategy.triplea.ui.screen.drawable.SeaZoneOutlineDrawable) VcDrawable(games.strategy.triplea.ui.screen.drawable.VcDrawable) BattleDrawable(games.strategy.triplea.ui.screen.drawable.BattleDrawable) LandTerritoryDrawable(games.strategy.triplea.ui.screen.drawable.LandTerritoryDrawable) OptionalExtraTerritoryBordersDrawable(games.strategy.triplea.ui.screen.drawable.OptionalExtraTerritoryBordersDrawable) IDrawable(games.strategy.triplea.ui.screen.drawable.IDrawable) KamikazeZoneDrawable(games.strategy.triplea.ui.screen.drawable.KamikazeZoneDrawable) TerritoryNameDrawable(games.strategy.triplea.ui.screen.drawable.TerritoryNameDrawable) HashSet(java.util.HashSet)

Aggregations

IDrawable (games.strategy.triplea.ui.screen.drawable.IDrawable)5 BasicStroke (java.awt.BasicStroke)2 HashSet (java.util.HashSet)2 PlayerID (games.strategy.engine.data.PlayerID)1 TerritoryAttachment (games.strategy.triplea.attachments.TerritoryAttachment)1 BattleDrawable (games.strategy.triplea.ui.screen.drawable.BattleDrawable)1 BlockadeZoneDrawable (games.strategy.triplea.ui.screen.drawable.BlockadeZoneDrawable)1 CapitolMarkerDrawable (games.strategy.triplea.ui.screen.drawable.CapitolMarkerDrawable)1 ConvoyZoneDrawable (games.strategy.triplea.ui.screen.drawable.ConvoyZoneDrawable)1 OptionalExtraBorderLevel (games.strategy.triplea.ui.screen.drawable.IDrawable.OptionalExtraBorderLevel)1 KamikazeZoneDrawable (games.strategy.triplea.ui.screen.drawable.KamikazeZoneDrawable)1 LandTerritoryDrawable (games.strategy.triplea.ui.screen.drawable.LandTerritoryDrawable)1 MapTileDrawable (games.strategy.triplea.ui.screen.drawable.MapTileDrawable)1 OptionalExtraTerritoryBordersDrawable (games.strategy.triplea.ui.screen.drawable.OptionalExtraTerritoryBordersDrawable)1 SeaZoneOutlineDrawable (games.strategy.triplea.ui.screen.drawable.SeaZoneOutlineDrawable)1 TerritoryNameDrawable (games.strategy.triplea.ui.screen.drawable.TerritoryNameDrawable)1 VcDrawable (games.strategy.triplea.ui.screen.drawable.VcDrawable)1 Stopwatch (games.strategy.triplea.util.Stopwatch)1 Color (java.awt.Color)1 Font (java.awt.Font)1