Ejemplo n.º 1
0
 private void highlightBoardSquare(int row, int col) {
   Cuboid sq = getSquare(row, col);
   MaterialData squareHighlightColor = boardStyle.getHighlightMaterial(col + (row % 2) % 2 == 1);
   switch (boardStyle.getHighlightStyle()) {
     case EDGES:
       sq.getFace(CuboidDirection.East).fill(squareHighlightColor);
       sq.getFace(CuboidDirection.North).fill(squareHighlightColor);
       sq.getFace(CuboidDirection.West).fill(squareHighlightColor);
       sq.getFace(CuboidDirection.South).fill(squareHighlightColor);
       break;
     case CORNERS:
       for (Block b : sq.corners()) {
         b.setTypeIdAndData(
             squareHighlightColor.getItemTypeId(), squareHighlightColor.getData(), false);
       }
       break;
     case CHECKERED:
     case CHEQUERED:
       for (Block b : sq) {
         if ((b.getLocation().getBlockX() - b.getLocation().getBlockZ()) % 2 == 0) {
           b.setTypeIdAndData(
               squareHighlightColor.getItemTypeId(), squareHighlightColor.getData(), false);
         }
       }
       break;
     default:
       break;
   }
   if (ChessCraft.getInstance().getDynmapIntegration() != null) {
     ChessCraft.getInstance().getDynmapIntegration().triggerUpdate(sq);
   }
 }
Ejemplo n.º 2
0
 private void highlightBoardSquare(int row, int col, boolean highlight) {
   if (!highlight) {
     paintBoardSquare(row, col, null);
   } else {
     Cuboid sq = getSquare(row, col);
     MaterialWithData squareHighlightColor =
         boardStyle.getHighlightMaterial(col + (row % 2) % 2 == 1);
     switch (boardStyle.getHighlightStyle()) {
       case EDGES:
         sq.getFace(CuboidDirection.East).fill(squareHighlightColor);
         sq.getFace(CuboidDirection.North).fill(squareHighlightColor);
         sq.getFace(CuboidDirection.West).fill(squareHighlightColor);
         sq.getFace(CuboidDirection.South).fill(squareHighlightColor);
         break;
       case CORNERS:
         for (Block b : sq.corners()) {
           squareHighlightColor.applyToBlock(b);
         }
         break;
       case CHECKERED:
       case CHEQUERED:
         for (Block b : sq) {
           if ((b.getLocation().getBlockX() - b.getLocation().getBlockZ()) % 2 == 0) {
             squareHighlightColor.applyToBlock(b.getLocation().getBlock());
           }
         }
         break;
     }
   }
 }
Ejemplo n.º 3
0
  /**
   * Use Bresenham's algorithm to draw line between two squares on the board
   *
   * @param from Square index of the first square
   * @param to Square index of the second square
   * @param isHighlighting True if drawing a highlight, false if erasing it
   */
  private void drawHighlightLine(int from, int to, boolean isHighlighting) {
    if (from < 0 || to < 0 || from >= 64 || to >= 64) {
      return;
    }

    Cuboid s1 = getSquare(Chess.sqiToRow(from), Chess.sqiToCol(from));
    Cuboid s2 = getSquare(Chess.sqiToRow(to), Chess.sqiToCol(to));
    Location loc1 = s1.getRelativeBlock(s1.getSizeX() / 2, 0, s1.getSizeZ() / 2).getLocation();
    Location loc2 = s2.getRelativeBlock(s2.getSizeX() / 2, 0, s2.getSizeZ() / 2).getLocation();

    int dx = Math.abs(loc1.getBlockX() - loc2.getBlockX());
    int dz = Math.abs(loc1.getBlockZ() - loc2.getBlockZ());
    int sx = loc1.getBlockX() < loc2.getBlockX() ? 1 : -1;
    int sz = loc1.getBlockZ() < loc2.getBlockZ() ? 1 : -1;
    int err = dx - dz;

    while (loc1.getBlockX() != loc2.getBlockX() || loc1.getBlockZ() != loc2.getBlockZ()) {
      int sqi = getSquareAt(loc1);
      MaterialData m =
          isHighlighting
              ? boardStyle.getHighlightMaterial(Chess.isWhiteSquare(sqi))
              : (Chess.isWhiteSquare(sqi)
                  ? boardStyle.getWhiteSquareMaterial()
                  : boardStyle.getBlackSquareMaterial());
      loc1.getBlock().setTypeIdAndData(m.getItemTypeId(), m.getData(), false);
      int e2 = 2 * err;
      if (e2 > -dz) {
        err -= dz;
        loc1.add(sx, 0, 0);
      }
      if (e2 < dx) {
        err += dx;
        loc1.add(0, 0, sz);
      }
    }
  }