Search in sources :

Example 1 with LandTerritoryDrawable

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

the class SmallMapImageManager method updateTerritoryOwner.

public void updateTerritoryOwner(final Territory t, final GameData data, final MapData mapData) {
    if (t.isWater()) {
        return;
    }
    final Rectangle bounds = new Rectangle(mapData.getBoundingRect(t.getName()));
    // create a large image for the territory
    final Image largeImage = Util.createImage(bounds.width, bounds.height, true);
    // make it transparent
    // http://www-106.ibm.com/developerworks/library/j-begjava/
    {
        final Graphics2D g = (Graphics2D) largeImage.getGraphics();
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f));
        g.setColor(new Color(0));
        g.fillRect(0, 0, bounds.width, bounds.height);
        g.dispose();
    }
    // draw the territory
    {
        final Graphics2D g = (Graphics2D) largeImage.getGraphics();
        g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        final LandTerritoryDrawable drawable = new LandTerritoryDrawable(t.getName());
        drawable.draw(bounds, data, g, mapData, null, null);
        g.dispose();
    }
    // scale it down
    int thumbWidth = (int) (bounds.width * view.getRatioX());
    int thumbHeight = (int) (bounds.height * view.getRatioY());
    // make the image a little bigger
    // the images wont overlap perfectly after being scaled, make them a little bigger to rebalance that
    thumbWidth += 3;
    thumbHeight += 3;
    final int thumbsX = (int) (bounds.x * view.getRatioX()) - 1;
    final int thumbsY = (int) (bounds.y * view.getRatioY()) - 1;
    // create the thumb image
    final Image thumbImage = Util.createImage(thumbWidth, thumbHeight, true);
    {
        final Graphics g = thumbImage.getGraphics();
        g.drawImage(largeImage, 0, 0, thumbImage.getWidth(null), thumbImage.getHeight(null), null);
        g.dispose();
    }
    {
        final Graphics g = offscreen.getGraphics();
        // draw it on our offscreen
        g.drawImage(thumbImage, thumbsX, thumbsY, thumbImage.getWidth(null), thumbImage.getHeight(null), null);
        g.dispose();
    }
}
Also used : Graphics(java.awt.Graphics) LandTerritoryDrawable(games.strategy.triplea.ui.screen.drawable.LandTerritoryDrawable) Color(java.awt.Color) Rectangle(java.awt.Rectangle) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 2 with LandTerritoryDrawable

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

LandTerritoryDrawable (games.strategy.triplea.ui.screen.drawable.LandTerritoryDrawable)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 IDrawable (games.strategy.triplea.ui.screen.drawable.IDrawable)1 OptionalExtraBorderLevel (games.strategy.triplea.ui.screen.drawable.IDrawable.OptionalExtraBorderLevel)1 KamikazeZoneDrawable (games.strategy.triplea.ui.screen.drawable.KamikazeZoneDrawable)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 Color (java.awt.Color)1 Graphics (java.awt.Graphics)1 Graphics2D (java.awt.Graphics2D)1 Image (java.awt.Image)1 Rectangle (java.awt.Rectangle)1 BufferedImage (java.awt.image.BufferedImage)1