chessPiecesOverlay.patch

File Metadata

Author
timotheegiet
Created
Oct 29 2019, 9:02 PM

chessPiecesOverlay.patch

diff --git a/src/activities/chess/Chess.qml b/src/activities/chess/Chess.qml
index 1840d25f..883f92c9 100644
--- a/src/activities/chess/Chess.qml
+++ b/src/activities/chess/Chess.qml
@@ -33,7 +33,9 @@ ActivityBase {
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 @@ ActivityBase {
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 @@ ActivityBase {
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 @@ ActivityBase {
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 @@ ActivityBase {
}
}
+ 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 @@ ActivityBase {
}
}
-
Rectangle {
id: boardBg
width: items.cellSize * 8.2
@@ -408,10 +453,19 @@ ActivityBase {
}
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 @@ ActivityBase {
}
}
+ 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
index c88c3b07..efca60e0 100644
--- a/src/activities/chess/chess.js
+++ b/src/activities/chess/chess.js
@@ -52,6 +52,8 @@ function initLevel() {
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
index a85fcf9c..7374d77b 100644
--- a/src/activities/chess_partyend/ChessPartyEnd.qml
+++ b/src/activities/chess_partyend/ChessPartyEnd.qml
@@ -27,6 +27,7 @@ import "../chess"
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 - -"],