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();
}
}
Aggregations