X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=backend.c;h=34b4c36dda644fda8bf6c5c61f22fd9c688bc89c;hb=3aadc726d957f0e8cdeae3c65ff19808a979a4e3;hp=763b0fc3b634297eaa9feecd22e018103edcf71e;hpb=0aa6ca9ac4e3f41c3a3085b834c4dd52fbdc8039;p=xboard.git diff --git a/backend.c b/backend.c index 763b0fc..34b4c36 100644 --- a/backend.c +++ b/backend.c @@ -6097,6 +6097,51 @@ UserMoveEvent(fromX, fromY, toX, toY, promoChar) } void +PromoDialog(int h, int w, Board board, Boolean clearBoard) +{ // dummy routine to mimic with pseudo-popup what front-end should do: + // display a popup with h x w mini-board + int i, j; + DisplayMessage("Click on your piece of choice", ""); + DrawPosition(TRUE, board); +} + +int hTab[(int)EmptySquare/2+1] = { 1,1,1,1,1,1,2,1,2,3,2,3,3,3,2,3,4,3,3,4,4,3,4 }; +int wTab[(int)EmptySquare/2+1] = { 1,1,2,3,4,5,3,7,4,3,5,4,4,5,7,5,4,6,6,5,5,7,6 }; +Board promoBoard; +int promotionChoice = 0; + +void PromoPopUp(ChessSquare piece) +{ // determine the layout of the piece-choice dialog + int w, h, i, j, nr; + ChessSquare list[EmptySquare]; + + if(gameInfo.variant == VariantShogi) { + // non-Pawn promotes; must be shogi + h = 1; w = 1; list[0] = piece; + if(PieceToChar(PROMOTED piece) != '.') { + // promoted version is enabled + w = 2; list[1] = PROMOTED piece; + } + } else { + // Pawn, promotes to any enabled other piece + h = 1; w = nr = 0; + for(i=1; i 0 - : x == 0 && y >= BOARD_HEIGHT - gameInfo.holdingsSize && y < BOARD_HEIGHT-1) ) { + : x == 0 && y >= BOARD_HEIGHT - gameInfo.holdingsSize && y < BOARD_HEIGHT-1); // click in right holdings, for determining promotion piece - ChessSquare p = boards[currentMove][y][x]; + if(promotionChoice == 1 && inHoldings || promotionChoice == 2 && x >= BOARD_LEFT && x < BOARD_RGHT) { + p = promoBoard[y][x]; if(appData.debugMode) fprintf(debugFP, "square contains %d\n", (int)p); if(p != EmptySquare) { FinishMove(NormalMove, fromX, fromY, toX, toY, ToLower(PieceToChar(p))); fromX = fromY = -1; + promotionChoice = 0; return; } } + promotionChoice = 0; // only one chance: if click not OK it is interpreted as cancel DrawPosition(FALSE, boards[currentMove]); return; } @@ -6323,18 +6371,18 @@ void LeftClick(ClickType clickType, int xPix, int yPix) SetHighlights(fromX, fromY, toX, toY); if(gameInfo.variant == VariantSuper || gameInfo.variant == VariantGreat) { // [HGM] super: promotion to captured piece selected from holdings - ChessSquare p = boards[currentMove][fromY][fromX], q = boards[currentMove][toY][toX]; - promotionChoice = TRUE; + ChessSquare p = boards[currentMove][fromY][fromX]; + promotionChoice = 1; + CopyBoard(promoBoard, boards[currentMove]); // kludge follows to temporarily execute move on display, without promoting yet - boards[currentMove][fromY][fromX] = EmptySquare; // move Pawn to 8th rank - boards[currentMove][toY][toX] = p; - DrawPosition(FALSE, boards[currentMove]); - boards[currentMove][fromY][fromX] = p; // take back, but display stays - boards[currentMove][toY][toX] = q; + promoBoard[fromY][fromX] = EmptySquare; // move Pawn to 8th rank + promoBoard[toY][toX] = p; + DrawPosition(FALSE, promoBoard); DisplayMessage("Click in holdings to choose piece", ""); return; } - PromotionPopUp(); + CopyBoard(promoBoard, boards[currentMove]); + PromoPopUp(boards[currentMove][fromY][fromX]); } else { UserMoveEvent(fromX, fromY, toX, toY, promoChoice); if (!appData.highlightLastMove || gotPremove) ClearHighlights();