diff options
author | Marvin Borner | 2020-04-10 01:06:07 +0200 |
---|---|---|
committer | Marvin Borner | 2020-04-10 01:06:07 +0200 |
commit | 1a7c61dfb1da9de54e276e241495359d40c80ef7 (patch) | |
tree | 0f47cddf4bd0604fa1374f0f631c1435e72acd3e | |
parent | 0a63c0e671cb015700bbbb97efa8242381b60b55 (diff) |
Added working selector and mover
-rw-r--r-- | qml/Functions.qml | 40 | ||||
-rw-r--r-- | qml/Square.qml | 8 | ||||
-rw-r--r-- | qml/images/bb.svg (renamed from qml/images/bbishop.svg) | 0 | ||||
-rw-r--r-- | qml/images/bk.svg (renamed from qml/images/bking.svg) | 0 | ||||
-rw-r--r-- | qml/images/bn.svg (renamed from qml/images/bknight.svg) | 0 | ||||
-rw-r--r-- | qml/images/bp.svg (renamed from qml/images/bpawn.svg) | 0 | ||||
-rw-r--r-- | qml/images/bq.svg (renamed from qml/images/bqueen.svg) | 0 | ||||
-rw-r--r-- | qml/images/br.svg (renamed from qml/images/brook.svg) | 0 | ||||
-rw-r--r-- | qml/images/wb.svg (renamed from qml/images/wbishop.svg) | 0 | ||||
-rw-r--r-- | qml/images/wk.svg (renamed from qml/images/wking.svg) | 0 | ||||
-rw-r--r-- | qml/images/wn.svg (renamed from qml/images/wknight.svg) | 0 | ||||
-rw-r--r-- | qml/images/wp.svg (renamed from qml/images/wpawn.svg) | 0 | ||||
-rw-r--r-- | qml/images/wq.svg (renamed from qml/images/wqueen.svg) | 0 | ||||
-rw-r--r-- | qml/images/wr.svg (renamed from qml/images/wrook.svg) | 0 | ||||
-rw-r--r-- | qml/pages/Board.qml | 2 | ||||
-rw-r--r-- | src/harbour-sailchess.cpp | 10 |
16 files changed, 38 insertions, 22 deletions
diff --git a/qml/Functions.qml b/qml/Functions.qml index 7e32f4e..4b90cc7 100644 --- a/qml/Functions.qml +++ b/qml/Functions.qml @@ -5,21 +5,43 @@ Item { id: functions function get_piece(i) { - if (i === 0 || i === 7) return "rook"; - else if (i === 1 || i === 6) return "knight"; - else if (i === 2 || i === 5) return "bishop"; - else if (i === 3) return "queen"; - else if (i === 4) return "king"; - else if (i >= 8 && i <= 15) return "pawn"; + if (i === 0 || i === 7) return "r"; + else if (i === 1 || i === 6) return "n"; + else if (i === 2 || i === 5) return "b"; + else if (i === 3) return "q"; + else if (i === 4) return "k"; + else if (i >= 8 && i <= 15) return "p"; } function fill() { for (var i = 0; i < 16; i++) { const piece = get_piece(i); - repeater.itemAt(i).image = piece !== "" ? "images/b" + piece + ".svg" : ""; - repeater.itemAt(-i + 63).image = piece !== "" ? "images/w" + piece + ".svg" : ""; + + board.itemAt(i).piece = "b" + piece; + board.itemAt(-i + 63).piece = "w" + piece; } // Swap white king & queen - repeater.itemAt(60).image = [repeater.itemAt(59).image, repeater.itemAt(59).image = repeater.itemAt(60).image][0]; + board.itemAt(60).piece = [board.itemAt(59).piece, board.itemAt(59).piece = board.itemAt(60).piece][0]; + } + + property var selected: [] + function select(i) { + if (selected.length < 2) { + if (selected.indexOf(i) === -1) selected.push(i) + else selected.splice(selected.indexOf(i), 1) + + if (selected.length === 2) { + board.itemAt(selected[0]).border.width = 0; + move(selected[0], selected[1]); + } else { + board.itemAt(i).border.width ^= parseInt(0.1 * board.itemAt(i).width); + } + } + } + + function move(from, to) { + board.itemAt(to).piece = board.itemAt(from).piece; + board.itemAt(from).piece = ""; + selected = []; } } diff --git a/qml/Square.qml b/qml/Square.qml index 78b7a5d..b1e3e0c 100644 --- a/qml/Square.qml +++ b/qml/Square.qml @@ -2,17 +2,21 @@ import QtQuick 2.0 Rectangle { property int i: 0 - property string image: "" + property string piece: "" + property string image: piece !== "" ? "images/" + piece + ".svg" : "" + width: page.width / 8 height: this.width color: ((i >> 3 ^ i) & 1) == 0 ? "#e8ebef" : "#7d8796" border.color: "yellow" border.width: 0 + MouseArea { anchors.fill: parent - onClicked: parent.border.width ^= parseInt(0.1 * parent.width) + onClicked: functions.select(i); } Image { + id: piece_image sourceSize.width: parent.width sourceSize.height: parent.height source: image diff --git a/qml/images/bbishop.svg b/qml/images/bb.svg index 4ce248f..4ce248f 100644 --- a/qml/images/bbishop.svg +++ b/qml/images/bb.svg diff --git a/qml/images/bking.svg b/qml/images/bk.svg index d90dc73..d90dc73 100644 --- a/qml/images/bking.svg +++ b/qml/images/bk.svg diff --git a/qml/images/bknight.svg b/qml/images/bn.svg index 02b0894..02b0894 100644 --- a/qml/images/bknight.svg +++ b/qml/images/bn.svg diff --git a/qml/images/bpawn.svg b/qml/images/bp.svg index 072f2fe..072f2fe 100644 --- a/qml/images/bpawn.svg +++ b/qml/images/bp.svg diff --git a/qml/images/bqueen.svg b/qml/images/bq.svg index 6f1e4a5..6f1e4a5 100644 --- a/qml/images/bqueen.svg +++ b/qml/images/bq.svg diff --git a/qml/images/brook.svg b/qml/images/br.svg index 337af8f..337af8f 100644 --- a/qml/images/brook.svg +++ b/qml/images/br.svg diff --git a/qml/images/wbishop.svg b/qml/images/wb.svg index 0f28d08..0f28d08 100644 --- a/qml/images/wbishop.svg +++ b/qml/images/wb.svg diff --git a/qml/images/wking.svg b/qml/images/wk.svg index 8b2d7b7..8b2d7b7 100644 --- a/qml/images/wking.svg +++ b/qml/images/wk.svg diff --git a/qml/images/wknight.svg b/qml/images/wn.svg index 644d6e8..644d6e8 100644 --- a/qml/images/wknight.svg +++ b/qml/images/wn.svg diff --git a/qml/images/wpawn.svg b/qml/images/wp.svg index 1142516..1142516 100644 --- a/qml/images/wpawn.svg +++ b/qml/images/wp.svg diff --git a/qml/images/wqueen.svg b/qml/images/wq.svg index 97043c5..97043c5 100644 --- a/qml/images/wqueen.svg +++ b/qml/images/wq.svg diff --git a/qml/images/wrook.svg b/qml/images/wr.svg index 8d2d932..8d2d932 100644 --- a/qml/images/wrook.svg +++ b/qml/images/wr.svg diff --git a/qml/pages/Board.qml b/qml/pages/Board.qml index efa79f7..4bb5d9c 100644 --- a/qml/pages/Board.qml +++ b/qml/pages/Board.qml @@ -34,7 +34,7 @@ Page { columns: 8 rows: 8 Repeater { - id: repeater + id: board model: 64 delegate: Square { i: index diff --git a/src/harbour-sailchess.cpp b/src/harbour-sailchess.cpp index e7df625..819f873 100644 --- a/src/harbour-sailchess.cpp +++ b/src/harbour-sailchess.cpp @@ -6,15 +6,5 @@ int main(int argc, char *argv[]) { - // SailfishApp::main() will display "qml/harbour-sailchess.qml", if you need more - // control over initialization, you can use: - // - // - SailfishApp::application(int, char *[]) to get the QGuiApplication * - // - SailfishApp::createView() to get a new QQuickView * instance - // - SailfishApp::pathTo(QString) to get a QUrl to a resource file - // - SailfishApp::pathToMainQml() to get a QUrl to the main QML file - // - // To display the view, call "show()" (will show fullscreen on device). - return SailfishApp::main(argc, argv); } |