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 } } } @@ -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 { @@ -215,7 +232,6 @@ } } - Rectangle { id: boardBg width: items.cellSize * 8.2 @@ -408,10 +424,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 +481,36 @@ } } + TakenPiecesList { + id: whiteTakenPieces + openWidth: (parent.width - boardBg.width) / 3 + edge: false + } + TakenPiecesList { + id: blackTakenPieces + openWidth: (parent.width - boardBg.width) / 3 + edge: true + } + + Button { + id: drawerButton + text: qsTr("Taken Pieces List") + z: 100 + style: GCButtonStyle { theme: "light" } + visible: displayTakenPiecesButton + height: 25 * ApplicationInfo.ratio + anchors { + top:parent.top + topMargin: 10 + horizontalCenter: parent.horizontalCenter + } + + onClicked: { + whiteTakenPieces.open = !whiteTakenPieces.open + blackTakenPieces.open = !blackTakenPieces.open + } + } + DialogHelp { id: dialogHelp onClose: home() diff --git a/src/activities/chess/TakenPiecesList.qml b/src/activities/chess/TakenPiecesList.qml new file mode 100644 --- /dev/null +++ b/src/activities/chess/TakenPiecesList.qml @@ -0,0 +1,68 @@ +/* GCompris - TakenPiecesList.qml + * + * Copyright (C) 2018 Smit S. Patil + * + * Authors: + * Smit S. Patil + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +import QtQuick 2.6 +import "chess.js" as Activity + +Rectangle { + + property alias takenPiecesModel: pieceList + property var pushedLast: [] + property double openWidth + property bool open: false + + // left = false, right = true + property bool edge + + height: parent.height + width: open ? openWidth : 0 + color: "#88111111" + + Behavior on width { + NumberAnimation { duration: 200 } + } + + anchors { + left: edge ? undefined : parent.left + right: edge ? parent.right : undefined + } + + Flow { + anchors.fill:parent + layoutDirection: edge ? Qt.RightToLeft : Qt.LeftToRight + + Repeater { + model: ListModel { id:pieceList } + Piece { + id: piece + sourceSize.width: items.cellSize + width: open ? piece.height : 0 + height: parent.height / 15 + source: img ? Activity.url + img + '.svg' : '' + img: model.img + newPos: model.pos + + Behavior on width { + NumberAnimation { duration: 200 } + } + } + } + } +} 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 - -"],