Index: src/activities/chess/Chess.qml =================================================================== --- src/activities/chess/Chess.qml +++ src/activities/chess/Chess.qml @@ -34,6 +34,7 @@ property bool acceptClick: true property bool twoPlayers: false property int coordsOpacity: 1 + property int movesNum: 0 // difficultyByLevel means that at level 1 computer is bad better at last level property bool difficultyByLevel: true property var fen: [ @@ -59,6 +60,35 @@ activity.stop.connect(stop) } + 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" } + height: 25 * ApplicationInfo.ratio + anchors { + top:parent.top + topMargin: 10 + horizontalCenter: parent.horizontalCenter + } + + onClicked: { + whiteTakenPieces.open = !whiteTakenPieces.open + blackTakenPieces.open = !blackTakenPieces.open + } + } + // Add here the QML items you need to access in javascript QtObject { id: items @@ -88,6 +118,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 } } } @@ -146,7 +178,20 @@ height: 30 * ApplicationInfo.ratio text: qsTr("Undo"); style: GCButtonStyle { theme: "light" } - onClicked: Activity.undo() + onClicked: { + Activity.undo() + movesNum-- + if(blackTakenPieces.pushedLast[blackTakenPieces.pushedLast.length-1] == movesNum) { + blackTakenPieces.pushedLast.pop() + blackTakenPieces.takenPiecesModel.remove(blackTakenPieces.takenPiecesModel.count-1) + } + movesNum++ + if(whiteTakenPieces.pushedLast[whiteTakenPieces.pushedLast.length-1] == movesNum) { + whiteTakenPieces.pushedLast.pop() + whiteTakenPieces.takenPiecesModel.remove(whiteTakenPieces.takenPiecesModel.count-1) + } + movesNum-=2 + } enabled: items.history.length > 0 ? 1 : 0 opacity: enabled Behavior on opacity { @@ -384,10 +429,19 @@ } function moveTo(from, to) { + movesNum++ 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(movesNum) + } else { + blackTakenPieces.takenPiecesModel.append(toPiece) + blackTakenPieces.pushedLast.push(movesNum) + } + } else items.audioEffects.play('qrc:/gcompris/src/core/resource/sounds/scroll.wav') toPiece.hide(from) Index: src/activities/chess/TakenPiecesList.qml =================================================================== --- /dev/null +++ src/activities/chess/TakenPiecesList.qml @@ -0,0 +1,68 @@ +/* GCompris - chess.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 } + } + } + } + } +} Index: src/activities/chess/chess.js =================================================================== --- src/activities/chess/chess.js +++ src/activities/chess/chess.js @@ -52,6 +52,9 @@ items.positions = 0 // Force a model reload items.positions = simplifiedState(state['board']) clearAcceptMove() + + items.whiteTakenPieceModel.clear() + items.blackTakenPieceModel.clear() } function nextLevel() {