Search in sources :

Example 1 with UnitsDrawer

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

the class MapPanel method setMouseShadowUnits.

void setMouseShadowUnits(final Collection<Unit> units) {
    if (units == null || units.isEmpty()) {
        movementLeftForCurrentUnits = "";
        mouseShadowImage = null;
        SwingUtilities.invokeLater(this::repaint);
        return;
    }
    final Tuple<Integer, Integer> movementLeft = TripleAUnit.getMinAndMaxMovementLeft(CollectionUtils.getMatches(units, Matches.unitIsBeingTransported().negate()));
    movementLeftForCurrentUnits = movementLeft.getFirst() + (movementLeft.getSecond() > movementLeft.getFirst() ? "+" : "");
    gameData.acquireReadLock();
    try {
        movementFuelCost = Route.getMovementFuelCostCharge(units, routeDescription.getRoute(), units.iterator().next().getOwner(), gameData);
    } finally {
        gameData.releaseReadLock();
    }
    final Set<UnitCategory> categories = UnitSeperator.categorize(units);
    final int iconWidth = uiContext.getUnitImageFactory().getUnitImageWidth();
    final int horizontalSpace = 5;
    final BufferedImage img = Util.createImage(categories.size() * (horizontalSpace + iconWidth), uiContext.getUnitImageFactory().getUnitImageHeight(), true);
    final Graphics2D g = img.createGraphics();
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f));
    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 Rectangle bounds = new Rectangle(0, 0, 0, 0);
    getData().acquireReadLock();
    try {
        int i = 0;
        for (final UnitCategory category : categories) {
            final Point place = new Point(i * (iconWidth + horizontalSpace), 0);
            final UnitsDrawer drawer = new UnitsDrawer(category.getUnits().size(), category.getType().getName(), category.getOwner().getName(), place, category.getDamaged(), category.getBombingDamage(), category.getDisabled(), false, "", uiContext);
            drawer.draw(bounds, gameData, g, uiContext.getMapData(), null, null);
            i++;
        }
    } finally {
        getData().releaseReadLock();
    }
    mouseShadowImage = img;
    SwingUtilities.invokeLater(this::repaint);
    g.dispose();
}
Also used : UnitsDrawer(games.strategy.triplea.ui.screen.UnitsDrawer) Rectangle(java.awt.Rectangle) Point(java.awt.Point) UnitCategory(games.strategy.triplea.util.UnitCategory) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Aggregations

UnitsDrawer (games.strategy.triplea.ui.screen.UnitsDrawer)1 UnitCategory (games.strategy.triplea.util.UnitCategory)1 Graphics2D (java.awt.Graphics2D)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 BufferedImage (java.awt.image.BufferedImage)1