diff --git a/src/activities/chess/Chess.qml b/src/activities/chess/Chess.qml --- a/src/activities/chess/Chess.qml +++ b/src/activities/chess/Chess.qml @@ -33,7 +33,9 @@ property bool acceptClick: true property bool twoPlayers: false + property bool displayTakenPiecesButton: true property int coordsOpacity: 1 + property int movesCount: 0 // difficultyByLevel means that at level 1 computer is bad better at last level property bool difficultyByLevel: true property var fen: [ @@ -88,6 +90,8 @@ property string message property bool isWarningMessage property alias trigComputerMove: trigComputerMove + property alias whiteTakenPieceModel: whiteTakenPieces.takenPiecesModel + property alias blackTakenPieceModel: blackTakenPieces.takenPiecesModel Behavior on cellSize { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 1000 } } } @@ -136,7 +140,7 @@ Grid { spacing: 60 * ApplicationInfo.ratio - columns: items.isPortrait ? 3 : 1 + columns: items.isPortrait ? 4 : 1 anchors.horizontalCenter: parent.horizontalCenter horizontalItemAlignment: Grid.AlignHCenter verticalItemAlignment: Grid.AlignVCenter @@ -147,7 +151,20 @@ width: height text: ""; style: GCButtonStyle { theme: "light" } - onClicked: Activity.undo() + onClicked: { + Activity.undo() + movesCount-- + if(blackTakenPieces.pushedLast[blackTakenPieces.pushedLast.length-1] == movesCount) { + blackTakenPieces.pushedLast.pop() + blackTakenPieces.takenPiecesModel.remove(blackTakenPieces.takenPiecesModel.count-1) + } + movesCount++ + if(whiteTakenPieces.pushedLast[whiteTakenPieces.pushedLast.length-1] == movesCount) { + whiteTakenPieces.pushedLast.pop() + whiteTakenPieces.takenPiecesModel.remove(whiteTakenPieces.takenPiecesModel.count-1) + } + movesCount-=2 + } enabled: items.history.length > 0 ? 1 : 0 opacity: enabled Image { @@ -196,6 +213,35 @@ } } + Button { + id: drawerButton + height: 30 * ApplicationInfo.ratio + width: height + text: ""; + style: GCButtonStyle { theme: "light" } + + onClicked: { + whiteTakenPieces.open = !whiteTakenPieces.open + blackTakenPieces.open = !blackTakenPieces.open + } + + enabled: displayTakenPiecesButton + opacity: enabled + Image { + source: Activity.url + 'captured.svg' + height: parent.height + width: height + sourceSize.height: height + fillMode: Image.PreserveAspectFit + } + Behavior on opacity { + PropertyAnimation { + easing.type: Easing.InQuad + duration: 200 + } + } + } + Button { height: undo.height width: undo.height @@ -215,7 +261,6 @@ } } - Rectangle { id: boardBg width: items.cellSize * 8.2 @@ -408,10 +453,19 @@ } function moveTo(from, to) { + movesCount ++ var fromPiece = getPieceAt(from) var toPiece = getPieceAt(to) - if(toPiece.img !== '') + if(toPiece.img !== '') { items.audioEffects.play('qrc:/gcompris/src/core/resource/sounds/smudge.wav') + if(toPiece.isWhite) { + whiteTakenPieces.takenPiecesModel.append(toPiece) + whiteTakenPieces.pushedLast.push(movesCount) + } else { + blackTakenPieces.takenPiecesModel.append(toPiece) + blackTakenPieces.pushedLast.push(movesCount) + } + } else items.audioEffects.play('qrc:/gcompris/src/core/resource/sounds/scroll.wav') toPiece.hide(from) @@ -456,6 +510,17 @@ } } + TakenPiecesList { + id: whiteTakenPieces + openWidth: items.cellSize + edge: false + } + TakenPiecesList { + id: blackTakenPieces + openWidth: items.cellSize + edge: true + } + DialogHelp { id: dialogHelp onClose: home() diff --git a/src/activities/chess/chess.js b/src/activities/chess/chess.js --- a/src/activities/chess/chess.js +++ b/src/activities/chess/chess.js @@ -52,6 +52,8 @@ items.positions = 0 // Force a model reload items.positions = simplifiedState(state['board']) clearAcceptMove() + items.whiteTakenPieceModel.clear() + items.blackTakenPieceModel.clear() } function nextLevel() { diff --git a/src/activities/chess_partyend/ChessPartyEnd.qml b/src/activities/chess_partyend/ChessPartyEnd.qml --- a/src/activities/chess_partyend/ChessPartyEnd.qml +++ b/src/activities/chess_partyend/ChessPartyEnd.qml @@ -27,6 +27,7 @@ Chess { twoPlayers: false difficultyByLevel: false + displayTakenPiecesButton: false fen: [ ["", "4k3/8/8/8/8/8/8/K4QQ1 w - -"], ["", "1k6/8/8/8/8/8/8/K4RR1 w - -"],