summaryrefslogtreecommitdiff
path: root/qml
diff options
context:
space:
mode:
Diffstat (limited to 'qml')
-rw-r--r--qml/actions.js4
-rw-r--r--qml/pages/Board.qml11
-rw-r--r--qml/pages/Goban.qml84
-rw-r--r--qml/pages/Point.qml64
4 files changed, 82 insertions, 81 deletions
diff --git a/qml/actions.js b/qml/actions.js
index 314015f..40b9330 100644
--- a/qml/actions.js
+++ b/qml/actions.js
@@ -17,8 +17,8 @@ function isLastCol(index, cols) {
/**
* Check if the case on the grid belongs to the first row
*/
-function isFirstRow(index, rows) {
- return index < rows;
+function isFirstRow(index, cols) {
+ return index < cols;
}
/**
diff --git a/qml/pages/Board.qml b/qml/pages/Board.qml
index 27b1974..27fc319 100644
--- a/qml/pages/Board.qml
+++ b/qml/pages/Board.qml
@@ -23,13 +23,20 @@ Page {
width: parent.width;
IconButton {
- width: parent.width / 2;
+ width: (parent.width - parent.height) / 2;
icon.source: "image://theme/icon-m-back"
onClicked: console.log("Previous!")
}
+ Image {
+ width: parent.height;
+ source: "../content/gfx/" + (goban.currentPlayer ? "white":"black") + ".png"
+ height: parent.height;
+ scale: 0.5
+ }
+
IconButton {
- width: parent.width / 2;
+ width: (parent.width - parent.height) / 2;
icon.source: "image://theme/icon-m-refresh"
onClicked: goban.start()
}
diff --git a/qml/pages/Goban.qml b/qml/pages/Goban.qml
index baffa39..60c78e9 100644
--- a/qml/pages/Goban.qml
+++ b/qml/pages/Goban.qml
@@ -37,7 +37,7 @@ Item {
currentPlayer = true;
for (var i = 0; i < goban.rows * goban.columns; i++) {
- repeater.itemAt(i).clear();
+ repeater.itemAt(i).remove(false);
}
var initial
@@ -53,14 +53,14 @@ Item {
var aw = initial.AW;
if (aw !== undefined) {
aw.forEach(function (pos) {
- goban.getItemAt(pos[0], pos[1]).setColor(currentPlayer);
+ goban.getItemAt(pos[0], pos[1]).put(currentPlayer, false);
});
}
var ab = initial.AB;
if (ab !== undefined) {
ab.forEach(function (pos) {
- goban.getItemAt(pos[0], pos[1]).setColor(!currentPlayer);
+ goban.getItemAt(pos[0], pos[1]).put(!currentPlayer, false);
});
}
@@ -98,11 +98,13 @@ Item {
*/
function clickHandler(index) {
+ if ( (!limitLeft && Actions.isFirstCol(index, goban.columns))
+ || (!limitRight && Actions.isLastCol(index, goban.columns))
+ || (!limitTop && Actions.isFirstRow(index, goban.columns))
+ || (!limitBottom && Actions.isLastRow(index, goban.columns, goban.rows)) ) {
+
+ console.log("click outside", index, goban.rows, Actions.isFirstRow(index, goban.columns));
- if ( !limitLeft && Actions.isFirstCol(index, goban.columns)
- || !limitRight && Actions.isLastCol(index, goban.columns)
- || !limitTop && Actions.isFirstRow(index, goban.rows)
- || !limitBottom && Actions.isLastRow(index, goban.columns, goban.rows) ) {
return;
}
@@ -139,14 +141,14 @@ Item {
// return;
// }
- point.put(currentPlayer);
+ point.put(currentPlayer, true);
if (neighbors.length !== 0) {
toRemove.forEach(function(neighbor) {
Actions.getChainToRemove(neighbor, repeater, goban.columns, goban.rows, isOponnent).
forEach(function(x) {
- repeater.itemAt(x).remove();
+ repeater.itemAt(x).remove(true);
})
});
@@ -155,7 +157,7 @@ Item {
*/
Actions.getChainToRemove(index, repeater, goban.columns, goban.rows, isPlayer).
forEach(function(x) {
- repeater.itemAt(x).remove();
+ repeater.itemAt(x).remove(true);
});
/*
@@ -194,20 +196,14 @@ Item {
Rectangle {
- function isOpen(index) {
- if ( (index === goban.rows - 1 && !limitBottom) || (index === 0 && !limitTop)) {
- return "transparent"
- }
- return "black"
- }
-
x: goban.x + (caseSize / 2)
y: goban.y + (caseSize / 2) + (index * caseSize)
width: goban.width - caseSize;
- color: isOpen(index)
+ color: "black"
+ visible: !(index === goban.rows - 1 && !limitBottom) || (index === 0 && !limitTop)
height: 1
}
@@ -221,21 +217,17 @@ Item {
Rectangle {
- function isOpen(index) {
- if ( (index === goban.columns - 1 && !limitRight) || (index === 0 && !limitLeft)) {
- return "transparent"
- }
- return "black"
- }
-
x: goban.x + (caseSize / 2) + (index * caseSize)
y: goban.y + (caseSize / 2)
height: goban.height - caseSize;
- color: isOpen(index)
+ color: "black"
+
width: 1
+
+ visible: !(index === goban.columns - 1 && !limitRight) || (index === 0 && !limitLeft);
}
@@ -259,43 +251,17 @@ Item {
model: goban.columns * goban.rows
id : repeater
- Item {
-
- function put(isWhite) {
- piece.type = isWhite ? "white" : "black";
- piece.state = "shown";
- }
-
- function setColor(isWhite) {
- piece.init(isWhite ? "white" : "black");
- }
-
- function remove() {
- piece.state = "remove"
- }
-
- function clear() {
- piece.type = "";
- piece.state = "";
- }
-
- function getType() {
- if (piece.state == "remove") {
- return "";
- } else {
- return piece.type;
- }
- }
-
+ Point{
width: caseSize; height: caseSize
+ id : piece
- property bool mark: false
-
- Point{
- id : piece
- width: caseSize; height: caseSize
+ MouseArea {
+ id: interactiveArea
+ anchors.fill: parent
+ onClicked: clickHandler(index);
}
+
}
}
}
diff --git a/qml/pages/Point.qml b/qml/pages/Point.qml
index e889336..03a1e39 100644
--- a/qml/pages/Point.qml
+++ b/qml/pages/Point.qml
@@ -2,21 +2,46 @@ import QtQuick 2.0
Item {
- property string type: "";
- property alias piece_scale: piece.scale;
+ /**
+ * A mark on the stone for identify it easily.
+ */
+ property bool mark: false
- function getImageForType() {
- if ("" === type) {
- return ""
+ /*
+ * Make the stone appear.
+ */
+ function put(isWhite, animation) {
+ if (animation) {
+ state = "shown";
+ } else {
+ piece.opacity = 1;
+ piece.scale = 1;
+ state = "";
}
- return "../content/gfx/" + type + ".png"
+ piece.type = isWhite ? "white" : "black";
}
- function init(initType) {
- type = initType;
- piece.opacity = 1;
- piece.scale = 1;
+ /**
+ * Make the stone disappear.
+ */
+ function remove(animation) {
+ if (animation) {
+ state = "remove"
+ } else {
+ piece.type = "";
+ state = "";
+ }
+ }
+ /*
+ * return the current stone type.
+ */
+ function getType() {
+ if (state == "remove") {
+ return "";
+ } else {
+ return piece.type;
+ }
}
states: [
@@ -25,7 +50,7 @@ Item {
PropertyChanges { target: piece; opacity:1 }
}, State {
name: "remove"
- onCompleted: type = "";
+ onCompleted: piece.type = "";
}
]
@@ -52,16 +77,19 @@ Item {
}
]
- MouseArea {
-
- id: interactiveArea
- anchors.fill: parent
- onClicked: clickHandler(index);
- }
-
Image {
id: piece
anchors.fill: parent
source: getImageForType();
+
+ property string type: "";
+
+ function getImageForType() {
+ if ("" === type) {
+ return ""
+ }
+ return "../content/gfx/" + type + ".png"
+ }
+
}
}