Search in sources :

Example 6 with SOCVillage

use of soc.game.SOCVillage in project JSettlers2 by jdmonin.

the class SOCBoardPanel method pieceValueUpdated.

/**
 * A playing piece's value was updated:
 * {@code _SC_CLVI} village cloth count, or
 * {@code _SC_PIRI} pirate fortress strength.
 * Repaint that piece (if needed) on the board.
 * @param piece  Piece that was updated, includes its new value
 * @since 2.0.00
 */
public void pieceValueUpdated(final SOCPlayingPiece piece) {
    if (piece instanceof SOCFortress) {
        final SOCFortress fort = (SOCFortress) piece;
        if ((0 == fort.getStrength()) && (0 == ((SOCBoardLarge) board).getPirateHex())) {
            // All players have recaptured their fortresses: The pirate fleet & path is removed.
            flushBoardLayoutAndRepaint();
            // <--- Early return: repaint whole board ---
            return;
        }
        final int pn = piece.getPlayerNumber();
        // repaint this piece in the AWT thread
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                // Local var in case field becomes null in other thread during paint
                Image ibuf = buffer;
                if (ibuf != null)
                    drawFortress(ibuf.getGraphics(), fort, pn, false);
                Graphics bpanG = getGraphics();
                if (bpanG != null)
                    drawFortress(bpanG, fort, pn, false);
                else
                    repaint();
            }
        });
    } else if (piece instanceof SOCVillage) {
        // Otherwise no update needed, village cloth count is handled in tooltip hover.
        if (((SOCVillage) piece).getCloth() == 0)
            flushBoardLayoutAndRepaint();
    } else {
        // generic catch-all for future piece types: just repaint the board.
        flushBoardLayoutAndRepaint();
    }
}
Also used : Graphics(java.awt.Graphics) SOCVillage(soc.game.SOCVillage) SOCFortress(soc.game.SOCFortress) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage)

Aggregations

SOCVillage (soc.game.SOCVillage)6 SOCFortress (soc.game.SOCFortress)4 SOCBoardLarge (soc.game.SOCBoardLarge)3 SOCPlayer (soc.game.SOCPlayer)3 SOCCity (soc.game.SOCCity)2 SOCGame (soc.game.SOCGame)2 SOCRoad (soc.game.SOCRoad)2 SOCSettlement (soc.game.SOCSettlement)2 SOCShip (soc.game.SOCShip)2 Color (java.awt.Color)1 Graphics (java.awt.Graphics)1 Graphics2D (java.awt.Graphics2D)1 Image (java.awt.Image)1 BufferedImage (java.awt.image.BufferedImage)1 HashSet (java.util.HashSet)1 SOCPlayingPiece (soc.game.SOCPlayingPiece)1 SOCResourceSet (soc.game.SOCResourceSet)1 Connection (soc.server.genericServer.Connection)1