From 2a8ca81a3dafe1d5d65d545a2b7076f989b755a9 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Fri, 13 Apr 2012 18:38:51 +0200 Subject: [PATCH] Use in-place sweep-selection for click-click under-promotion With detour under-promotion a piece cycles through all possible choices during backwards dragging. But in a click-click move there is no dragging. This used to be solved by letting the second click start a drag event of the default promotion choice, which you could accept by immediately releasing the mouse button, or drag around to change it first. The dragging in this case seemed a little unnatural, because the to-square was already indicated by the down-click. So it has been changed now to the promo choice appearing on the down-clicked to-square, followed by EditPosition-like sweep-selection on that square when one wants to under- promote. The move is always accepted no matter where the up-click takes place, except when it takes place on the from-square (which offers a last- resort abort possibiliy). Note that click-click promotion is essential in variants where it is not obvious from the from-square alone that a promotion is imminent, but where it depends on the to-square. (Such as Shogi.) There drag-drop detour under- promotion is not possible. --- backend.c | 31 +++++++++++++++++++------------ 1 files changed, 19 insertions(+), 12 deletions(-) diff --git a/backend.c b/backend.c index 9ac6a58..265a55c 100644 --- a/backend.c +++ b/backend.c @@ -5173,6 +5173,12 @@ Sweep (int step) } while(PieceToChar(promoSweep) == '.' || PieceToChar(promoSweep) == '~' || promoSweep == pawn || appData.testLegality && (promoSweep == king || gameInfo.variant == VariantShogi && promoSweep != PROMOTED last && last != PROMOTED promoSweep && last != promoSweep)); + if(toX >= 0) { + int victim = boards[currentMove][toY][toX]; + boards[currentMove][toY][toX] = promoSweep; + DrawPosition(FALSE, boards[currentMove]); + boards[currentMove][toY][toX] = victim; + } else ChangeDragPiece(promoSweep); } @@ -6971,7 +6977,7 @@ LeftClick (ClickType clickType, int xPix, int yPix) { int x, y; Boolean saveAnimate; - static int second = 0, promotionChoice = 0, clearFlag = 0; + static int second = 0, promotionChoice = 0, clearFlag = 0, sweepSelecting = 0; char promoChoice = NULLCHAR; ChessSquare piece; static TimeMark lastClickTime, prevClickTime; @@ -6995,7 +7001,7 @@ LeftClick (ClickType clickType, int xPix, int yPix) defaultPromoChoice = promoSweep; promoSweep = EmptySquare; // terminate sweep promoDefaultAltered = TRUE; - if(!selectFlag && (x != toX || y != toY)) x = fromX, y = fromY; // and fake up-click on same square if we were still selecting + if(!selectFlag && !sweepSelecting && (x != toX || y != toY)) x = fromX, y = fromY; // and fake up-click on same square if we were still selecting } if(promotionChoice) { // we are waiting for a click to indicate promotion piece @@ -7154,9 +7160,10 @@ LeftClick (ClickType clickType, int xPix, int yPix) /* Undo animation damage if any */ DrawPosition(FALSE, NULL); } - if (second) { + if (second || sweepSelecting) { /* Second up/down in same square; just abort move */ - second = 0; + if(sweepSelecting) DrawPosition(FALSE, boards[currentMove]); + second = sweepSelecting = 0; fromX = fromY = -1; gatingPiece = EmptySquare; ClearHighlights(); @@ -7173,9 +7180,12 @@ LeftClick (ClickType clickType, int xPix, int yPix) /* we now have a different from- and (possibly off-board) to-square */ /* Completed move */ - toX = x; - toY = y; - saveAnimate = appData.animate; + if(!sweepSelecting) { + toX = x; + toY = y; + saveAnimate = appData.animate; + } else sweepSelecting = 0; // this must be the up-click corresponding to the down-click that started the sweep + if (clickType == Press) { if(gameMode == EditPosition && boards[currentMove][fromY][fromX] == EmptySquare) { // must be Edit Position mode with empty-square selected @@ -7186,16 +7196,13 @@ LeftClick (ClickType clickType, int xPix, int yPix) if(HasPromotionChoice(fromX, fromY, toX, toY, &promoChoice, FALSE)) { if(appData.sweepSelect) { ChessSquare piece = boards[currentMove][fromY][fromX]; - ChessSquare victim = boards[currentMove][toY][toX]; - boards[currentMove][toY][toX] = piece; // kludge: make sure there is something to grab for drag - DragPieceBegin(xPix, yPix, TRUE); dragging = 1; - boards[currentMove][toY][toX] = victim; promoSweep = defaultPromoChoice; if(PieceToChar(PROMOTED piece) == '+') promoSweep = PROMOTED piece; selectFlag = 0; lastX = xPix; lastY = yPix; Sweep(0); // Pawn that is going to promote: preview promotion piece + sweepSelecting = 1; DisplayMessage("", _("Pull pawn backwards to under-promote")); - DrawPosition(FALSE, boards[currentMove]); + MarkTargetSquares(1); } return; // promo popup appears on up-click } -- 1.7.0.4